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

allow a way to run jobs in parallel #3271

Merged
merged 10 commits into from
Aug 1, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Bug Fixes:
- Fix triggers of "Bad CMake Executable" error message. [#2368](https://github.com/microsoft/vscode-cmake-tools/issues/2368)
- Don't ignore empty cache string variables when configuring from presets. [#1842](https://github.com/microsoft/vscode-cmake-tools/issues/1842)
- Fix active build configuration warning coming from CppTools. [#2353](https://github.com/microsoft/vscode-cmake-tools/issues/2353)
- Allow a way to run ctests in parallel by setting `cmake.ctest.allowParallelJobs` to `true`. [#3271](https://github.com/microsoft/vscode-cmake-tools/pull/3271)
snehara99 marked this conversation as resolved.
Show resolved Hide resolved

Improvements:
- Decreased the number of cases where we reconfigure erroneously upon usage of `cmake.getLaunchTargetPath`. [#2878](https://github.com/microsoft/vscode-cmake-tools/issues/2878)
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,12 @@
"description": "%cmake-tools.configuration.cmake.ctest.parallelJobs.description%",
"scope": "resource"
},
"cmake.ctest.allowParallelJobs": {
"type": "boolean",
"default": false,
"description": "%cmake-tools.configuration.cmake.ctest.allowParallelJobs.description%",
"scope": "window"
snehara99 marked this conversation as resolved.
Show resolved Hide resolved
},
"cmake.parseBuildDiagnostics": {
"type": "boolean",
"default": true,
Expand Down
6 changes: 5 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@
"cmake-tools.configuration.cmake.buildToolArgs.description": "Additional arguments to pass to the underlying build tool when building.",
"cmake-tools.configuration.cmake.parallelJobs.description": "The number of parallel build jobs. Use zero to automatically detect the number of CPUs. Setting this to 1 will omit the parallelism flag (-j) from the underlying build command, which has a generator-dependent effect on build parallelism.",
"cmake-tools.configuration.cmake.ctestPath.description": "Path to CTest executable. If null, will be inferred from cmake.cmakePath (recommended to leave null).",
"cmake-tools.configuration.cmake.ctest.parallelJobs.description": "The number of parallel test jobs. Use zero to use the value of cmake.parallelJobs.",
"cmake-tools.configuration.cmake.ctest.parallelJobs.description": {
"message": "The number of parallel test jobs. Use zero to use the value of cmake.parallelJobs. This only works when `#cmake.ctest.allowParallelJobs` is set to `true`.",
"comment": "Markdown text between `` should not be translated or localized (they represent literal text) and the capitalization, spacing, and punctuation (including the ``) should not be altered."
},
"cmake-tools.configuration.cmake.ctest.allowParallelJobs.description": "Allows ctests to be run in parallel, however the result output may be garbled as a result.",
"cmake-tools.configuration.cmake.parseBuildDiagnostics.description": "Parse compiler output for warnings and errors.",
"cmake-tools.configuration.cmake.enabledOutputParsers.description": {
"message": "Output parsers to use. Supported parsers `cmake`, `gcc`, `gnuld` for GNULD-style linker output, `msvc` for Microsoft Visual C++, `ghs` for the Green Hills compiler with --no_wrap_diagnostics --brief_diagnostics, and `diab` for the Wind River Diab compiler.",
Expand Down
9 changes: 7 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ export interface ExtensionConfigurationSettings {
buildArgs: string[];
buildToolArgs: string[];
parallelJobs: number | undefined;
allowParallelJobs: boolean;
ctestPath: string;
ctest: { parallelJobs: number };
ctest: { parallelJobs: number; allowParallelJobs: boolean };
parseBuildDiagnostics: boolean;
enabledOutputParsers: string[];
debugConfig: CppDebugConfiguration;
Expand Down Expand Up @@ -301,6 +302,9 @@ export class ConfigurationReader implements vscode.Disposable {
get ctestParallelJobs(): number | null {
return this.configData.ctest.parallelJobs;
}
get ctestAllowParallelJobs(): boolean {
return this.configData.ctest.allowParallelJobs;
}
get parseBuildDiagnostics(): boolean {
return !!this.configData.parseBuildDiagnostics;
}
Expand Down Expand Up @@ -483,8 +487,9 @@ export class ConfigurationReader implements vscode.Disposable {
buildArgs: new vscode.EventEmitter<string[]>(),
buildToolArgs: new vscode.EventEmitter<string[]>(),
parallelJobs: new vscode.EventEmitter<number>(),
allowParallelJobs: new vscode.EventEmitter<boolean>(),
ctestPath: new vscode.EventEmitter<string>(),
ctest: new vscode.EventEmitter<{ parallelJobs: number }>(),
ctest: new vscode.EventEmitter<{ parallelJobs: number; allowParallelJobs: boolean }>(),
parseBuildDiagnostics: new vscode.EventEmitter<boolean>(),
enabledOutputParsers: new vscode.EventEmitter<string[]>(),
debugConfig: new vscode.EventEmitter<CppDebugConfiguration>(),
Expand Down
50 changes: 49 additions & 1 deletion src/ctest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,61 @@ export class CTestDriver implements vscode.Disposable {
if (!testExplorer) {
log.info(localize('no.tests.found', 'No tests found'));
return -1;
} else {
} else if (!this.ws.config.ctestAllowParallelJobs) {
const tests = this.testItemCollectionToArray(testExplorer.items);
const run = testExplorer.createTestRun(new vscode.TestRunRequest());
const ctestArgs = await this.getCTestArgs(driver, customizedTask, testPreset);
const returnCode = await this.runCTestHelper(tests, run, driver, undefined, ctestArgs, undefined, customizedTask, consumer);
run.end();
return returnCode;
} else {
// below code taken from #3032 PR (before changes in how tests are run)
const ctestpath = await this.ws.getCTestPath(driver.cmakePathFromPreset);
if (ctestpath === null) {
log.info(localize('ctest.path.not.set', 'CTest path is not set'));
return -2;
}

let ctestArgs: string[];
if (customizedTask && testPreset) {
ctestArgs = ['-T', 'test'].concat(testArgs(testPreset));
} else if (!customizedTask && driver.useCMakePresets) {
if (!driver.testPreset) {
log.error(localize('test.preset.not.set', 'Test preset is not set'));
return -3;
}
// Add a few more args so we can show the result in status bar
ctestArgs = ['-T', 'test'].concat(testArgs(driver.testPreset));
} else {
const configuration = driver.currentBuildType;
const opts = driver.expansionOptions;
const jobs = await expandString(this.ws.config.numCTestJobs, opts);
const defaultArgs = [];
for (const value of this.ws.config.ctestDefaultArgs) {
defaultArgs.push(await expandString(value, opts));
}
const args = [];
for (const value of this.ws.config.ctestArgs) {
args.push(await expandString(value, opts));
}
ctestArgs = [`-j${jobs}`, '-C', configuration].concat(defaultArgs, args);
}

const child = driver.executeCommand(
ctestpath,
ctestArgs,
((customizedTask && consumer) ? consumer : new CTestOutputLogger()),
{ environment: await driver.getCTestCommandEnvironment(), cwd: driver.binaryDir });
const res = await child.result;
// not sure if direct comparison can be made to replace reloadTests with refreshTests
await this.refreshTests(driver);
if (res.retc === null) {
log.info(localize('ctest.run.terminated', 'CTest run was terminated'));
return -1;
} else {
log.info(localize('ctest.finished.with.code', 'CTest finished with return code {0}', res.retc));
}
return res.retc;
}
}

Expand Down
4 changes: 3 additions & 1 deletion test/unit-tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ function createConfig(conf: Partial<ExtensionConfigurationSettings>): Configurat
buildArgs: [],
buildToolArgs: [],
parallelJobs: 0,
allowParallelJobs: false,
snehara99 marked this conversation as resolved.
Show resolved Hide resolved
ctestPath: '',
ctest: {
parallelJobs: 0
parallelJobs: 0,
allowParallelJobs: false
},
parseBuildDiagnostics: true,
enabledOutputParsers: [],
Expand Down
Loading