Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix debug command test #1287

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions assets/test/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"program": "${workspaceFolder:test}/defaultPackage/.build/debug/PackageExe",
"args": [],
"cwd": "${workspaceFolder:test}/defaultPackage",
"preLaunchTask": "swift: Build Debug PackageExe (defaultPackage)"
"preLaunchTask": "swift: Build Debug PackageExe (defaultPackage)",
"disableASLR": false,
"initCommands": ["settings set target.disable-aslr false"],
},
{
"type": "swift-lldb",
Expand All @@ -16,7 +18,9 @@
"program": "${workspaceFolder:test}/defaultPackage/.build/release/PackageExe",
"args": [],
"cwd": "${workspaceFolder:test}/defaultPackage",
"preLaunchTask": "swift: Build Release PackageExe (defaultPackage)"
"preLaunchTask": "swift: Build Release PackageExe (defaultPackage)",
"disableASLR": false,
"initCommands": ["settings set target.disable-aslr false"],
}
]
}
8 changes: 6 additions & 2 deletions test/integration-tests/SwiftSnippet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ suite("SwiftSnippet Test Suite @slow", function () {
workspaceContext = ctx;

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

test("Run `Swift: Debug Swift Snippet` command for snippet file", async () => {
const bpPromise = waitForDebugAdapterRequest("Run hello", "stackTrace");
const bpPromise = waitForDebugAdapterRequest(
"Run hello",
workspaceContext.toolchain.swiftVersion,
"stackTrace"
);
const sessionPromise = waitUntilDebugSessionTerminates("Run hello");

const succeeded = vscode.commands.executeCommand("swift.debugSnippet");
Expand Down
29 changes: 11 additions & 18 deletions test/integration-tests/commands/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@ import { testAssetUri } from "../../fixtures";
import { FolderContext } from "../../../src/FolderContext";
import { WorkspaceContext } from "../../../src/WorkspaceContext";
import { Commands } from "../../../src/commands";
import { makeDebugConfigurations } from "../../../src/debugger/launch";
import { Workbench } from "../../../src/utilities/commands";
import { continueSession, waitForDebugAdapterRequest } from "../../utilities/debug";
import {
activateExtensionForSuite,
folderInRootWorkspace,
updateSettings,
} from "../utilities/testutilities";
import { activateExtensionForSuite, folderInRootWorkspace } from "../utilities/testutilities";
import { Version } from "../../../src/utilities/version";

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

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

activateExtensionForSuite({
async setup(ctx) {
// The description of this package is crashing on Windows with Swift 5.9.x and below,
// preventing it from being built. The cleanup in the teardown is failng as well with
// an EBUSY error. Skip this test on Windows until the issue is resolved.
if (process.platform === "win32") {
// The description of this package is crashing on Windows with Swift 5.9.x and below
award999 marked this conversation as resolved.
Show resolved Hide resolved
if (
process.platform === "win32" &&
ctx.toolchain.swiftVersion.isLessThan(new Version(6, 0, 0))
) {
this.skip();
}

Expand All @@ -55,11 +52,6 @@ suite("Build Commands", function () {
folderContext = await folderInRootWorkspace("defaultPackage", workspaceContext);
await workspaceContext.focusFolder(folderContext);
await vscode.window.showTextDocument(uri);
const settingsTeardown = await updateSettings({
"swift.autoGenerateLaunchConfigurations": true,
});
await makeDebugConfigurations(folderContext, undefined, true);
return settingsTeardown;
},
async teardown() {
await vscode.commands.executeCommand(Workbench.ACTION_CLOSEALLEDITORS);
Expand Down Expand Up @@ -92,13 +84,14 @@ suite("Build Commands", function () {
expect(afterItemCount).to.be.lessThan(beforeItemCount);
});

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

Expand Down
53 changes: 33 additions & 20 deletions test/utilities/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import * as vscode from "vscode";
import { DebugProtocol } from "@vscode/debugprotocol";
import { Workbench } from "../../src/utilities/commands";
import { DebugAdapter } from "../../src/debugger/debugAdapter";
import { Version } from "../../src/utilities/version";

export async function continueSession(): Promise<void> {
await vscode.commands.executeCommand(Workbench.ACTION_DEBUG_CONTINUE);
Expand All @@ -29,26 +31,30 @@ export async function continueSession(): Promise<void> {
*/
export async function waitForDebugAdapterMessage<T extends DebugProtocol.ProtocolMessage>(
name: string,
version: Version,
matches: (message: T) => boolean
): Promise<T> {
return await new Promise<T>(res => {
const disposable = vscode.debug.registerDebugAdapterTrackerFactory("swift-lldb", {
createDebugAdapterTracker: function (
session: vscode.DebugSession
): vscode.ProviderResult<vscode.DebugAdapterTracker> {
if (session.name !== name) {
return;
}
return {
onDidSendMessage(message) {
if (matches(message)) {
disposable.dispose();
res(message);
}
},
};
},
});
const disposable = vscode.debug.registerDebugAdapterTrackerFactory(
DebugAdapter.getLaunchConfigType(version),
{
createDebugAdapterTracker: function (
session: vscode.DebugSession
): vscode.ProviderResult<vscode.DebugAdapterTracker> {
if (session.name !== name) {
return;
}
return {
onDidSendMessage(message) {
if (matches(message)) {
disposable.dispose();
res(message);
}
},
};
},
}
);
});
}

Expand Down Expand Up @@ -78,10 +84,12 @@ export async function waitUntilDebugSessionTerminates(name: string): Promise<vsc
*/
export async function waitForDebugAdapterRequest(
name: string,
version: Version,
command: string
): Promise<DebugProtocol.Request> {
return await waitForDebugAdapterMessage(
name,
version,
(m: DebugProtocol.Request) => m.command === command
);
}
Expand All @@ -96,9 +104,14 @@ export async function waitForDebugAdapterRequest(
*/
export async function waitForDebugAdapterEvent(
name: string,
version: Version,
event: string
): Promise<DebugProtocol.Event> {
return await waitForDebugAdapterMessage(name, (m: DebugProtocol.Event) => m.event === event);
return await waitForDebugAdapterMessage(
name,
version,
(m: DebugProtocol.Event) => m.event === event
);
}

/**
Expand All @@ -107,7 +120,7 @@ export async function waitForDebugAdapterEvent(
* @param name The name of the debug session to wait for.
* @returns exit code of the DAP
*/
export async function waitForDebugAdapterExit(name: string): Promise<number> {
const message = await waitForDebugAdapterEvent(name, "exited");
export async function waitForDebugAdapterExit(name: string, version: Version): Promise<number> {
const message = await waitForDebugAdapterEvent(name, version, "exited");
return message.body.exitCode;
}
Loading