Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(431)

Side by Side Diff: utils/testrunner/run_pipeline.dart

Issue 10977069: New testrunner that runs the test pipleine in an isolate. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, 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 /** The default pipeline code for running a test file. */
6 #library('pipeline');
7 #import('dart:isolate');
8 #import('dart:io');
9 #source('pipeline_utils.dart');
10
11 /**
12 * The configuration passed in to the pipeline runner; this essentially
13 * contains all the command line arguments passded to testrunner plus some
14 * synthesized ones.
15 */
16 Map config;
17
18 /** Paths to the various generated temporary files. */
19 String tempDartFile = null;
20 String tempHtmlFile = null;
21 String tempChildDartFile = null;
22 String tempJsFile = null;
23 String tempChildJsFile = null;
24
25 /**
26 * Path to the Dart script file referenced from the HTML wrapper (or
27 * that is compiled to a Javascript file referenced from the HTML wrapper).
28 */
29 String sourceFile = null;
30
31 /** Path to the script file referenced from the HTML wrapper (Dart or JS). */
32 String scriptFile = null;
33
34 /** MIME type of the script. */
35 String scriptType;
36
37 /** Process id for the HTTP server. */
38 int serverId;
39
40 void main() {
41 port.receive((cfg, replyPort) {
42 config = cfg;
43 initPipeline(replyPort);
44 wrapStage();
45 });
46 }
47
48 /** Initial pipeline stage - generates Dart and HTML wrapper files. */
49 wrapStage() {
50 var tmpDir = config["tempdir"];
51 var testFile = config["testfile"];
52
53 // Make sure the temp dir exists.
54 var d = new Directory(tmpDir);
55 if (!d.existsSync()) {
56 d.createSync();
57 }
58
59 // Generate names for the generated wrapper files.
60 tempDartFile = createTempName(tmpDir, testFile, '.dart');
61 if (config["runtime"] != 'vm') {
62 tempHtmlFile = createTempName(tmpDir, testFile, '.html');
63 if (config["layout"]) {
64 tempChildDartFile =
65 createTempName(tmpDir, testFile, '-child.dart');
66 }
67 if (config["runtime"] == 'drt-js') {
68 tempJsFile = createTempName(tmpDir, testFile, '.js');
69 if (config["layout"]) {
70 tempChildJsFile =
71 createTempName(tmpDir, testFile, '-child.js');
72 }
73 }
74 }
75
76 // Create the test controller Dart wrapper.
77 var directives, extras;
78
79 if (config["layout"]) {
80 directives = '''
81 #import('dart:uri');
82 #import('dart:io');
83 #import('dart:math');
84 #source('${config["runnerDir"]}/layout_test_controller.dart');
85 ''';
86 extras = '''
87 sourceDir = '${config["expectedDirectory"]}';
88 baseUrl = 'file://$tempHtmlFile';
89 tprint = (msg) => print('###\$msg');
90 notifyDone = (e) => exit(e);
91 ''';
92 } else if (config["runtime"] == "vm") {
93 directives = '''
94 #import('dart:io');
95 #import('dart:isolate');
96 #import('${config["unittest"]}', prefix:'unittest');
97 #import('${config["testfile"]}', prefix: 'test');
98 #source('${config["runnerDir"]}/standard_test_runner.dart');
99 ''';
100 extras = '''
101 includeFilters = ${config["include"]};
102 excludeFilters = ${config["exclude"]};
103 tprint = (msg) => print('###\$msg');
104 notifyDone = (e) => exit(e);
105 ''';
106 } else {
107 directives = '''
108 #import('dart:html');
109 #import('dart:isolate');
110 #import('${config["unittest"]}', prefix:'unittest');
111 #import('${config["testfile"]}', prefix: 'test');
112 #source('${config["runnerDir"]}/standard_test_runner.dart');
113 ''';
114 extras = '''
115 includeFilters = ${config["include"]};
116 excludeFilters = ${config["exclude"]};
117 tprint = (msg) => query('#console').addText('###\$msg\\n');
118 notifyDone = (e) => window.postMessage('done', '*');
119 ''';
120 }
121
122 var action = 'process(test.main, unittest.runTests)';
123 if (config["layout-text"]) {
124 action = 'runTextLayoutTests()';
125 } else if (config["layout-pixel"]) {
126 action = 'runPixelLayoutTests()';
127 } else if (config["list-tests"]) {
128 action = 'process(test.main, listTests)';
129 } else if (config["list-groups"]) {
130 action = 'process(test.main, listGroups)';
131 } else if (config["isolate"]) {
132 action = 'process(test.main, runIsolateTests)';
133 }
134
135 logMessage('Creating $tempDartFile');
136 writeFile(tempDartFile, '''
137 #library('test_controller');
138 $directives
139
140 main() {
141 immediate = ${config["immediate"]};
142 includeTime = ${config["time"]};
143 passFormat = '${config["pass-format"]}';
144 failFormat = '${config["fail-format"]}';
145 errorFormat = '${config["error-format"]}';
146 listFormat = '${config["list-format"]}';
147 regenerate = ${config["regenerate"]};
148 summarize = ${config["summary"]};
149 testfile = '$testFile';
150 drt = '${config["drt"]}';
151 $extras
152 $action;
153 }
154 ''');
155
156 // Create the child wrapper for layout tests.
157 if (config["layout"]) {
158 logMessage('Creating $tempChildDartFile');
159 writeFile(tempChildDartFile, '''
160 #library('layout_test');
161 #import('dart:math');
162 #import('dart:isolate');
163 #import('dart:html');
164 #import('dart:uri');
165 #import('${config["unittest"]}', prefix:'unittest');
166 #import('$testFile', prefix: 'test');
167 #source('${config["runnerDir"]}/layout_test_runner.dart');
168
169 main() {
170 includeFilters = ${config["include"]};
171 excludeFilters = ${config["exclude"]};
172 runTests(test.main);
173 }
174 ''');
175 }
176
177
178 // Create the HTML wrapper and compile to Javascript if necessary.
179 var isJavascript = config["runtime"] == 'drt-js';
180 if (config["runtime"] == 'drt-dart' || isJavascript) {
181 var bodyElements, runAsText;
182
183 if (config["layout"]) {
184 sourceFile = tempChildDartFile;
185 scriptFile = isJavascript ? tempChildJsFile : tempChildDartFile;
186 bodyElements = '';
187 } else {
188 sourceFile = tempDartFile;
189 scriptFile = isJavascript ? tempJsFile : tempDartFile;
190 bodyElements = '<div id="container"></div><pre id="console"></pre>';
191 runAsText = "window.testRunner.dumpAsText();";
192 }
193 scriptType = isJavascript ? 'text/javascript' : 'application/dart';
194
195 if (config["runtime"] == 'drt-dart' || isJavascript) {
196 logMessage('Creating $tempHtmlFile');
197 writeFile(tempHtmlFile, '''
198 <!DOCTYPE html>
199 <html>
200 <head>
201 <meta charset="utf-8">
202 <title>$testFile</title>
203 <link rel="stylesheet" href="${config["runnerDir"]}/testrunner.css">
204 <script type='text/javascript'>
205 if (window.testRunner) {
206 function handleMessage(m) {
207 if (m.data == 'done') {
208 window.testRunner.notifyDone();
209 }
210 }
211 window.testRunner.waitUntilDone();
212 $runAsText
213 window.addEventListener("message", handleMessage, false);
214 }
215 if (!$isJavascript && navigator.webkitStartDart) {
216 navigator.webkitStartDart();
217 }
218 </script>
219 </head>
220 <body>
221 $bodyElements
222 <script type='$scriptType' src='$scriptFile'></script>
223 </script>
224 <script
225 src="http://dart.googlecode.com/svn/branches/bleeding_edge/dart/client/dart.js">
226 </script>
227 </body>
228 </html>
229 ''');
230 }
231 }
232 compileStage(isJavascript);
233 }
234
235 /** Second stage of pipeline - compiles Dart to Javascript if needed. */
236 compileStage(isJavascript) {
237 if (isJavascript) { // Compile the Dart file.
238 if (config["checked"]) {
239 runCommand(config["dart2js"],
240 [ '--enable_checked_mode', '--out=$scriptFile', '$sourceFile' ]).
241 then(runTestStage);
242 } else {
243 runCommand(config["dart2js"],
244 [ '--out=$scriptFile', '$sourceFile' ]).
245 then(runTestStage);
246 }
247 } else {
248 runTestStage(0);
249 }
250 }
251
252 /** Third stage of pipeline - runs the tests. */
253 runTestStage(_) {
254 if (config["server"]) { // Start the HTTP server.
255 serverId = startProcess(config["dart"],
256 [ '${config["runnerDir"]}/http_server_test_runner.dart',
257 '--port=${config["port"]}',
258 '--root=${config["root"]}']);
259 }
260
261 var cmd, args;
262 if (config["runtime"] == 'vm' || config["layout"]) { // Run the tests.
263 if (config["checked"]) {
264 cmd = config["dart"];
265 args = [ '--enable_asserts', '--enable_type_checks', tempDartFile ];
266 } else {
267 cmd = config["dart"];
268 args = [ tempDartFile ];
269 }
270 } else {
271 cmd = config["drt"];
272 args = [ '--no-timeout', tempHtmlFile ];
273 }
274 runCommand(cmd, args, config["timeout"]).then(cleanupStage);
275 }
276
277 /**
278 * Final stage of the pipeline - clean up generated files and notify
279 * the originator that started the isolate.
280 */
281 cleanupStage(exitcode) {
282 if (config["server"]) { // Stop the HTTP server.
283 stopProcess(serverId);
284 }
285
286 if (!config["keep_files"]) { // Remove the temporary files.
287 cleanup(tempDartFile);
288 cleanup(tempHtmlFile);
289 cleanup(tempJsFile);
290 cleanup(tempChildDartFile);
291 cleanup(tempChildJsFile);
292 }
293 completePipeline(exitcode);
294 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698