OLD | NEW |
| (Empty) |
1 // Copyright (c) 2015, 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' show | |
6 Future; | |
7 | |
8 import 'dart:io' show | |
9 Directory, | |
10 Process, | |
11 ProcessResult; | |
12 | |
13 import 'package:expect/expect.dart' show | |
14 Expect; | |
15 | |
16 import '../fletchc/run.dart' show | |
17 export; | |
18 | |
19 import 'utils.dart' show | |
20 withTempDirectory; | |
21 | |
22 const String buildDirectory = | |
23 const String.fromEnvironment('test.dart.build-dir'); | |
24 | |
25 final String multiprogramRunner = '$buildDirectory/multiprogram_cc_test'; | |
26 | |
27 typedef Future NoArgFuture(); | |
28 | |
29 List duplicateList(List a, int n) { | |
30 var result = new List(n * a.length); | |
31 for (int i = 0; i < n; i++) { | |
32 result.setRange(i * a.length, (i + 1) * a.length, a); | |
33 } | |
34 return result; | |
35 } | |
36 | |
37 Future<Map<String, NoArgFuture>> listTests() async { | |
38 var tests = <String, NoArgFuture>{ | |
39 'multiprogram_tests/should_fail': | |
40 () => runTest('sequence', ['compiletime_error', 0]), | |
41 | |
42 'multiprogram_tests/parallel': | |
43 () => runTest('parallel', [ | |
44 'process_links', 0, | |
45 'compiletime_error', 254, | |
46 'runtime_error', 255, | |
47 'unhandled_signal', 255, | |
48 ]), | |
49 | |
50 'multiprogram_tests/sequence': | |
51 () => runTest('sequence', [ | |
52 'process_links', 0, | |
53 'compiletime_error', 254, | |
54 'runtime_error', 255, | |
55 'unhandled_signal', 255, | |
56 ]), | |
57 | |
58 'multiprogram_tests/many_programs': | |
59 () => runTest('batch=50', [ | |
60 'process_links', 0, | |
61 'compiletime_error', 254, | |
62 'runtime_error', 255, | |
63 'unhandled_signal', 255, | |
64 ], duplicate: 200), | |
65 | |
66 'multiprogram_tests/immutable_gc': | |
67 () => runTest('overlapped=11', [ | |
68 'immutable_gc', 0, | |
69 'process_links', 0, | |
70 'compiletime_error', 254, | |
71 'runtime_error', 255, | |
72 'unhandled_signal', 255, | |
73 ], duplicate: 3), | |
74 | |
75 'multiprogram_tests/mutable_gc': | |
76 () => runTest('overlapped=11', [ | |
77 'mutable_gc', 0, | |
78 'process_links', 0, | |
79 'compiletime_error', 254, | |
80 'runtime_error', 255, | |
81 'unhandled_signal', 255, | |
82 ], duplicate: 3), | |
83 | |
84 'multiprogram_tests/stress_test': | |
85 () => runTest('overlapped=3', [ | |
86 'mutable_gc', 0, | |
87 'compute', 0, | |
88 'immutable_gc', 0, | |
89 ], duplicate: 2), | |
90 }; | |
91 | |
92 // Dummy use of [main] to make analyzer happy. | |
93 main; | |
94 | |
95 return tests; | |
96 } | |
97 | |
98 Future runTest(String mode, List testNamesWithExitCodes, {int duplicate}) { | |
99 return withTempDirectory((Directory temp) async { | |
100 List<String> snapshotsExitcodeTuples = <String>[]; | |
101 | |
102 // Generate snapshots. | |
103 for (int i = 0; i < testNamesWithExitCodes.length ~/2; i++) { | |
104 String testName = testNamesWithExitCodes[2 * i]; | |
105 int exitcode = testNamesWithExitCodes[2 * i + 1]; | |
106 String snapshotFilename = '${temp.absolute.path}/$testName.snapshot'; | |
107 snapshotsExitcodeTuples.addAll([snapshotFilename, '$exitcode']); | |
108 print('Making snapshot $snapshotFilename'); | |
109 await export(testFilename(testName), snapshotFilename); | |
110 print('Making snapshot $snapshotFilename - done'); | |
111 } | |
112 | |
113 if (duplicate != null) { | |
114 snapshotsExitcodeTuples = duplicateList( | |
115 snapshotsExitcodeTuples, duplicate); | |
116 } | |
117 | |
118 var arguments = [] | |
119 ..add(mode) | |
120 ..addAll(snapshotsExitcodeTuples); | |
121 | |
122 // Run all the snapshots inside one fletch vm. | |
123 print("Running $multiprogramRunner ${arguments.join(' ')}"); | |
124 ProcessResult result = await Process.run(multiprogramRunner, arguments); | |
125 print("Done running $multiprogramRunner ${arguments.join(' ')}:"); | |
126 print("<STDOUT>:\n${result.stdout}\n"); | |
127 print("<STDERR>:\n${result.stderr}\n"); | |
128 print("<EXITCODE>:\n${result.exitCode}\n"); | |
129 | |
130 // Validate the result. | |
131 Expect.equals(0, result.exitCode); | |
132 }); | |
133 } | |
134 | |
135 String testFilename(String name, [String generated = '']) | |
136 => '${testDirectory(generated)}/${name}.dart'; | |
137 | |
138 String testDirectory([String generated = '']) | |
139 => 'tests/multiprogram_tests$generated'; | |
140 | |
141 main() async { | |
142 var tests = await listTests(); | |
143 for (var name in tests.keys) { | |
144 print('Running test "$name".'); | |
145 await tests[name](); | |
146 } | |
147 } | |
OLD | NEW |