Skip to content

Commit 7da04d0

Browse files
sstricklCommit Queue
authored andcommitted
[dartdev] Factor out cross compilation tests into a separate test file.
Since current cross compilation tests are flaky due to being dependent on the uploaded artifacts, separate them out into a separate file that can be approved without hiding other failures in the compile test suite until they can be more properly fixed. Do some cleanup and refactoring to abstract out the common parts of the cross compilation failure tests as well. TEST=pkg/dartdev Issue: #61181 Change-Id: I1bee602f6d19ebd175bd27f6aded7a1909d1944f Cq-Include-Trybots: luci.dart.try:pkg-linux-release-arm64-try,pkg-linux-release-try,pkg-mac-release-arm64-try,pkg-mac-release-try,pkg-win-release-arm64-try,pkg-win-release-try,dart-sdk-linux-riscv64-try,dart-sdk-linux-arm64-try,dart-sdk-linux-try,dart-sdk-mac-try,dart-sdk-win-arm64-try,dart-sdk-win-try,dart-sdk-mac-arm64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442060 Reviewed-by: Alexander Markov <[email protected]> Commit-Queue: Tess Strickland <[email protected]>
1 parent 8acd589 commit 7da04d0

File tree

3 files changed

+169
-188
lines changed

3 files changed

+169
-188
lines changed

pkg/dartdev/lib/src/commands/compile.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import '../vm_interop_handler.dart';
2626

2727
const int genericErrorExitCode = 255;
2828
const int compileErrorExitCode = 254;
29+
const int crossCompileErrorExitCode = 128;
2930

3031
class Option {
3132
final String flag;
@@ -597,7 +598,7 @@ Remove debugging information from the output and save it separately to the speci
597598
stderr.writeln('Unsupported target platform $target.');
598599
stderr.writeln('Supported target platforms: '
599600
'${supportedTargetPlatforms.join(', ')}');
600-
return 128;
601+
return crossCompileErrorExitCode;
601602
}
602603

603604
var cacheDir = getDartStorageDirectory();

pkg/dartdev/test/commands/compile_test.dart

Lines changed: 23 additions & 187 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import 'dart:math';
88
import 'package:code_assets/code_assets.dart';
99
import 'package:dart2native/dart2native_macho.dart' show pipeStream;
1010
import 'package:dart2native/macho.dart';
11+
import 'package:dartdev/src/commands/compile.dart'
12+
show compileErrorExitCode, genericErrorExitCode;
1113
import 'package:hooks_runner/hooks_runner.dart';
1214
import 'package:path/path.dart' as path;
1315
import 'package:test/test.dart';
1416

1517
import '../utils.dart';
1618

