Commit 29c4cf0e authored by Simon Zünd's avatar Simon Zünd Committed by V8 LUCI CQ

[inspector] Move restart-frame test helpers into protocol-test.js

R=bmeurer@chromium.org

Bug: chromium:1303521
Change-Id: Iff7247fda94037ff4f9d37f334d386eb4e63ce62
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3595819
Commit-Queue: Simon Zünd <szuend@chromium.org>
Auto-Submit: Simon Zünd <szuend@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80038}
parent f6cb7987
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
utils.load('test/inspector/debugger/restart-frame/restart-frame-test.js');
const {session, Protocol} =
InspectorTest.start('Checks that requesting to restart a non-existant frame fails cleanly');
......@@ -12,7 +10,7 @@ session.setupScriptMap();
(async () => {
await Protocol.Debugger.enable();
await RestartFrameTest.evaluateAndWaitForPause(`
await InspectorTest.evaluateAndWaitForPause(`
(function foo() { debugger; })();
`);
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
utils.load('test/inspector/debugger/restart-frame/restart-frame-test.js');
const {session, contextGroup, Protocol} =
InspectorTest.start('Checks that restart frame fails for generator or async functions.');
......@@ -13,9 +11,9 @@ async function testCase(description, snippet, restartFrameIndex) {
InspectorTest.log('');
InspectorTest.log(description);
const { callFrames, evaluatePromise } = await RestartFrameTest.evaluateAndWaitForPause(snippet);
const { callFrames, evaluatePromise } = await InspectorTest.evaluateAndWaitForPause(snippet);
// These are negative tests where the following call is expected to fail.
await RestartFrameTest.restartFrameAndWaitForPause(callFrames, restartFrameIndex);
await InspectorTest.restartFrameAndWaitForPause(callFrames, restartFrameIndex);
// All snippets are written so a single resume is enough.
Protocol.Debugger.resume();
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
utils.load('test/inspector/debugger/restart-frame/restart-frame-test.js');
const {session, contextGroup, Protocol} =
InspectorTest.start('Checks that restart frame fails when embedder frames would be unwound');
......@@ -21,11 +19,11 @@ function entrypoint() {
(async () => {
await Protocol.Debugger.enable();
const { callFrames } = await RestartFrameTest.evaluateAndWaitForPause('entrypoint()');
const { callFrames } = await InspectorTest.evaluateAndWaitForPause('entrypoint()');
// Restart the `entrypoint` frame. Inbetween is the C++ API method `callbackForTests`.
const restartFrameIndex = 1; // 0 is `breaker`, 1 is `entrypoint`.
await RestartFrameTest.restartFrameAndWaitForPause(callFrames, restartFrameIndex);
await InspectorTest.restartFrameAndWaitForPause(callFrames, restartFrameIndex);
InspectorTest.completeTest();
})();
// Copyright 2022 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.
RestartFrameTest = {};
RestartFrameTest.evaluateAndWaitForPause = async (expression) => {
const pausedPromise = Protocol.Debugger.oncePaused();
const evaluatePromise = Protocol.Runtime.evaluate({ expression });
const { params: { callFrames } } = await pausedPromise;
InspectorTest.log('Paused at (after evaluation):');
await session.logSourceLocation(callFrames[0].location);
// Ignore the last frame, it's always an anonymous empty frame for the
// Runtime#evaluate call.
InspectorTest.log('Pause stack:');
for (const frame of callFrames.slice(0, -1)) {
InspectorTest.log(` ${frame.functionName}:${frame.location.lineNumber} (canBeRestarted = ${frame.canBeRestarted ?? false})`);
}
InspectorTest.log('');
return { callFrames, evaluatePromise };
};
RestartFrameTest.restartFrameAndWaitForPause = async (callFrames, index) => {
const pausedPromise = Protocol.Debugger.oncePaused();
const frame = callFrames[index];
InspectorTest.log(`Restarting function "${frame.functionName}" ...`);
const response = await Protocol.Debugger.restartFrame({ callFrameId: frame.callFrameId, mode: 'StepInto' });
if (response.error) {
InspectorTest.log(`Failed to restart function "${frame.functionName}":`);
InspectorTest.logMessage(response.error);
return;
}
const { params: { callFrames: pausedCallFrames } } = await pausedPromise;
InspectorTest.log('Paused at (after restart):');
await session.logSourceLocation(pausedCallFrames[0].location);
return callFrames;
};
......@@ -4,8 +4,6 @@
// Flags: --allow-natives-syntax
utils.load('test/inspector/debugger/restart-frame/restart-frame-test.js');
const {session, contextGroup, Protocol} =
InspectorTest.start('Checks that restarting an inlined frame works.');
......@@ -53,12 +51,12 @@ h();
await Protocol.Debugger.setBreakpointByUrl({ url: 'test.js', lineNumber: 4 });
const { callFrames, evaluatePromise } = await RestartFrameTest.evaluateAndWaitForPause('h()');
const { callFrames, evaluatePromise } = await InspectorTest.evaluateAndWaitForPause('h()');
({ result: { result: { value } } } = await Protocol.Runtime.evaluate({ expression: 'isOptimized(h)' }));
InspectorTest.log(`Optimization status for function "h" after we paused? ${value}`);
await RestartFrameTest.restartFrameAndWaitForPause(callFrames, 1);
await InspectorTest.restartFrameAndWaitForPause(callFrames, 1);
// Restarting the frame means we hit the breakpoint a second time.
Protocol.Debugger.resume();
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
utils.load('test/inspector/debugger/restart-frame/restart-frame-test.js');
const {session, Protocol} =
InspectorTest.start('Checks that restarting the top frame hits a debugger statement twice');
......@@ -21,9 +19,9 @@ foo();
(async () => {
await Protocol.Debugger.enable();
const { callFrames } = await RestartFrameTest.evaluateAndWaitForPause(source);
const { callFrames } = await InspectorTest.evaluateAndWaitForPause(source);
await RestartFrameTest.restartFrameAndWaitForPause(callFrames, 0);
await InspectorTest.restartFrameAndWaitForPause(callFrames, 0);
Protocol.Debugger.resume(); // Resuming hits the 'debugger' stmt again.
await Protocol.Debugger.oncePaused();
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
utils.load('test/inspector/debugger/restart-frame/restart-frame-test.js');
const {session, Protocol} =
InspectorTest.start('Checks that after restarting the top frame, local variables are reset');
......@@ -22,7 +20,7 @@ foo();
(async () => {
await Protocol.Debugger.enable();
const { callFrames } = await RestartFrameTest.evaluateAndWaitForPause(source);
const { callFrames } = await InspectorTest.evaluateAndWaitForPause(source);
let { callFrameId } = callFrames[0];
InspectorTest.log('Evaluating x:');
......@@ -34,7 +32,7 @@ foo();
InspectorTest.log('Evaluating z:');
InspectorTest.logMessage(await Protocol.Debugger.evaluateOnCallFrame({ callFrameId, expression: 'z' }));
const callFramesAfter = await RestartFrameTest.restartFrameAndWaitForPause(callFrames, 0);
const callFramesAfter = await InspectorTest.restartFrameAndWaitForPause(callFrames, 0);
({ callFrameId } = callFramesAfter[0]);
InspectorTest.log('Evaluating x:');
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
utils.load('test/inspector/debugger/restart-frame/restart-frame-test.js');
const {session, Protocol} =
InspectorTest.start('Checks that restarting the top frame works with breakpoints');
......@@ -26,8 +24,8 @@ function foo() {
url: 'testRestartFrame.js',
});
const { callFrames } = await RestartFrameTest.evaluateAndWaitForPause('foo()');
await RestartFrameTest.restartFrameAndWaitForPause(callFrames, 0);
const { callFrames } = await InspectorTest.evaluateAndWaitForPause('foo()');
await InspectorTest.restartFrameAndWaitForPause(callFrames, 0);
Protocol.Debugger.resume(); // Resuming hits the breakpoint again.
await Protocol.Debugger.oncePaused();
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
utils.load('test/inspector/debugger/restart-frame/restart-frame-test.js');
const {session, contextGroup, Protocol} =
InspectorTest.start('Checks that restarting every frame on the stack works.');
......@@ -40,8 +38,8 @@ function F() {
`, 0, 0, 'test.js');
async function testCase(frameIndex) {
const { callFrames, evaluatePromise } = await RestartFrameTest.evaluateAndWaitForPause('F()');
await RestartFrameTest.restartFrameAndWaitForPause(callFrames, frameIndex);
const { callFrames, evaluatePromise } = await InspectorTest.evaluateAndWaitForPause('F()');
await InspectorTest.restartFrameAndWaitForPause(callFrames, frameIndex);
Protocol.Debugger.resume(); // Resuming hits the 'debugger' stmt again.
await Protocol.Debugger.oncePaused();
......
......@@ -495,3 +495,45 @@ InspectorTest.start = function(description) {
utils.print(e.stack);
}
}
/**
* Two helper functions for the tests in `debugger/restart-frame/*`.
*/
InspectorTest.evaluateAndWaitForPause = async (expression) => {
const pausedPromise = Protocol.Debugger.oncePaused();
const evaluatePromise = Protocol.Runtime.evaluate({ expression });
const { params: { callFrames } } = await pausedPromise;
InspectorTest.log('Paused at (after evaluation):');
await session.logSourceLocation(callFrames[0].location);
// Ignore the last frame, it's always an anonymous empty frame for the
// Runtime#evaluate call.
InspectorTest.log('Pause stack:');
for (const frame of callFrames.slice(0, -1)) {
InspectorTest.log(` ${frame.functionName}:${frame.location.lineNumber} (canBeRestarted = ${frame.canBeRestarted ?? false})`);
}
InspectorTest.log('');
return { callFrames, evaluatePromise };
};
InspectorTest.restartFrameAndWaitForPause = async (callFrames, index) => {
const pausedPromise = Protocol.Debugger.oncePaused();
const frame = callFrames[index];
InspectorTest.log(`Restarting function "${frame.functionName}" ...`);
const response = await Protocol.Debugger.restartFrame({ callFrameId: frame.callFrameId, mode: 'StepInto' });
if (response.error) {
InspectorTest.log(`Failed to restart function "${frame.functionName}":`);
InspectorTest.logMessage(response.error);
return;
}
const { params: { callFrames: pausedCallFrames } } = await pausedPromise;
InspectorTest.log('Paused at (after restart):');
await session.logSourceLocation(pausedCallFrames[0].location);
return callFrames;
};
......@@ -13,13 +13,12 @@ PROTOCOL_TEST_JS = "protocol-test.js"
WASM_INSPECTOR_JS = "wasm-inspector-test.js"
EXPECTED_SUFFIX = "-expected.txt"
RESOURCES_FOLDER = "resources"
RESTART_FRAME_JS = "restart-frame-test.js"
class TestLoader(testsuite.JSTestLoader):
@property
def excluded_files(self):
return {PROTOCOL_TEST_JS, WASM_INSPECTOR_JS, RESTART_FRAME_JS}
return {PROTOCOL_TEST_JS, WASM_INSPECTOR_JS}
@property
def excluded_dirs(self):
......@@ -60,8 +59,6 @@ class TestCase(testcase.TestCase):
os.path.join('test', 'inspector', 'debugger', 'resources',
'break-locations.js'),
os.path.join('test', 'inspector', WASM_INSPECTOR_JS),
os.path.join('test', 'inspector', 'debugger', 'restart-frame',
RESTART_FRAME_JS),
]
@property
......
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