LCOV - code coverage report
Current view: top level - test/cctest/compiler - test-linkage.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 58 58 100.0 %
Date: 2017-10-20 Functions: 8 8 100.0 %

          Line data    Source code
       1             : // Copyright 2014 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 "src/api.h"
       6             : #include "src/code-factory.h"
       7             : #include "src/code-stubs.h"
       8             : #include "src/compilation-info.h"
       9             : #include "src/compiler.h"
      10             : #include "src/compiler/common-operator.h"
      11             : #include "src/compiler/graph.h"
      12             : #include "src/compiler/linkage.h"
      13             : #include "src/compiler/machine-operator.h"
      14             : #include "src/compiler/node.h"
      15             : #include "src/compiler/operator.h"
      16             : #include "src/compiler/pipeline.h"
      17             : #include "src/compiler/schedule.h"
      18             : #include "src/objects-inl.h"
      19             : #include "src/parsing/parse-info.h"
      20             : #include "src/zone/zone.h"
      21             : #include "test/cctest/cctest.h"
      22             : 
      23             : namespace v8 {
      24             : namespace internal {
      25             : namespace compiler {
      26             : 
      27       47436 : static Operator dummy_operator(IrOpcode::kParameter, Operator::kNoWrite,
      28       23718 :                                "dummy", 0, 0, 0, 0, 0, 0);
      29             : 
      30             : // So we can get a real JS function.
      31          12 : static Handle<JSFunction> Compile(const char* source) {
      32             :   Isolate* isolate = CcTest::i_isolate();
      33             :   Handle<String> source_code = isolate->factory()
      34             :                                    ->NewStringFromUtf8(CStrVector(source))
      35          24 :                                    .ToHandleChecked();
      36             :   Handle<SharedFunctionInfo> shared =
      37             :       Compiler::GetSharedFunctionInfoForScript(
      38             :           source_code, MaybeHandle<String>(), 0, 0, v8::ScriptOriginOptions(),
      39             :           MaybeHandle<Object>(), Handle<Context>(isolate->native_context()),
      40             :           nullptr, nullptr, v8::ScriptCompiler::kNoCompileOptions,
      41          24 :           NOT_NATIVES_CODE, MaybeHandle<FixedArray>())
      42          24 :           .ToHandleChecked();
      43             :   return isolate->factory()->NewFunctionFromSharedFunctionInfo(
      44          12 :       shared, isolate->native_context());
      45             : }
      46             : 
      47             : 
      48       23724 : TEST(TestLinkageCreate) {
      49           6 :   HandleAndZoneScope handles;
      50           6 :   Handle<JSFunction> function = Compile("a + b");
      51             :   Handle<SharedFunctionInfo> shared(function->shared());
      52             :   CompilationInfo info(handles.main_zone(), function->GetIsolate(), shared,
      53          12 :                        function);
      54           6 :   CallDescriptor* descriptor = Linkage::ComputeIncoming(info.zone(), &info);
      55          12 :   CHECK(descriptor);
      56           6 : }
      57             : 
      58             : 
      59       23724 : TEST(TestLinkageJSFunctionIncoming) {
      60             :   const char* sources[] = {"(function() { })", "(function(a) { })",
      61           6 :                            "(function(a,b) { })", "(function(a,b,c) { })"};
      62             : 
      63          30 :   for (int i = 0; i < 3; i++) {
      64          18 :     HandleAndZoneScope handles;
      65             :     Handle<JSFunction> function =
      66             :         Handle<JSFunction>::cast(v8::Utils::OpenHandle(
      67          18 :             *v8::Local<v8::Function>::Cast(CompileRun(sources[i]))));
      68             :     Handle<SharedFunctionInfo> shared(function->shared());
      69             :     CompilationInfo info(handles.main_zone(), function->GetIsolate(), shared,
      70          36 :                          function);
      71          72 :     CallDescriptor* descriptor = Linkage::ComputeIncoming(info.zone(), &info);
      72          18 :     CHECK(descriptor);
      73             : 
      74          18 :     CHECK_EQ(1 + i, static_cast<int>(descriptor->JSParameterCount()));
      75          18 :     CHECK_EQ(1, static_cast<int>(descriptor->ReturnCount()));
      76          36 :     CHECK_EQ(Operator::kNoProperties, descriptor->properties());
      77          18 :     CHECK_EQ(true, descriptor->IsJSFunctionCall());
      78          18 :   }
      79           6 : }
      80             : 
      81             : 
      82       23724 : TEST(TestLinkageJSCall) {
      83           6 :   HandleAndZoneScope handles;
      84           6 :   Handle<JSFunction> function = Compile("a + c");
      85             :   Handle<SharedFunctionInfo> shared(function->shared());
      86             :   CompilationInfo info(handles.main_zone(), function->GetIsolate(), shared,
      87          12 :                        function);
      88             : 
      89         198 :   for (int i = 0; i < 32; i++) {
      90         576 :     CallDescriptor* descriptor = Linkage::GetJSCallDescriptor(
      91         192 :         info.zone(), false, i, CallDescriptor::kNoFlags);
      92         192 :     CHECK(descriptor);
      93         192 :     CHECK_EQ(i, static_cast<int>(descriptor->JSParameterCount()));
      94         192 :     CHECK_EQ(1, static_cast<int>(descriptor->ReturnCount()));
      95         384 :     CHECK_EQ(Operator::kNoProperties, descriptor->properties());
      96         192 :     CHECK_EQ(true, descriptor->IsJSFunctionCall());
      97           6 :   }
      98           6 : }
      99             : 
     100             : 
     101       23724 : TEST(TestLinkageRuntimeCall) {
     102             :   // TODO(titzer): test linkage creation for outgoing runtime calls.
     103           6 : }
     104             : 
     105             : 
     106       23724 : TEST(TestLinkageStubCall) {
     107           6 :   Isolate* isolate = CcTest::InitIsolateOnce();
     108           6 :   Zone zone(isolate->allocator(), ZONE_NAME);
     109           6 :   Callable callable = Builtins::CallableFor(isolate, Builtins::kToNumber);
     110          12 :   CompilationInfo info(ArrayVector("test"), isolate, &zone, Code::STUB);
     111          18 :   CallDescriptor* descriptor = Linkage::GetStubCallDescriptor(
     112             :       isolate, &zone, callable.descriptor(), 0, CallDescriptor::kNoFlags,
     113          12 :       Operator::kNoProperties);
     114           6 :   CHECK(descriptor);
     115           6 :   CHECK_EQ(0, static_cast<int>(descriptor->StackParameterCount()));
     116           6 :   CHECK_EQ(1, static_cast<int>(descriptor->ReturnCount()));
     117          12 :   CHECK_EQ(Operator::kNoProperties, descriptor->properties());
     118          12 :   CHECK_EQ(false, descriptor->IsJSFunctionCall());
     119             :   // TODO(titzer): test linkage creation for outgoing stub calls.
     120           6 : }
     121             : 
     122             : }  // namespace compiler
     123             : }  // namespace internal
     124       71154 : }  // namespace v8

Generated by: LCOV version 1.10