Commit 4719dae1 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm][inspector][test] Add more tests for code offsets

The code offsets are sometimes wrong when compiled with streaming
compilation. Thus add more tests for synchronous, asynchronous, and
streaming compilation. The reported code offsets should all match. This
will be fixed in a follow-up CL.

In order to make asynchronous WebAssembly compilation finish, the
inspector-test executable needs to pump the message loop before waiting
for new tasks to come in, just as other executables like d8.
This is added in this CL, but because of another bug this is skipped in
the stress-incremental-marking variant. Hence the new tests are also
skipped there.

R=szuend@chromium.org
CC=ahaas@chromium.org

Bug: chromium:1150303, v8:10748
Change-Id: Ie1d63c8d6795e61627d838b7fa7b21e6728befc0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2562382Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71483}
parent f60ccbf5
Tests reported code offsets on wasm scripts
Wasm script parsed: ID 0, startColumn: 0, endColumn: 29, codeOffset: 0
Wasm script parsed: ID 1, startColumn: 0, endColumn: 29, codeOffset: 0
Wasm script parsed: ID 2, startColumn: 0, endColumn: 32, codeOffset: 31
Wasm script parsed: ID 3, startColumn: 0, endColumn: 32, codeOffset: 31
Wasm script parsed: ID 4, startColumn: 0, endColumn: 40, codeOffset: 36
Wasm script parsed: ID 5, startColumn: 0, endColumn: 40, codeOffset: 36
Wasm script parsed: ID 6, startColumn: 0, endColumn: 44, codeOffset: 36
Wasm script parsed: ID 7, startColumn: 0, endColumn: 44, codeOffset: 36
Tests reported code offsets on wasm scripts
Wasm script parsed: ID 0, startColumn: 0, endColumn: 29, codeOffset: 0
Wasm script parsed: ID 1, startColumn: 0, endColumn: 29, codeOffset: 0
Wasm script parsed: ID 2, startColumn: 0, endColumn: 32, codeOffset: 31
Wasm script parsed: ID 3, startColumn: 0, endColumn: 32, codeOffset: 0
Wasm script parsed: ID 4, startColumn: 0, endColumn: 40, codeOffset: 36
Wasm script parsed: ID 5, startColumn: 0, endColumn: 40, codeOffset: 36
Wasm script parsed: ID 6, startColumn: 0, endColumn: 44, codeOffset: 36
Wasm script parsed: ID 7, startColumn: 0, endColumn: 44, codeOffset: 40
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-test-streaming
utils.load('test/inspector/debugger/wasm-script-code-offset.js');
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
utils.load('test/inspector/wasm-inspector-test.js');
let {session, contextGroup, Protocol} =
InspectorTest.start('Tests reported code offsets on wasm scripts');
// Include a sentinel in every module to avoid re-using a cached module.
let sentinel = 0;
function addHeader(binary, num_functions) {
binary.emit_header();
// Add a custom section with the sentinel.
var custom_section = new Binary();
custom_section.emit_u8(0); // section code
custom_section.emit_u8(10); // section length
custom_section.emit_string('sentinel'); // name
custom_section.emit_bytes([sentinel]); // payload
++sentinel;
binary.emit_bytes(custom_section.trunc_buffer());
// Type section with a single function type with no params and no returns.
binary.emit_section(kTypeSectionCode, section => {
section.emit_u32v(1); // count
section.emit_u8(kWasmFunctionTypeForm);
section.emit_u32v(0); // params
section.emit_u32v(0); // results
});
// Function section with {num_functions} many functions.
binary.emit_section(kFunctionSectionCode, section => {
section.emit_u32v(num_functions);
for (let i = 0; i < num_functions; ++i) {
section.emit_u32v(0); // type index
}
});
}
function createModuleWithNoCodeSection() {
let binary = new Binary;
addHeader(binary, 0);
return binary.trunc_buffer();
}
function createModuleWithEmptyCodeSection() {
let binary = new Binary;
addHeader(binary, 0);
// Section code.
binary.emit_u8(kCodeSectionCode);
// Section length (1).
binary.emit_u32v(1);
// Payload (functions count: 0).
binary.emit_u32v(0);
return binary.trunc_buffer();
}
function createModuleWithFiveByteSectionLength() {
let binary = new Binary;
addHeader(binary, 1);
// Section code.
binary.emit_u8(kCodeSectionCode);
// Section length (4 as 5-byte LEB).
binary.emit_bytes([0x84, 0x80, 0x80, 0x80, 0x00]);
binary.emit_u32v(1); // functions count
binary.emit_u32v(2); // body size
binary.emit_u32v(0); // num locals
binary.emit_bytes([kExprEnd]); // body
return binary.trunc_buffer();
}
function createModuleWithFiveBytePayload() {
let binary = new Binary;
addHeader(binary, 1);
// Section code.
binary.emit_u8(kCodeSectionCode);
// Section length (8).
binary.emit_bytes([0x88, 0x80, 0x80, 0x80, 0x00]);
// Functions count (1 as 5-byte LEB).
binary.emit_bytes([0x81, 0x80, 0x80, 0x80, 0x00]);
binary.emit_u32v(2); // body size
binary.emit_u32v(0); // num locals
binary.emit_bytes([kExprEnd]); // body
return binary.trunc_buffer();
}
function compileSync(bytes) {
new WebAssembly.Module(new Uint8Array(bytes));
}
function compileAsync(bytes) {
WebAssembly.compile(new Uint8Array(bytes));
}
contextGroup.addScript(
`${compileSync}${compileAsync}`, 0, 0, 'v8://test/compileFunctions');
(async function test() {
Protocol.Debugger.enable();
let script_ids = new Map();
let generators = [
createModuleWithNoCodeSection, createModuleWithEmptyCodeSection,
createModuleWithFiveByteSectionLength, createModuleWithFiveBytePayload
];
for (let generator of generators) {
session.Protocol.Runtime.evaluate({
'expression': `
compileSync([${generator()}]);
compileAsync([${generator()}]);
`
});
// Wait for both wasm scripts to be there and print their information.
for (let wasm_scripts = 0; wasm_scripts < 2;) {
({params} = await Protocol.Debugger.onceScriptParsed());
if (!params.url.startsWith('wasm://')) continue;
if (!script_ids.has(params.scriptId)) {
script_ids.set(params.scriptId, script_ids.size);
}
// Print script IDs to ensure that script are not deduplicated (via
// cache).
let stable_id = script_ids.get(params.scriptId);
InspectorTest.log(`Wasm script parsed: ID ${stable_id}, startColumn: ${
params.startColumn}, endColumn: ${params.endColumn}, codeOffset: ${
params.codeOffset}`);
++wasm_scripts;
}
}
InspectorTest.completeTest();
})();
......@@ -146,6 +146,14 @@
'type-profiler/type-profile-start-stop': [SKIP],
}], # gc_stress
##############################################################################
['variant == stress_incremental_marking', {
# Because of https://crbug.com/v8/10748 we skip pumping the message loop
# in inspector tests, which makes this test fail.
'debugger/wasm-script-code-offset': [SKIP],
'debugger/wasm-script-code-offset-streaming': [SKIP],
}], # variant == stress_incremental_marking
##############################################################################
['variant == stress_js_bg_compile_wasm_code_gc', {
# Skip tests that fail with GC stress: https://crbug.com/v8/10748
......
......@@ -86,7 +86,10 @@ void TaskRunner::RunMessageLoop(bool only_protocol) {
// tests are fixed.
if (!i::FLAG_stress_incremental_marking) {
while (v8::platform::PumpMessageLoop(
v8::internal::V8::GetCurrentPlatform(), isolate())) {
v8::internal::V8::GetCurrentPlatform(), isolate(),
isolate()->HasPendingBackgroundTasks()
? platform::MessageLoopBehavior::kWaitForWork
: platform::MessageLoopBehavior::kDoNotWait)) {
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment