Skip to content

Commit 212cf99

Browse files
committed
adding threading=0 plus the ability to pass random args.
1 parent 11bb059 commit 212cf99

File tree

7 files changed

+51
-17
lines changed

7 files changed

+51
-17
lines changed

src/CodeQLToolkit.Features.Test/Commands/BaseExecuteUnitTestsCommandTarget.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public abstract class BaseExecuteUnitTestsCommandTarget : CommandTarget
1414
public string RunnerOS { get; set; }
1515
public string CLIVersion { get; set; }
1616
public string STDLibIdent { get; set; }
17+
public string ExtraCodeQLArgs { get; set; }
1718
}
1819
}
1920

src/CodeQLToolkit.Features.Test/Commands/Targets/Actions/ExecuteUnitTestsCommandTarget.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public override void Run()
7272
process.StartInfo.UseShellExecute = false;
7373
process.StartInfo.RedirectStandardOutput = true;
7474
process.StartInfo.RedirectStandardError = false;
75-
process.StartInfo.Arguments = $"test run --failing-exitcode=122 --slice={slice+1}/{NumThreads} --ram=2048 --format=json --search-path={Language} {testPathString}";
75+
process.StartInfo.Arguments = $"test run {ExtraCodeQLArgs} --failing-exitcode=122 --slice={slice+1}/{NumThreads} --ram=2048 --format=json --search-path={Language} {testPathString}";
7676

7777
process.Start();
7878

src/CodeQLToolkit.Features.Test/Commands/TestCommandFeature.cs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,17 @@ public void Register(Command parentCommand)
5151
var workDirectoryOption = new Option<string>("--work-dir", () => Path.GetTempPath(), "Where to place intermediate execution output files.") { IsRequired = true };
5252
var languageOption = new Option<string>("--language", $"The language to run tests for.") { IsRequired = true }.FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray());
5353
var runnerOSOption = new Option<string>("--runner-os", $"Label for the operating system running these tests.") { IsRequired = true };
54-
var cliVersionOption = new Option<string>("--cli-version", $"The version of the cli running the tests.") { IsRequired = true };
55-
var stdLibIdentOption = new Option<string>("--stdlib-ident", $"A string identifying the standard library used.") { IsRequired = true };
54+
//var cliVersionOption = new Option<string>("--cli-version", $"The version of the cli running the tests.") { IsRequired = true };
55+
//var stdLibIdentOption = new Option<string>("--stdlib-ident", $"A string identifying the standard library used.") { IsRequired = true };
56+
var extraCodeQLOptions = new Option<string>("--codeql-args", $"Extra arguments to pass to CodeQL.") { IsRequired = false };
5657

5758
unitTestsCommand.Add(numThreadsOption);
5859
unitTestsCommand.Add(workDirectoryOption);
5960
unitTestsCommand.Add(languageOption);
6061
unitTestsCommand.Add(runnerOSOption);
61-
unitTestsCommand.Add(cliVersionOption);
62-
unitTestsCommand.Add(stdLibIdentOption);
62+
//unitTestsCommand.Add(cliVersionOption);
63+
//unitTestsCommand.Add(stdLibIdentOption);
64+
unitTestsCommand.Add(extraCodeQLOptions);
6365

6466
// a command validates the tests
6567
var validateUnitTestsCommand = new Command("validate-unit-tests", "Validates a unit test run in a fashion suitable for use in CI/CD systems.");
@@ -89,8 +91,8 @@ public void Register(Command parentCommand)
8991

9092
}, Globals.BasePathOption, Globals.AutomationTypeOption, matrixOSVersion);
9193

92-
93-
unitTestsCommand.SetHandler((basePath, automationType, numThreads, workDirectory, language, runnerOS, cliVersion, stdLibIdent) => {
94+
//stdLibIdent
95+
unitTestsCommand.SetHandler((basePath, automationType, numThreads, workDirectory, language, runnerOS, extraArgs) => {
9496

9597
Log<TestCommandFeature>.G().LogInformation("Executing execute-unit-tests command...");
9698

@@ -100,17 +102,38 @@ public void Register(Command parentCommand)
100102
AutomationTypeHelper.AutomationTypeFromString(automationType)
101103
);
102104

105+
// lookup cliVersion and stdLibIdent
106+
var c = new QLTConfig()
107+
{
108+
Base = basePath
109+
};
110+
111+
if (!File.Exists(c.CodeQLConfigFilePath))
112+
{
113+
ProcessUtils.DieWithError($"Cannot read values from missing file {c.CodeQLConfigFilePath}");
114+
}
115+
116+
var config = c.FromFile();
117+
103118
featureTarget.Base = basePath;
104119
featureTarget.NumThreads = numThreads;
105120
featureTarget.WorkDirectory = workDirectory;
106121
featureTarget.Language = language;
107122
featureTarget.RunnerOS = runnerOS;
108-
featureTarget.CLIVersion = cliVersion;
109-
featureTarget.STDLibIdent = stdLibIdent;
123+
featureTarget.CLIVersion = c.CodeQLCLI;
124+
featureTarget.STDLibIdent = c.CodeQLStandardLibrary;
125+
featureTarget.ExtraCodeQLArgs = extraArgs;
110126

111127
featureTarget.Run();
112128

113-
}, Globals.BasePathOption, Globals.AutomationTypeOption, numThreadsOption, workDirectoryOption, languageOption, runnerOSOption, cliVersionOption, stdLibIdentOption);
129+
}, Globals.BasePathOption,
130+
Globals.AutomationTypeOption,
131+
numThreadsOption,
132+
workDirectoryOption,
133+
languageOption,
134+
runnerOSOption,
135+
extraCodeQLOptions
136+
);
114137

