Skip to content

Commit 052d583

Browse files
authored
Fix debug command test (#1287)
* Fix debug command test * Timing issue waiting for the debug configuration to be created, but we should not have to do this * Using existing launch config, the adapter tracker was waiting for "swift-lldb" but we fallback to the "lldb" type for swift versions < 6.0 Issue: #1269 * Don't disable ASLR for Linux
1 parent 9d1c700 commit 052d583

File tree

4 files changed

+56
-42
lines changed

4 files changed

+56
-42
lines changed

assets/test/.vscode/launch.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"program": "${workspaceFolder:test}/defaultPackage/.build/debug/PackageExe",
88
"args": [],
99
"cwd": "${workspaceFolder:test}/defaultPackage",
10-
"preLaunchTask": "swift: Build Debug PackageExe (defaultPackage)"
10+
"preLaunchTask": "swift: Build Debug PackageExe (defaultPackage)",
11+
"disableASLR": false,
12+
"initCommands": ["settings set target.disable-aslr false"],
1113
},
1214
{
1315
"type": "swift-lldb",
@@ -16,7 +18,9 @@
1618
"program": "${workspaceFolder:test}/defaultPackage/.build/release/PackageExe",
1719
"args": [],
1820
"cwd": "${workspaceFolder:test}/defaultPackage",
19-
"preLaunchTask": "swift: Build Release PackageExe (defaultPackage)"
21+
"preLaunchTask": "swift: Build Release PackageExe (defaultPackage)",
22+
"disableASLR": false,
23+
"initCommands": ["settings set target.disable-aslr false"],
2024
}
2125
]
2226
}

