LCOV - code coverage report
Current view: top level - test/cctest/torque - test-torque.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 269 269 100.0 %
Date: 2019-01-20 Functions: 31 31 100.0 %

          Line data    Source code
       1             : // Copyright 2015 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #include <cmath>
       6             : 
       7             : #include "src/api-inl.h"
       8             : #include "src/base/utils/random-number-generator.h"
       9             : #include "src/builtins/builtins-promise-gen.h"
      10             : #include "src/builtins/builtins-string-gen.h"
      11             : #include "src/char-predicates.h"
      12             : #include "src/code-factory.h"
      13             : #include "src/code-stub-assembler.h"
      14             : #include "src/compiler/node.h"
      15             : #include "src/debug/debug.h"
      16             : #include "src/elements-kind.h"
      17             : #include "src/isolate.h"
      18             : #include "src/objects-inl.h"
      19             : #include "src/objects/promise-inl.h"
      20             : #include "test/cctest/compiler/code-assembler-tester.h"
      21             : #include "test/cctest/compiler/function-tester.h"
      22             : #include "torque-generated/builtins-test-from-dsl-gen.h"
      23             : 
      24             : namespace v8 {
      25             : namespace internal {
      26             : namespace compiler {
      27             : 
      28             : namespace {
      29             : 
      30             : typedef CodeAssemblerLabel Label;
      31             : typedef CodeAssemblerVariable Variable;
      32             : 
      33         280 : class TestTorqueAssembler : public CodeStubAssembler,
      34             :                             public TestBuiltinsFromDSLAssembler {
      35             :  public:
      36             :   explicit TestTorqueAssembler(CodeAssemblerState* state)
      37         140 :       : CodeStubAssembler(state), TestBuiltinsFromDSLAssembler(state) {}
      38             : };
      39             : 
      40             : }  // namespace
      41             : 
      42       28342 : TEST(TestConstexpr1) {
      43           5 :   Isolate* isolate(CcTest::InitIsolateOnce());
      44           5 :   CodeAssemblerTester asm_tester(isolate, 0);
      45           5 :   TestTorqueAssembler m(asm_tester.state());
      46             :   {
      47           5 :     m.TestConstexpr1();
      48          10 :     m.Return(m.UndefinedConstant());
      49             :   }
      50           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
      51          10 :   ft.Call();
      52           5 : }
      53             : 
      54       28342 : TEST(TestConstexprIf) {
      55           5 :   Isolate* isolate(CcTest::InitIsolateOnce());
      56           5 :   CodeAssemblerTester asm_tester(isolate, 0);
      57           5 :   TestTorqueAssembler m(asm_tester.state());
      58             :   {
      59           5 :     m.TestConstexprIf();
      60          10 :     m.Return(m.UndefinedConstant());
      61             :   }
      62           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
      63          10 :   ft.Call();
      64           5 : }
      65             : 
      66       28342 : TEST(TestConstexprReturn) {
      67           5 :   Isolate* isolate(CcTest::InitIsolateOnce());
      68           5 :   CodeAssemblerTester asm_tester(isolate, 0);
      69           5 :   TestTorqueAssembler m(asm_tester.state());
      70             :   {
      71           5 :     m.TestConstexprReturn();
      72          10 :     m.Return(m.UndefinedConstant());
      73             :   }
      74           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
      75          10 :   ft.Call();
      76           5 : }
      77             : 
      78       28342 : TEST(TestGotoLabel) {
      79           5 :   Isolate* isolate(CcTest::InitIsolateOnce());
      80           5 :   CodeAssemblerTester asm_tester(isolate, 0);
      81           5 :   TestTorqueAssembler m(asm_tester.state());
      82          10 :   { m.Return(m.TestGotoLabel()); }
      83           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
      84          10 :   ft.CheckCall(ft.true_value());
      85           5 : }
      86             : 
      87       28342 : TEST(TestGotoLabelWithOneParameter) {
      88           5 :   Isolate* isolate(CcTest::InitIsolateOnce());
      89           5 :   CodeAssemblerTester asm_tester(isolate, 0);
      90           5 :   TestTorqueAssembler m(asm_tester.state());
      91          10 :   { m.Return(m.TestGotoLabelWithOneParameter()); }
      92           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
      93          10 :   ft.CheckCall(ft.true_value());
      94           5 : }
      95             : 
      96       28342 : TEST(TestGotoLabelWithTwoParameters) {
      97           5 :   Isolate* isolate(CcTest::InitIsolateOnce());
      98           5 :   CodeAssemblerTester asm_tester(isolate, 0);
      99           5 :   TestTorqueAssembler m(asm_tester.state());
     100          10 :   { m.Return(m.TestGotoLabelWithTwoParameters()); }
     101           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
     102          10 :   ft.CheckCall(ft.true_value());
     103           5 : }
     104             : 
     105       28342 : TEST(TestPartiallyUnusedLabel) {
     106           5 :   Isolate* isolate(CcTest::InitIsolateOnce());
     107           5 :   CodeAssemblerTester asm_tester(isolate, 0);
     108           5 :   TestTorqueAssembler m(asm_tester.state());
     109          10 :   { m.Return(m.TestPartiallyUnusedLabel()); }
     110           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
     111          10 :   ft.CheckCall(ft.true_value());
     112           5 : }
     113             : 
     114       28342 : TEST(TestBuiltinSpecialization) {
     115           5 :   Isolate* isolate(CcTest::InitIsolateOnce());
     116           5 :   CodeAssemblerTester asm_tester(isolate, 0);
     117           5 :   TestTorqueAssembler m(asm_tester.state());
     118             :   {
     119          10 :     Node* temp = m.SmiConstant(0);
     120           5 :     m.TestBuiltinSpecialization(m.UncheckedCast<Context>(temp));
     121          10 :     m.Return(m.UndefinedConstant());
     122             :   }
     123           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
     124          10 :   ft.Call();
     125           5 : }
     126             : 
     127       28342 : TEST(TestMacroSpecialization) {
     128           5 :   Isolate* isolate(CcTest::InitIsolateOnce());
     129           5 :   CodeAssemblerTester asm_tester(isolate, 0);
     130           5 :   TestTorqueAssembler m(asm_tester.state());
     131             :   {
     132           5 :     m.TestMacroSpecialization();
     133          10 :     m.Return(m.UndefinedConstant());
     134             :   }
     135           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
     136          10 :   ft.Call();
     137           5 : }
     138             : 
     139       28342 : TEST(TestFunctionPointers) {
     140           5 :   Isolate* isolate(CcTest::InitIsolateOnce());
     141             :   const int kNumParams = 0;
     142           5 :   CodeAssemblerTester asm_tester(isolate, kNumParams);
     143           5 :   TestTorqueAssembler m(asm_tester.state());
     144             :   {
     145             :     TNode<Context> context =
     146           5 :         m.UncheckedCast<Context>(m.Parameter(kNumParams + 2));
     147          10 :     m.Return(m.TestFunctionPointers(context));
     148             :   }
     149           5 :   FunctionTester ft(asm_tester.GenerateCode(), kNumParams);
     150          10 :   ft.CheckCall(ft.true_value());
     151           5 : }
     152             : 
     153       28342 : TEST(TestTernaryOperator) {
     154           5 :   Isolate* isolate(CcTest::InitIsolateOnce());
     155             :   const int kNumParams = 1;
     156           5 :   CodeAssemblerTester asm_tester(isolate, kNumParams);
     157           5 :   TestTorqueAssembler m(asm_tester.state());
     158             :   {
     159           5 :     TNode<Smi> arg = m.UncheckedCast<Smi>(m.Parameter(0));
     160          10 :     m.Return(m.TestTernaryOperator(arg));
     161             :   }
     162           5 :   FunctionTester ft(asm_tester.GenerateCode(), kNumParams);
     163             :   Handle<Object> result1 =
     164          10 :       ft.Call(Handle<Smi>(Smi::FromInt(-5), isolate)).ToHandleChecked();
     165          10 :   CHECK_EQ(-15, Handle<Smi>::cast(result1)->value());
     166             :   Handle<Object> result2 =
     167          10 :       ft.Call(Handle<Smi>(Smi::FromInt(3), isolate)).ToHandleChecked();
     168          15 :   CHECK_EQ(103, Handle<Smi>::cast(result2)->value());
     169           5 : }
     170             : 
     171       28342 : TEST(TestFunctionPointerToGeneric) {
     172           5 :   Isolate* isolate(CcTest::InitIsolateOnce());
     173           5 :   CodeAssemblerTester asm_tester(isolate, 0);
     174           5 :   TestTorqueAssembler m(asm_tester.state());
     175             :   {
     176          10 :     Node* temp = m.SmiConstant(0);
     177           5 :     m.TestFunctionPointerToGeneric(m.UncheckedCast<Context>(temp));
     178          10 :     m.Return(m.UndefinedConstant());
     179             :   }
     180           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
     181          10 :   ft.Call();
     182           5 : }
     183             : 
     184       28342 : TEST(TestUnsafeCast) {
     185           5 :   Isolate* isolate(CcTest::InitIsolateOnce());
     186           5 :   CodeAssemblerTester asm_tester(isolate, 0);
     187           5 :   TestTorqueAssembler m(asm_tester.state());
     188             :   {
     189          10 :     Node* temp = m.SmiConstant(0);
     190          10 :     Node* n = m.SmiConstant(10);
     191             :     m.Return(m.TestUnsafeCast(m.UncheckedCast<Context>(temp),
     192          10 :                               m.UncheckedCast<Number>(n)));
     193             :   }
     194           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
     195          10 :   ft.CheckCall(ft.true_value());
     196           5 : }
     197             : 
     198       28342 : TEST(TestHexLiteral) {
     199           5 :   Isolate* isolate(CcTest::InitIsolateOnce());
     200           5 :   CodeAssemblerTester asm_tester(isolate, 0);
     201           5 :   TestTorqueAssembler m(asm_tester.state());
     202             :   {
     203           5 :     m.TestHexLiteral();
     204          10 :     m.Return(m.UndefinedConstant());
     205             :   }
     206           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
     207          10 :   ft.Call();
     208           5 : }
     209             : 
     210       28342 : TEST(TestModuleConstBindings) {
     211           5 :   Isolate* isolate(CcTest::InitIsolateOnce());
     212           5 :   CodeAssemblerTester asm_tester(isolate, 0);
     213           5 :   TestTorqueAssembler m(asm_tester.state());
     214             :   {
     215           5 :     m.TestModuleConstBindings();
     216          10 :     m.Return(m.UndefinedConstant());
     217             :   }
     218           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
     219          10 :   ft.Call();
     220           5 : }
     221             : 
     222       28342 : TEST(TestLocalConstBindings) {
     223           5 :   Isolate* isolate(CcTest::InitIsolateOnce());
     224           5 :   CodeAssemblerTester asm_tester(isolate, 0);
     225           5 :   TestTorqueAssembler m(asm_tester.state());
     226             :   {
     227           5 :     m.TestLocalConstBindings();
     228          10 :     m.Return(m.UndefinedConstant());
     229             :   }
     230           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
     231          10 :   ft.Call();
     232           5 : }
     233             : 
     234       28342 : TEST(TestForLoop) {
     235           5 :   Isolate* isolate(CcTest::InitIsolateOnce());
     236           5 :   CodeAssemblerTester asm_tester(isolate, 0);
     237           5 :   TestTorqueAssembler m(asm_tester.state());
     238             :   {
     239           5 :     m.TestForLoop();
     240          10 :     m.Return(m.UndefinedConstant());
     241             :   }
     242           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
     243          10 :   ft.Call();
     244           5 : }
     245             : 
     246       28342 : TEST(TestTypeswitch) {
     247           5 :   CcTest::InitializeVM();
     248             :   Isolate* isolate(CcTest::i_isolate());
     249             :   i::HandleScope scope(isolate);
     250             :   Handle<Context> context =
     251          10 :       Utils::OpenHandle(*v8::Isolate::GetCurrent()->GetCurrentContext());
     252          10 :   CodeAssemblerTester asm_tester(isolate, 0);
     253           5 :   TestTorqueAssembler m(asm_tester.state());
     254             :   {
     255           5 :     m.TestTypeswitch(m.UncheckedCast<Context>(m.HeapConstant(context)));
     256          10 :     m.Return(m.UndefinedConstant());
     257             :   }
     258           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
     259           5 :   ft.Call();
     260           5 : }
     261             : 
     262       28342 : TEST(TestGenericOverload) {
     263           5 :   CcTest::InitializeVM();
     264             :   Isolate* isolate(CcTest::i_isolate());
     265             :   i::HandleScope scope(isolate);
     266             :   Handle<Context> context =
     267          10 :       Utils::OpenHandle(*v8::Isolate::GetCurrent()->GetCurrentContext());
     268          10 :   CodeAssemblerTester asm_tester(isolate, 0);
     269           5 :   TestTorqueAssembler m(asm_tester.state());
     270             :   {
     271           5 :     m.TestGenericOverload(m.UncheckedCast<Context>(m.HeapConstant(context)));
     272          10 :     m.Return(m.UndefinedConstant());
     273             :   }
     274           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
     275           5 :   ft.Call();
     276           5 : }
     277             : 
     278       28342 : TEST(TestLogicalOperators) {
     279           5 :   Isolate* isolate(CcTest::InitIsolateOnce());
     280           5 :   CodeAssemblerTester asm_tester(isolate, 0);
     281           5 :   TestTorqueAssembler m(asm_tester.state());
     282             :   {
     283           5 :     m.TestLogicalOperators();
     284          10 :     m.Return(m.UndefinedConstant());
     285             :   }
     286           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
     287          10 :   ft.Call();
     288           5 : }
     289             : 
     290       28342 : TEST(TestOtherwiseAndLabels) {
     291           5 :   Isolate* isolate(CcTest::InitIsolateOnce());
     292           5 :   CodeAssemblerTester asm_tester(isolate, 0);
     293           5 :   TestTorqueAssembler m(asm_tester.state());
     294             :   {
     295           5 :     m.TestOtherwiseWithCode1();
     296           5 :     m.TestOtherwiseWithCode2();
     297           5 :     m.TestOtherwiseWithCode3();
     298           5 :     m.TestForwardLabel();
     299          10 :     m.Return(m.UndefinedConstant());
     300             :   }
     301           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
     302          10 :   ft.Call();
     303           5 : }
     304             : 
     305       28342 : TEST(TestCatch1) {
     306           5 :   CcTest::InitializeVM();
     307             :   Isolate* isolate(CcTest::i_isolate());
     308             :   i::HandleScope scope(isolate);
     309             :   Handle<Context> context =
     310          10 :       Utils::OpenHandle(*v8::Isolate::GetCurrent()->GetCurrentContext());
     311          10 :   CodeAssemblerTester asm_tester(isolate, 0);
     312           5 :   TestTorqueAssembler m(asm_tester.state());
     313             :   {
     314             :     TNode<Smi> result =
     315           5 :         m.TestCatch1(m.UncheckedCast<Context>(m.HeapConstant(context)));
     316             :     USE(result);
     317             :     CSA_ASSERT(&m, m.WordEqual(result, m.SmiConstant(1)));
     318          10 :     m.Return(m.UndefinedConstant());
     319             :   }
     320           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
     321           5 :   ft.Call();
     322           5 : }
     323             : 
     324       28342 : TEST(TestCatch2) {
     325           5 :   CcTest::InitializeVM();
     326             :   Isolate* isolate(CcTest::i_isolate());
     327             :   i::HandleScope scope(isolate);
     328             :   Handle<Context> context =
     329          10 :       Utils::OpenHandle(*v8::Isolate::GetCurrent()->GetCurrentContext());
     330          10 :   CodeAssemblerTester asm_tester(isolate, 0);
     331           5 :   TestTorqueAssembler m(asm_tester.state());
     332             :   {
     333             :     TNode<Smi> result =
     334           5 :         m.TestCatch2(m.UncheckedCast<Context>(m.HeapConstant(context)));
     335             :     USE(result);
     336             :     CSA_ASSERT(&m, m.WordEqual(result, m.SmiConstant(2)));
     337          10 :     m.Return(m.UndefinedConstant());
     338             :   }
     339           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
     340           5 :   ft.Call();
     341           5 : }
     342             : 
     343       28342 : TEST(TestCatch3) {
     344           5 :   CcTest::InitializeVM();
     345             :   Isolate* isolate(CcTest::i_isolate());
     346             :   i::HandleScope scope(isolate);
     347             :   Handle<Context> context =
     348          10 :       Utils::OpenHandle(*v8::Isolate::GetCurrent()->GetCurrentContext());
     349          10 :   CodeAssemblerTester asm_tester(isolate, 0);
     350           5 :   TestTorqueAssembler m(asm_tester.state());
     351             :   {
     352             :     TNode<Smi> result =
     353           5 :         m.TestCatch3(m.UncheckedCast<Context>(m.HeapConstant(context)));
     354             :     USE(result);
     355             :     CSA_ASSERT(&m, m.WordEqual(result, m.SmiConstant(2)));
     356          10 :     m.Return(m.UndefinedConstant());
     357             :   }
     358           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
     359           5 :   ft.Call();
     360           5 : }
     361             : 
     362       28342 : TEST(TestLookup) {
     363           5 :   CcTest::InitializeVM();
     364             :   Isolate* isolate(CcTest::i_isolate());
     365             :   i::HandleScope scope(isolate);
     366             :   Handle<Context> context =
     367          10 :       Utils::OpenHandle(*v8::Isolate::GetCurrent()->GetCurrentContext());
     368          10 :   CodeAssemblerTester asm_tester(isolate, 0);
     369           5 :   TestTorqueAssembler m(asm_tester.state());
     370             :   {
     371           5 :     m.TestQualifiedAccess(m.UncheckedCast<Context>(m.HeapConstant(context)));
     372          10 :     m.Return(m.UndefinedConstant());
     373             :   }
     374           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
     375           5 :   ft.Call();
     376           5 : }
     377             : 
     378       28342 : TEST(TestFrame1) {
     379           5 :   CcTest::InitializeVM();
     380             :   Isolate* isolate(CcTest::i_isolate());
     381             :   i::HandleScope scope(isolate);
     382             :   Handle<Context> context =
     383          10 :       Utils::OpenHandle(*v8::Isolate::GetCurrent()->GetCurrentContext());
     384          10 :   CodeAssemblerTester asm_tester(isolate);
     385           5 :   TestTorqueAssembler m(asm_tester.state());
     386             :   {
     387           5 :     m.TestFrame1(m.UncheckedCast<Context>(m.HeapConstant(context)));
     388          10 :     m.Return(m.UndefinedConstant());
     389             :   }
     390           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
     391           5 :   ft.Call();
     392           5 : }
     393             : 
     394       28342 : TEST(TestNew) {
     395           5 :   CcTest::InitializeVM();
     396             :   Isolate* isolate(CcTest::i_isolate());
     397             :   i::HandleScope scope(isolate);
     398             :   Handle<Context> context =
     399          10 :       Utils::OpenHandle(*v8::Isolate::GetCurrent()->GetCurrentContext());
     400          10 :   CodeAssemblerTester asm_tester(isolate);
     401           5 :   TestTorqueAssembler m(asm_tester.state());
     402             :   {
     403           5 :     m.TestNew(m.UncheckedCast<Context>(m.HeapConstant(context)));
     404          10 :     m.Return(m.UndefinedConstant());
     405             :   }
     406           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
     407           5 :   ft.Call();
     408           5 : }
     409             : 
     410       28342 : TEST(TestStructConstructor) {
     411           5 :   CcTest::InitializeVM();
     412             :   Isolate* isolate(CcTest::i_isolate());
     413             :   i::HandleScope scope(isolate);
     414             :   Handle<Context> context =
     415          10 :       Utils::OpenHandle(*v8::Isolate::GetCurrent()->GetCurrentContext());
     416          10 :   CodeAssemblerTester asm_tester(isolate);
     417           5 :   TestTorqueAssembler m(asm_tester.state());
     418             :   {
     419           5 :     m.TestStructConstructor(m.UncheckedCast<Context>(m.HeapConstant(context)));
     420          10 :     m.Return(m.UndefinedConstant());
     421             :   }
     422           5 :   FunctionTester ft(asm_tester.GenerateCode(), 0);
     423           5 :   ft.Call();
     424           5 : }
     425             : 
     426             : }  // namespace compiler
     427             : }  // namespace internal
     428       85011 : }  // namespace v8

Generated by: LCOV version 1.10