Skip to content

Commit 6f44e99

Browse files
mkustermanncommit-bot@chromium.org
authored andcommitted
[vm/aot] Add test which passes both AOT size information flags --print-instructions-sizes-to/--write-v8-snapshot-profile-to
It was reported that passing both flags would sometimes crash gen_snapshot. This test can ensure it works and continues to work. Change-Id: Ib58685e815a628efb786a001b91e48728d4b5a8d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/122142 Reviewed-by: Vyacheslav Egorov <vegorov@google.com> Commit-Queue: Martin Kustermann <kustermann@google.com>
1 parent 354921f commit 6f44e99

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import "dart:async";
6+
import "dart:io";
7+
import "dart:convert";
8+
9+
import 'package:expect/expect.dart';
10+
import 'package:path/path.dart' as path;
11+
12+
main(List<String> args) async {
13+
if (!Platform.executable.endsWith("dart_precompiled_runtime")) {
14+
return; // Running in JIT: AOT binaries not available.
15+
}
16+
17+
if (Platform.isAndroid) {
18+
return; // SDK tree and gen_snapshot not available on the test device.
19+
}
20+
21+
final buildDir = path.dirname(Platform.executable);
22+
final sdkDir = path.dirname(path.dirname(buildDir));
23+
final platformDill = path.join(buildDir, 'vm_platform_strong.dill');
24+
final genSnapshot = path.join(buildDir, 'gen_snapshot');
25+
final aotRuntime = path.join(buildDir, 'dart_precompiled_runtime');
26+
27+
await withTempDir((String tempDir) async {
28+
final script = path.join(sdkDir, 'pkg/kernel/bin/dump.dart');
29+
final scriptDill = path.join(tempDir, 'kernel_dump.dill');
30+
final appHeapsnapshot = path.join(tempDir, 'app.heapsnapshot');
31+
final appSizesJson = path.join(tempDir, 'app-sizes.json');
32+
33+
// Compile script to Kernel IR.
34+
await run('pkg/vm/tool/gen_kernel', <String>[
35+
'--aot',
36+
'--platform=$platformDill',
37+
'-o',
38+
scriptDill,
39+
script,
40+
]);
41+
42+
// Run the AOT compiler with the size information flags set.
43+
final elfFile = path.join(tempDir, 'aot.snapshot');
44+
await Future.wait(<Future>[
45+
run(genSnapshot, <String>[
46+
'--snapshot-kind=app-aot-elf',
47+
'--print-instructions-sizes-to=$appSizesJson',
48+
'--write-v8-snapshot-profile-to=$appHeapsnapshot',
49+
'--elf=$elfFile',
50+
scriptDill,
51+
]),
52+
]);
53+
54+
// Ensure we can actually run the code.
55+
await Future.wait(<Future>[
56+
run(aotRuntime, <String>[
57+
elfFile,
58+
scriptDill,
59+
path.join(tempDir, 'ignored.txt'),
60+
]),
61+
]);
62+
63+
// Ensure we can read the files and they look legitimate.
64+
final appHeapsnapshotBytes = await readFile(appHeapsnapshot);
65+
final snapshotMap = json.decode(appHeapsnapshotBytes);
66+
Expect.isTrue(snapshotMap is Map);
67+
Expect.isTrue(snapshotMap.keys.contains('snapshot'));
68+
69+
final appSizesJsonBytes = await readFile(appSizesJson);
70+
final sizeList = json.decode(appSizesJsonBytes);
71+
Expect.isTrue(sizeList is List);
72+
Expect.isTrue(sizeList[0] is Map);
73+
Expect.isTrue(sizeList[0].keys.toSet().containsAll(['n', 's']));
74+
});
75+
}
76+
77+
Future<String> readFile(String file) {
78+
return new File(file).readAsString();
79+
}
80+
81+
Future run(String executable, List<String> args) async {
82+
print('Running $executable ${args.join(' ')}');
83+
84+
final result = await Process.run(executable, args);
85+
final String stdout = result.stdout;
86+
final String stderr = result.stderr;
87+
if (stdout.isNotEmpty) {
88+
print('stdout:');
89+
print(stdout);
90+
}
91+
if (stderr.isNotEmpty) {
92+
print('stderr:');
93+
print(stderr);
94+
}
95+
96+
if (result.exitCode != 0) {
97+
throw 'Command failed with non-zero exit code (was ${result.exitCode})';
98+
}
99+
}
100+
101+
Future withTempDir(Future fun(String dir)) async {
102+
final tempDir =
103+
Directory.systemTemp.createTempSync('aot-size-info-flags-test');
104+
try {
105+
await fun(tempDir.path);
106+
} finally {
107+
tempDir.deleteSync(recursive: true);
108+
}
109+
}

runtime/tests/vm/vm.status

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ cc/IsolateReload_PendingUnqualifiedCall_InstanceToStatic: Fail # Issue 32981
1313
cc/IsolateReload_PendingUnqualifiedCall_StaticToInstance: Fail # Issue 32981
1414
cc/Profiler_StringInterpolation: Fail # Issue 37208
1515
dart/data_uri_import_test/none: SkipByDesign
16+
dart/emit_aot_size_info_flag_test: Pass, Slow # Spawns several subprocesses
1617
dart/slow_path_shared_stub_test: Pass, Slow # Uses --shared-slow-path-triggers-gc flag.
1718
dart/snapshot_version_test: Skip # This test is a Dart1 test (script snapshot)
1819
dart/stack_overflow_shared_test: Pass, Slow # Uses --shared-slow-path-triggers-gc flag.
@@ -252,6 +253,7 @@ dart/redirection_type_shuffling_test/00: RuntimeError, Pass
252253
dart/redirection_type_shuffling_test/none: RuntimeError
253254

254255
[ $mode == debug || $runtime != dart_precompiled || $system == android ]
256+
dart/emit_aot_size_info_flag_test: SkipByDesign # This test is for VM AOT only and is quite slow (so we don't run it in debug mode).
255257
dart/use_bare_instructions_flag_test: SkipByDesign # This test is for VM AOT only and is quite slow (so we don't run it in debug mode).
256258

257259
# It makes no sense to run any test that uses spawnURI under the simulator

0 commit comments

Comments
 (0)