115138

116139
validateUnitTestsCommand.SetHandler((resultsDirectory) =>

src/CodeQLToolkit.Features.Test/Lifecycle/BaseLifecycleTarget.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ abstract public class BaseLifecycleTarget : ILifecycleTarget
1111
public int NumThreads { get; set; }
1212
public string UseRunner { get; set; }
1313

14+
public string ExtraArgs { get; set; }
15+
1416
}
1517
}

src/CodeQLToolkit.Features.Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,21 @@ public override void Run()
2121
var tmpLanguage = Language;
2222
Language = null;
2323

24+
var codeqlArgs = "--threads=0";
25+
26+
if(ExtraArgs!= null && ExtraArgs.Length > 0)
27+
{
28+
codeqlArgs = $"{codeqlArgs} {ExtraArgs}";
29+
}
30+
2431
WriteTemplateIfOverwriteOrNotExists("install-codeql", Path.Combine(Base, ".github", "actions", "install-codeql", "action.yml"), "install-codeql action");
2532
WriteTemplateIfOverwriteOrNotExists("install-qlt", Path.Combine(Base, ".github", "actions", "install-qlt", "action.yml"), "install-qlt action");
2633
WriteTemplateIfOverwriteOrNotExists("run-unit-tests", Path.Combine(Base, ".github", "workflows", $"run-codeql-unit-tests-{tmpLanguage}.yml"), $"Run CodeQL Unit Tests ({Language})", new
2734
{
2835
numThreads = NumThreads,
2936
useRunner = UseRunner,
30-
language = tmpLanguage
37+
language = tmpLanguage,
38+
codeqlArgs = codeqlArgs
3139
});
3240

3341
Language = tmpLanguage;

src/CodeQLToolkit.Features.Test/Lifecycle/TestLifecycleFeature.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,20 @@ public void Register(Command parentCommand)
3737
var numThreadsOption = new Option<int>("--num-threads", () => 4, "Number of threads to use during test execution.");
3838
var useRunnerOption = new Option<string>("--use-runner", () => "ubuntu-latest", "The runner(s) to use. Should be a comma-seperated list of actions runners.");
3939
var languageOption = new Option<string>("--language", $"The language to generate automation for.") { IsRequired = true }.FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray());
40+
var extraCodeQLOptions = new Option<string>("--codeql-args", $"Extra arguments to pass to CodeQL.") { IsRequired = false };
4041

4142
initCommand.AddOption(overwriteExistingOption);
4243
initCommand.AddOption(numThreadsOption);
4344
initCommand.AddOption(useRunnerOption);
4445
initCommand.AddOption(languageOption);
45-
46+
initCommand.AddOption(extraCodeQLOptions);
4647

4748

4849
parentCommand.Add(initCommand);
4950

5051

5152

52-
initCommand.SetHandler((basePath, automationType, overwriteExisting, numThreads, useRunner, language) =>
53+
initCommand.SetHandler((basePath, automationType, overwriteExisting, numThreads, useRunner, language, extraArgs) =>
5354
{
5455
Log<TestLifecycleFeature>.G().LogInformation("Executing init command...");
5556

@@ -65,10 +66,10 @@ public void Register(Command parentCommand)
6566
featureTarget.NumThreads = numThreads;
6667
featureTarget.UseRunner = useRunner;
6768
featureTarget.Language = language;
68-
69+
featureTarget.ExtraArgs = extraArgs;
6970
featureTarget.Run();
7071

71-
}, Globals.BasePathOption, Globals.AutomationTypeOption, overwriteExistingOption, numThreadsOption, useRunnerOption, languageOption);
72+
}, Globals.BasePathOption, Globals.AutomationTypeOption, overwriteExistingOption, numThreadsOption, useRunnerOption, languageOption, extraCodeQLOptions);
7273

7374
}
7475

src/CodeQLToolkit.Features.Test/Templates/Test/Actions/run-unit-tests.liquid

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,10 @@ jobs:
8888
run: >
8989
{% endraw %}
9090
qlt test run execute-unit-tests
91+
--codeql-args "{{ codeql_args }}"
9192
--num-threads {{ num_threads }}
9293
--language {{ language }}
9394
--runner-os $RUNNER_OS
94-
--cli-version $CODEQL_CLI
95-
--stdlib-ident $CODEQL_STDLIB_IDENT
9695
--work-dir $RUNNER_TMP
9796
{% raw %}
9897
- name: Upload test results

0 commit comments

Comments
 (0)