test/integration-tests/SwiftSnippet.test.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ suite("SwiftSnippet Test Suite @slow", function () {
5050
workspaceContext = ctx;
5151

5252
const folder = await folderInRootWorkspace("defaultPackage", workspaceContext);
53-
if (folder.workspaceContext.toolchain.swiftVersion.isLessThan(new Version(6, 0, 0))) {
53+
if (folder.workspaceContext.toolchain.swiftVersion.isLessThan(new Version(5, 9, 0))) {
5454
this.skip();
5555
}
5656
await waitForNoRunningTasks();
@@ -83,7 +83,11 @@ suite("SwiftSnippet Test Suite @slow", function () {
8383
});
8484

8585
test("Run `Swift: Debug Swift Snippet` command for snippet file", async () => {
86-
const bpPromise = waitForDebugAdapterRequest("Run hello", "stackTrace");
86+
const bpPromise = waitForDebugAdapterRequest(
87+
"Run hello",
88+
workspaceContext.toolchain.swiftVersion,
89+
"stackTrace"
90+
);
8791
const sessionPromise = waitUntilDebugSessionTerminates("Run hello");
8892

8993
const succeeded = vscode.commands.executeCommand("swift.debugSnippet");

test/integration-tests/commands/build.test.ts

+11-18
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,14 @@ import { testAssetUri } from "../../fixtures";
2121
import { FolderContext } from "../../../src/FolderContext";
2222
import { WorkspaceContext } from "../../../src/WorkspaceContext";
2323
import { Commands } from "../../../src/commands";
24-
import { makeDebugConfigurations } from "../../../src/debugger/launch";
2524
import { Workbench } from "../../../src/utilities/commands";
2625
import { continueSession, waitForDebugAdapterRequest } from "../../utilities/debug";
27-
import {
28-
activateExtensionForSuite,
29-
folderInRootWorkspace,
30-
updateSettings,
31-
} from "../utilities/testutilities";
26+
import { activateExtensionForSuite, folderInRootWorkspace } from "../utilities/testutilities";
27+
import { Version } from "../../../src/utilities/version";
3228

33-
suite("Build Commands", function () {
29+
suite("Build Commands @slow", function () {
3430
// Default timeout is a bit too short, give it a little bit more time
35-
this.timeout(120 * 1000);
31+
this.timeout(2 * 60 * 1000);
3632

3733
let folderContext: FolderContext;
3834
let workspaceContext: WorkspaceContext;
@@ -43,10 +39,11 @@ suite("Build Commands", function () {
4339

4440
activateExtensionForSuite({
4541
async setup(ctx) {
46-
// The description of this package is crashing on Windows with Swift 5.9.x and below,
47-
// preventing it from being built. The cleanup in the teardown is failng as well with
48-
// an EBUSY error. Skip this test on Windows until the issue is resolved.
49-
if (process.platform === "win32") {
42+
// The description of this package is crashing on Windows with Swift 5.9.x and below
43+
if (
44+
process.platform === "win32" &&
45+
ctx.toolchain.swiftVersion.isLessThan(new Version(6, 0, 0))
46+
) {
5047
this.skip();
5148
}
5249

@@ -55,11 +52,6 @@ suite("Build Commands", function () {
5552
folderContext = await folderInRootWorkspace("defaultPackage", workspaceContext);
5653
await workspaceContext.focusFolder(folderContext);
5754
await vscode.window.showTextDocument(uri);
58-
const settingsTeardown = await updateSettings({
59-
"swift.autoGenerateLaunchConfigurations": true,
60-
});
61-
await makeDebugConfigurations(folderContext, undefined, true);
62-
return settingsTeardown;
6355
},
6456
async teardown() {
6557
await vscode.commands.executeCommand(Workbench.ACTION_CLOSEALLEDITORS);
@@ -92,13 +84,14 @@ suite("Build Commands", function () {
9284
expect(afterItemCount).to.be.lessThan(beforeItemCount);
9385
});
9486

95-
test("Swift: Debug Build @slow", async () => {
87+
test("Swift: Debug Build", async () => {
9688
vscode.debug.addBreakpoints(breakpoints);
9789
// Promise used to indicate we hit the break point.
9890
// NB: "stopped" is the exact command when debuggee has stopped due to break point,
9991
// but "stackTrace" is the deterministic sync point we will use to make sure we can execute continue
10092
const bpPromise = waitForDebugAdapterRequest(
10193
"Debug PackageExe (defaultPackage)",
94+
workspaceContext.toolchain.swiftVersion,
10295
"stackTrace"
10396
);
10497

test/utilities/debug.ts

+33-20
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import * as vscode from "vscode";
1515
import { DebugProtocol } from "@vscode/debugprotocol";
1616
import { Workbench } from "../../src/utilities/commands";
17+
import { DebugAdapter } from "../../src/debugger/debugAdapter";
18+
import { Version } from "../../src/utilities/version";
1719

1820
export async function continueSession(): Promise<void> {
1921
await vscode.commands.executeCommand(Workbench.ACTION_DEBUG_CONTINUE);
@@ -29,26 +31,30 @@ export async function continueSession(): Promise<void> {
2931
*/
3032
export async function waitForDebugAdapterMessage<T extends DebugProtocol.ProtocolMessage>(
3133
name: string,
34+
version: Version,
3235
matches: (message: T) => boolean
3336
): Promise<T> {
3437
return await new Promise<T>(res => {
35-
const disposable = vscode.debug.registerDebugAdapterTrackerFactory("swift-lldb", {
36-
createDebugAdapterTracker: function (
37-
session: vscode.DebugSession
38-
): vscode.ProviderResult<vscode.DebugAdapterTracker> {
39-
if (session.name !== name) {
40-
return;
41-
}
42-
return {
43-
onDidSendMessage(message) {
44-
if (matches(message)) {
45-
disposable.dispose();
46-
res(message);
47-
}
48-
},
49-
};
50-
},
51-
});
38+
const disposable = vscode.debug.registerDebugAdapterTrackerFactory(
39+
DebugAdapter.getLaunchConfigType(version),
40+
{
41+
createDebugAdapterTracker: function (
42+
session: vscode.DebugSession
43+
): vscode.ProviderResult<vscode.DebugAdapterTracker> {
44+
if (session.name !== name) {
45+
return;
46+
}
47+
return {
48+
onDidSendMessage(message) {
49+
if (matches(message)) {
50+
disposable.dispose();
51+
res(message);
52+
}
53+
},
54+
};
55+
},
56+
}
57+
);
5258
});
5359
}
5460

@@ -78,10 +84,12 @@ export async function waitUntilDebugSessionTerminates(name: string): Promise<vsc
7884
*/
7985
export async function waitForDebugAdapterRequest(
8086
name: string,
87+
version: Version,
8188
command: string
8289
): Promise<DebugProtocol.Request> {
8390
return await waitForDebugAdapterMessage(
8491
name,
92+
version,
8593
(m: DebugProtocol.Request) => m.command === command
8694
);
8795
}
@@ -96,9 +104,14 @@ export async function waitForDebugAdapterRequest(
96104
*/
97105
export async function waitForDebugAdapterEvent(
98106
name: string,
107+
version: Version,
99108
event: string
100109
): Promise<DebugProtocol.Event> {
101-
return await waitForDebugAdapterMessage(name, (m: DebugProtocol.Event) => m.event === event);
110+
return await waitForDebugAdapterMessage(
111+
name,
112+
version,
113+
(m: DebugProtocol.Event) => m.event === event
114+
);
102115
}
103116

104117
/**
@@ -107,7 +120,7 @@ export async function waitForDebugAdapterEvent(
107120
* @param name The name of the debug session to wait for.
108121
* @returns exit code of the DAP
109122
*/
110-
export async function waitForDebugAdapterExit(name: string): Promise<number> {
111-
const message = await waitForDebugAdapterEvent(name, "exited");
123+
export async function waitForDebugAdapterExit(name: string, version: Version): Promise<number> {
124+
const message = await waitForDebugAdapterEvent(name, version, "exited");
112125
return message.body.exitCode;
113126
}

0 commit comments

Comments
 (0)