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

[wasm] Add test to check if we can pause execution

This adds a webtest to check if we can pause execution in a script
compiled using streaming compilation.

Bug: chromium:1079328
Change-Id: I68756c333a0ff69294f5bf210b0a6004412ee774
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2202897
Commit-Queue: Kim-Anh Tran <kimanh@chromium.org>
Reviewed-by: default avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771524}
parent f30cfe5e
......@@ -244,10 +244,15 @@ var TestRunner = class {
}
}
_replaceUUID(url) {
const uuidRegex = new RegExp('[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}');
return url.replace(uuidRegex, 'UUID');
}
logCallFrames(callFrames) {
for (let frame of callFrames) {
let functionName = frame.functionName || '(anonymous)';
let url = frame.url;
let url = this._replaceUUID(frame.url);
let location = frame.location || frame;
this.log(`${functionName} at ${url}:${
location.lineNumber
......
Test pausing in wasm script.
Did enable debugger.
Paused on debugger.
call_debugger at :2:4
call_func at blob:file:///UUID:0:72
main at blob:file:///UUID:0:81
(anonymous) at :59:39
Resumed execution.
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function compileStreamingAndBreak() {
function call_debugger() {
debugger;
}
// Call from wasm to js.
// TODO(kimanh): Find a way to use the WasmModuleBuilder.
const moduleHeader = [0x0,0x61,0x73,0x6d];
const moduleVersion = [0x1,0x0,0x0,0x0];
const typeSection = [0x1,0xd,0x4, // Type section.
0x60,0x0,0x0, // Function type.
0x60,0x0,0x0, // Function type.
0x60,0x0,0x0, // Function type.
0x60,0x0,0x0]; // Function type.
const importSection = [0x2,0xc,0x1, // Import section.
0x3,0x78,0x78,0x78, // Module name.
0x4,0x66,0x75,0x6e,0x63, // Field name.
0x0, // Import kind.
0x0]; // Import index.
const funcDelaration = [0x3,0x3,0x2, // Function section.
0x1, // Function type.
0x3]; // Function type.
const tableSection = [0x4,0x4,0x1, // Table section.
0x70,0x0,0x1]; // Funcref, no max, min 1.
const exportSection = [0x7,0x8,0x1, // Export section.
0x4,0x6d,0x61,0x69,0x6e, // Export name.
0x0, // Export kind.
0x2]; // Export index.
const elementsSection = [0x9,0x7,0x1, // Element section.
0x0, // Active, no index.
0x41,0x0,0xb,0x1,0x1]; // i32.const 0, index 1
const functionBodies = [0xa,0x11,0x2, // Code section.
0x4,0x0,0x10,0x0,0xb, // Function body 1.
0xa,0x0,0x2,0x40,0x41, // Function body 2.
0x0,0x11,0x2,0x0,0xb,0xb]; // Function body 2.
const names = [0x0,0x19, // Name section.
0x4,0x6e,0x61,0x6d,0x65, // Name section name.
0x1,0x12,0x2, // 2 function names.
0x1,0x9,0x63,0x61,0x6c,0x6c, // Name at index 1.
0x5f,0x66,0x75,0x6e,0x63, // Name at index 1.
0x2,0x4,0x6d,0x61,0x69,0x6e]; // Name at index 2.
const wasm = Uint8Array.from([
...moduleHeader,
...moduleVersion,
...typeSection,
...importSection,
...funcDelaration,
...tableSection,
...exportSection,
...elementsSection,
...functionBodies,
...names]);
let b = new Blob([wasm.buffer], {type: 'application/wasm'});
let bURL = URL.createObjectURL(b);
fetch(bURL)
.then(WebAssembly.compileStreaming)
.then(module => new WebAssembly.Instance(module, {xxx: {func: call_debugger}}))
.then(instance => instance.exports.main())
}
(async function(testRunner) {
const {session, dp} = await testRunner.startBlank(
'Test pausing in wasm script.');
let debuggerId = (await dp.Debugger.enable()).result.debuggerId;
let debuggers = new Map([[debuggerId, dp.Debugger]]);
testRunner.log('Did enable debugger.');
await session.evaluate('(' + compileStreamingAndBreak + ')()');
let {params: {callFrames, stackTrace, stackTraceId}} = await dp.Debugger.oncePaused();
testRunner.log('Paused on debugger.');
await testRunner.logStackTrace(debuggers,
{callFrames, stackTrace, stackTraceId},
debuggerId);
await dp.Debugger.resume();
testRunner.log('Resumed execution.');
testRunner.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