Commit 7074113d authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm][test] Refactor breakpoint inspector test

Before adding another test for removing breakpoint, this CL modernizes
the existing test for setting breakpoints.

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

Bug: chromium:837572
Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I642f9673f327f4ec569a4f67a61b5e264cf25b8f
Reviewed-on: https://chromium-review.googlesource.com/c/1264636Reviewed-by: 's avatarAleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56514}
parent 47d34a31
Tests stepping through wasm scripts
Installing code an global variable.
Calling instantiate function.
Waiting for two wasm scripts to be parsed.
Ignoring script with url v8://test/callInstantiate
Got wasm script: wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-0
Requesting source for wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-0...
Got wasm script: wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-1
Requesting source for wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-1...
func $wasm_A
nop
nop
end
Tests stepping through wasm scripts.
Instantiating.
Waiting for two wasm scripts (ignoring first non-wasm script).
Source of script wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-0:
1: func $wasm_A
2: nop
3: nop
4: end
func $wasm_B (param i32)
loop
get_local 0
if
get_local 0
i32.const 1
i32.sub
set_local 0
call 0
br 1
end
end
end
Source of script wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-1:
1: func $wasm_B (param i32)
2: loop
3: get_local 0
4: if
5: get_local 0
6: i32.const 1
7: i32.sub
8: set_local 0
9: call 0
10: br 1
11: end
12: end
13: end
Setting breakpoint on line 8 (on the setlocal before the call), url wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-1
Setting breakpoint on line 7 (on the setlocal before the call), url wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-1
Setting breakpoint on line 6 (on the setlocal before the call), url wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-1
Setting breakpoint on line 5 (on the setlocal before the call), url wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-1
Setting breakpoint on line 3 (on the setlocal before the call), url wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-1
Setting breakpoint on line 4 (on the setlocal before the call), url wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-1
3
4
5
6
7
8
3
4
5
6
7
8
3
4
5
6
7
8
3
4
5
6
7
8
3
Setting breakpoint on line 8 on script wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-1
Setting breakpoint on line 7 on script wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-1
Setting breakpoint on line 6 on script wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-1
Setting breakpoint on line 5 on script wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-1
Setting breakpoint on line 3 on script wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-1
Setting breakpoint on line 4 on script wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-1
Calling main(4)
Breaking on line 3
Breaking on line 4
Breaking on line 5
Breaking on line 6
Breaking on line 7
Breaking on line 8
Breaking on line 3
Breaking on line 4
Breaking on line 5
Breaking on line 6
Breaking on line 7
Breaking on line 8
Breaking on line 3
Breaking on line 4
Breaking on line 5
Breaking on line 6
Breaking on line 7
Breaking on line 8
Breaking on line 3
Breaking on line 4
Breaking on line 5
Breaking on line 6
Breaking on line 7
Breaking on line 8
Breaking on line 3
exports.main returned!
Finished!
......@@ -2,14 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let {session, contextGroup, Protocol} = InspectorTest.start('Tests stepping through wasm scripts');
const {session, contextGroup, Protocol} =
InspectorTest.start('Tests stepping through wasm scripts.');
utils.load('test/mjsunit/wasm/wasm-constants.js');
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder();
const builder = new WasmModuleBuilder();
var func_a_idx =
const func_a_idx =
builder.addFunction('wasm_A', kSig_v_v).addBody([kExprNop, kExprNop]).index;
// wasm_B calls wasm_A <param0> times.
......@@ -31,128 +32,66 @@ builder.addFunction('wasm_B', kSig_v_i)
])
.exportAs('main');
var module_bytes = builder.toArray();
const module_bytes = builder.toArray();
function instantiate(bytes) {
var buffer = new ArrayBuffer(bytes.length);
var view = new Uint8Array(buffer);
for (var i = 0; i < bytes.length; ++i) {
let buffer = new ArrayBuffer(bytes.length);
let view = new Uint8Array(buffer);
for (let i = 0; i < bytes.length; ++i) {
view[i] = bytes[i] | 0;
}
var module = new WebAssembly.Module(buffer);
// Set global variable.
instance = new WebAssembly.Instance(module);
let module = new WebAssembly.Module(buffer);
return new WebAssembly.Instance(module);
}
var evalWithUrl = (code, url) => Protocol.Runtime.evaluate(
{'expression': code + '\n//# sourceURL=v8://test/' + url});
const getResult = msg => msg.result || InspectorTest.logMessage(msg);
var wasm_B_scriptId;
var sources = {};
var urls = {};
var afterTwoSourcesCallback;
const evalWithUrl = (code, url) =>
Protocol.Runtime
.evaluate({'expression': code + '\n//# sourceURL=v8://test/' + url})
.then(getResult);
Protocol.Debugger.onPaused((msg) => {
var loc = msg.params.callFrames[0].location;
InspectorTest.log(loc.lineNumber);
function setBreakpoint(line, script) {
InspectorTest.log(
'Setting breakpoint on line ' + line + ' on script ' + script.url);
return Protocol.Debugger
.setBreakpoint(
{'location': {'scriptId': script.scriptId, 'lineNumber': line}})
.then(getResult);
}
Protocol.Debugger.onPaused(pause_msg => {
let loc = pause_msg.params.callFrames[0].location;
InspectorTest.log('Breaking on line ' + loc.lineNumber);
Protocol.Debugger.resume();
});
Protocol.Debugger.enable()
.then(() => InspectorTest.log('Installing code an global variable.'))
.then(
() => evalWithUrl('var instance;\n' + instantiate.toString(), 'setup'))
.then(() => InspectorTest.log('Calling instantiate function.'))
.then(
() =>
(evalWithUrl(
'instantiate(' + JSON.stringify(module_bytes) + ')',
'callInstantiate'),
0))
.then(waitForTwoWasmScripts)
.then(
() => InspectorTest.log(
'Setting breakpoint on line 8 (on the setlocal before the call), url ' +
urls[wasm_B_scriptId]))
.then(
() => Protocol.Debugger.setBreakpoint(
{'location': {'scriptId': wasm_B_scriptId, 'lineNumber': 8}}))
.then(
() => InspectorTest.log(
'Setting breakpoint on line 7 (on the setlocal before the call), url ' +
urls[wasm_B_scriptId]))
.then(
() => Protocol.Debugger.setBreakpoint(
{'location': {'scriptId': wasm_B_scriptId, 'lineNumber': 7}}))
.then(
() => InspectorTest.log(
'Setting breakpoint on line 6 (on the setlocal before the call), url ' +
urls[wasm_B_scriptId]))
.then(
() => Protocol.Debugger.setBreakpoint(
{'location': {'scriptId': wasm_B_scriptId, 'lineNumber': 6}}))
.then(
() => InspectorTest.log(
'Setting breakpoint on line 5 (on the setlocal before the call), url ' +
urls[wasm_B_scriptId]))
.then(
() => Protocol.Debugger.setBreakpoint(
{'location': {'scriptId': wasm_B_scriptId, 'lineNumber': 5}}))
.then(
() => InspectorTest.log(
'Setting breakpoint on line 3 (on the setlocal before the call), url ' +
urls[wasm_B_scriptId]))
.then(
() => Protocol.Debugger.setBreakpoint(
{'location': {'scriptId': wasm_B_scriptId, 'lineNumber': 3}}))
.then(
() => InspectorTest.log(
'Setting breakpoint on line 4 (on the setlocal before the call), url ' +
urls[wasm_B_scriptId]))
.then(
() => Protocol.Debugger.setBreakpoint(
{'location': {'scriptId': wasm_B_scriptId, 'lineNumber': 4}}))
.then(printFailure)
.then(() => evalWithUrl('instance.exports.main(4)', 'runWasm'))
.then(() => InspectorTest.log('exports.main returned!'))
.then(() => InspectorTest.log('Finished!'))
.then(InspectorTest.completeTest);
function printFailure(message) {
if (!message.result) {
InspectorTest.logMessage(message);
}
return message;
}
function waitForTwoWasmScripts() {
var num = 0;
InspectorTest.log('Waiting for two wasm scripts to be parsed.');
var promise = new Promise(fulfill => gotBothSources = fulfill);
function waitForMore() {
if (num == 2) return promise;
Protocol.Debugger.onceScriptParsed()
.then(handleNewScript)
.then(waitForMore);
(async function test() {
await Protocol.Debugger.enable();
InspectorTest.log('Instantiating.');
// Spawn asynchronously:
let instantiate_code = 'const instance = (' + instantiate + ')(' +
JSON.stringify(module_bytes) + ');';
evalWithUrl(instantiate_code, 'instantiate');
InspectorTest.log(
'Waiting for two wasm scripts (ignoring first non-wasm script).');
const [, {params: wasm_script_a}, {params: wasm_script_b}] =
await Protocol.Debugger.onceScriptParsed(3);
for (script of [wasm_script_a, wasm_script_b]) {
InspectorTest.log('Source of script ' + script.url + ':');
let src_msg =
await Protocol.Debugger.getScriptSource({scriptId: script.scriptId});
let lines = getResult(src_msg).scriptSource.replace(/\s+$/, '').split('\n');
InspectorTest.log(
lines.map((line, nr) => (nr + 1) + ': ' + line).join('\n') + '\n');
}
function handleNewScript(msg) {
var url = msg.params.url;
if (!url.startsWith('wasm://')) {
InspectorTest.log('Ignoring script with url ' + url);
return;
}
num += 1;
var scriptId = msg.params.scriptId;
urls[scriptId] = url;
InspectorTest.log('Got wasm script: ' + url);
if (url.substr(-2) == '-1') wasm_B_scriptId = scriptId;
InspectorTest.log('Requesting source for ' + url + '...');
Protocol.Debugger.getScriptSource({scriptId: scriptId})
.then(printFailure)
.then(msg => sources[scriptId] = msg.result.scriptSource)
.then(InspectorTest.log)
.then(() => Object.keys(sources).length == 2 ? gotBothSources() : 0);
for (line of [8, 7, 6, 5, 3, 4]) {
await setBreakpoint(line, wasm_script_b);
}
waitForMore();
return promise;
}
InspectorTest.log('Calling main(4)');
await evalWithUrl('instance.exports.main(4)', 'runWasm');
InspectorTest.log('exports.main returned!');
InspectorTest.log('Finished!');
InspectorTest.completeTest();
})();
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