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

[wasm][debug] Clean up inspector tests

Pulling out common functionality related to dumping scope properties.

Bug: chromium:1093165
Change-Id: I7de377b8812b6181bac21fc0d90c416568b0d640
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2237126
Commit-Queue: Kim-Anh Tran <kimanh@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68277}
parent c828fc64
......@@ -28,9 +28,7 @@ v8_executable("inspector-test") {
"//build/win:default_exe_manifest",
]
data_deps = [
"../../tools:v8_testrunner",
]
data_deps = [ "../../tools:v8_testrunner" ]
data = [
"console/",
......@@ -46,6 +44,7 @@ v8_executable("inspector-test") {
"sessions/",
"testcfg.py",
"type-profiler/",
"wasm-inspector-test.js",
]
cflags = []
......
......@@ -6,6 +6,7 @@ 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;
const configs = {
......@@ -29,11 +30,6 @@ function instantiate(bytes) {
const evalWithUrl = (code, url) => Protocol.Runtime.evaluate(
{'expression': code + '\n//# sourceURL=v8://test/' + url});
function getWasmValue(value) {
return typeof (value.value) === 'undefined' ? value.unserializableValue :
value.value;
}
Protocol.Debugger.onPaused(async msg => {
let loc = msg.params.callFrames[0].location;
let line = [`Paused at offset ${loc.columnNumber}`];
......@@ -43,7 +39,8 @@ Protocol.Debugger.onPaused(async msg => {
if (scope.type == 'module') continue;
var scope_properties =
await Protocol.Runtime.getProperties({objectId: scope.object.objectId});
let str = scope_properties.result.result.map(elem => getWasmValue(elem.value)).join(', ');
let str = scope_properties.result.result.map(
elem => WasmInspectorTest.getWasmValue(elem.value)).join(', ');
line.push(`${scope.type}: [${str}]`);
}
InspectorTest.log(line.join('; '));
......
......@@ -4,6 +4,8 @@
// Flags: --experimental-wasm-type-reflection
utils.load('test/inspector/wasm-inspector-test.js');
let {session, contextGroup, Protocol} = InspectorTest.start(
'Test retrieving scope information from compiled Liftoff frames');
session.setupScriptMap();
......@@ -53,7 +55,7 @@ async function printPauseLocationsAndContinue(msg) {
}
var properties = await Protocol.Runtime.getProperties(
{'objectId': scope.object.objectId});
await dumpScopeProperties(properties);
await WasmInspectorTest.dumpScopeProperties(properties);
}
}
InspectorTest.log();
......@@ -159,88 +161,3 @@ async function waitForWasmScripts() {
}
return wasm_script_ids;
}
async function getScopeValues(name, value) {
if (value.type == 'object') {
if (value.subtype == 'typedarray') return value.description;
if (name == 'instance') return dumpInstanceProperties(value);
if (name == 'function tables') return dumpTables(value);
let msg = await Protocol.Runtime.getProperties({objectId: value.objectId});
printIfFailure(msg);
const printProperty = function(elem) {
return `"${elem.name}": ${getWasmValue(elem.value)} (${elem.value.subtype})`;
}
return msg.result.result.map(printProperty).join(', ');
}
return getWasmValue(value) + ' (' + value.subtype + ')';
}
async function dumpScopeProperties(message) {
printIfFailure(message);
for (var value of message.result.result) {
var value_str = await getScopeValues(value.name, value.value);
InspectorTest.log(' ' + value.name + ': ' + value_str);
}
}
function recursiveGetPropertiesWrapper(value, depth) {
return recursiveGetProperties({result: {result: [value]}}, depth);
}
async function recursiveGetProperties(value, depth) {
if (depth > 0) {
const properties = await Promise.all(value.result.result.map(
x => {return Protocol.Runtime.getProperties({objectId: x.value.objectId});}));
const recursiveProperties = await Promise.all(properties.map(
x => {return recursiveGetProperties(x, depth - 1);}));
return recursiveProperties.flat();
}
return value;
}
async function dumpTables(tablesObj) {
let msg = await Protocol.Runtime.getProperties({objectId: tablesObj.objectId});
var tables_str = [];
for (var table of msg.result.result) {
const func_entries = await recursiveGetPropertiesWrapper(table, 2);
var functions = [];
for (var func of func_entries) {
for (var value of func.result.result) {
functions.push(`${value.name}: ${value.value.description}`);
}
}
const functions_str = functions.join(', ');
tables_str.push(` ${table.name}: ${functions_str}`);
}
return '\n' + tables_str.join('\n');
}
async function dumpInstanceProperties(instanceObj) {
function invokeGetter(property) {
return this[JSON.parse(property)];
}
const exportsName = 'exports';
let exportsObj = await Protocol.Runtime.callFunctionOn(
{objectId: instanceObj.objectId,
functionDeclaration: invokeGetter.toString(),
arguments: [{value: JSON.stringify(exportsName)}]
});
printIfFailure(exportsObj);
let exports = await Protocol.Runtime.getProperties(
{objectId: exportsObj.result.result.objectId});
printIfFailure(exports);
const printExports = function(value) {
return `"${value.name}" (${value.value.className})`;
}
const formattedExports = exports.result.result.map(printExports).join(', ');
return `${exportsName}: ${formattedExports}`
}
function getWasmValue(wasmValue) {
return typeof (wasmValue.value) === 'undefined' ?
wasmValue.unserializableValue :
wasmValue.value;
}
......@@ -4,6 +4,8 @@
// Flags: --experimental-wasm-type-reflection
utils.load('test/inspector/wasm-inspector-test.js');
let {session, contextGroup, Protocol} = InspectorTest.start(
'Test retrieving scope information when pausing in wasm functions');
session.setupScriptMap();
......@@ -58,7 +60,7 @@ async function printPauseLocationsAndContinue(msg) {
}
var properties = await Protocol.Runtime.getProperties(
{'objectId': scope.object.objectId});
await dumpScopeProperties(properties);
await WasmInspectorTest.dumpScopeProperties(properties);
}
}
InspectorTest.log();
......@@ -157,88 +159,3 @@ async function waitForWasmScripts() {
}
return wasm_script_ids;
}
async function getScopeValues(name, value) {
if (value.type == 'object') {
if (value.subtype == 'typedarray') return value.description;
if (name == 'instance') return dumpInstanceProperties(value);
if (name == 'function tables') return dumpTables(value);
let msg = await Protocol.Runtime.getProperties({objectId: value.objectId});
printIfFailure(msg);
const printProperty = function(elem) {
return `"${elem.name}": ${getWasmValue(elem.value)} (${elem.value.subtype})`;
}
return msg.result.result.map(printProperty).join(', ');
}
return getWasmValue(value) + ' (' + value.subtype + ')';
}
async function dumpScopeProperties(message) {
printIfFailure(message);
for (var value of message.result.result) {
var value_str = await getScopeValues(value.name, value.value);
InspectorTest.log(' ' + value.name + ': ' + value_str);
}
}
function recursiveGetPropertiesWrapper(value, depth) {
return recursiveGetProperties({result: {result: [value]}}, depth);
}
async function recursiveGetProperties(value, depth) {
if (depth > 0) {
const properties = await Promise.all(value.result.result.map(
x => {return Protocol.Runtime.getProperties({objectId: x.value.objectId});}));
const recursiveProperties = await Promise.all(properties.map(
x => {return recursiveGetProperties(x, depth - 1);}));
return recursiveProperties.flat();
}
return value;
}
async function dumpTables(tablesObj) {
let msg = await Protocol.Runtime.getProperties({objectId: tablesObj.objectId});
var tables_str = [];
for (var table of msg.result.result) {
const func_entries = await recursiveGetPropertiesWrapper(table, 2);
var functions = [];
for (var func of func_entries) {
for (var value of func.result.result) {
functions.push(`${value.name}: ${value.value.description}`);
}
}
const functions_str = functions.join(', ');
tables_str.push(` ${table.name}: ${functions_str}`);
}
return '\n' + tables_str.join('\n');
}
async function dumpInstanceProperties(instanceObj) {
function invokeGetter(property) {
return this[JSON.parse(property)];
}
const exportsName = 'exports';
let exportsObj = await Protocol.Runtime.callFunctionOn(
{objectId: instanceObj.objectId,
functionDeclaration: invokeGetter.toString(),
arguments: [{value: JSON.stringify(exportsName)}]
});
printIfFailure(exportsObj);
let exports = await Protocol.Runtime.getProperties(
{objectId: exportsObj.result.result.objectId});
printIfFailure(exports);
const printExports = function(value) {
return `"${value.name}" (${value.value.className})`;
}
const formattedExports = exports.result.result.map(printExports).join(', ');
return `${exportsName}: ${formattedExports}`
}
function getWasmValue(wasmValue) {
return typeof (wasmValue.value) === 'undefined' ?
wasmValue.unserializableValue :
wasmValue.value;
}
......@@ -7,6 +7,7 @@ const {session, contextGroup, Protocol} =
session.setupScriptMap();
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
utils.load('test/inspector/wasm-inspector-test.js');
const builder = new WasmModuleBuilder();
......@@ -82,10 +83,7 @@ Protocol.Debugger.onPaused(async msg => {
InspectorTest.logObject(' - scope (' + scope.type + '):');
var properties = await Protocol.Runtime.getProperties(
{'objectId': scope.object.objectId});
for (var value of properties.result.result) {
var value_str = await getScopeValues(value.name, value.value);
InspectorTest.log(' ' + value.name + ': ' + value_str);
}
await WasmInspectorTest.dumpScopeProperties(properties);
}
}
......@@ -103,45 +101,6 @@ Protocol.Debugger.onPaused(async msg => {
Protocol.Debugger.resume();
});
function getWasmValue(value) {
return typeof (value.value) === 'undefined' ? value.unserializableValue :
value.value;
}
async function getScopeValues(name, value) {
if (value.type == 'object') {
if (name == 'instance') return dumpInstanceProperties(value);
let msg = await Protocol.Runtime.getProperties({objectId: value.objectId});
const printProperty = function(elem) {
return `"${elem.name}": ${getWasmValue(elem.value)} (${elem.value.subtype})`;
}
return msg.result.result.map(printProperty).join(', ');
}
return getWasmValue(value) + ' (' + value.subtype + ')';
}
async function dumpInstanceProperties(instanceObj) {
function invokeGetter(property) {
return this[JSON.parse(property)];
}
const exportsName = 'exports';
let exportsObj = await Protocol.Runtime.callFunctionOn(
{objectId: instanceObj.objectId,
functionDeclaration: invokeGetter.toString(),
arguments: [{value: JSON.stringify(exportsName)}]
});
let exports = await Protocol.Runtime.getProperties(
{objectId: exportsObj.result.result.objectId});
const printExports = function(value) {
return `"${value.name}" (${value.value.className})`;
}
const formattedExports = exports.result.result.map(printExports).join(', ');
return `${exportsName}: ${formattedExports}`
}
(async function test() {
await Protocol.Debugger.enable();
InspectorTest.log('Instantiating.');
......
......@@ -10,13 +10,14 @@ from testrunner.objects import testcase
from testrunner.outproc import base as outproc
PROTOCOL_TEST_JS = "protocol-test.js"
WASM_INSPECTOR_JS = "wasm-inspector-test.js"
EXPECTED_SUFFIX = "-expected.txt"
RESOURCES_FOLDER = "resources"
class TestLoader(testsuite.JSTestLoader):
@property
def excluded_files(self):
return {PROTOCOL_TEST_JS}
return {PROTOCOL_TEST_JS, WASM_INSPECTOR_JS}
@property
def excluded_dirs(self):
......
// 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.
WasmInspectorTest = {}
WasmInspectorTest.dumpScopeProperties = async function(message) {
printIfFailure(message);
for (var value of message.result.result) {
var value_str = await getScopeValues(value.name, value.value);
InspectorTest.log(' ' + value.name + ': ' + value_str);
}
}
WasmInspectorTest.getWasmValue = function(wasmValue) {
return typeof (wasmValue.value) === 'undefined' ?
wasmValue.unserializableValue :
wasmValue.value;
}
function printIfFailure(message) {
if (!message.result) {
InspectorTest.logMessage(message);
}
return message;
}
async function getScopeValues(name, value) {
if (value.type == 'object') {
if (value.subtype == 'typedarray') return value.description;
if (name == 'instance') return dumpInstanceProperties(value);
if (name == 'function tables') return dumpTables(value);
let msg = await Protocol.Runtime.getProperties({objectId: value.objectId});
printIfFailure(msg);
const printProperty = function(elem) {
const wasmValue = WasmInspectorTest.getWasmValue(elem.value);
return `"${elem.name}": ${wasmValue} (${elem.value.subtype})`;
}
return msg.result.result.map(printProperty).join(', ');
}
return WasmInspectorTest.getWasmValue(value) + ' (' + value.subtype + ')';
}
function recursiveGetPropertiesWrapper(value, depth) {
return recursiveGetProperties({result: {result: [value]}}, depth);
}
async function recursiveGetProperties(value, depth) {
if (depth > 0) {
const properties = await Promise.all(value.result.result.map(
x => {return Protocol.Runtime.getProperties({objectId: x.value.objectId});}));
const recursiveProperties = await Promise.all(properties.map(
x => {return recursiveGetProperties(x, depth - 1);}));
return recursiveProperties.flat();
}
return value;
}
async function dumpTables(tablesObj) {
let msg = await Protocol.Runtime.getProperties({objectId: tablesObj.objectId});
var tables_str = [];
for (var table of msg.result.result) {
const func_entries = await recursiveGetPropertiesWrapper(table, 2);
var functions = [];
for (var func of func_entries) {
for (var value of func.result.result) {
functions.push(`${value.name}: ${value.value.description}`);
}
}
const functions_str = functions.join(', ');
tables_str.push(` ${table.name}: ${functions_str}`);
}
return '\n' + tables_str.join('\n');
}
async function dumpInstanceProperties(instanceObj) {
function invokeGetter(property) {
return this[JSON.parse(property)];
}
const exportsName = 'exports';
let exportsObj = await Protocol.Runtime.callFunctionOn(
{objectId: instanceObj.objectId,
functionDeclaration: invokeGetter.toString(),
arguments: [{value: JSON.stringify(exportsName)}]
});
printIfFailure(exportsObj);
let exports = await Protocol.Runtime.getProperties(
{objectId: exportsObj.result.result.objectId});
printIfFailure(exports);
const printExports = function(value) {
return `"${value.name}" (${value.value.className})`;
}
const formattedExports = exports.result.result.map(printExports).join(', ');
return `${exportsName}: ${formattedExports}`
}
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