17-
const int compileErrorExitCode = 254;
18-
1919
void main() {
2020
ensureRunFromSdkBinDart();
2121

@@ -27,21 +27,13 @@ const String soundNullSafetyWarning =
2727
"Warning: Option '--sound-null-safety' is deprecated.";
2828

2929
const String failedAssertionError = 'Failed assertion: line';
30-
String usingTargetOSMessageForPlatform(String targetOS) =>
30+
String usingTargetOSMessage(OS targetOS) =>
3131
'Specializing Platform getters for target OS $targetOS.';
32-
final String usingTargetOSMessage =
33-
usingTargetOSMessageForPlatform(Platform.operatingSystem);
34-
String unsupportedTargetError(Target target) =>
35-
'Unsupported target platform $target';
32+
final String targetingHostOSMessage = usingTargetOSMessage(Target.current.os);
3633

3734
void defineCompileTests() {
38-
final host = Target.current;
3935
// AOT compilation is not available on IA32.
40-
final bool isRunningOnIA32 = host.architecture == Architecture.ia32;
41-
// Cross compilation is not available on 32-bit architectures.
42-
final bool isRunningOn32Bit = isRunningOnIA32 ||
43-
host.architecture == Architecture.arm ||
44-
host.architecture == Architecture.riscv32;
36+
final bool isRunningOnIA32 = Target.current.architecture == Architecture.ia32;
4537

4638
if (Platform.isMacOS) {
4739
test('Compile exe for MacOS signing', () async {
@@ -266,7 +258,7 @@ void defineCompileTests() {
266258
'-v',
267259
inFile,
268260
]);
269-
expect(result.stdout, isNot(contains(usingTargetOSMessage)));
261+
expect(result.stdout, isNot(contains(targetingHostOSMessage)));
270262
expect(result.stderr, isNot(contains(soundNullSafetyMessage)));
271263
expect(result.exitCode, 0);
272264
final file = File(outFile);
@@ -294,7 +286,7 @@ void defineCompileTests() {
294286
);
295287

296288
// Executables should be (host) OS-specific by default.
297-
expect(result.stdout, contains(usingTargetOSMessage));
289+
expect(result.stdout, contains(targetingHostOSMessage));
298290
expect(result.stderr, isEmpty);
299291
expect(result.exitCode, 0);
300292
expect(File(outFile).existsSync(), true,
@@ -365,7 +357,7 @@ void defineCompileTests() {
365357
],
366358
);
367359

368-
expect(result.stdout, contains(usingTargetOSMessage));
360+
expect(result.stdout, contains(targetingHostOSMessage));
369361
expect(result.stderr, isEmpty);
370362
expect(result.exitCode, 0);
371363
expect(File(outFile).existsSync(), true,
@@ -418,95 +410,6 @@ void defineCompileTests() {
418410
expect(result.exitCode, 0);
419411
}, skip: isRunningOnIA32);
420412

421-
Future<void> basicCrossCompileTest(Target target) async {
422-
final p = project(
423-
mainSrc: 'void main() {print(const String.fromEnvironment("cross"));}');
424-
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
425-
final outFile = path.canonicalize(path.join(p.dirPath, 'myexe'));
426-
final result = await p.run(
427-
[
428-
'compile',
429-
'exe',
430-
'-v',
431-
'--target-os',
432-
target.os.name,
433-
'--target-arch',
434-
target.architecture.name,
435-
'-o',
436-
outFile,
437-
inFile,
438-
],
439-
);
440-
441-
if (result.exitCode != 0) {
442-
print('Subcommand terminated with exit code ${result.exitCode}.');
443-
if (result.stdout.isNotEmpty) {
444-
print('Subcommand stdout:');
445-
print(result.stdout);
446-
}
447-
if (result.stderr.isNotEmpty) {
448-
print('Subcommand stderr:');
449-
print(result.stderr);
450-
}
451-
}
452-
453-
expect(result.stdout,
454-
contains(usingTargetOSMessageForPlatform(target.os.name)));
455-
expect(result.stderr, isNot(contains(unsupportedTargetError(target))));
456-
expect(result.exitCode, 0);
457-
}
458-
459-
final crossCompileOSes = [
460-
OS.linux,
461-
];
462-
463-
final crossCompileArchitectures = [
464-
Architecture.arm,
465-
Architecture.arm64,
466-
Architecture.riscv64,
467-
Architecture.x64,
468-
];
469-
470-
for (final os in crossCompileOSes) {
471-
for (final arch in crossCompileArchitectures) {
472-
if (os == host.os && arch == host.architecture) continue;
473-
final target = Target.fromArchitectureAndOS(arch, os);
474-
test('Compile executable can cross compile to $os $arch',
475-
() async => basicCrossCompileTest(target),
476-
skip: isRunningOn32Bit);
477-
}
478-
}
479-
480-
test('Compile executable cannot compile cross-OS', () async {
481-
final p = project(
482-
mainSrc: 'void main() {print(const String.fromEnvironment("cross"));}');
483-
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
484-
final outFile = path.canonicalize(path.join(p.dirPath, 'myexe'));
485-
// Make sure targetOS is always unsupported (not Linux and not matches host
486-
// OS) to trigger an error.
487-
final targetOS = Platform.isWindows ? OS.macOS : OS.windows;
488-
final targetArch = Architecture.arm64;
489-
final target = Target.fromArchitectureAndOS(targetArch, targetOS);
490-
final result = await p.run(
491-
[
492-
'compile',
493-
'exe',
494-
'-v',
495-
'--target-os',
496-
targetOS.name,
497-
'--target-arch',
498-
targetArch.name,
499-
'-o',
500-
outFile,
501-
inFile,
502-
],
503-
);
504-
505-
expect(result.stdout, isNot(contains(usingTargetOSMessage)));
506-
expect(result.stderr, contains(unsupportedTargetError(target)));
507-
expect(result.exitCode, 128);
508-
}, skip: isRunningOnIA32);
509-
510413
test('Compile and run aot snapshot', () async {
511414
final p = project(mainSrc: 'void main() { print("I love AOT"); }');
512415
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
@@ -524,7 +427,7 @@ void defineCompileTests() {
524427
);
525428

526429
// AOT snapshots should be OS-specific by default.
527-
expect(result.stdout, contains(usingTargetOSMessage));
430+
expect(result.stdout, contains(targetingHostOSMessage));
528431
expect(result.stderr, isEmpty);
529432
expect(result.exitCode, 0);
530433
expect(File(outFile).existsSync(), true,
@@ -541,73 +444,6 @@ void defineCompileTests() {
541444
expect(result.exitCode, 0);
542445
}, skip: isRunningOnIA32);
543446

544-
test('Compile aot snapshot can compile to host platform', () async {
545-
final targetOS = Platform.operatingSystem;
546-
final p = project(mainSrc: 'void main() { print("I love $targetOS"); }');
547-
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
548-
final outFile = path.canonicalize(path.join(p.dirPath, 'main.aot'));
549-
550-
var result = await p.run(
551-
[
552-
'compile',
553-
'aot-snapshot',
554-
'-v',
555-
'--target-os',
556-
targetOS,
557-
'-o',
558-
'main.aot',
559-
inFile,
560-
],
561-
);
562-
563-
expect(result.stdout, contains(usingTargetOSMessageForPlatform(targetOS)));
564-
expect(result.stderr, isEmpty);
565-
expect(result.exitCode, 0);
566-
expect(File(outFile).existsSync(), true,
567-
reason: 'File not found: $outFile');
568-
569-
final Directory binDir = File(Platform.resolvedExecutable).parent;
570-
result = Process.runSync(
571-
path.join(binDir.path, 'dartaotruntime'),
572-
[outFile],
573-
);
574-
575-
expect(result.stdout, contains('I love $targetOS'));
576-
expect(result.stderr, isEmpty);
577-
expect(result.exitCode, 0);
578-
}, skip: isRunningOnIA32);
579-
580-
test('Compile aot snapshot cannot compile cross platform', () async {
581-
// Make sure targetOS is always unsupported (not Linux and not matches host
582-
// OS) to trigger an error.
583-
final targetOS = Platform.isWindows ? OS.macOS : OS.windows;
584-
final targetArch = Architecture.arm64;
585-
final target = Target.fromArchitectureAndOS(targetArch, targetOS);
586-
final p = project(mainSrc: 'void main() { print("I love $targetOS"); }');
587-
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
588-
589-
var result = await p.run(
590-
[
591-
'compile',
592-
'aot-snapshot',
593-
'-v',
594-
'--target-os',
595-
targetOS.name,
596-
'--target-arch',
597-
targetArch.name,
598-
'-o',
599-
'main.aot',
600-
inFile,
601-
],
602-
);
603-
604-
expect(result.stdout,
605-
isNot(contains(usingTargetOSMessageForPlatform(targetOS.name))));
606-
expect(result.stderr, contains(unsupportedTargetError(target)));
607-
608-
expect(result.exitCode, isNot(0));
609-
}, skip: isRunningOnIA32);
610-
611447
test('Compile and run kernel snapshot', () async {
612448
final p = project(mainSrc: 'void main() { print("I love kernel"); }');
613449
final outFile = path.join(p.dirPath, 'main.dill');
@@ -623,7 +459,7 @@ void defineCompileTests() {
623459
);
624460
expect(File(outFile).existsSync(), true,
625461
reason: 'File not found: $outFile');
626-
expect(result.stdout, isNot(contains(usingTargetOSMessage)));
462+
expect(result.stdout, isNot(contains(targetingHostOSMessage)));
627463
expect(result.stderr, isNot(contains(soundNullSafetyMessage)));
628464
expect(result.exitCode, 0);
629465

@@ -653,7 +489,7 @@ void defineCompileTests() {
653489
'-v',
654490
inFile,
655491
]);
656-
expect(result.stdout, isNot(contains(usingTargetOSMessage)));
492+
expect(result.stdout, isNot(contains(targetingHostOSMessage)));
657493
expect(result.stderr, isEmpty);
658494
expect(result.exitCode, 0);
659495
final file = File(outFile);
@@ -683,7 +519,7 @@ void defineCompileTests() {
683519
outFile,
684520
inFile,
685521
]);
686-
expect(result.stdout, isNot(contains(usingTargetOSMessage)));
522+
expect(result.stdout, isNot(contains(targetingHostOSMessage)));
687523
expect(result.stderr, isEmpty);
688524
expect(result.exitCode, 0);
689525
final file = File(outFile);
@@ -853,7 +689,7 @@ void main() {
853689
);
854690

855691
// Only printed when -v/--verbose is used, not --verbosity.
856-
expect(result.stdout, isNot(contains(usingTargetOSMessage)));
692+
expect(result.stdout, isNot(contains(targetingHostOSMessage)));
857693
expect(result.stdout, isNot(contains(soundNullSafetyMessage)));
858694
expect(result.stderr, isEmpty);
859695
expect(result.exitCode, 0);
@@ -883,7 +719,7 @@ void main() {
883719
);
884720

885721
// Only printed when -v/--verbose is used, not --verbosity.
886-
expect(result.stdout, isNot(contains(usingTargetOSMessage)));
722+
expect(result.stdout, isNot(contains(targetingHostOSMessage)));
887723
expect(result.stdout, isNot(contains(soundNullSafetyMessage)));
888724
expect(result.stderr, isEmpty);
889725
expect(result.exitCode, 0);
@@ -910,7 +746,7 @@ void main() {
910746
);
911747

912748
// Only printed when -v/--verbose is used, not --verbosity.
913-
expect(result.stdout, isNot(contains(usingTargetOSMessage)));
749+
expect(result.stdout, isNot(contains(targetingHostOSMessage)));
914750
expect(result.stdout, isNot(contains(soundNullSafetyMessage)));
915751
expect(result.stderr, isEmpty);
916752
expect(result.exitCode, 0);
@@ -977,7 +813,7 @@ void main() {}
977813

978814
expect(result.stderr,
979815
contains('Error: The output file "foo" does not end with ".wasm"'));
980-
expect(result.exitCode, 255);
816+
expect(result.exitCode, genericErrorExitCode);
981817
}, skip: isRunningOnIA32);
982818

983819
test('Compile wasm with error', () async {
@@ -1166,7 +1002,7 @@ void main() {
11661002
);
11671003

11681004
// Only printed when -v/--verbose is used, not --verbosity.
1169-
expect(result.stdout, isNot(contains(usingTargetOSMessage)));
1005+
expect(result.stdout, isNot(contains(targetingHostOSMessage)));
11701006
expect(result.stdout, isNot(contains(soundNullSafetyMessage)));
11711007
expect(result.stderr, isEmpty);
11721008
expect(result.exitCode, 0);
@@ -1196,7 +1032,7 @@ void main() {
11961032
);
11971033

11981034
// Only printed when -v/--verbose is used, not --verbosity.
1199-
expect(result.stdout, isNot(contains(usingTargetOSMessage)));
1035+
expect(result.stdout, isNot(contains(targetingHostOSMessage)));
12001036
expect(result.stdout, isNot(contains(soundNullSafetyMessage)));
12011037
expect(result.stderr, isEmpty);
12021038
expect(result.exitCode, 0);
@@ -1223,7 +1059,7 @@ void main() {
12231059
);
12241060

12251061
// Only printed when -v/--verbose is used, not --verbosity.
1226-
expect(result.stdout, isNot(contains(usingTargetOSMessage)));
1062+
expect(result.stdout, isNot(contains(targetingHostOSMessage)));
12271063
expect(result.stdout, isNot(contains(soundNullSafetyMessage)));
12281064
expect(result.stderr, isEmpty);
12291065
expect(result.exitCode, 0);
@@ -1299,7 +1135,7 @@ void main() {}
12991135
(dynamic o) => '$o'.contains('Unable to open file'),
13001136
),
13011137
);
1302-
expect(result.exitCode, 255);
1138+
expect(result.exitCode, genericErrorExitCode);
13031139
});
13041140

13051141
test('Compile kernel with invalid trailing argument', () async {
@@ -1347,7 +1183,7 @@ void main() {}
13471183
],
13481184
);
13491185

1350-
expect(result.stdout, isNot(contains(usingTargetOSMessage)));
1186+
expect(result.stdout, isNot(contains(targetingHostOSMessage)));
13511187
expect(result.stderr, isNot(contains(soundNullSafetyMessage)));
13521188
expect(result.exitCode, 0);
13531189
expect(File(outFile).existsSync(), true,
@@ -1567,10 +1403,10 @@ void main() {
15671403
);
15681404

15691405
// Only printed when -v/--verbose is used, not --verbosity.
1570-
expect(result.stdout, isNot(contains(usingTargetOSMessage)));
1406+
expect(result.stdout, isNot(contains(targetingHostOSMessage)));
15711407
expect(result.stdout, isNot(contains(soundNullSafetyMessage)));
15721408
expect(result.stderr, contains(failedAssertionError));
1573-
expect(result.exitCode, 255);
1409+
expect(result.exitCode, genericErrorExitCode);
15741410

15751411
result = await p.run(
15761412
['--enable-asserts', outFile],

0 commit comments

Comments
 (0)