Skip to content

Commit acf8084

Browse files
Fix nightly debugging test failures (#1388)
* change "swift-lldb" debug configs to "swift" in tests * add option to disable CodeLLDB settings prompt * don't use liblldb on Swift versions <5.10 * disable flaky dependency tests until they can be fixed * bump timeout for package resolve v2 test
1 parent 5550413 commit acf8084

File tree

12 files changed

+111
-48
lines changed

12 files changed

+111
-48
lines changed

assets/test/.vscode/launch.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"configurations": [
33
{
4-
"type": "swift-lldb",
4+
"type": "swift",
55
"request": "launch",
66
"name": "Debug PackageExe (defaultPackage)",
77
"program": "${workspaceFolder:test}/defaultPackage/.build/debug/PackageExe",
@@ -12,7 +12,7 @@
1212
"initCommands": ["settings set target.disable-aslr false"],
1313
},
1414
{
15-
"type": "swift-lldb",
15+
"type": "swift",
1616
"request": "launch",
1717
"name": "Release PackageExe (defaultPackage)",
1818
"program": "${workspaceFolder:test}/defaultPackage/.build/release/PackageExe",

assets/test/.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"swift.disableAutoResolve": true,
33
"swift.autoGenerateLaunchConfigurations": false,
4-
"swift.debugger.useDebugAdapterFromToolchain": true,
4+
"swift.debugger.debugAdapter": "lldb-dap",
5+
"swift.debugger.setupCodeLLDB": "alwaysUpdateGlobal",
56
"swift.additionalTestArguments": [
67
"-Xswiftc",
78
"-DTEST_ARGUMENT_SET_VIA_TEST_BUILD_ARGUMENTS_SETTING"

assets/test/defaultPackage/.vscode/launch.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"configurations": [
33
{
4-
"type": "swift-lldb",
4+
"type": "swift",
55
"request": "launch",
66
"name": "Debug package1",
77
"program": "${workspaceFolder:defaultPackage}/.build/debug/package1",
@@ -10,7 +10,7 @@
1010
"preLaunchTask": "swift: Build Debug package1"
1111
},
1212
{
13-
"type": "swift-lldb",
13+
"type": "swift",
1414
"request": "launch",
1515
"name": "Release package1",
1616
"program": "${workspaceFolder:defaultPackage}/.build/release/package1",

assets/test/diagnostics/.vscode/launch.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"configurations": [
33
{
4-
"type": "swift-lldb",
4+
"type": "swift",
55
"request": "launch",
66
"args": [],
77
"cwd": "${workspaceFolder:diagnostics}",
@@ -10,7 +10,7 @@
1010
"preLaunchTask": "swift: Build Debug diagnostics"
1111
},
1212
{
13-
"type": "swift-lldb",
13+
"type": "swift",
1414
"request": "launch",
1515
"args": [],
1616
"cwd": "${workspaceFolder:diagnostics}",
@@ -19,7 +19,7 @@
1919
"preLaunchTask": "swift: Build Release diagnostics"
2020
},
2121
{
22-
"type": "swift-lldb",
22+
"type": "swift",
2323
"request": "launch",
2424
"args": [],
2525
"cwd": "${workspaceFolder:diagnostics}",
@@ -28,7 +28,7 @@
2828
"preLaunchTask": "swift: Build Debug diagnostics"
2929
},
3030
{
31-
"type": "swift-lldb",
31+
"type": "swift",
3232
"request": "launch",
3333
"args": [],
3434
"cwd": "${workspaceFolder:diagnostics}",

package.json

+26-7
Original file line numberDiff line numberDiff line change
@@ -673,20 +673,39 @@
673673
"Use the `lldb-dap` executable from the toolchain. Requires Swift 6 or later.",
674674
"Use the CodeLLDB extension's debug adapter."
675675
],
676-
"order": 1
677-
},
678-
"swift.debugger.useDebugAdapterFromToolchain": {
679-
"type": "boolean",
680-
"default": false,
681-
"markdownDeprecationMessage": "**Deprecated**: Use the `swift.debugger.debugAdapter` setting instead. This will be removed in future versions of the Swift extension.",
682-
"markdownDescription": "Use the LLDB debug adapter packaged with the Swift toolchain as your debug adapter. Note: this is only available starting with Swift 6. The CodeLLDB extension will be used if your Swift toolchain does not contain lldb-dap.",
676+
"markdownDescription": "Select which debug adapter to use to debus Swift executables.",
683677
"order": 1
684678
},
685679
"swift.debugger.path": {
686680
"type": "string",
687681
"default": "",
688682
"markdownDescription": "Path to lldb debug adapter.",
689683
"order": 2
684+
},
685+
"swift.debugger.setupCodeLLDB": {
686+
"type": "string",
687+
"default": "prompt",
688+
"enum": [
689+
"prompt",
690+
"alwaysUpdateGlobal",
691+
"alwaysUpdateWorkspace",
692+
"never"
693+
],
694+
"enumDescriptions": [
695+
"Prompt to update CodeLLDB settings when they are incorrect.",
696+
"Always automatically update CodeLLDB settings globally when they are incorrect.",
697+
"Always automatically update CodeLLDB settings in the workspace when they are incorrect.",
698+
"Never automatically update CodeLLDB settings when they are incorrect."
699+
],
700+
"markdownDescription": "Choose how CodeLLDB settings are updated when debugging Swift executables.",
701+
"order": 3
702+
},
703+
"swift.debugger.useDebugAdapterFromToolchain": {
704+
"type": "boolean",
705+
"default": false,
706+
"markdownDeprecationMessage": "**Deprecated**: Use the `swift.debugger.debugAdapter` setting instead. This will be removed in future versions of the Swift extension.",
707+
"markdownDescription": "Use the LLDB debug adapter packaged with the Swift toolchain as your debug adapter. Note: this is only available starting with Swift 6. The CodeLLDB extension will be used if your Swift toolchain does not contain lldb-dap.",
708+
"order": 4
690709
}
691710
}
692711
},

src/configuration.ts

+12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
import * as vscode from "vscode";
1616

1717
export type DebugAdapters = "auto" | "lldb-dap" | "CodeLLDB";
18+
export type SetupCodeLLDBOptions =
19+
| "prompt"
20+
| "alwaysUpdateGlobal"
21+
| "alwaysUpdateWorkspace"
22+
| "never";
1823
export type CFamilySupportOptions = "enable" | "disable" | "cpptools-inactive";
1924
export type ActionAfterBuildError = "Focus Problems" | "Focus Terminal" | "Do Nothing";
2025
export type OpenAfterCreateNewProjectOptions =
@@ -54,6 +59,8 @@ export interface DebuggerConfiguration {
5459
readonly customDebugAdapterPath: string;
5560
/** Whether or not to disable setting up the debugger */
5661
readonly disable: boolean;
62+
/** User choices for updating CodeLLDB settings */
63+
readonly setupCodeLLDB: SetupCodeLLDBOptions;
5764
}
5865

5966
/** workspace folder configuration */
@@ -219,6 +226,11 @@ const configuration = {
219226
.getConfiguration("swift.debugger")
220227
.get<boolean>("disable", false);
221228
},
229+
get setupCodeLLDB(): SetupCodeLLDBOptions {
230+
return vscode.workspace
231+
.getConfiguration("swift.debugger")
232+
.get<SetupCodeLLDBOptions>("setupCodeLLDB", "prompt");
233+
},
222234
};
223235
},
224236
/** Files and directories to exclude from the code coverage. */

src/debugger/debugAdapterFactory.ts

+22-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { SwiftOutputChannel } from "../ui/SwiftOutputChannel";
2222
import { fileExists } from "../utilities/filesystem";
2323
import { getLLDBLibPath } from "./lldb";
2424
import { getErrorDescription } from "../utilities/utilities";
25+
import configuration from "../configuration";
2526

2627
/**
2728
* Registers the active debugger with the extension, and reregisters it
@@ -172,13 +173,27 @@ export class LLDBDebugConfigurationProvider implements vscode.DebugConfiguration
172173
) {
173174
return;
174175
}
175-
const userSelection = await vscode.window.showInformationMessage(
176-
"The Swift extension needs to update some CodeLLDB settings to enable debugging features. Do you want to set this up in your global settings or workspace settings?",
177-
{ modal: true },
178-
"Global",
179-
"Workspace",
180-
"Run Anyway"
181-
);
176+
let userSelection: "Global" | "Workspace" | "Run Anyway" | undefined = undefined;
177+
switch (configuration.debugger.setupCodeLLDB) {
178+
case "prompt":
179+
userSelection = await vscode.window.showInformationMessage(
180+
"The Swift extension needs to update some CodeLLDB settings to enable debugging features. Do you want to set this up in your global settings or workspace settings?",
181+
{ modal: true },
182+
"Global",
183+
"Workspace",
184+
"Run Anyway"
185+
);
186+
break;
187+
case "alwaysUpdateGlobal":
188+
userSelection = "Global";
189+
break;
190+
case "alwaysUpdateWorkspace":
191+
userSelection = "Workspace";
192+
break;
193+
case "never":
194+
userSelection = "Run Anyway";
195+
break;
196+
}
182197
switch (userSelection) {
183198
case "Global":
184199
lldbConfig.update("library", libLldbPath, vscode.ConfigurationTarget.Global);

test/integration-tests/SwiftPackage.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ suite("SwiftPackage Test Suite", () => {
5959
const spmPackage = await SwiftPackage.create(testAssetUri("package5.6"), toolchain);
6060
assert.strictEqual(spmPackage.isValid, true);
6161
assert(spmPackage.resolved !== undefined);
62-
}).timeout(15000);
62+
}).timeout(20000);
6363

6464
test("Identity case-insensitivity", async () => {
6565
const spmPackage = await SwiftPackage.create(testAssetUri("identity-case"), toolchain);

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ suite("Dependency Commmands Test Suite", function () {
106106
}
107107

108108
test("Swift: Reset Package Dependencies", async function () {
109+
this.skip(); // https://github.com/swiftlang/vscode-swift/issues/1316
109110
// spm reset after using local dependency is broken on windows
110111
if (process.platform === "win32") {
111112
this.skip();
@@ -121,7 +122,8 @@ suite("Dependency Commmands Test Suite", function () {
121122
expect(dep?.type).to.equal("remote");
122123
});
123124

124-
test("Swift: Revert To Original Version", async () => {
125+
test("Swift: Revert To Original Version", async function () {
126+
this.skip(); // https://github.com/swiftlang/vscode-swift/issues/1316
125127
await useLocalDependencyTest();
126128

127129
const result = await vscode.commands.executeCommand(

test/integration-tests/testexplorer/TestExplorerIntegration.test.ts

+1-23
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import {
4646
updateSettings,
4747
} from "../utilities/testutilities";
4848
import { Commands } from "../../../src/commands";
49-
import { SwiftToolchain } from "../../../src/toolchain/toolchain";
5049

5150
suite("Test Explorer Suite", function () {
5251
const MAX_TEST_RUN_TIME_MINUTES = 5;
@@ -129,36 +128,15 @@ suite("Test Explorer Suite", function () {
129128
});
130129

131130
suite("CodeLLDB", () => {
132-
async function getLLDBDebugAdapterPath() {
133-
switch (process.platform) {
134-
case "linux":
135-
return "/usr/lib/liblldb.so";
136-
case "darwin":
137-
case "win32":
138-
return await (await SwiftToolchain.create()).getLLDBDebugAdapter();
139-
default:
140-
throw new Error("Please provide the path to lldb for this platform");
141-
}
142-
}
143-
144131
let resetSettings: (() => Promise<void>) | undefined;
145132
beforeEach(async function () {
146133
// CodeLLDB on windows doesn't print output and so cannot be parsed
147134
if (process.platform === "win32") {
148135
this.skip();
149136
}
150137

151-
const lldbPath =
152-
process.env["CI"] === "1"
153-
? {
154-
"lldb.library": await getLLDBDebugAdapterPath(),
155-
"lldb.launch.expressions": "native",
156-
}
157-
: {};
158-
159138
resetSettings = await updateSettings({
160-
"swift.debugger.useDebugAdapterFromToolchain": false,
161-
...lldbPath,
139+
"swift.debugger.debugAdapter": "CodeLLDB",
162140
});
163141
});
164142

test/integration-tests/utilities/testutilities.ts

+10
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const extensionBootstrapper = (() => {
7373
) {
7474
let workspaceContext: WorkspaceContext | undefined;
7575
let autoTeardown: void | (() => Promise<void>);
76+
let restoreSettings: (() => Promise<void>) | undefined;
7677
before(async function () {
7778
// Always activate the extension. If no test assets are provided,
7879
// default to adding `defaultPackage` to the workspace.
@@ -92,6 +93,12 @@ const extensionBootstrapper = (() => {
9293
if (requiresDebugger && configuration.debugger.disable) {
9394
this.skip();
9495
}
96+
// CodeLLDB does not work with libllbd in Swift toolchains prior to 5.10
97+
if (workspaceContext.swiftVersion.isLessThan(new Version(5, 10, 0))) {
98+
restoreSettings = await updateSettings({
99+
"swift.debugger.setupCodeLLDB": "never",
100+
});
101+
}
95102
if (!setup) {
96103
return;
97104
}
@@ -121,6 +128,9 @@ const extensionBootstrapper = (() => {
121128
if (autoTeardown) {
122129
await autoTeardown();
123130
}
131+
if (restoreSettings) {
132+
await restoreSettings();
133+
}
124134
} catch (error) {
125135
if (workspaceContext) {
126136
console.error(`Error during test/suite teardown, captured logs are:`);

test/unit-tests/debugger/debugAdapterFactory.test.ts

+26
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { SwiftToolchain } from "../../../src/toolchain/toolchain";
3838
import { SwiftOutputChannel } from "../../../src/ui/SwiftOutputChannel";
3939
import * as debugAdapter from "../../../src/debugger/debugAdapter";
4040
import { Result } from "../../../src/utilities/result";
41+
import configuration from "../../../src/configuration";
4142

4243
suite("LLDBDebugAdapterExecutableFactory Tests", () => {
4344
const mockDebugAdapter = mockGlobalModule(DebugAdapter);
@@ -83,6 +84,7 @@ suite("LLDBDebugConfigurationProvider Tests", () => {
8384
suite("CodeLLDB selected in settings", () => {
8485
let mockLldbConfiguration: MockedObject<vscode.WorkspaceConfiguration>;
8586
const mockLLDB = mockGlobalModule(lldb);
87+
const mockDebuggerConfig = mockGlobalObject(configuration, "debugger");
8688
const mockWorkspace = mockGlobalObject(vscode, "workspace");
8789

8890
setup(() => {
@@ -95,6 +97,7 @@ suite("LLDBDebugConfigurationProvider Tests", () => {
9597
});
9698
mockWorkspace.getConfiguration.returns(instance(mockLldbConfiguration));
9799
mockLLDB.getLLDBLibPath.resolves(Result.makeSuccess("/path/to/liblldb.dyLib"));
100+
mockDebuggerConfig.setupCodeLLDB = "prompt";
98101
mockDebugAdapter.getLaunchConfigType.returns(LaunchConfigType.CODE_LLDB);
99102
});
100103

@@ -135,6 +138,29 @@ suite("LLDBDebugConfigurationProvider Tests", () => {
135138
"/path/to/liblldb.dyLib"
136139
);
137140
});
141+
142+
test("avoids prompting the user about CodeLLDB if requested in settings", async () => {
143+
mockDebuggerConfig.setupCodeLLDB = "alwaysUpdateGlobal";
144+
mockLldbConfiguration.get.withArgs("library").returns(undefined);
145+
const configProvider = new LLDBDebugConfigurationProvider(
146+
"darwin",
147+
instance(mockToolchain),
148+
instance(mockOutputChannel)
149+
);
150+
await expect(
151+
configProvider.resolveDebugConfiguration(undefined, {
152+
name: "Test Launch Config",
153+
type: SWIFT_LAUNCH_CONFIG_TYPE,
154+
request: "launch",
155+
program: "${workspaceFolder}/.build/debug/executable",
156+
})
157+
).to.eventually.be.an("object");
158+
expect(mockWindow.showInformationMessage).to.not.have.been.called;
159+
expect(mockLldbConfiguration.update).to.have.been.calledWith(
160+
"library",
161+
"/path/to/liblldb.dyLib"
162+
);
163+
});
138164
});
139165

140166
suite("lldb-dap selected in settings", () => {

0 commit comments

Comments
 (0)