Skip to content

Commit af5221f

Browse files
sstricklCommit Queue
authored andcommitted
[test_runner] Convert boolean use-elf to an enum gen-snapshot-format.
Currently, the configuration code only has a boolean option, 'use-elf' for specifying the output format for gen_snapshot. If false, then the output format is assumed to be assembly. Add a new GenSnapshotFormat enum and replace the old 'use-elf' option with a new 'gen-snapshot-format' option. The new enum has two getters: * snapshotType returns the appropriate string to pass to gen_snapshot via the '--snapshot-type' option. * fileOption returns the name of the option used to specify the output path for the given format. In addition, make it so the Configuration only has a non-null genSnapshotFormat field if the compiler is Compiler.dartkp to avoid spurious differences in Configurations that are created with different GenSnapshotFormat values when the configurations in question don't actually call gen_snapshot. TEST=pkg/smith/test/configuration_test.dart (and the CI in general) Change-Id: I7f17dc8d3a1bb6d4bf57750bc5ef4a16b8a78c11 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429980 Reviewed-by: Ryan Macnak <[email protected]> Commit-Queue: Tess Strickland <[email protected]>
1 parent 38ef28a commit af5221f

File tree

7 files changed

+129
-72
lines changed

7 files changed

+129
-72
lines changed

pkg/smith/lib/configuration.dart

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,15 @@ class Configuration {
238238
var system = enumOption("system", System.names, System.find);
239239
var nnbdMode = enumOption("nnbd", NnbdMode.names, NnbdMode.find);
240240
var sanitizer = enumOption("sanitizer", Sanitizer.names, Sanitizer.find);
241+
var genSnapshotFormat = enumOption(
242+
"gen-snapshot-format", GenSnapshotFormat.names, GenSnapshotFormat.find);
241243

242244
// Fill in any missing values using defaults when possible.
243245
architecture ??= Architecture.host;
244246
system ??= System.host;
245247
nnbdMode ??= NnbdMode.strong;
246248
sanitizer ??= Sanitizer.none;
249+
genSnapshotFormat ??= GenSnapshotFormat.assembly;
247250

248251
// Infer runtime from executable if we don't know runtime and compiler.
249252
if (runtime == null && compiler == null && words.contains("custom")) {
@@ -295,9 +298,9 @@ class Configuration {
295298
isCsp: boolOption("csp"),
296299
enableHostAsserts: boolOption("host-asserts"),
297300
isMinified: boolOption("minified"),
301+
genSnapshotFormat: genSnapshotFormat,
298302
useAnalyzerCfe: boolOption("use-cfe"),
299303
useAnalyzerFastaParser: boolOption("analyzer-use-fasta-parser"),
300-
useElf: boolOption("use-elf"),
301304
useHotReload: boolOption("hot-reload"),
302305
useHotReloadRollback: boolOption("hot-reload-rollback"),
303306
useSdk: boolOption("use-sdk"),
@@ -369,7 +372,7 @@ class Configuration {
369372
final bool useAnalyzerCfe;
370373
final bool useAnalyzerFastaParser;
371374

372-
final bool useElf;
375+
final GenSnapshotFormat? genSnapshotFormat;
373376

374377
final bool useHotReload;
375378
final bool useHotReloadRollback;
@@ -395,9 +398,9 @@ class Configuration {
395398
bool? isCsp,
396399
bool? enableHostAsserts,
397400
bool? isMinified,
401+
GenSnapshotFormat? genSnapshotFormat,
398402
bool? useAnalyzerCfe,
399403
bool? useAnalyzerFastaParser,
400-
bool? useElf,
401404
bool? useHotReload,
402405
bool? useHotReloadRollback,
403406
bool? useSdk,
@@ -417,9 +420,11 @@ class Configuration {
417420
isCsp = isCsp ?? false,
418421
enableHostAsserts = enableHostAsserts ?? false,
419422
isMinified = isMinified ?? false,
423+
// Use a null output for non-precompiler targets.
424+
genSnapshotFormat =
425+
compiler == Compiler.dartkp ? genSnapshotFormat : null,
420426
useAnalyzerCfe = useAnalyzerCfe ?? false,
421427
useAnalyzerFastaParser = useAnalyzerFastaParser ?? false,
422-
useElf = useElf ?? false,
423428
useHotReload = useHotReload ?? false,
424429
useHotReloadRollback = useHotReloadRollback ?? false,
425430
useSdk = useSdk ?? false,
@@ -456,9 +461,9 @@ class Configuration {
456461
required this.isCsp,
457462
required this.enableHostAsserts,
458463
required this.isMinified,
464+
required this.genSnapshotFormat,
459465
required this.useAnalyzerCfe,
460466
required this.useAnalyzerFastaParser,
461-
required this.useElf,
462467
required this.useHotReload,
463468
required this.useHotReloadRollback,
464469
required this.useSdk,
@@ -493,9 +498,9 @@ class Configuration {
493498
isCsp: source.isCsp,
494499
enableHostAsserts: source.enableHostAsserts,
495500
isMinified: source.isMinified,
501+
genSnapshotFormat: source.genSnapshotFormat,
496502
useAnalyzerCfe: source.useAnalyzerCfe,
497503
useAnalyzerFastaParser: source.useAnalyzerFastaParser,
498-
useElf: source.useElf,
499504
useHotReload: source.useHotReload,
500505
useHotReloadRollback: source.useHotReloadRollback,
501506
useSdk: source.useSdk,
@@ -531,7 +536,7 @@ class Configuration {
531536
isMinified == other.isMinified &&
532537
useAnalyzerCfe == other.useAnalyzerCfe &&
533538
useAnalyzerFastaParser == other.useAnalyzerFastaParser &&
534-
useElf == other.useElf &&
539+
genSnapshotFormat == other.genSnapshotFormat &&
535540
useHotReload == other.useHotReload &&
536541
useHotReloadRollback == other.useHotReloadRollback &&
537542
useSdk == other.useSdk &&
@@ -566,6 +571,7 @@ class Configuration {
566571
mode.hashCode ^
567572
runtime.hashCode ^
568573
system.hashCode ^
574+
genSnapshotFormat.hashCode ^
569575
nnbdMode.hashCode ^
570576
builderTag.hashCode ^
571577
genKernelOptions.join(" & ").hashCode ^
@@ -583,7 +589,6 @@ class Configuration {
583589
isMinified,
584590
useAnalyzerCfe,
585591
useAnalyzerFastaParser,
586-
useElf,
587592
useHotReload,
588593
useHotReloadRollback,
589594
useSdk,
@@ -623,6 +628,11 @@ class Configuration {
623628
if (isCsp) fields.add("csp");
624629
if (enableHostAsserts) fields.add("host-asserts");
625630
if (isMinified) fields.add("minified");
631+
// Only output the requested gen_snapshot format if using gen_snapshot
632+
// or the output is unexpectedly non-null.
633+
if (compiler == Compiler.dartkp || genSnapshotFormat != null) {
634+
fields.add("gen-snapshot-format: $genSnapshotFormat");
635+
}
626636
if (useAnalyzerCfe) fields.add("use-cfe");
627637
if (useAnalyzerFastaParser) fields.add("analyzer-use-fasta-parser");
628638
if (useHotReload) fields.add("hot-reload");
@@ -681,6 +691,15 @@ class Configuration {
681691
boolField("csp", isCsp, other.isCsp);
682692
boolField("host-asserts", enableHostAsserts, other.enableHostAsserts);
683693
boolField("minified", isMinified, other.isMinified);
694+
// Only output the requested gen_snapshot format if using gen_snapshot
695+
// or the output is unexpectedly non-null.
696+
if (compiler == Compiler.dartkp ||
697+
other.compiler == Compiler.dartkp ||
698+
genSnapshotFormat != null ||
699+
other.genSnapshotFormat != null) {
700+
fields.add(
701+
"gen-snapshot-format: $genSnapshotFormat ${other.genSnapshotFormat}");
702+
}
684703
boolField("use-cfe", useAnalyzerCfe, other.useAnalyzerCfe);
685704
boolField("analyzer-use-fasta-parser", useAnalyzerFastaParser,
686705
other.useAnalyzerFastaParser);
@@ -816,6 +835,33 @@ class Architecture extends NamedEnum {
816835
}
817836
}
818837

838+
/// Specifies the output format used by gen_snapshot to create AOT snapshots.
839+
class GenSnapshotFormat extends NamedEnum {
840+
static const assembly = GenSnapshotFormat._('assembly', 'assembly');
841+
static const elf = GenSnapshotFormat._('elf', 'elf');
842+
static const machODylib = GenSnapshotFormat._('macho-dylib', 'macho');
843+
844+
static final List<String> names = _all.keys.toList();
845+
846+
static final _all = Map<String, GenSnapshotFormat>.fromIterable([
847+
assembly,
848+
elf,
849+
machODylib,
850+
], key: (format) => (format as GenSnapshotFormat).name);
851+
852+
static GenSnapshotFormat find(String name) {
853+
var format = _all[name];
854+
if (format != null) return format;
855+
856+
throw ArgumentError('Unknown gen_snapshot format "$name".');
857+
}
858+
859+
String get snapshotType => 'app-aot-$name';
860+
861+
final String fileOption;
862+
const GenSnapshotFormat._(super.name, this.fileOption);
863+
}
864+
819865
class Compiler extends NamedEnum {
820866
static const dart2js = Compiler._('dart2js');
821867
static const dart2analyzer = Compiler._('dart2analyzer');

pkg/smith/test/configuration_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ void main() {
390390
isMinified: true,
391391
useAnalyzerCfe: true,
392392
useAnalyzerFastaParser: true,
393-
useElf: true,
393+
genSnapshotFormat: GenSnapshotFormat.elf,
394394
useHotReload: true,
395395
useHotReloadRollback: true,
396396
useSdk: true,

pkg/test_runner/lib/src/compiler_configuration.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ class PrecompilerCompilerConfiguration extends CompilerConfiguration
884884
tempDir, arguments, environmentOverrides));
885885
}
886886

887-
if (!_configuration.useElf) {
887+
if (_configuration.genSnapshotFormat == GenSnapshotFormat.assembly) {
888888
commands.add(
889889
computeAssembleCommand(tempDir, arguments, environmentOverrides));
890890
if (!_configuration.keepGeneratedFiles) {
@@ -893,7 +893,8 @@ class PrecompilerCompilerConfiguration extends CompilerConfiguration
893893
}
894894
}
895895

896-
if (_configuration.useElf && _isAndroid) {
896+
if (_isAndroid &&
897+
_configuration.genSnapshotFormat == GenSnapshotFormat.elf) {
897898
// On Android, run the NDK's "strip" tool with "--strip-unneeded" to copy
898899
// Flutter's workflow. Skip this step on tests for DWARF (which may get
899900
// stripped).
@@ -970,17 +971,16 @@ class PrecompilerCompilerConfiguration extends CompilerConfiguration
970971
}
971972
}
972973

974+
var format = _configuration.genSnapshotFormat!;
975+
var basename = (format == GenSnapshotFormat.assembly) ? 'out.S' : 'out.aotsnapshot';
976+
// Whether or not loading units are used. Mach-O doesn't currently support
977+
// this, and this isn't done for assembly output to avoid having to handle
978+
// the assembly of multiple assembly output files.
979+
var split = format == GenSnapshotFormat.elf;
973980
var args = [
974-
if (_configuration.useElf) ...[
975-
"--snapshot-kind=app-aot-elf",
976-
"--elf=$tempDir/out.aotsnapshot",
977-
// Only splitting with a ELF to avoid having to setup compilation of
978-
// multiple assembly files in the test harness.
979-
"--loading-unit-manifest=$tempDir/ignored.json",
980-
] else ...[
981-
"--snapshot-kind=app-aot-assembly",
982-
"--assembly=$tempDir/out.S",
983-
],
981+
"--snapshot-kind=${format.snapshotType}",
982+
"--${format.fileOption}=$tempDir/$basename",
983+
if (split) "--loading-unit-manifest=$tempDir/ignored.json",
984984
if (_isAndroid && (_isArm || _isArmX64)) ...[
985985
'--no-sim-use-hardfp',
986986
],

pkg/test_runner/lib/src/configuration.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class TestConfiguration {
122122
bool get isSimulator => architecture.isSimulator;
123123
bool get useAnalyzerCfe => configuration.useAnalyzerCfe;
124124
bool get useAnalyzerFastaParser => configuration.useAnalyzerFastaParser;
125-
bool get useElf => configuration.useElf;
125+
GenSnapshotFormat? get genSnapshotFormat => configuration.genSnapshotFormat;
126126
bool get useSdk => configuration.useSdk;
127127
bool get enableAsserts => configuration.enableAsserts;
128128
bool get useQemu => configuration.useQemu;
@@ -475,6 +475,11 @@ class TestConfiguration {
475475
isValid = false;
476476
}
477477

478+
if (compiler == Compiler.dartkp && genSnapshotFormat == null) {
479+
print("Error: gen_snapshot output format must be specified in AOT mode.");
480+
isValid = false;
481+
}
482+
478483
if (shard < 1 || shard > shardCount) {
479484
print("Error: shard index is $shard out of $shardCount shards");
480485
isValid = false;

pkg/test_runner/lib/src/options.dart

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ riscv32, riscv64, simriscv32, simriscv64''')
116116
defaultsTo: Platform.operatingSystem,
117117
hide: true,
118118
help: 'The operating system to run tests on.')
119+
..addMultiOption('gen-snapshot-format',
120+
allowed: ['all', ...GenSnapshotFormat.names],
121+
defaultsTo: [GenSnapshotFormat.assembly.name],
122+
hide: true,
123+
help: 'The output format used by gen_snapshot.')
119124
..addMultiOption('sanitizer',
120125
allowed: ['all', ...Sanitizer.names],
121126
defaultsTo: [Sanitizer.none.name],
@@ -165,12 +170,6 @@ test options, specifying how tests should be run.''')
165170
aliases: ['use_blobs'],
166171
hide: true,
167172
help: 'Use mmap instead of shared libraries for precompilation.')
168-
..addFlag(
169-
'use-elf',
170-
aliases: ['use_elf'],
171-
hide: true,
172-
help: 'Directly generate an ELF shared libraries for precompilation.',
173-
)
174173
..addFlag('use-qemu',
175174
aliases: ['use_qemu'],
176175
hide: true,
@@ -417,7 +416,7 @@ has been specified on the command line.''')
417416
'enable-asserts',
418417
'use-cfe',
419418
'analyzer-use-fasta-parser',
420-
'use-elf',
419+
'gen-snapshot-format',
421420
'use-sdk',
422421
'hot-reload',
423422
'hot-reload-rollback',
@@ -612,6 +611,10 @@ has been specified on the command line.''')
612611
var system = System.find(systemName);
613612
var runtimes = [...(data["runtime"] as List<String>).map(Runtime.find)];
614613
var compilers = [...(data["compiler"] as List<String>).map(Compiler.find)];
614+
var formats = [
615+
...(data["gen-snapshot-format"] as List<String>)
616+
.map(GenSnapshotFormat.find)
617+
];
615618

616619
// Pick default compilers or runtimes if only one or the other is provided.
617620
if (runtimes.isEmpty) {
@@ -772,37 +775,40 @@ has been specified on the command line.''')
772775
}
773776
for (var sanitizerName in sanitizers) {
774777
var sanitizer = Sanitizer.find(sanitizerName);
775-
var timeout = data["timeout"] != null
776-
? int.parse(data["timeout"] as String)
777-
: null;
778-
var configuration = Configuration(
779-
"custom-configuration-${configurationNumber++}",
780-
architecture,
781-
compiler,
782-
mode,
783-
runtime,
784-
system,
785-
nnbdMode: nnbdMode,
786-
sanitizer: sanitizer,
787-
timeout: timeout,
788-
enableAsserts: data['enable-asserts'] as bool,
789-
useAnalyzerCfe: data["use-cfe"] as bool,
790-
useAnalyzerFastaParser:
791-
data["analyzer-use-fasta-parser"] as bool,
792-
useElf: data["use-elf"] as bool,
793-
useSdk: data["use-sdk"] as bool,
794-
useHotReload: data["hot-reload"] as bool,
795-
useHotReloadRollback: data["hot-reload-rollback"] as bool,
796-
enableHostAsserts: data["host-asserts"] as bool,
797-
isCsp: data["csp"] as bool,
798-
isMinified: data["minified"] as bool,
799-
vmOptions: vmOptions,
800-
dart2jsOptions: dart2jsOptions,
801-
ddcOptions: ddcOptions,
802-
experiments: experiments,
803-
builderTag: data["builder-tag"] as String?,
804-
useQemu: data["use-qemu"] as bool);
805-
addConfiguration(configuration);
778+
// Expand formats.
779+
for (final format in formats) {
780+
var timeout = data["timeout"] != null
781+
? int.parse(data["timeout"] as String)
782+
: null;
783+
var configuration = Configuration(
784+
"custom-configuration-${configurationNumber++}",
785+
architecture,
786+
compiler,
787+
mode,
788+
runtime,
789+
system,
790+
nnbdMode: nnbdMode,
791+
sanitizer: sanitizer,
792+
timeout: timeout,
793+
enableAsserts: data['enable-asserts'] as bool,
794+
useAnalyzerCfe: data["use-cfe"] as bool,
795+
useAnalyzerFastaParser:
796+
data["analyzer-use-fasta-parser"] as bool,
797+
useSdk: data["use-sdk"] as bool,
798+
useHotReload: data["hot-reload"] as bool,
799+
useHotReloadRollback: data["hot-reload-rollback"] as bool,
800+
enableHostAsserts: data["host-asserts"] as bool,
801+
isCsp: data["csp"] as bool,
802+
isMinified: data["minified"] as bool,
803+
genSnapshotFormat: format,
804+
vmOptions: vmOptions,
805+
dart2jsOptions: dart2jsOptions,
806+
ddcOptions: ddcOptions,
807+
experiments: experiments,
808+
builderTag: data["builder-tag"] as String?,
809+
useQemu: data["use-qemu"] as bool);
810+
addConfiguration(configuration);
811+
}
806812
}
807813
}
808814
}

pkg/test_runner/lib/src/runtime_configuration.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ abstract class RuntimeConfiguration {
5151
case Runtime.dartPrecompiled:
5252
if (configuration.system == System.android) {
5353
return DartPrecompiledAdbRuntimeConfiguration(
54-
configuration.useElf,
54+
configuration.genSnapshotFormat == GenSnapshotFormat.elf,
5555
);
5656
} else if (configuration.system == System.fuchsia) {
5757
return DartkFuchsiaEmulatorRuntimeConfiguration(true);
5858
}
5959
return DartPrecompiledRuntimeConfiguration(
60-
configuration.useElf,
60+
configuration.genSnapshotFormat == GenSnapshotFormat.elf,
6161
);
6262
}
6363
throw "unreachable";

0 commit comments

Comments
 (0)