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

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 var tempDartFile = null;
20 var tempHtmlFile = null;
21 var tempChildDartFile = null;
22 var tempJsFile = null;
23 var 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 var sourceFile = null;
30
31 /** Path to the script file referenced from the HTML wrapper (Dart or JS). */
32 var scriptFile = null;
33
34 /** MIME type of the script. */
35 var scriptType;
36
37 /** Process id for the HTTP server. */
38 var 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 testFile = config["testfile"];
51 // Generate names for the generated wrapper files.
52 tempDartFile = createTempName(config["tempdir"], testFile, '.dart');
53 if (config["runtime"] != 'vm') {
54 tempHtmlFile = createTempName(config["tempdir"], testFile, '.html');
55 if (config["layout"]) {
56 tempChildDartFile =
57 createTempName(config["tempdir"], testFile, '-child.dart');
58 }
59 if (config["runtime"] == 'drt-js') {
60 tempJsFile = createTempName(config["tempdir"], testFile, '.js');
61 if (config.layout) {
62 tempChildJsFile =
63 createTempName(config["tempdir"], testFile, '-child.js');
64 }
65 }
66 }
67
68 // Create the test controller Dart wrapper.
69 var directives, extras;
70
71 if (config["layout"]) {
72 directives = '''
73 #import('dart:uri');
74 #import('dart:io');
75 #import('dart:math');
76 #source('${config["runnerDir"]}/layout_test_controller.dart');
77 ''';
78 extras = '''
79 sourceDir = '${config["expectedDirectory"]}';
80 baseUrl = 'file://$tempHtmlFile';
81 tprint = (msg) => print('###\$msg');
82 notifyDone = (e) => exit(e);
83 ''';
84 } else if (config["runtime"] == "vm") {
85 directives = '''
86 #import('dart:io');
87 #import('dart:isolate');
88 #import('${config["unittest"]}', prefix:'unittest');
89 #import('${config["testfile"]}', prefix: 'test');
90 #source('${config["runnerDir"]}/standard_test_runner.dart');
91 ''';
92 extras = '''
93 includeFilters = ${config["include"]};
94 excludeFilters = ${config["exclude"]};
95 tprint = (msg) => print('###\$msg');
96 notifyDone = (e) => exit(e);
97 ''';
98 } else {
99 directives = '''
100 #import('dart:html');
101 #import('dart:isolate');
102 #import('${config["unittest"]}', prefix:'unittest');
103 #import('${config["testfile"]}', prefix: 'test');
104 #source('${config["runnerDir"]}/standard_test_runner.dart');
105 ''';
106 extras = '''
107 includeFilters = ${config["include"]};
108 excludeFilters = ${config["exclude"]};
109 tprint = (msg) => query('#console').addText('###\$msg\\n');
110 notifyDone = (e) => window.postMessage('done', '*');
111 ''';
112 }
113
114 var action = 'process(test.main, unittest.runTests)';
115 if (config["layout-text"]) {
116 action = 'runTextLayoutTests()';
117 } else if (config["layout-pixel"]) {
118 action = 'runPixelLayoutTests()';
119 } else if (config["list-tests"]) {
120 action = 'process(test.main, listTests)';
121 } else if (config["list-groups"]) {
122 action = 'process(test.main, listGroups)';
123 } else if (config["isolate"]) {
124 action = 'process(test.main, runIsolateTests)';
125 }
126
127 logMessage('Creating $tempDartFile');
128 writeFile(tempDartFile, '''
129 #library('test_controller');
130 $directives
131
132 main() {
133 immediate = ${config["immediate"]};
134 includeTime = ${config["time"]};
135 passFormat = '${config["pass-format"]}';
136 failFormat = '${config["fail-format"]}';
137 errorFormat = '${config["error-format"]}';
138 listFormat = '${config["list-format"]}';
139 regenerate = ${config["regenerate"]};
140 summarize = ${config["summary"]};
141 testfile = '$testFile';
142 drt = '${config["drt"]}';
143 $extras
144 $action;
145 }
146 ''');
147
148 // Create the child wrapper for layout tests.
149 if (config["layout"]) {
150 logMessage('Creating $tempChildDartFile');
151 writeFile(tempChildDartFile, '''
152 #library('layout_test');
153 #import('dart:math');
154 #import('dart:isolate');
155 #import('dart:html');
156 #import('dart:uri');
157 #import('${config["unittest"]}', prefix:'unittest');
158 #import('$testFile', prefix: 'test');
159 #source('${config["runnerDir"]}/layout_test_runner.dart');
160
161 main() {
162 includeFilters = ${config["include"]};
163 excludeFilters = ${config["exclude"]};
164 runTests(test.main);
165 }
166 ''');
167 }
168
169
170 // Create the HTML wrapper and compile to Javascript if necessary.
171 var isJavascript = config["runtime"] == 'drt-js';
172 if (config["runtime"] == 'drt-dart' || isJavascript) {
173 var bodyElements, runAsText;
174
175 if (config["layout"]) {
176 sourceFile = tempChildDartFile;
177 scriptFile = isJavascript ? tempChildJsFile : tempChildDartFile;
178 bodyElements = '';
179 } else {
180 sourceFile = tempDartFile;
181 scriptFile = isJavascript ? tempJsFile : tempDartFile;
182 bodyElements = '<div id="container"></div><pre id="console"></pre>';
183 runAsText = "window.testRunner.dumpAsText();";
184 }
185 scriptType = isJavascript ? 'text/javascript' : 'application/dart';
186
187 if (config["runtime"] == 'drt-dart' || isJavascript) {
188 logMessage('Creating $tempHtmlFile');
189 writeFile(tempHtmlFile, '''
190 <!DOCTYPE html>
191 <html>
192 <head>
193 <meta charset="utf-8">
194 <title>$testFile</title>
195 <link rel="stylesheet" href="${config["runnerDir"]}/testrunner.css">
196 <script type='text/javascript'>
197 if (window.testRunner) {
198 function handleMessage(m) {
199 if (m.data == 'done') {
200 window.testRunner.notifyDone();
201 }
202 }
203 window.testRunner.waitUntilDone();
204 $runAsText
205 window.addEventListener("message", handleMessage, false);
206 }
207 if (!$isJavascript && navigator.webkitStartDart) {
208 navigator.webkitStartDart();
209 }
210 </script>
211 </head>
212 <body>
213 $bodyElements
214 <script type='$scriptType' src='$scriptFile'></script>
215 </script>
216 <script
217 src="http://dart.googlecode.com/svn/branches/bleeding_edge/dart/client/dart.js">
218 </script>
219 </body>
220 </html>
221 ''');
222 }
223 }
224 compileStage(isJavascript);
225 }
226
227 /** Second stage of pipeline - compiles Dart to Javascript if needed. */
228 compileStage(isJavascript) {
229 if (isJavascript) { // Compile the Dart file.
230 if (config["checked"]) {
231 runCommand(config["dart2js"],
232 [ '--enable_checked_mode', '--out=$scriptFile', '$sourceFile' ]).
233 then(runTestStage);
234 } else {
235 runCommand(config["dart2js"],
236 [ '--out=$scriptFile', '$sourceFile' ]).
237 then(runTestStage);
238 }
239 } else {
240 runTestStage();
241 }
242 }
243
244 /** Third stage of pipeline - runs the tests. */
245 runTestStage() {
246 if (config["server"]) { // Start the HTTP server.
247 serverId = startProcess(config["dart"],
248 [ '${config["runnerDir"]}/http_server_test_runner.dart',
249 '--port=${config["port"]}',
250 '--root=${config["root"]}']);
251 }
252
253 var cmd, args;
254 if (config["runtime"] == 'vm' || config["layout"]) { // Run the tests.
255 if (config["checked"]) {
256 cmd = config["dart"];
257 args = [ '--enable_asserts', '--enable_type_checks', tempDartFile ];
258 } else {
259 cmd = config["dart"];
260 args = [ tempDartFile ];
261 }
262 } else {
263 cmd = config["drt"];
264 args = [ '--no-timeout', tempHtmlFile ];
265 }
266 runCommand(cmd, args, config["timeout"]).then(cleanupStage);
267 }
268
269 /**
270 * Final stage of the pipeline - clean up generated files and notify
271 * the originator that started the isolate.
272 */
273 cleanupStage(exitcode) {
274 if (config["server"]) { // Stop the HTTP server.
275 stopProcess(serverId);
276 }
277
278 if (!config["keep_files"]) { // Remove the temporary files.
279 cleanup(tempDartFile);
280 cleanup(tempHtmlFile);
281 cleanup(tempJsFile);
282 cleanup(tempChildDartFile);
283 cleanup(tempChildJsFile);
284 }
285 completePipeline(exitcode);
286 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698