Commit f21291bc authored by Kim-Anh Tran's avatar Kim-Anh Tran Committed by Commit Bot

[wasm][debug] Clean up inspector tests

Extract commonly used instantiate() and evalWithUrl() functions.

Bug: chromium:1093165
Change-Id: I14f8b49d556bc70d2092a80b41c5bbf678efd1a9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2245599
Commit-Queue: Kim-Anh Tran <kimanh@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68356}
parent 85776893
......@@ -2,30 +2,18 @@
// 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');
const {session, contextGroup, Protocol} = InspectorTest.start(
'Test that breakpoints do not survive a restart of the debugger.');
session.setupScriptMap();
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
const func =
builder.addFunction('func', kSig_v_v).addBody([kExprNop]).exportFunc();
const module_bytes = JSON.stringify(builder.toArray());
function instantiate(bytes) {
let buffer = new ArrayBuffer(bytes.length);
let view = new Uint8Array(buffer);
for (let i = 0; i < bytes.length; ++i) {
view[i] = bytes[i] | 0;
}
let module = new WebAssembly.Module(buffer);
return new WebAssembly.Instance(module);
}
contextGroup.addScript(instantiate.toString());
const module_bytes = builder.toArray();
Protocol.Debugger.onPaused(async msg => {
await session.logSourceLocation(msg.params.callFrames[0].location);
......@@ -36,8 +24,7 @@ Protocol.Debugger.onPaused(async msg => {
await Protocol.Debugger.enable();
InspectorTest.log('Instantiating.');
// Spawn asynchronously:
Protocol.Runtime.evaluate(
{'expression': `const instance = instantiate(${module_bytes});`});
WasmInspectorTest.instantiate(module_bytes);
InspectorTest.log(
'Waiting for wasm script (ignoring first non-wasm script).');
const [, {params: wasm_script}] = await Protocol.Debugger.onceScriptParsed(2);
......
......@@ -4,11 +4,11 @@
// Flags: --allow-natives-syntax
utils.load('test/inspector/wasm-inspector-test.js');
let {session, contextGroup, Protocol} =
InspectorTest.start('Tests that cloning a module notifies the debugger');
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
let builder = new WasmModuleBuilder();
builder.addFunction('f', kSig_v_v).addBody([]).exportAs('f');
let moduleBytes = JSON.stringify(builder.toArray());
......
Tests debug command for wasm
Installing code and global variable.
Calling instantiate function.
Waiting for wasm scripts to be parsed.
Ignoring script with url v8://test/callInstantiate
Ignoring script with url v8://test/instantiate
Got wasm script: wasm://wasm/7d022e0e
paused No 1
Script wasm://wasm/7d022e0e byte offset 35: Wasm opcode 0x20
......
......@@ -2,11 +2,11 @@
// 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 debug command for wasm');
session.setupScriptMap();
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
let builder = new WasmModuleBuilder();
// wasm_A
......@@ -22,21 +22,6 @@ builder.addFunction('wasm_A', kSig_i_i)
let module_bytes = builder.toArray();
function instantiate(bytes) {
let buffer = new ArrayBuffer(bytes.length);
let view = new Uint8Array(buffer);
for (let i = 0; i < bytes.length; ++i) {
view[i] = bytes[i] | 0;
}
let module = new WebAssembly.Module(buffer);
// Set global variable.
instance = new WebAssembly.Instance(module);
}
let evalWithUrl = (code, url) => Protocol.Runtime.evaluate(
{'expression': code + '\n//# sourceURL=v8://test/' + url});
let breakCount;
Protocol.Debugger.onPaused(async message => {
......@@ -44,7 +29,7 @@ Protocol.Debugger.onPaused(async message => {
InspectorTest.log("paused No " + breakCount);
var frames = message.params.callFrames;
await session.logSourceLocation(frames[0].location);
let action= 'resume';
let action = 'resume';
InspectorTest.log('Debugger.' + action)
await Protocol.Debugger[action]();
})
......@@ -62,12 +47,8 @@ function test() {
breakCount = 0;
breakpointId = 0;
await Protocol.Debugger.enable();
InspectorTest.log('Installing code and global variable.');
await evalWithUrl('var instance;\n' + instantiate.toString(), 'setup');
InspectorTest.log('Calling instantiate function.');
evalWithUrl(
'instantiate(' + JSON.stringify(module_bytes) + ')', 'callInstantiate');
const scriptId = await waitForWasmScript();
WasmInspectorTest.instantiate(module_bytes);
await waitForWasmScript();
await Protocol.Runtime.evaluate({ expression: 'test()', includeCommandLineAPI: true});
InspectorTest.log('exports.main returned!');
InspectorTest.log('Finished!');
......
......@@ -4,23 +4,11 @@
// Flags: --expose-wasm --wasm-expose-debug-eval
utils.load('test/inspector/wasm-inspector-test.js');
const {session, contextGroup, Protocol} =
InspectorTest.start('Tests wasm debug-evaluate');
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
function instantiate(bytes) {
let buffer = new ArrayBuffer(bytes.length);
let view = new Uint8Array(buffer);
for (let i = 0; i < bytes.length; ++i) {
view[i] = bytes[i] | 0;
}
let module = new WebAssembly.Module(buffer);
return new WebAssembly.Instance(module);
}
contextGroup.addScript(instantiate.toString());
function printFailure(message) {
if (!message.result) {
InspectorTest.logMessage(message);
......@@ -54,9 +42,7 @@ async function runTest(testName, breakLine, debuggeeBytes, snippetBytes) {
handleDebuggerPaused.bind(null, snippetBytes));
InspectorTest.log('Test: ' + testName);
const scriptListener = getWasmScript();
const module = JSON.stringify(debuggeeBytes);
await Protocol.Runtime.evaluate(
{'expression': `const instance = instantiate(${module})`});
await WasmInspectorTest.instantiate(debuggeeBytes);
const script = await scriptListener;
const msg = await Protocol.Debugger.setBreakpoint({
'location': {
......
......@@ -4,13 +4,13 @@
// Flags: --experimental-wasm-reftypes
utils.load('test/inspector/wasm-inspector-test.js');
let {session, contextGroup, Protocol} =
InspectorTest.start('Test wasm scope information with externref globals');
(async function() {
try {
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
let builder = new WasmModuleBuilder();
builder.addImportedGlobal('m', 'global', kWasmExternRef, false);
let func = builder.addFunction('func', kSig_v_v)
......
Tests breakable locations in wasm
Running testFunction...
Script nr 0 parsed. URL: v8://test/setup
Script nr 1 parsed. URL: v8://test/runTestFunction
Script nr 2 parsed. URL: wasm://wasm/354ada0e
Script nr 0 parsed. URL: v8://test/instantiate
Script nr 1 parsed. URL: wasm://wasm/354ada0e
This is a wasm script (nr 0).
Querying breakable locations for all wasm scripts now...
Requesting all breakable locations in wasm script 0
......@@ -53,7 +52,7 @@ Setting at wasm://wasm/354ada0e:0:58
Success!
Running wasm code...
Missing breakpoints: 10
Script nr 3 parsed. URL: v8://test/runWasm
Script nr 2 parsed. URL: v8://test/runWasm
Stopped at wasm://wasm/354ada0e:0:48
Missing breakpoints: 9
Stopped at wasm://wasm/354ada0e:0:50
......
......@@ -4,9 +4,9 @@
// Flags: --expose-wasm
let {session, contextGroup, Protocol} = InspectorTest.start('Tests breakable locations in wasm');
utils.load('test/inspector/wasm-inspector-test.js');
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
let {session, contextGroup, Protocol} = InspectorTest.start('Tests breakable locations in wasm');
var builder = new WasmModuleBuilder();
......@@ -32,36 +32,17 @@ builder.addFunction('main', kSig_v_i)
var module_bytes = builder.toArray();
function testFunction(bytes) {
var buffer = new ArrayBuffer(bytes.length);
var view = new Uint8Array(buffer);
for (var 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);
}
var evalWithUrl = (code, url) => Protocol.Runtime.evaluate(
{'expression': code + '\n//# sourceURL=v8://test/' + url});
var setupCode = testFunction.toString() + ';\nvar module_bytes = ' +
JSON.stringify(module_bytes) + ';\nvar instance;';
Protocol.Debugger.enable();
Protocol.Debugger.onScriptParsed(handleScriptParsed);
async function runTest() {
InspectorTest.log('Running testFunction...');
await evalWithUrl(setupCode, 'setup');
await evalWithUrl('testFunction(module_bytes)', 'runTestFunction');
await WasmInspectorTest.instantiate(module_bytes);
await getBreakableLocationsForAllWasmScripts();
await setAllBreakableLocations();
InspectorTest.log('Running wasm code...');
// Begin executing code:
var promise = evalWithUrl('instance.exports.main(1)', 'runWasm');
var promise = WasmInspectorTest.evalWithUrl('instance.exports.main(1)', 'runWasm');
await waitForAllPauses();
// Code should now complete
await promise;
......
......@@ -2,11 +2,11 @@
// 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('Test wasm global names');
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
let builder = new WasmModuleBuilder();
builder.addImportedGlobal('module_name', 'imported_global', kWasmI32, false);
let func = builder.addFunction('func', kSig_v_i)
......
......@@ -2,9 +2,9 @@
// 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 imports in wasm');
utils.load('test/inspector/wasm-inspector-test.js');
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
let {session, contextGroup, Protocol} = InspectorTest.start('Tests imports in wasm');
// Build two modules A and B. A defines function func, which contains a
// breakpoint. This function is then imported by B and called via main. The
......@@ -36,21 +36,18 @@ function instantiate(bytes, imp) {
instances.push(new WebAssembly.Instance(module, imp));
}
var evalWithUrl = (code, url) => Protocol.Runtime.evaluate(
{'expression': code + '\n//# sourceURL=v8://test/' + url});
session.setupScriptMap();
// Main promise chain:
Protocol.Debugger.enable()
.then(() => InspectorTest.log('Installing code and global variable.'))
.then(
() => evalWithUrl(
() => WasmInspectorTest.evalWithUrl(
'var instances = [];\n' + instantiate.toString(), 'setup'))
.then(() => InspectorTest.log('Calling instantiate function for module A.'))
.then(
() =>
(evalWithUrl(
(WasmInspectorTest.evalWithUrl(
'instantiate(' + JSON.stringify(module_a_bytes) + ')',
'instantiateA'),
0))
......@@ -66,13 +63,13 @@ Protocol.Debugger.enable()
.then(() => InspectorTest.log('Calling instantiate function for module B.'))
.then(
() =>
(evalWithUrl(
(WasmInspectorTest.evalWithUrl(
'instantiate(' + JSON.stringify(module_b_bytes) +
', {imp: {f: instances[0].exports.func}})',
'instantiateB'),
0))
.then(() => InspectorTest.log('Calling main function on module B.'))
.then(() => evalWithUrl('instances[1].exports.main()', 'runWasm'))
.then(() => WasmInspectorTest.evalWithUrl('instances[1].exports.main()', 'runWasm'))
.then(() => InspectorTest.log('exports.main returned.'))
.then(() => InspectorTest.log('Finished.'))
.then(InspectorTest.completeTest);
......@@ -89,7 +86,7 @@ Protocol.Debugger.oncePaused()
.then(
() => InspectorTest.log(
'Getting current stack trace via "new Error().stack".'))
.then(() => evalWithUrl('new Error().stack', 'getStack'))
.then(() => WasmInspectorTest.evalWithUrl('new Error().stack', 'getStack'))
.then(msg => InspectorTest.log(msg.result.result.value))
.then(Protocol.Debugger.resume);
......
Test inspecting register values in Liftoff.
Installing instantiate function.
Testing i32.
Waiting for wasm script.
Setting 20 breakpoints.
......
......@@ -5,7 +5,6 @@
const {session, contextGroup, Protocol} =
InspectorTest.start('Test inspecting register values in Liftoff.');
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
utils.load('test/inspector/wasm-inspector-test.js');
const num_locals = 10;
......@@ -16,20 +15,6 @@ const configs = {
f64: {type: kWasmF64, add: kExprF64Add, from_i32: kExprF64SConvertI32}
};
function instantiate(bytes) {
let buffer = new ArrayBuffer(bytes.length);
let view = new Uint8Array(buffer);
for (let i = 0; i < bytes.length; ++i) {
view[i] = bytes[i] | 0;
}
let module = new WebAssembly.Module(buffer);
return new WebAssembly.Instance(module);
}
const evalWithUrl = (code, url) => Protocol.Runtime.evaluate(
{'expression': code + '\n//# sourceURL=v8://test/' + url});
Protocol.Debugger.onPaused(async msg => {
let loc = msg.params.callFrames[0].location;
let line = [`Paused at offset ${loc.columnNumber}`];
......@@ -85,9 +70,7 @@ async function testConfig(config) {
const [module_bytes, breakpoints] = buildModuleBytes(config);
const instance_name = `instance_${config}`;
// Spawn asynchronously:
let instantiate_code = evalWithUrl(
`const ${instance_name} = instantiate(${JSON.stringify(module_bytes)});`,
'instantiate');
WasmInspectorTest.instantiate(module_bytes, instance_name);
InspectorTest.log('Waiting for wasm script.');
const [, {params: wasm_script}] = await Protocol.Debugger.onceScriptParsed(2);
InspectorTest.log(`Setting ${breakpoints.length} breakpoints.`);
......@@ -101,14 +84,12 @@ async function testConfig(config) {
});
}
InspectorTest.log('Calling main.');
await evalWithUrl(`${instance_name}.exports.main()`, `run_${config}`);
await WasmInspectorTest.evalWithUrl(`${instance_name}.exports.main()`, `run_${config}`);
InspectorTest.log('main returned.');
}
(async function test() {
await Protocol.Debugger.enable();
InspectorTest.log('Installing instantiate function.');
await evalWithUrl(instantiate, 'install_instantiate');
for (let config in configs) {
await testConfig(config);
}
......
......@@ -2,11 +2,11 @@
// 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('Test wasm memory names');
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
let func;
// No name memory.
......
Tests remove breakpoint from wasm scripts.
Installing code and global variable.
Calling instantiate function.
Waiting for wasm scripts to be parsed.
Ignoring script with url v8://test/callInstantiate
Ignoring script with url v8://test/instantiate
Got wasm script: wasm://wasm/7d022e0e
Setting breakpoint on line 3 of wasm function
{
......@@ -10,10 +9,9 @@ Setting breakpoint on line 3 of wasm function
lineNumber : 0
scriptId : <scriptId>
}
BreakpointId: 4:0:39:6
paused No 1
Script wasm://wasm/7d022e0e byte offset 39: Wasm opcode 0x6b
Remove breakpoint with breakpointId: 4:0:39:6
Remove breakpoint
Debugger.resume
exports.main returned!
Finished!
......@@ -2,11 +2,11 @@
// 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 remove breakpoint from wasm scripts.');
session.setupScriptMap();
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
let builder = new WasmModuleBuilder();
// wasm_A
......@@ -22,21 +22,6 @@ let func = builder.addFunction('wasm_A', kSig_i_i)
let module_bytes = builder.toArray();
function instantiate(bytes) {
let buffer = new ArrayBuffer(bytes.length);
let view = new Uint8Array(buffer);
for (let i = 0; i < bytes.length; ++i) {
view[i] = bytes[i] | 0;
}
let module = new WebAssembly.Module(buffer);
// Set global variable.
instance = new WebAssembly.Instance(module);
}
let evalWithUrl = (code, url) => Protocol.Runtime.evaluate(
{'expression': code + '\n//# sourceURL=v8://test/' + url});
let breakCount = 0;
let breakpointId = 0;
......@@ -46,7 +31,7 @@ Protocol.Debugger.onPaused(async message => {
var frames = message.params.callFrames;
await session.logSourceLocation(frames[0].location);
if (breakCount == 1) {
InspectorTest.log('Remove breakpoint with breakpointId: ' + breakpointId);
InspectorTest.log('Remove breakpoint');
await Protocol.Debugger.removeBreakpoint({breakpointId});
}
let action= 'resume';
......@@ -63,11 +48,8 @@ function test() {
(async function Test() {
await Protocol.Debugger.enable();
InspectorTest.log('Installing code and global variable.');
await evalWithUrl('var instance;\n' + instantiate.toString(), 'setup');
InspectorTest.log('Calling instantiate function.');
evalWithUrl(
'instantiate(' + JSON.stringify(module_bytes) + ')', 'callInstantiate');
WasmInspectorTest.instantiate(module_bytes);
const scriptId = await waitForWasmScript();
InspectorTest.log(
'Setting breakpoint on line 3 of wasm function');
......@@ -75,7 +57,6 @@ function test() {
{'location': {'scriptId': scriptId, 'lineNumber': 0, 'columnNumber': func.body_offset + 4}});
printFailure(msg);
InspectorTest.logMessage(msg.result.actualLocation);
InspectorTest.logMessage('BreakpointId: '+ msg.result.breakpointId);
breakpointId = msg.result.breakpointId;
await Protocol.Runtime.evaluate({ expression: 'test()' });
await Protocol.Runtime.evaluate({ expression: 'test()' });
......
......@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
InspectorTest.log('Checks resetting context group with wasm.');
utils.load('test/inspector/wasm-inspector-test.js');
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
InspectorTest.log('Checks resetting context group with wasm.');
var builder = new WasmModuleBuilder();
......@@ -22,18 +22,6 @@ builder.addFunction('wasm_func', kSig_i_i)
var 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) {
view[i] = bytes[i] | 0;
}
var module = new WebAssembly.Module(buffer);
// Set global variable.
instance = new WebAssembly.Instance(module);
}
var contextGroup1 = new InspectorTest.ContextGroup();
var session1 = contextGroup1.connect();
session1.setupScriptMap();
......@@ -47,10 +35,10 @@ session2.setupScriptMap();
await session2.Protocol.Debugger.enable();
session1.Protocol.Runtime.evaluate({
expression: `var instance;(${instantiate.toString()})(${JSON.stringify(module_bytes)})`});
expression: `var instance = (${WasmInspectorTest.instantiateFromBuffer})(${JSON.stringify(module_bytes)})`});
session2.Protocol.Runtime.evaluate({
expression: `var instance;(${instantiate.toString()})(${JSON.stringify(module_bytes)})`});
expression: `var instance = (${WasmInspectorTest.instantiateFromBuffer})(${JSON.stringify(module_bytes)})`});
contextGroup2.reset();
......
......@@ -583,10 +583,10 @@ at (anonymous) (0:17):
-- skipped globals
Paused:
instance.exports.main(4)#
instance.exports.main(4)
Scope:
at (anonymous) (0:24):
at (anonymous) (1:31):
- scope (global):
-- skipped globals
......
Test retrieving scope information from compiled Liftoff frames
Installing instantiate code.
Waiting for wasm script to be parsed.
Calling instantiate function.
Waiting for wasm script to be parsed.
Got wasm script!
Setting breakpoint on line 2 (first instruction) of third function
{
......@@ -345,10 +344,10 @@ at (anonymous) (0:17):
-- skipped globals
Paused:
instance.exports.main(42)#
instance.exports.main(42)
Scope:
at (anonymous) (0:25):
at (anonymous) (1:31):
- scope (global):
-- skipped globals
......
......@@ -12,8 +12,6 @@ session.setupScriptMap();
Protocol.Debugger.enable();
Protocol.Debugger.onPaused(printPauseLocationsAndContinue);
let evaluate = code => Protocol.Runtime.evaluate({expression: code});
let breakpointLocation = -1;
(async function test() {
......@@ -30,7 +28,7 @@ let breakpointLocation = -1;
InspectorTest.logMessage(breakpoint.result.actualLocation);
// Now run the wasm code.
await evaluate('instance.exports.main(42)');
await WasmInspectorTest.evalWithUrl('instance.exports.main(42)', 'runWasm');
InspectorTest.log('exports.main returned. Test finished.');
InspectorTest.completeTest();
})();
......@@ -63,8 +61,6 @@ async function printPauseLocationsAndContinue(msg) {
}
async function instantiateWasm() {
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder();
// Add a global, memory and exports to populate the module scope.
builder.addGlobal(kWasmI32, true).exportAs('exported_global');
......@@ -115,30 +111,20 @@ async function instantiateWasm() {
var module_bytes = builder.toArray();
breakpointLocation = func.body_offset;
function instantiate(bytes) {
var buffer = new ArrayBuffer(bytes.length);
var view = new Uint8Array(buffer);
for (var i = 0; i < bytes.length; ++i) {
view[i] = bytes[i] | 0;
}
function addWasmJSToTable() {
// Create WasmJS functions to test the function tables output.
const js_func = function js_func() { return 7; };
const wasmjs_func = new WebAssembly.Function({parameters:[], results:['i32']}, js_func);
const wasmjs_anonymous_func = new WebAssembly.Function({parameters:[], results:['i32']}, _ => 7);
var module = new WebAssembly.Module(buffer);
const instance = new WebAssembly.Instance(module);
instance.exports.exported_table.set(0, wasmjs_func);
instance.exports.exported_table.set(1, wasmjs_anonymous_func);
return instance;
}
InspectorTest.log('Installing instantiate code.');
await evaluate(instantiate.toString());
InspectorTest.log('Calling instantiate function.');
evaluate('var instance = instantiate(' + JSON.stringify(module_bytes) + ');');
await WasmInspectorTest.instantiate(module_bytes);
await WasmInspectorTest.evalWithUrl(`(${addWasmJSToTable})()`, 'populateTable');
}
function printIfFailure(message) {
......
......@@ -12,8 +12,6 @@ session.setupScriptMap();
Protocol.Debugger.enable();
Protocol.Debugger.onPaused(printPauseLocationsAndContinue);
let evaluate = code => Protocol.Runtime.evaluate({expression: code});
let breakpointLocation = undefined; // Will be set by {instantiateWasm}.
(async function test() {
......@@ -35,7 +33,7 @@ let breakpointLocation = undefined; // Will be set by {instantiateWasm}.
InspectorTest.logMessage(breakpoint.result.actualLocation);
// Now run the wasm code.
await evaluate('instance.exports.main(4)');
await WasmInspectorTest.evalWithUrl('instance.exports.main(4)', 'runWasm');
InspectorTest.log('exports.main returned. Test finished.');
InspectorTest.completeTest();
})();
......@@ -68,8 +66,6 @@ async function printPauseLocationsAndContinue(msg) {
}
async function instantiateWasm() {
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder();
// Add a global, memory and exports to populate the module scope.
builder.addGlobal(kWasmI32, true).exportAs('exported_global');
......@@ -115,28 +111,19 @@ async function instantiateWasm() {
let moduleBytes = builder.toArray();
breakpointLocation = func.body_offset;
function instantiate(bytes) {
var buffer = new ArrayBuffer(bytes.length);
var view = new Uint8Array(buffer);
for (var i = 0; i < bytes.length; ++i) {
view[i] = bytes[i] | 0;
}
function addWasmJSToTable() {
// Create WasmJS functions to test the function tables output.
const js_func = function js_func() { return 7; };
const wasmjs_func = new WebAssembly.Function({parameters:[], results:['i32']}, js_func);
const wasmjs_anonymous_func = new WebAssembly.Function({parameters:[], results:['i32']}, _ => 7);
var module = new WebAssembly.Module(buffer);
const instance = new WebAssembly.Instance(module);
instance.exports.exported_table.set(0, wasmjs_func);
instance.exports.exported_table.set(1, wasmjs_anonymous_func);
return instance;
}
InspectorTest.log('Calling instantiate function.');
evaluate(`var instance = (${instantiate})(${JSON.stringify(moduleBytes)})`);
await WasmInspectorTest.instantiate(moduleBytes);
await WasmInspectorTest.evalWithUrl(`(${addWasmJSToTable})()`, 'populateTable');
}
function printIfFailure(message) {
......
......@@ -4,6 +4,8 @@
// Flags: --expose-wasm
utils.load('test/inspector/wasm-inspector-test.js');
InspectorTest.log("Tests how wasm scripts are reported with name");
let contextGroup = new InspectorTest.ContextGroup();
......@@ -12,8 +14,6 @@ let sessions = [
trackScripts(),
];
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder();
builder.addFunction('nopFunction', kSig_v_v).addBody([kExprNop]);
var module_bytes = builder.toArray();
......
......@@ -4,6 +4,8 @@
// Flags: --expose-wasm
utils.load('test/inspector/wasm-inspector-test.js');
InspectorTest.log("Tests how wasm scripts are reported");
let contextGroup = new InspectorTest.ContextGroup();
......@@ -15,8 +17,6 @@ let sessions = [
trackScripts(),
];
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
// Create module with given custom sections.
function createModule(...customSections) {
var builder = new WasmModuleBuilder();
......
......@@ -2,13 +2,12 @@
// 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');
const {session, contextGroup, Protocol} =
InspectorTest.start('Tests stepping through wasm scripts.');
session.setupScriptMap();
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
utils.load('test/inspector/wasm-inspector-test.js');
const builder = new WasmModuleBuilder();
const func_a =
......@@ -35,24 +34,8 @@ const func_b = builder.addFunction('wasm_B', kSig_v_i)
const module_bytes = builder.toArray();
function instantiate(bytes) {
let buffer = new ArrayBuffer(bytes.length);
let view = new Uint8Array(buffer);
for (let i = 0; i < bytes.length; ++i) {
view[i] = bytes[i] | 0;
}
let module = new WebAssembly.Module(buffer);
return new WebAssembly.Instance(module);
}
const getResult = msg => msg.result || InspectorTest.logMessage(msg);
const evalWithUrl = (code, url) =>
Protocol.Runtime
.evaluate({'expression': code + '\n//# sourceURL=v8://test/' + url})
.then(getResult);
function setBreakpoint(offset, scriptId, scriptUrl) {
InspectorTest.log(
'Setting breakpoint at offset ' + offset + ' on script ' + scriptUrl);
......@@ -105,9 +88,7 @@ Protocol.Debugger.onPaused(async msg => {
await Protocol.Debugger.enable();
InspectorTest.log('Instantiating.');
// Spawn asynchronously:
let instantiate_code = 'const instance = (' + instantiate + ')(' +
JSON.stringify(module_bytes) + ');';
evalWithUrl(instantiate_code, 'instantiate');
WasmInspectorTest.instantiate(module_bytes);
InspectorTest.log(
'Waiting for wasm script (ignoring first non-wasm script).');
// Ignore javascript and full module wasm script, get scripts for functions.
......@@ -116,7 +97,7 @@ Protocol.Debugger.onPaused(async msg => {
// breakpoint, new ones will be added.
await setBreakpoint(func_a.body_offset, wasm_script.scriptId, wasm_script.url);
InspectorTest.log('Calling main(4)');
await evalWithUrl('instance.exports.main(4)', 'runWasm');
await WasmInspectorTest.evalWithUrl('instance.exports.main(4)', 'runWasm');
InspectorTest.log('exports.main returned!');
InspectorTest.log('Finished!');
InspectorTest.completeTest();
......
......@@ -2,11 +2,11 @@
// 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');
const {session, contextGroup, Protocol} =
InspectorTest.start('Tests stepping through wasm scripts.');
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
const func_a_idx =
......@@ -33,24 +33,8 @@ const func_b = builder.addFunction('wasm_B', kSig_v_i)
const module_bytes = builder.toArray();
function instantiate(bytes) {
let buffer = new ArrayBuffer(bytes.length);
let view = new Uint8Array(buffer);
for (let i = 0; i < bytes.length; ++i) {
view[i] = bytes[i] | 0;
}
let module = new WebAssembly.Module(buffer);
return new WebAssembly.Instance(module);
}
const getResult = msg => msg.result || InspectorTest.logMessage(msg);
const evalWithUrl = (code, url) =>
Protocol.Runtime
.evaluate({'expression': code + '\n//# sourceURL=v8://test/' + url})
.then(getResult);
function setBreakpoint(offset, script) {
InspectorTest.log(
'Setting breakpoint at offset ' + offset + ' on script ' + script.url);
......@@ -73,9 +57,7 @@ Protocol.Debugger.onPaused(pause_msg => {
await Protocol.Debugger.enable();
InspectorTest.log('Instantiating.');
// Spawn asynchronously:
let instantiate_code = 'const instance = (' + instantiate + ')(' +
JSON.stringify(module_bytes) + ');';
evalWithUrl(instantiate_code, 'instantiate');
WasmInspectorTest.instantiate(module_bytes);
InspectorTest.log(
'Waiting for wasm script (ignoring first non-wasm script).');
// Ignore javascript and full module wasm script, get scripts for functions.
......@@ -84,7 +66,7 @@ Protocol.Debugger.onPaused(pause_msg => {
await setBreakpoint(func_b.body_offset + offset, wasm_script);
}
InspectorTest.log('Calling main(4)');
await evalWithUrl('instance.exports.main(4)', 'runWasm');
await WasmInspectorTest.evalWithUrl('instance.exports.main(4)', 'runWasm');
InspectorTest.log('exports.main returned!');
InspectorTest.log('Finished!');
InspectorTest.completeTest();
......
......@@ -4,9 +4,9 @@
// Flags: --expose-wasm
let {session, contextGroup, Protocol} = InspectorTest.start('Tests how wasm scrips report the source');
utils.load('test/inspector/wasm-inspector-test.js');
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
let {session, contextGroup, Protocol} = InspectorTest.start('Tests how wasm scrips report the source');
var builder = new WasmModuleBuilder();
......
......@@ -4,9 +4,9 @@
// Flags: --expose-wasm
let {session, contextGroup, Protocol} = InspectorTest.start('Tests call stack in wasm scripts');
utils.load('test/inspector/wasm-inspector-test.js');
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
let {session, contextGroup, Protocol} = InspectorTest.start('Tests call stack in wasm scripts');
var builder = new WasmModuleBuilder();
......
......@@ -2,12 +2,12 @@
// 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');
const {session, contextGroup, Protocol} =
InspectorTest.start('Test scope inspection and stepping after a trap.');
session.setupScriptMap();
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
// Create a function which computes the div of the first two arguments.
......@@ -23,18 +23,7 @@ builder.addFunction('div', kSig_i_iii)
])
.exportFunc();
const module_bytes = JSON.stringify(builder.toArray());
function instantiate(bytes) {
let buffer = new ArrayBuffer(bytes.length);
let view = new Uint8Array(buffer);
for (let i = 0; i < bytes.length; ++i) {
view[i] = bytes[i] | 0;
}
let module = new WebAssembly.Module(buffer);
return new WebAssembly.Instance(module);
}
const module_bytes = builder.toArray();
function getShortLocationString(location) {
return `${location.lineNumber}:${location.columnNumber}`;
......@@ -69,15 +58,13 @@ function call_div() {
}
}
contextGroup.addScript(instantiate.toString());
contextGroup.addScript(call_div.toString());
(async function test() {
await Protocol.Debugger.enable();
await Protocol.Debugger.setPauseOnExceptions({state: 'all'});
InspectorTest.log('Instantiating.');
await Protocol.Runtime.evaluate(
{'expression': `const instance = instantiate(${module_bytes});`});
await WasmInspectorTest.instantiate(module_bytes);
InspectorTest.log('Calling div function.');
await Protocol.Runtime.evaluate({'expression': 'call_div()'});
InspectorTest.log('Finished.');
......
......@@ -2,12 +2,12 @@
// 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 stepping through wasm scripts by byte offsets');
session.setupScriptMap();
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder();
var func_a_idx =
......@@ -36,28 +36,13 @@ builder.addFunction('wasm_B', kSig_v_i)
var 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) {
view[i] = bytes[i] | 0;
}
var module = new WebAssembly.Module(buffer);
// Set global variable.
instance = new WebAssembly.Instance(module);
}
(async function test() {
for (const action of ['stepInto', 'stepOver', 'stepOut', 'resume'])
InspectorTest.logProtocolCommandCalls('Debugger.' + action);
await Protocol.Debugger.enable();
InspectorTest.log('Setting up global instance variable.');
Protocol.Runtime.evaluate({
expression: `var instance;` +
`(${instantiate.toString()})(${JSON.stringify(module_bytes)})`
});
WasmInspectorTest.instantiate(module_bytes);
const [, {params: wasmScript}] = await Protocol.Debugger.onceScriptParsed(2);
InspectorTest.log('Got wasm script: ' + wasmScript.url);
......
Tests stepping from javascript into wasm
Installing code and global variable.
Calling instantiate function.
Waiting for wasm scripts to be parsed.
Ignoring script with url v8://test/callInstantiate
Ignoring script with url v8://test/instantiate
Got wasm script: wasm://wasm/7d022e0e
Setting breakpoint on i32.const
{
......
......@@ -2,12 +2,12 @@
// 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 stepping from javascript into wasm');
session.setupScriptMap();
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
let builder = new WasmModuleBuilder();
// wasm_A
......@@ -21,21 +21,6 @@ let func = builder.addFunction('wasm_A', kSig_i_i)
let module_bytes = builder.toArray();
function instantiate(bytes) {
let buffer = new ArrayBuffer(bytes.length);
let view = new Uint8Array(buffer);
for (let i = 0; i < bytes.length; ++i) {
view[i] = bytes[i] | 0;
}
let module = new WebAssembly.Module(buffer);
// Set global variable.
instance = new WebAssembly.Instance(module);
}
let evalWithUrl = (code, url) => Protocol.Runtime.evaluate(
{'expression': code + '\n//# sourceURL=v8://test/' + url});
Protocol.Debugger.onPaused(async message => {
InspectorTest.log('paused');
var frames = message.params.callFrames;
......@@ -61,11 +46,8 @@ function test() {
(async function Test() {
await Protocol.Debugger.enable();
InspectorTest.log('Installing code and global variable.');
await evalWithUrl('var instance;\n' + instantiate.toString(), 'setup');
InspectorTest.log('Calling instantiate function.');
evalWithUrl(
'instantiate(' + JSON.stringify(module_bytes) + ')', 'callInstantiate');
WasmInspectorTest.instantiate(module_bytes);
const scriptId = await waitForWasmScript();
InspectorTest.log('Setting breakpoint on i32.const');
let msg = await Protocol.Debugger.setBreakpoint({
......
......@@ -2,12 +2,12 @@
// 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 stepping through wasm scripts by byte offsets');
session.setupScriptMap();
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder();
var func_a_idx =
......@@ -54,28 +54,13 @@ let fact = builder.addFunction('fact', kSig_i_i)
var 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) {
view[i] = bytes[i] | 0;
}
var module = new WebAssembly.Module(buffer);
// Set global variable.
instance = new WebAssembly.Instance(module);
}
(async function test() {
for (const action of ['stepInto', 'stepOver', 'stepOut', 'resume'])
InspectorTest.logProtocolCommandCalls('Debugger.' + action);
await Protocol.Debugger.enable();
InspectorTest.log('Setting up global instance variable.');
Protocol.Runtime.evaluate({
expression: `var instance;` +
`(${instantiate.toString()})(${JSON.stringify(module_bytes)})`
});
WasmInspectorTest.instantiate(module_bytes);
const [, {params: wasmScript}] = await Protocol.Debugger.onceScriptParsed(2);
InspectorTest.log('Got wasm script: ' + wasmScript.url);
......
Tests stepping to javascript from wasm
Installing code and global variable.
Calling instantiate function.
Waiting for wasm scripts to be parsed.
Ignoring script with url v8://test/callInstantiate
Ignoring script with url v8://test/instantiate
Got wasm script: wasm://wasm/242f4a16
Setting breakpoint at start of wasm function
{
......
......@@ -2,11 +2,11 @@
// 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 stepping to javascript from wasm');
session.setupScriptMap();
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
let builder = new WasmModuleBuilder();
// wasm_A
......@@ -20,21 +20,6 @@ let func = builder.addFunction('wasm_A', kSig_v_v)
let module_bytes = builder.toArray();
function instantiate(bytes) {
let buffer = new ArrayBuffer(bytes.length);
let view = new Uint8Array(buffer);
for (let i = 0; i < bytes.length; ++i) {
view[i] = bytes[i] | 0;
}
let module = new WebAssembly.Module(buffer);
// Set global variable.
instance = new WebAssembly.Instance(module);
}
let evalWithUrl = (code, url) => Protocol.Runtime.evaluate(
{'expression': code + '\n//# sourceURL=v8://test/' + url});
Protocol.Debugger.onPaused(async message => {
InspectorTest.log("paused");
var frames = message.params.callFrames;
......@@ -78,11 +63,8 @@ function test() {
(async function Test() {
await Protocol.Debugger.enable();
InspectorTest.log('Installing code and global variable.');
await evalWithUrl('var instance;\n' + instantiate.toString(), 'setup');
InspectorTest.log('Calling instantiate function.');
evalWithUrl(
'instantiate(' + JSON.stringify(module_bytes) + ')', 'callInstantiate');
WasmInspectorTest.instantiate(module_bytes);
const scriptId = await waitForWasmScript();
InspectorTest.log(
'Setting breakpoint at start of wasm function');
......
Tests stepping through wasm scripts with source maps
Installing code an global variable and instantiate.
Got wasm script: wasm://wasm/9b4bf87e
Script sourceMapURL: abc
Requesting source for wasm://wasm/9b4bf87e...
......
......@@ -2,12 +2,12 @@
// 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 stepping through wasm scripts with source maps');
session.setupScriptMap();
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder();
var func_a_idx =
......@@ -36,26 +36,12 @@ builder.addCustomSection('sourceMappingURL', [3, 97, 98, 99]);
var 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) {
view[i] = bytes[i] | 0;
}
var module = new WebAssembly.Module(buffer);
// Set global variable.
instance = new WebAssembly.Instance(module);
}
(async function test() {
for (const action of ['stepInto', 'stepOver', 'stepOut', 'resume'])
InspectorTest.logProtocolCommandCalls('Debugger.' + action);
await Protocol.Debugger.enable();
InspectorTest.log('Installing code an global variable and instantiate.');
Protocol.Runtime.evaluate({
expression: `var instance;(${instantiate.toString()})(${JSON.stringify(module_bytes)})`});
WasmInspectorTest.instantiate(module_bytes);
const [, {params: wasmScript}] = await Protocol.Debugger.onceScriptParsed(2);
InspectorTest.log('Got wasm script: ' + wasmScript.url);
......
......@@ -2,11 +2,11 @@
// 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 unnamed function in wasm scripts');
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder();
var imported_idx = builder.addImport('mode', 'import_func', kSig_v_v);
......
......@@ -2,8 +2,30 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
WasmInspectorTest = {}
WasmInspectorTest.evalWithUrl = (code, url) =>
Protocol.Runtime
.evaluate({'expression': code + '\n//# sourceURL=v8://test/' + url})
.then(printIfFailure);
WasmInspectorTest.instantiateFromBuffer = function(bytes) {
var buffer = new ArrayBuffer(bytes.length);
var view = new Uint8Array(buffer);
for (var i = 0; i < bytes.length; ++i) {
view[i] = bytes[i] | 0;
}
const module = new WebAssembly.Module(buffer);
return new WebAssembly.Instance(module);
}
WasmInspectorTest.instantiate = async function(bytes, instance_name = 'instance') {
const instantiate_code = `var ${instance_name} = (${WasmInspectorTest.instantiateFromBuffer})(${JSON.stringify(bytes)});`;
await WasmInspectorTest.evalWithUrl(instantiate_code, 'instantiate');
}
WasmInspectorTest.dumpScopeProperties = async function(message) {
printIfFailure(message);
for (var value of message.result.result) {
......
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