Skip to content

Commit ec0d042

Browse files
karlklosecommit-bot@chromium.org
authored andcommitted
[infra] Support multiple named configurations in test infrastructure
This change allows to run test.dart and pkg/test_runner with multiple arguments for the -n option to run tests for multiple configurations with one invocation. Change-Id: If62e0bfc364460fa415c7f700f7e449b0de56987 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/122395 Commit-Queue: Karl Klose <karlklose@google.com> Reviewed-by: William Hesse <whesse@google.com>
1 parent b334ea8 commit ec0d042

File tree

4 files changed

+267
-230
lines changed

4 files changed

+267
-230
lines changed

pkg/test_runner/lib/src/options.dart

Lines changed: 101 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -679,10 +679,87 @@ compiler.''',
679679
var progress = Progress.find(data["progress"] as String);
680680
var nnbdMode = NnbdMode.find(data["nnbd"] as String);
681681

682+
void addConfiguration(Configuration innerConfiguration,
683+
[String namedConfiguration]) {
684+
var configuration = TestConfiguration(
685+
configuration: innerConfiguration,
686+
progress: progress,
687+
selectors: selectors,
688+
testList: data["test_list_contents"] as List<String>,
689+
repeat: data["repeat"] as int,
690+
batch: !(data["noBatch"] as bool),
691+
batchDart2JS: data["dart2js_batch"] as bool,
692+
copyCoreDumps: data["copy_coredumps"] as bool,
693+
isVerbose: data["verbose"] as bool,
694+
listTests: data["list"] as bool,
695+
listStatusFiles: data["list_status_files"] as bool,
696+
cleanExit: data["clean_exit"] as bool,
697+
silentFailures: data["silent_failures"] as bool,
698+
printTiming: data["time"] as bool,
699+
printReport: data["report"] as bool,
700+
reportInJson: data["report_in_json"] as bool,
701+
resetBrowser: data["reset_browser_configuration"] as bool,
702+
skipCompilation: data["skip_compilation"] as bool,
703+
writeDebugLog: data["write_debug_log"] as bool,
704+
writeResults: data["write_results"] as bool,
705+
writeLogs: data["write_logs"] as bool,
706+
drtPath: data["drt"] as String,
707+
chromePath: data["chrome"] as String,
708+
safariPath: data["safari"] as String,
709+
firefoxPath: data["firefox"] as String,
710+
dartPath: data["dart"] as String,
711+
dartPrecompiledPath: data["dart_precompiled"] as String,
712+
genSnapshotPath: data["gen-snapshot"] as String,
713+
keepGeneratedFiles: data["keep_generated_files"] as bool,
714+
taskCount: data["tasks"] as int,
715+
shardCount: data["shards"] as int,
716+
shard: data["shard"] as int,
717+
stepName: data["step_name"] as String,
718+
testServerPort: data["test_server_port"] as int,
719+
testServerCrossOriginPort:
720+
data['test_server_cross_origin_port'] as int,
721+
testDriverErrorPort: data["test_driver_error_port"] as int,
722+
localIP: data["local_ip"] as String,
723+
sharedOptions: sharedOptions,
724+
packages: data["packages"] as String,
725+
packageRoot: data["package_root"] as String,
726+
suiteDirectory: data["suite_dir"] as String,
727+
outputDirectory: data["output_directory"] as String,
728+
reproducingArguments:
729+
_reproducingCommand(data, namedConfiguration != null),
730+
fastTestsOnly: data["fast_tests"] as bool,
731+
printPassingStdout: data["print_passing_stdout"] as bool);
732+
733+
if (configuration.validate()) {
734+
result.add(configuration);
735+
}
736+
}
737+
738+
String namedConfigurationOption = data["named_configuration"] as String;
739+
if (namedConfigurationOption != null) {
740+
List<String> namedConfigurations = namedConfigurationOption.split(',');
741+
var testMatrixFile = "tools/bots/test_matrix.json";
742+
var testMatrix = TestMatrix.fromPath(testMatrixFile);
743+
for (String namedConfiguration in namedConfigurations) {
744+
var configuration = testMatrix.configurations.singleWhere(
745+
(c) => c.name == namedConfiguration,
746+
orElse: () => null);
747+
if (configuration == null) {
748+
var names = testMatrix.configurations
749+
.map((configuration) => configuration.name)
750+
.toList();
751+
names.sort();
752+
_fail('The named configuration "$namedConfiguration" does not exist.'
753+
' The following configurations are available:\n'
754+
' * ${names.join('\n * ')}');
755+
}
756+
addConfiguration(configuration);
757+
}
758+
return result;
759+
}
760+
682761
// Expand runtimes.
683762
for (var runtime in runtimes) {
684-
// Start installing the runtime if needed.
685-
686763
// Expand architectures.
687764
var architectures = data["arch"] as String;
688765
if (architectures == "all") {
@@ -700,82 +777,28 @@ compiler.''',
700777
for (var modeName in modes.split(",")) {
701778
var mode = Mode.find(modeName);
702779
var system = System.find(data["system"] as String);
703-
var namedConfiguration =
704-
_namedConfiguration(data["named_configuration"] as String);
705-
var innerConfiguration = namedConfiguration ??
706-
Configuration("custom configuration", architecture, compiler,
707-
mode, runtime, system,
708-
nnbdMode: nnbdMode,
709-
timeout: data["timeout"] as int,
710-
enableAsserts: data["enable_asserts"] as bool,
711-
useAnalyzerCfe: data["use_cfe"] as bool,
712-
useAnalyzerFastaParser:
713-
data["analyzer_use_fasta_parser"] as bool,
714-
useBlobs: data["use_blobs"] as bool,
715-
useElf: data["use_elf"] as bool,
716-
useSdk: data["use_sdk"] as bool,
717-
useHotReload: data["hot_reload"] as bool,
718-
useHotReloadRollback: data["hot_reload_rollback"] as bool,
719-
isHostChecked: data["host_checked"] as bool,
720-
isCsp: data["csp"] as bool,
721-
isMinified: data["minified"] as bool,
722-
vmOptions: vmOptions,
723-
dart2jsOptions: dart2jsOptions,
724-
experiments: experiments,
725-
babel: data['babel'] as String,
726-
builderTag: data["builder_tag"] as String);
727-
var configuration = TestConfiguration(
728-
configuration: innerConfiguration,
729-
progress: progress,
730-
selectors: selectors,
731-
testList: data["test_list_contents"] as List<String>,
732-
repeat: data["repeat"] as int,
733-
batch: !(data["noBatch"] as bool),
734-
batchDart2JS: data["dart2js_batch"] as bool,
735-
copyCoreDumps: data["copy_coredumps"] as bool,
736-
isVerbose: data["verbose"] as bool,
737-
listTests: data["list"] as bool,
738-
listStatusFiles: data["list_status_files"] as bool,
739-
cleanExit: data["clean_exit"] as bool,
740-
silentFailures: data["silent_failures"] as bool,
741-
printTiming: data["time"] as bool,
742-
printReport: data["report"] as bool,
743-
reportInJson: data["report_in_json"] as bool,
744-
resetBrowser: data["reset_browser_configuration"] as bool,
745-
skipCompilation: data["skip_compilation"] as bool,
746-
writeDebugLog: data["write_debug_log"] as bool,
747-
writeResults: data["write_results"] as bool,
748-
writeLogs: data["write_logs"] as bool,
749-
drtPath: data["drt"] as String,
750-
chromePath: data["chrome"] as String,
751-
safariPath: data["safari"] as String,
752-
firefoxPath: data["firefox"] as String,
753-
dartPath: data["dart"] as String,
754-
dartPrecompiledPath: data["dart_precompiled"] as String,
755-
genSnapshotPath: data["gen-snapshot"] as String,
756-
keepGeneratedFiles: data["keep_generated_files"] as bool,
757-
taskCount: data["tasks"] as int,
758-
shardCount: data["shards"] as int,
759-
shard: data["shard"] as int,
760-
stepName: data["step_name"] as String,
761-
testServerPort: data["test_server_port"] as int,
762-
testServerCrossOriginPort:
763-
data['test_server_cross_origin_port'] as int,
764-
testDriverErrorPort: data["test_driver_error_port"] as int,
765-
localIP: data["local_ip"] as String,
766-
sharedOptions: sharedOptions,
767-
packages: data["packages"] as String,
768-
packageRoot: data["package_root"] as String,
769-
suiteDirectory: data["suite_dir"] as String,
770-
outputDirectory: data["output_directory"] as String,
771-
reproducingArguments:
772-
_reproducingCommand(data, namedConfiguration != null),
773-
fastTestsOnly: data["fast_tests"] as bool,
774-
printPassingStdout: data["print_passing_stdout"] as bool);
775-
776-
if (configuration.validate()) {
777-
result.add(configuration);
778-
}
780+
var configuration = Configuration("custom configuration",
781+
architecture, compiler, mode, runtime, system,
782+
nnbdMode: nnbdMode,
783+
timeout: data["timeout"] as int,
784+
enableAsserts: data["enable_asserts"] as bool,
785+
useAnalyzerCfe: data["use_cfe"] as bool,
786+
useAnalyzerFastaParser:
787+
data["analyzer_use_fasta_parser"] as bool,
788+
useBlobs: data["use_blobs"] as bool,
789+
useElf: data["use_elf"] as bool,
790+
useSdk: data["use_sdk"] as bool,
791+
useHotReload: data["hot_reload"] as bool,
792+
useHotReloadRollback: data["hot_reload_rollback"] as bool,
793+
isHostChecked: data["host_checked"] as bool,
794+
isCsp: data["csp"] as bool,
795+
isMinified: data["minified"] as bool,
796+
vmOptions: vmOptions,
797+
dart2jsOptions: dart2jsOptions,
798+
experiments: experiments,
799+
babel: data['babel'] as String,
800+
builderTag: data["builder_tag"] as String);
801+
addConfiguration(configuration);
779802
}
780803
}
781804
}
@@ -934,25 +957,6 @@ class OptionParseException implements Exception {
934957
OptionParseException(this.message);
935958
}
936959

