v8/test/inspector/debugger/wasm-global-names.js
Benedikt Meurer 6f448efbef [inspector] Make wasm tests fail rather than time out.
Consistently use InspectorTest.runAsyncTestSuite() in wasm inspector
tests to make tests easier to debug (they'll fail instead of timing
out in case of errors).

Bug: chromium:1162229, chromium:1071432
Change-Id: I7aada196f9e34071aa1bb059bb45f85f75226060
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2609414
Commit-Queue: Yang Guo <yangguo@chromium.org>
Auto-Submit: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71908}
2021-01-05 07:38:57 +00:00

67 lines
2.4 KiB
JavaScript

// 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('Test wasm global names');
let builder = new WasmModuleBuilder();
builder.addImportedGlobal('module_name', 'imported_global', kWasmI32, false);
let func = builder.addFunction('func', kSig_v_i)
.addBody([
kExprGlobalGet, 0, //
kExprDrop, //
])
.exportAs('main');
var o = builder.addGlobal(kWasmI32, func).exportAs('exported_global');
builder.addGlobal(kWasmI32); // global2
let moduleBytes = builder.toArray();
InspectorTest.runAsyncTestSuite([
async function test() {
Protocol.Debugger.enable();
Protocol.Runtime.evaluate({
expression: `var instance = (${WasmInspectorTest.instantiateFromBuffer})(${JSON.stringify(moduleBytes)}, {module_name: {imported_global: 123}});`
});
InspectorTest.log('Waiting for wasm script to be parsed.');
let scriptId;
while (true) {
let msg = await Protocol.Debugger.onceScriptParsed();
if (msg.params.url.startsWith('wasm://')) {
scriptId = msg.params.scriptId;
break;
}
}
InspectorTest.log('Setting breakpoint in wasm.');
await Protocol.Debugger.setBreakpoint(
{location: {scriptId, lineNumber: 0, columnNumber: func.body_offset}});
InspectorTest.log('Running main.');
Protocol.Runtime.evaluate({expression: 'instance.exports.main()'});
let msg = await Protocol.Debugger.oncePaused();
let callFrames = msg.params.callFrames;
InspectorTest.log('Paused in debugger.');
let scopeChain = callFrames[0].scopeChain;
for (let scope of scopeChain) {
if (scope.type != 'module') continue;
let moduleObjectProps = (await Protocol.Runtime.getProperties({
'objectId': scope.object.objectId
})).result.result;
for (let prop of moduleObjectProps) {
if (prop.name != 'globals') continue;
let subProps = (await Protocol.Runtime.getProperties({
objectId: prop.value.objectId
})).result.result;
let values = subProps.map((value) => `"${value.name}"`).join(', ');
InspectorTest.log(` ${prop.name}: {${values}}`);
}
}
}
]);