Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** The default pipeline code for running a test file. */ | 5 /** The default pipeline code for running a test file. */ |
| 6 library pipeline; | 6 library pipeline; |
| 7 import 'dart:isolate'; | 7 import 'dart:isolate'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:math'; | |
| 9 part 'pipeline_utils.dart'; | 10 part 'pipeline_utils.dart'; |
| 10 | 11 |
| 11 /** | 12 /** |
| 12 * The configuration passed in to the pipeline runner; this essentially | 13 * The configuration passed in to the pipeline runner; this essentially |
| 13 * contains all the command line arguments passded to testrunner plus some | 14 * contains all the command line arguments passded to testrunner plus some |
| 14 * synthesized ones. | 15 * synthesized ones. |
| 15 */ | 16 */ |
| 16 Map config; | 17 Map config; |
| 17 | 18 |
| 18 /** Paths to the various generated temporary files. */ | 19 /** Paths to the various generated temporary files. */ |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 30 | 31 |
| 31 /** Path to the script file referenced from the HTML wrapper (Dart or JS). */ | 32 /** Path to the script file referenced from the HTML wrapper (Dart or JS). */ |
| 32 String scriptFile = null; | 33 String scriptFile = null; |
| 33 | 34 |
| 34 /** MIME type of the script. */ | 35 /** MIME type of the script. */ |
| 35 String scriptType; | 36 String scriptType; |
| 36 | 37 |
| 37 /** Process id for the HTTP server. */ | 38 /** Process id for the HTTP server. */ |
| 38 int serverId; | 39 int serverId; |
| 39 | 40 |
| 41 /** Port used by HTTP server. */ | |
| 42 int serverPort; | |
| 43 | |
| 44 /** Root directory for static files used by HTTP server. */ | |
| 45 String serverRoot; | |
| 46 | |
| 47 /** Path of the HTTP server script. */ | |
| 48 String serverPath; | |
| 49 | |
| 50 /** Number of attempts we will make to start the HTTP server. */ | |
| 51 const int MAX_SERVER_TRIES = 10; | |
| 52 | |
| 53 /** Amount of time we give the server to start, in msec. */ | |
| 54 const int SERVER_DELAY = 1000; | |
| 55 | |
| 40 void main() { | 56 void main() { |
| 41 port.receive((cfg, replyPort) { | 57 port.receive((cfg, replyPort) { |
| 42 config = cfg; | 58 config = cfg; |
| 43 initPipeline(replyPort); | 59 initPipeline(replyPort); |
| 44 wrapStage(); | 60 startHTTPServerStage(); |
| 61 }); | |
| 62 } | |
| 63 | |
| 64 /** Initial pipeline stage - starts the HTTP server, if appropriate. */ | |
| 65 | |
| 66 startHTTPServerStage() { | |
| 67 if (config["server"]) { | |
| 68 serverPath = config["testfile"]; | |
| 69 // Replace .dart with _server.dart to get test's server file, if any. | |
| 70 var truncLen = serverPath.length - '.dart'.length; | |
| 71 serverPath = '${serverPath.substring(0, truncLen)}_server.dart'; | |
| 72 var serverFile = new File(serverPath); | |
| 73 if (!serverFile.existsSync()) { | |
| 74 // No custom server; run the default server. | |
| 75 serverPath = '${config["runnerDir"]}/http_server_runner.dart'; | |
| 76 } | |
| 77 if (serverPath != null) { | |
| 78 serverRoot = config["root"]; | |
| 79 if (serverRoot == null) { | |
| 80 // Set the root to be the directory containing the test file. | |
| 81 serverRoot = getDirectory(config["testfile"]); | |
| 82 } | |
| 83 | |
| 84 if (config["port"] == null) { | |
| 85 // In this case we have to choose a random port and we need | |
| 86 // to see if the server starts successfully on that port. | |
| 87 var r = new Random(); | |
| 88 tryStartHTTPServer(r, MAX_SERVER_TRIES); | |
| 89 } else { | |
| 90 serverPort = parseInt(config["port"]); | |
| 91 // Start the HTTP server. | |
| 92 serverId = startProcess(config["dart"], | |
| 93 [ serverPath, '--port=$serverPort', '--root=$serverRoot']); | |
| 94 } | |
| 95 } | |
| 96 } | |
| 97 wrapStage(); | |
| 98 } | |
| 99 | |
| 100 void tryStartHTTPServer(Random r, int remainingAttempts) { | |
| 101 // Pick a port from 1024 to 32767. | |
| 102 serverPort = 1024 + r.nextInt(32768-1024); | |
|
Siggi Cherem (dart-lang)
2012/10/10 22:07:28
nit: spaces around -
gram
2012/10/10 23:36:04
Done.
| |
| 103 logMessage('Trying ${config["dart"]} $serverPath --port=$serverPort ' | |
| 104 '--root=$serverRoot'); | |
| 105 serverId = startProcess(config["dart"], | |
| 106 [ serverPath, '--port=$serverPort', '--root=$serverRoot']); | |
| 107 // Wait a second; if the process has exited try again with | |
| 108 // a different port, else go to next stage. | |
| 109 var t = new Timer(SERVER_DELAY, (t) { | |
|
Siggi Cherem (dart-lang)
2012/10/10 22:07:28
seems a bit brittle to wait 1 sec.
How about prin
gram
2012/10/10 23:36:04
Done.
| |
| 110 if (isProcessRunning(serverId)) { | |
| 111 wrapStage(); | |
| 112 } else if (remainingAttempts == 0){ | |
|
Siggi Cherem (dart-lang)
2012/10/10 22:07:28
nit: space before {
gram
2012/10/10 23:36:04
Done.
gram
2012/10/10 23:36:04
Done.
| |
| 113 print('Failed to start HTTP server after numerous attempts; aborting.'); | |
| 114 exit(1); | |
| 115 } else { | |
| 116 tryStartHTTPServer(r, remainingAttempts-1); | |
|
Siggi Cherem (dart-lang)
2012/10/10 22:07:28
nit: spaces
gram
2012/10/10 23:36:04
Done.
gram
2012/10/10 23:36:04
Done.
| |
| 117 } | |
| 45 }); | 118 }); |
| 46 } | 119 } |
| 47 | 120 |
| 48 /** Initial pipeline stage - generates Dart and HTML wrapper files. */ | 121 /** Initial pipeline stage - generates Dart and HTML wrapper files. */ |
| 49 wrapStage() { | 122 wrapStage() { |
| 50 var tmpDir = config["tempdir"]; | 123 var tmpDir = config["tempdir"]; |
| 51 var testFile = config["testfile"]; | 124 var testFile = config["testfile"]; |
| 52 | 125 |
| 53 // Make sure the temp dir exists. | 126 // Make sure the temp dir exists. |
| 54 var d = new Directory(tmpDir); | 127 var d = new Directory(tmpDir); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 import 'dart:isolate'; | 168 import 'dart:isolate'; |
| 96 import '${config["unittest"]}' as unittest; | 169 import '${config["unittest"]}' as unittest; |
| 97 import '${config["testfile"]}' as test; | 170 import '${config["testfile"]}' as test; |
| 98 part '${config["runnerDir"]}/standard_test_runner.dart'; | 171 part '${config["runnerDir"]}/standard_test_runner.dart'; |
| 99 '''; | 172 '''; |
| 100 extras = ''' | 173 extras = ''' |
| 101 includeFilters = ${config["include"]}; | 174 includeFilters = ${config["include"]}; |
| 102 excludeFilters = ${config["exclude"]}; | 175 excludeFilters = ${config["exclude"]}; |
| 103 tprint = (msg) => print('###\$msg'); | 176 tprint = (msg) => print('###\$msg'); |
| 104 notifyDone = (e) {}; | 177 notifyDone = (e) {}; |
| 178 unittest.testState["port"] = $serverPort; | |
| 105 '''; | 179 '''; |
| 106 } else { | 180 } else { |
| 107 directives = ''' | 181 directives = ''' |
| 108 import 'dart:html'; | 182 import 'dart:html'; |
| 109 import 'dart:isolate'; | 183 import 'dart:isolate'; |
| 110 import '${config["unittest"]}' as unittest; | 184 import '${config["unittest"]}' as unittest; |
| 111 import '${config["testfile"]}' as test; | 185 import '${config["testfile"]}' as test; |
| 112 part '${config["runnerDir"]}/standard_test_runner.dart'; | 186 part '${config["runnerDir"]}/standard_test_runner.dart'; |
| 113 '''; | 187 '''; |
| 114 extras = ''' | 188 extras = ''' |
| 115 includeFilters = ${config["include"]}; | 189 includeFilters = ${config["include"]}; |
| 116 excludeFilters = ${config["exclude"]}; | 190 excludeFilters = ${config["exclude"]}; |
| 117 tprint = (msg) => query('#console').addText('###\$msg\\n'); | 191 tprint = (msg) => query('#console').addText('###\$msg\\n'); |
| 118 notifyDone = (e) => window.postMessage('done', '*'); | 192 notifyDone = (e) => window.postMessage('done', '*'); |
| 193 unittest.testState["port"] = $serverPort; | |
| 119 '''; | 194 '''; |
| 120 } | 195 } |
| 121 | 196 |
| 122 var action = 'process(test.main, unittest.runTests)'; | 197 var action = 'process(test.main, unittest.runTests)'; |
| 123 if (config["layout-text"]) { | 198 if (config["layout-text"]) { |
| 124 action = 'runTextLayoutTests()'; | 199 action = 'runTextLayoutTests()'; |
| 125 } else if (config["layout-pixel"]) { | 200 } else if (config["layout-pixel"]) { |
| 126 action = 'runPixelLayoutTests()'; | 201 action = 'runPixelLayoutTests()'; |
| 127 } else if (config["list-tests"]) { | 202 } else if (config["list-tests"]) { |
| 128 action = 'process(test.main, listTests)'; | 203 action = 'process(test.main, listTests)'; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 import 'dart:isolate'; | 237 import 'dart:isolate'; |
| 163 import 'dart:html'; | 238 import 'dart:html'; |
| 164 import 'dart:uri'; | 239 import 'dart:uri'; |
| 165 import '${config["unittest"]}' as 'unittest' ; | 240 import '${config["unittest"]}' as 'unittest' ; |
| 166 import '$testFile', prefix: 'test' ; | 241 import '$testFile', prefix: 'test' ; |
| 167 part '${config["runnerDir"]}/layout_test_runner.dart'; | 242 part '${config["runnerDir"]}/layout_test_runner.dart'; |
| 168 | 243 |
| 169 main() { | 244 main() { |
| 170 includeFilters = ${config["include"]}; | 245 includeFilters = ${config["include"]}; |
| 171 excludeFilters = ${config["exclude"]}; | 246 excludeFilters = ${config["exclude"]}; |
| 247 unittest.testState["port"] = $serverPort; | |
| 172 runTests(test.main); | 248 runTests(test.main); |
| 173 } | 249 } |
| 174 '''); | 250 '''); |
| 175 } | 251 } |
| 176 | 252 |
| 177 | |
| 178 // Create the HTML wrapper and compile to Javascript if necessary. | 253 // Create the HTML wrapper and compile to Javascript if necessary. |
| 179 var isJavascript = config["runtime"] == 'drt-js'; | 254 var isJavascript = config["runtime"] == 'drt-js'; |
| 180 if (config["runtime"] == 'drt-dart' || isJavascript) { | 255 if (config["runtime"] == 'drt-dart' || isJavascript) { |
| 181 var bodyElements, runAsText; | 256 var bodyElements, runAsText; |
| 182 | 257 |
| 183 if (config["layout"]) { | 258 if (config["layout"]) { |
| 184 sourceFile = tempChildDartFile; | 259 sourceFile = tempChildDartFile; |
| 185 scriptFile = isJavascript ? tempChildJsFile : tempChildDartFile; | 260 scriptFile = isJavascript ? tempChildJsFile : tempChildDartFile; |
| 186 bodyElements = ''; | 261 bodyElements = ''; |
| 187 } else { | 262 } else { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 [ '--out=$scriptFile', '$sourceFile' ]). | 319 [ '--out=$scriptFile', '$sourceFile' ]). |
| 245 then(runTestStage); | 320 then(runTestStage); |
| 246 } | 321 } |
| 247 } else { | 322 } else { |
| 248 runTestStage(0); | 323 runTestStage(0); |
| 249 } | 324 } |
| 250 } | 325 } |
| 251 | 326 |
| 252 /** Third stage of pipeline - runs the tests. */ | 327 /** Third stage of pipeline - runs the tests. */ |
| 253 runTestStage(_) { | 328 runTestStage(_) { |
| 254 if (config["server"]) { | |
| 255 var serverPath = config["testfile"]; | |
| 256 // Replace .dart with _server.dart to get test's server file, if any. | |
| 257 var truncLen = serverPath.length - '.dart'.length; | |
| 258 serverPath = '${serverPath.substring(0, truncLen)}_server.dart'; | |
| 259 var serverFile = new File(serverPath); | |
| 260 if (!serverFile.existsSync()) { | |
| 261 // No custom server; run the default server. | |
| 262 serverPath = '${config["runnerDir"]}/http_server_runner.dart'; | |
| 263 } | |
| 264 if (serverPath != null) { | |
| 265 var root = config["root"]; | |
| 266 if (root == null) { | |
| 267 // Set the root to be the directory containing the test file. | |
| 268 root = getDirectory(config["testfile"]); | |
| 269 } | |
| 270 // Start the HTTP server. | |
| 271 serverId = startProcess(config["dart"], | |
| 272 [ serverPath, '--port=${config["port"]}', '--root=$root']); | |
| 273 } | |
| 274 } | |
| 275 | |
| 276 var cmd, args; | 329 var cmd, args; |
| 277 if (config["runtime"] == 'vm' || config["layout"]) { // Run the tests. | 330 if (config["runtime"] == 'vm' || config["layout"]) { // Run the tests. |
| 278 if (config["checked"]) { | 331 if (config["checked"]) { |
| 279 cmd = config["dart"]; | 332 cmd = config["dart"]; |
| 280 args = [ '--enable_asserts', '--enable_type_checks', tempDartFile ]; | 333 args = [ '--enable_asserts', '--enable_type_checks', tempDartFile ]; |
| 281 } else { | 334 } else { |
| 282 cmd = config["dart"]; | 335 cmd = config["dart"]; |
| 283 args = [ tempDartFile ]; | 336 args = [ tempDartFile ]; |
| 284 } | 337 } |
| 285 } else { | 338 } else { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 300 | 353 |
| 301 if (!config["keep-files"]) { // Remove the temporary files. | 354 if (!config["keep-files"]) { // Remove the temporary files. |
| 302 cleanup(tempDartFile); | 355 cleanup(tempDartFile); |
| 303 cleanup(tempHtmlFile); | 356 cleanup(tempHtmlFile); |
| 304 cleanup(tempJsFile); | 357 cleanup(tempJsFile); |
| 305 cleanup(tempChildDartFile); | 358 cleanup(tempChildDartFile); |
| 306 cleanup(tempChildJsFile); | 359 cleanup(tempChildJsFile); |
| 307 } | 360 } |
| 308 completePipeline(exitcode); | 361 completePipeline(exitcode); |
| 309 } | 362 } |
| OLD | NEW |