937-
Configuration _namedConfiguration(String template) {
938-
if (template == null) return null;
939-
940-
var testMatrixFile = "tools/bots/test_matrix.json";
941-
var testMatrix = TestMatrix.fromPath(testMatrixFile);
942-
var configuration = testMatrix.configurations
943-
.singleWhere((c) => c.name == template, orElse: () => null);
944-
if (configuration == null) {
945-
var names = testMatrix.configurations
946-
.map((configuration) => configuration.name)
947-
.toList();
948-
names.sort();
949-
_fail('The named configuration "$template" does not exist. The following '
950-
'configurations are available:\n * ${names.join('\n * ')}');
951-
}
952-
953-
return configuration;
954-
}
955-
956960
/// Throws an [OptionParseException] with [message].
957961
void _fail(String message) {
958962
throw OptionParseException(message);

pkg/test_runner/lib/src/test_configurations.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ final TEST_SUITE_DIRECTORIES = [
4545

4646
Future testConfigurations(List<TestConfiguration> configurations) async {
4747
var startTime = DateTime.now();
48-
var startStopwatch = Stopwatch()..start();
4948

5049
// Extract global options from first configuration.
5150
var firstConf = configurations[0];
@@ -209,7 +208,7 @@ Future testConfigurations(List<TestConfiguration> configurations) async {
209208
}
210209

211210
if (firstConf.writeResults) {
212-
eventListener.add(ResultWriter(firstConf, startTime, startStopwatch));
211+
eventListener.add(ResultWriter(firstConf.outputDirectory));
213212
}
214213

215214
if (firstConf.copyCoreDumps) {

pkg/test_runner/lib/src/test_progress.dart

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -708,15 +708,11 @@ String _buildSummaryEnd(Formatter formatter, int failedTests) {
708708
/// Writes a results.json file with a line for each test.
709709
/// Each line is a json map with the test name and result and expected result.
710710
class ResultWriter extends EventListener {
711-
final TestConfiguration _configuration;
712711
final List<Map> _results = [];
713712
final List<Map> _logs = [];
714713
final String _outputDirectory;
715-
final Stopwatch _startStopwatch;
716-
final DateTime _startTime;
717714

718-
ResultWriter(this._configuration, this._startTime, this._startStopwatch)
719-
: _outputDirectory = _configuration.outputDirectory;
715+
ResultWriter(this._outputDirectory);
720716

721717
void allTestsKnown() {
722718
// Write an empty result log file, that will be overwritten if any tests
@@ -729,10 +725,6 @@ class ResultWriter extends EventListener {
729725
lines.map((l) => l + '\n').join();
730726

731727
void done(TestCase test) {
732-
if (_configuration != test.configuration) {
733-
throw Exception("Two configurations in the same run. "
734-
"Cannot output results for multiple configurations.");
735-
}
736728
final name = test.displayName;
737729
final index = name.indexOf('/');
738730
final suite = name.substring(0, index);
@@ -742,7 +734,7 @@ class ResultWriter extends EventListener {
742734

743735
final record = {
744736
"name": name,
745-
"configuration": _configuration.configuration.name,
737+
"configuration": test.configuration.configuration.name,
746738
"suite": suite,
747739
"test_name": testName,
748740
"time_ms": time.inMilliseconds,

0 commit comments

Comments
 (0)