[test] Move inspector stopping to session

This patch moves the stop method from context group to session to enable
stopping each session independently. This is useful for testing that
stopping does not interact badly with other sessions.

Bug: chromium:1354043
Change-Id: I885cf49f2d4cf006fa5228edf2954099e45cfc6b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4100484
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Jaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/main@{#84797}
This commit is contained in:
Jaroslav Sevcik 2022-12-13 07:21:26 +01:00 committed by V8 LUCI CQ
parent a38209949f
commit d46662c084
6 changed files with 49 additions and 21 deletions

View File

@ -13,3 +13,8 @@ Pause error(?): Debugger agent is not enabled
Running test: testSessionStopDisallowsReenabling
Pause error(?) after stop: Debugger agent is not enabled
Pause error(?) after re-enable: Debugger agent is not enabled
Running test: testSessionStopDoesNotDisableOtherSessions
Session 1 pause error after stop: Debugger agent is not enabled
Session 2 paused: other
Session 2 evaluation: 42

View File

@ -13,7 +13,7 @@ InspectorTest.runAsyncTestSuite([
Protocol.Debugger.enable();
await Protocol.Debugger.pause();
const result = Protocol.Runtime.evaluate({expression: '42'});
contextGroup.stop();
session.stop();
InspectorTest.log(
`Evaluation returned: ${(await result).result.result.value}`);
},
@ -28,7 +28,7 @@ InspectorTest.runAsyncTestSuite([
const paused = Protocol.Debugger.oncePaused();
const result = Protocol.Runtime.evaluate({expression: '42'});
InspectorTest.log(`Paused: ${(await paused).params.reason}`);
contextGroup.stop();
session.stop();
InspectorTest.log(
`Evaluation returned: ${(await result).result.result.value}`);
},
@ -38,7 +38,7 @@ InspectorTest.runAsyncTestSuite([
let Protocol = session.Protocol;
await Protocol.Debugger.enable();
contextGroup.stop();
session.stop();
const pauseResult = await Protocol.Debugger.pause();
InspectorTest.log(`Pause error(?): ${pauseResult?.error?.message}`);
},
@ -48,7 +48,7 @@ InspectorTest.runAsyncTestSuite([
let Protocol = session.Protocol;
await Protocol.Debugger.enable();
contextGroup.stop();
session.stop();
const pauseResultAfterStop = await Protocol.Debugger.pause();
InspectorTest.log(
`Pause error(?) after stop: ${pauseResultAfterStop?.error?.message}`);
@ -56,5 +56,31 @@ InspectorTest.runAsyncTestSuite([
const pauseResult = await Protocol.Debugger.pause();
InspectorTest.log(
`Pause error(?) after re-enable: ${pauseResult?.error?.message}`);
}
},
async function testSessionStopDoesNotDisableOtherSessions() {
let contextGroup = new InspectorTest.ContextGroup();
let session1 = contextGroup.connect();
let Protocol1 = session1.Protocol;
await Protocol1.Debugger.enable();
let session2 = contextGroup.connect();
let Protocol2 = session2.Protocol;
await Protocol2.Debugger.enable();
session1.stop();
const pauseResult1 = await Protocol1.Debugger.pause();
InspectorTest.log(
`Session 1 pause error after stop: ${pauseResult1?.error?.message}`);
await Protocol2.Debugger.pause();
const paused = Protocol2.Debugger.oncePaused();
const result = Protocol2.Runtime.evaluate({expression: '42'});
InspectorTest.log(`Session 2 paused: ${(await paused).params.reason}`);
await Protocol2.Debugger.resume();
InspectorTest.log(
`Session 2 evaluation: ${(await result).result.result.value}`);
},
]);

View File

@ -279,13 +279,12 @@ class UtilsExtension : public InspectorIsolateData::SetupGlobalTask {
static void Stop(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1 || !args[0]->IsInt32()) {
FATAL("Internal error: stop(context_group_id).");
FATAL("Internal error: stop(session_id).");
}
int context_group_id = args[0].As<v8::Int32>()->Value();
RunSyncTask(backend_runner_,
[&context_group_id](InspectorIsolateData* data) {
data->Stop(context_group_id);
});
int session_id = args[0].As<v8::Int32>()->Value();
RunSyncTask(backend_runner_, [&session_id](InspectorIsolateData* data) {
data->Stop(session_id);
});
}
static void SetLogConsoleApiMessageCalls(

View File

@ -201,12 +201,10 @@ void InspectorIsolateData::BreakProgram(
}
}
void InspectorIsolateData::Stop(int context_group_id) {
void InspectorIsolateData::Stop(int session_id) {
v8::SealHandleScope seal_handle_scope(isolate());
for (int session_id : GetSessionIds(context_group_id)) {
auto it = sessions_.find(session_id);
if (it != sessions_.end()) it->second->stop();
}
auto it = sessions_.find(session_id);
if (it != sessions_.end()) it->second->stop();
}
void InspectorIsolateData::SchedulePauseOnNextStatement(

View File

@ -78,7 +78,7 @@ class InspectorIsolateData : public v8_inspector::V8InspectorClient {
void BreakProgram(int context_group_id,
const v8_inspector::StringView& reason,
const v8_inspector::StringView& details);
void Stop(int context_group_id);
void Stop(int session_id);
void SchedulePauseOnNextStatement(int context_group_id,
const v8_inspector::StringView& reason,
const v8_inspector::StringView& details);

View File

@ -160,10 +160,6 @@ InspectorTest.ContextGroup = class {
utils.cancelPauseOnNextStatement(this.id);
}
stop() {
utils.stop(this.id);
}
addScript(string, lineOffset, columnOffset, url) {
utils.compileAndRunWithOrigin(this.id, string, url || '', lineOffset || 0, columnOffset || 0, false);
}
@ -268,6 +264,10 @@ InspectorTest.Session = class {
utils.sendMessageToBackend(this.id, command);
}
stop() {
utils.stop(this.id);
}
setupScriptMap() {
if (this._scriptMap)
return;