LCOV - code coverage report
Current view: top level - test/cctest/wasm - test-run-wasm-relocation.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 19 19 100.0 %
Date: 2017-10-20 Functions: 3 3 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 <stdlib.h>
       6             : 
       7             : #include "src/assembler-inl.h"
       8             : #include "src/objects-inl.h"
       9             : #include "src/v8.h"
      10             : #include "test/cctest/cctest.h"
      11             : #include "test/cctest/compiler/c-signature.h"
      12             : #include "test/cctest/wasm/wasm-run-utils.h"
      13             : #include "test/common/wasm/wasm-macro-gen.h"
      14             : 
      15             : namespace v8 {
      16             : namespace internal {
      17             : namespace wasm {
      18             : namespace test_run_wasm_relocation {
      19             : 
      20       23724 : TEST(RunPatchWasmContext) {
      21           6 :   WasmRunner<uint32_t, uint32_t> r(kExecuteCompiled);
      22             :   Isolate* isolate = CcTest::i_isolate();
      23             : 
      24           6 :   r.builder().AddGlobal<uint32_t>();
      25           6 :   r.builder().AddGlobal<uint32_t>();
      26             : 
      27           6 :   BUILD(r, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_GET_GLOBAL(0));
      28           6 :   CHECK_EQ(1, r.builder().CodeTableLength());
      29             : 
      30             :   // Run with the old global data.
      31           6 :   CHECK_EQ(113, r.Call(113));
      32             : 
      33             :   WasmContext* old_wasm_context =
      34             :       r.builder().instance_object()->wasm_context()->get();
      35             :   Address old_wasm_context_address =
      36             :       reinterpret_cast<Address>(old_wasm_context);
      37             : 
      38           6 :   uint32_t new_global_data[3] = {0, 0, 0};
      39             :   WasmContext new_wasm_context = {0, 0,
      40           6 :                                   reinterpret_cast<byte*>(new_global_data)};
      41             : 
      42             :   // Patch in a new WasmContext that points to the new global data.
      43             :   int filter = 1 << RelocInfo::WASM_CONTEXT_REFERENCE;
      44             :   bool patched = false;
      45             :   Handle<Code> code = r.GetWrapperCode();
      46          12 :   for (RelocIterator it(*code, filter); !it.done(); it.next()) {
      47           6 :     CHECK_EQ(old_wasm_context_address, it.rinfo()->wasm_context_reference());
      48             :     it.rinfo()->set_wasm_context_reference(
      49           6 :         isolate, reinterpret_cast<Address>(&new_wasm_context));
      50             :     patched = true;
      51             :   }
      52           6 :   CHECK(patched);
      53           6 :   Assembler::FlushICache(isolate, code->instruction_start(),
      54          12 :                          code->instruction_size());
      55             : 
      56             :   // Run with the new global data.
      57           6 :   CHECK_EQ(115, r.Call(115));
      58           6 :   CHECK_EQ(115, new_global_data[0]);
      59           6 : }
      60             : 
      61             : }  // namespace test_run_wasm_relocation
      62             : }  // namespace wasm
      63             : }  // namespace internal
      64       71154 : }  // namespace v8

Generated by: LCOV version 1.10