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

          Line data    Source code
       1             : // Copyright 2016 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/factory.h"
       6             : #include "src/isolate.h"
       7             : #include "src/objects-inl.h"
       8             : #include "test/cctest/cctest.h"
       9             : 
      10             : namespace v8 {
      11             : namespace internal {
      12             : 
      13       23724 : TEST(CodeLayoutWithoutUnwindingInfo) {
      14           6 :   CcTest::InitializeVM();
      15             :   HandleScope handle_scope(CcTest::i_isolate());
      16             : 
      17             :   // "Hello, World!" in ASCII.
      18             :   byte buffer_array[13] = {0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20,
      19           6 :                            0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21};
      20             : 
      21             :   byte* buffer = &buffer_array[0];
      22             :   int buffer_size = sizeof(buffer_array);
      23             : 
      24             :   CodeDesc code_desc;
      25           6 :   code_desc.buffer = buffer;
      26           6 :   code_desc.buffer_size = buffer_size;
      27           6 :   code_desc.constant_pool_size = 0;
      28           6 :   code_desc.instr_size = buffer_size;
      29           6 :   code_desc.reloc_size = 0;
      30           6 :   code_desc.origin = nullptr;
      31           6 :   code_desc.unwinding_info = nullptr;
      32           6 :   code_desc.unwinding_info_size = 0;
      33             : 
      34             :   Handle<Code> code = CcTest::i_isolate()->factory()->NewCode(
      35           6 :       code_desc, Code::STUB, Handle<Object>::null());
      36             : 
      37           6 :   CHECK(!code->has_unwinding_info());
      38           6 :   CHECK_EQ(code->instruction_size(), buffer_size);
      39           6 :   CHECK_EQ(0, memcmp(code->instruction_start(), buffer, buffer_size));
      40           6 :   CHECK_EQ(code->instruction_end() - reinterpret_cast<byte*>(*code),
      41             :            Code::kHeaderSize + buffer_size - kHeapObjectTag);
      42           6 : }
      43             : 
      44       23724 : TEST(CodeLayoutWithUnwindingInfo) {
      45           6 :   CcTest::InitializeVM();
      46             :   HandleScope handle_scope(CcTest::i_isolate());
      47             : 
      48             :   // "Hello, World!" in ASCII.
      49             :   byte buffer_array[13] = {0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20,
      50           6 :                            0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21};
      51             : 
      52             :   // "JavaScript" in ASCII.
      53             :   byte unwinding_info_array[10] = {0x4a, 0x61, 0x76, 0x61, 0x53,
      54           6 :                                    0x63, 0x72, 0x69, 0x70, 0x74};
      55             : 
      56             :   byte* buffer = &buffer_array[0];
      57             :   int buffer_size = sizeof(buffer_array);
      58             :   byte* unwinding_info = &unwinding_info_array[0];
      59             :   int unwinding_info_size = sizeof(unwinding_info_array);
      60             : 
      61             :   CodeDesc code_desc;
      62           6 :   code_desc.buffer = buffer;
      63           6 :   code_desc.buffer_size = buffer_size;
      64           6 :   code_desc.constant_pool_size = 0;
      65           6 :   code_desc.instr_size = buffer_size;
      66           6 :   code_desc.reloc_size = 0;
      67           6 :   code_desc.origin = nullptr;
      68           6 :   code_desc.unwinding_info = unwinding_info;
      69           6 :   code_desc.unwinding_info_size = unwinding_info_size;
      70             : 
      71             :   Handle<Code> code = CcTest::i_isolate()->factory()->NewCode(
      72           6 :       code_desc, Code::STUB, Handle<Object>::null());
      73             : 
      74           6 :   CHECK(code->has_unwinding_info());
      75           6 :   CHECK_EQ(code->instruction_size(), buffer_size);
      76           6 :   CHECK_EQ(0, memcmp(code->instruction_start(), buffer, buffer_size));
      77             :   CHECK(IsAligned(code->GetUnwindingInfoSizeOffset(), 8));
      78           6 :   CHECK_EQ(code->unwinding_info_size(), unwinding_info_size);
      79          12 :   CHECK(
      80             :       IsAligned(reinterpret_cast<uintptr_t>(code->unwinding_info_start()), 8));
      81           6 :   CHECK_EQ(
      82             :       memcmp(code->unwinding_info_start(), unwinding_info, unwinding_info_size),
      83             :       0);
      84           6 :   CHECK_EQ(code->unwinding_info_end() - reinterpret_cast<byte*>(*code),
      85             :            Code::kHeaderSize + RoundUp(buffer_size, kInt64Size) + kInt64Size +
      86             :                unwinding_info_size - kHeapObjectTag);
      87           6 : }
      88             : 
      89             : }  // namespace internal
      90       71154 : }  // namespace v8

Generated by: LCOV version 1.10