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 Tests stepping through wasm scripts.
Installing code an global variable. Instantiating.
Calling instantiate function. Waiting for two wasm scripts (ignoring first non-wasm script).
Waiting for two wasm scripts to be parsed. Source of script wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-0:
Ignoring script with url v8://test/callInstantiate 1: func $wasm_A
Got wasm script: wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-0 2: nop
Requesting source for wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-0... 3: nop
Got wasm script: wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-1 4: end
Requesting source for wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-1...
func $wasm_A
nop
nop
end
func $wasm_B (param i32) Source of script wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-1:
loop 1: func $wasm_B (param i32)
get_local 0 2: loop
if 3: get_local 0
get_local 0 4: if
i32.const 1 5: get_local 0
i32.sub 6: i32.const 1
set_local 0 7: i32.sub
call 0 8: set_local 0
br 1 9: call 0
end 10: br 1
end 11: end
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 8 on script 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 7 on script 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 6 on script 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 5 on script 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 3 on script 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 Setting breakpoint on line 4 on script wasm://wasm/wasm-0c10a5fe/wasm-0c10a5fe-1
3 Calling main(4)
4 Breaking on line 3
5 Breaking on line 4
6 Breaking on line 5
7 Breaking on line 6
8 Breaking on line 7
3 Breaking on line 8
4 Breaking on line 3
5 Breaking on line 4
6 Breaking on line 5
7 Breaking on line 6
8 Breaking on line 7
3 Breaking on line 8
4 Breaking on line 3
5 Breaking on line 4
6 Breaking on line 5
7 Breaking on line 6
8 Breaking on line 7
3 Breaking on line 8
4 Breaking on line 3
5 Breaking on line 4
6 Breaking on line 5
7 Breaking on line 6
8 Breaking on line 7
3 Breaking on line 8
Breaking on line 3
exports.main returned! exports.main returned!
Finished! Finished!
...@@ -2,14 +2,15 @@ ...@@ -2,14 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // 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-constants.js');
utils.load('test/mjsunit/wasm/wasm-module-builder.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; builder.addFunction('wasm_A', kSig_v_v).addBody([kExprNop, kExprNop]).index;
// wasm_B calls wasm_A <param0> times. // wasm_B calls wasm_A <param0> times.
...@@ -31,128 +32,66 @@ builder.addFunction('wasm_B', kSig_v_i) ...@@ -31,128 +32,66 @@ builder.addFunction('wasm_B', kSig_v_i)
]) ])
.exportAs('main'); .exportAs('main');
var module_bytes = builder.toArray(); const module_bytes = builder.toArray();
function instantiate(bytes) { function instantiate(bytes) {
var buffer = new ArrayBuffer(bytes.length); let buffer = new ArrayBuffer(bytes.length);
var view = new Uint8Array(buffer); let view = new Uint8Array(buffer);
for (var i = 0; i < bytes.length; ++i) { for (let i = 0; i < bytes.length; ++i) {
view[i] = bytes[i] | 0; view[i] = bytes[i] | 0;
} }
var module = new WebAssembly.Module(buffer); let module = new WebAssembly.Module(buffer);
// Set global variable. return new WebAssembly.Instance(module);
instance = new WebAssembly.Instance(module);
} }
var evalWithUrl = (code, url) => Protocol.Runtime.evaluate( const getResult = msg => msg.result || InspectorTest.logMessage(msg);
{'expression': code + '\n//# sourceURL=v8://test/' + url});
var wasm_B_scriptId; const evalWithUrl = (code, url) =>
var sources = {}; Protocol.Runtime
var urls = {}; .evaluate({'expression': code + '\n//# sourceURL=v8://test/' + url})
var afterTwoSourcesCallback; .then(getResult);
Protocol.Debugger.onPaused((msg) => { function setBreakpoint(line, script) {
var loc = msg.params.callFrames[0].location; InspectorTest.log(
InspectorTest.log(loc.lineNumber); '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.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) { (async function test() {
if (!message.result) { await Protocol.Debugger.enable();
InspectorTest.logMessage(message); 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');
} }
return message; for (line of [8, 7, 6, 5, 3, 4]) {
} await setBreakpoint(line, wasm_script_b);
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);
} }
function handleNewScript(msg) { InspectorTest.log('Calling main(4)');
var url = msg.params.url; await evalWithUrl('instance.exports.main(4)', 'runWasm');
if (!url.startsWith('wasm://')) { InspectorTest.log('exports.main returned!');
InspectorTest.log('Ignoring script with url ' + url); InspectorTest.log('Finished!');
return; InspectorTest.completeTest();
} })();
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);
}
waitForMore();
return promise;
}
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