| OLD | NEW |
| 1 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 # Copyright (c) 2011, 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 | 5 |
| 6 """Runs a Dart unit test in different configurations. | |
| 7 | |
| 8 Currently supported architectures include dartium, chromium, ia32, x64, | |
| 9 arm, simarm, and dartc. | |
| 10 | |
| 11 Example: | |
| 12 run.py --arch=dartium --mode=release --test=Test.dart | |
| 13 | |
| 14 """ | |
| 15 | |
| 16 import os | 6 import os |
| 17 import platform | 7 import platform |
| 18 import re | 8 import re |
| 19 import shutil | 9 import shutil |
| 20 import subprocess | 10 import subprocess |
| 21 import sys | 11 import sys |
| 22 import tempfile | 12 import tempfile |
| 23 | 13 |
| 24 import utils | 14 import utils |
| 25 | 15 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 """Returns True if the source has a #library statement.""" | 127 """Returns True if the source has a #library statement.""" |
| 138 if LIBRARY_DEFINITION_PATTERN.search(source): | 128 if LIBRARY_DEFINITION_PATTERN.search(source): |
| 139 return True | 129 return True |
| 140 if SOURCE_OR_IMPORT_PATTERN.search(source): | 130 if SOURCE_OR_IMPORT_PATTERN.search(source): |
| 141 print ('WARNING for %s: Browser tests need a #library ' | 131 print ('WARNING for %s: Browser tests need a #library ' |
| 142 'for a file that #import or #source' % test) | 132 'for a file that #import or #source' % test) |
| 143 return False | 133 return False |
| 144 | 134 |
| 145 | 135 |
| 146 class Architecture(object): | 136 class Architecture(object): |
| 147 """Definitions for different ways to test based on the --arch flag.""" | 137 """Definitions for different ways to test based on the FOOBAR flag.""" |
| 148 | 138 |
| 149 def __init__(self, root_path, arch, mode, test): | 139 def __init__(self, root_path, arch, mode, FOOBAR, test): |
| 150 self.root_path = root_path | 140 self.root_path = root_path |
| 151 self.arch = arch | 141 self.arch = arch |
| 152 self.mode = mode | 142 self.mode = mode |
| 143 self.FOOBAR = FOOBAR |
| 153 self.test = test | 144 self.test = test |
| 154 self.build_root = utils.GetBuildRoot(OS_GUESS, self.mode, self.arch) | 145 self.build_root = utils.GetBuildRoot(OS_GUESS, self.mode, self.arch) |
| 155 source = file(test).read() | 146 source = file(test).read() |
| 156 self.vm_options = [] | 147 self.vm_options = [] |
| 157 self.dart_options = utils.ParseTestOptions(DART_OPTIONS_PATTERN, | 148 self.dart_options = utils.ParseTestOptions(DART_OPTIONS_PATTERN, |
| 158 source, | 149 source, |
| 159 root_path) | 150 root_path) |
| 160 self.is_web_test = _IsWebTest(source) | 151 self.is_web_test = _IsWebTest(source) |
| 161 self.temp_dir = None | 152 self.temp_dir = None |
| 162 | 153 |
| 163 def HasFatalTypeErrors(self): | 154 def HasFatalTypeErrors(self): |
| 164 """Returns True if this type of arch supports --fatal-type-errors.""" | 155 """Returns True if this type of FOOBAR supports --fatal-type-errors.""" |
| 165 return False | 156 return False |
| 166 | 157 |
| 167 def GetTestFrameworkPath(self): | 158 def GetTestFrameworkPath(self): |
| 168 """Path to dart source (TestFramework.dart) for testing framework.""" | 159 """Path to dart source (TestFramework.dart) for testing framework.""" |
| 169 return os.path.join(self.root_path, 'tests', 'isolate', 'src', | 160 return os.path.join(self.root_path, 'tests', 'isolate', 'src', |
| 170 'TestFramework.dart') | 161 'TestFramework.dart') |
| 171 | 162 |
| 172 | 163 |
| 173 class BrowserArchitecture(Architecture): | 164 class BrowserArchitecture(Architecture): |
| 174 """Architecture that runs compiled dart->JS through a browser.""" | 165 """Architecture that runs compiled dart->JS through a browser.""" |
| 175 | 166 |
| 176 def __init__(self, root_path, arch, mode, test): | 167 def __init__(self, root_path, arch, mode, FOOBAR, test): |
| 177 super(BrowserArchitecture, self).__init__(root_path, arch, mode, test) | 168 super(BrowserArchitecture, self).__init__(root_path, arch, mode, FOOBAR, tes
t) |
| 178 self.temp_dir = tempfile.mkdtemp() | 169 self.temp_dir = tempfile.mkdtemp() |
| 179 if not self.is_web_test: self.GenerateWebTestScript() | 170 if not self.is_web_test: self.GenerateWebTestScript() |
| 180 | 171 |
| 181 def GetTestScriptFile(self): | 172 def GetTestScriptFile(self): |
| 182 """Returns the name of the .dart file to compile.""" | 173 """Returns the name of the .dart file to compile.""" |
| 183 if self.is_web_test: return os.path.abspath(self.test) | 174 if self.is_web_test: return os.path.abspath(self.test) |
| 184 return os.path.join(self.temp_dir, 'test.dart') | 175 return os.path.join(self.temp_dir, 'test.dart') |
| 185 | 176 |
| 186 def GetHtmlContents(self): | 177 def GetHtmlContents(self): |
| 187 """Fills in the HTML_CONTENTS template with info for this architecture.""" | 178 """Fills in the HTML_CONTENTS template with info for this architecture.""" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 212 os.makedirs(html_path) | 203 os.makedirs(html_path) |
| 213 return html_path | 204 return html_path |
| 214 | 205 |
| 215 return self.temp_dir | 206 return self.temp_dir |
| 216 | 207 |
| 217 def GetTestContents(self, library_file): | 208 def GetTestContents(self, library_file): |
| 218 """Pastes a preamble on the front of the .dart file before testing.""" | 209 """Pastes a preamble on the front of the .dart file before testing.""" |
| 219 unittest_path = os.path.join(self.root_path, 'client', 'testing', | 210 unittest_path = os.path.join(self.root_path, 'client', 'testing', |
| 220 'unittest', 'unittest.dart') | 211 'unittest', 'unittest.dart') |
| 221 | 212 |
| 222 if self.arch == 'chromium': | 213 if self.FOOBAR == 'chromium': |
| 223 dom_path = os.path.join(self.root_path, 'client', 'testing', | 214 dom_path = os.path.join(self.root_path, 'client', 'testing', |
| 224 'unittest', 'dom_for_unittest.dart') | 215 'unittest', 'dom_for_unittest.dart') |
| 225 else: | 216 else: |
| 226 dom_path = os.path.join('dart:dom') | 217 dom_path = os.path.join('dart:dom') |
| 227 | 218 |
| 228 test_framework_path = self.GetTestFrameworkPath() | 219 test_framework_path = self.GetTestFrameworkPath() |
| 229 test_path = os.path.abspath(self.test) | 220 test_path = os.path.abspath(self.test) |
| 230 | 221 |
| 231 inputs = { | 222 inputs = { |
| 232 'unittest': unittest_path, | 223 'unittest': unittest_path, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 def Cleanup(self): | 308 def Cleanup(self): |
| 318 """Removes temporary files created for the test.""" | 309 """Removes temporary files created for the test.""" |
| 319 if self.temp_dir: | 310 if self.temp_dir: |
| 320 shutil.rmtree(self.temp_dir) | 311 shutil.rmtree(self.temp_dir) |
| 321 self.temp_dir = None | 312 self.temp_dir = None |
| 322 | 313 |
| 323 | 314 |
| 324 class ChromiumArchitecture(BrowserArchitecture): | 315 class ChromiumArchitecture(BrowserArchitecture): |
| 325 """Architecture that runs compiled dart->JS through a chromium DRT.""" | 316 """Architecture that runs compiled dart->JS through a chromium DRT.""" |
| 326 | 317 |
| 327 def __init__(self, root_path, arch, mode, test): | 318 def __init__(self, root_path, arch, mode, FOOBAR, test): |
| 328 super(ChromiumArchitecture, self).__init__(root_path, arch, mode, test) | 319 super(ChromiumArchitecture, self).__init__(root_path, arch, mode, FOOBAR, te
st) |
| 329 | 320 |
| 330 def GetScriptType(self): | 321 def GetScriptType(self): |
| 331 return 'text/javascript' | 322 return 'text/javascript' |
| 332 | 323 |
| 333 def GetScriptPath(self): | 324 def GetScriptPath(self): |
| 334 """Returns the name of the output .js file to create.""" | 325 """Returns the name of the output .js file to create.""" |
| 335 path = self.GetTestScriptFile() | 326 path = self.GetTestScriptFile() |
| 336 return os.path.abspath(os.path.join(self.temp_dir, | 327 return os.path.abspath(os.path.join(self.temp_dir, |
| 337 os.path.basename(path) + '.js')) | 328 os.path.basename(path) + '.js')) |
| 338 | 329 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 361 cmd.append(self.GetTestScriptFile()) | 352 cmd.append(self.GetTestScriptFile()) |
| 362 return cmd | 353 return cmd |
| 363 | 354 |
| 364 def Compile(self): | 355 def Compile(self): |
| 365 return ExecuteCommand(self.GetCompileCommand()) | 356 return ExecuteCommand(self.GetCompileCommand()) |
| 366 | 357 |
| 367 | 358 |
| 368 class DartiumArchitecture(BrowserArchitecture): | 359 class DartiumArchitecture(BrowserArchitecture): |
| 369 """Architecture that runs dart in an VM embedded in DumpRenderTree.""" | 360 """Architecture that runs dart in an VM embedded in DumpRenderTree.""" |
| 370 | 361 |
| 371 def __init__(self, root_path, arch, mode, test): | 362 def __init__(self, root_path, arch, mode, FOOBAR, test): |
| 372 super(DartiumArchitecture, self).__init__(root_path, arch, mode, test) | 363 super(DartiumArchitecture, self).__init__(root_path, arch, mode, FOOBAR, tes
t) |
| 373 | 364 |
| 374 def GetScriptType(self): | 365 def GetScriptType(self): |
| 375 return 'application/dart' | 366 return 'application/dart' |
| 376 | 367 |
| 377 def GetScriptPath(self): | 368 def GetScriptPath(self): |
| 378 return 'file:///' + self.GetTestScriptFile() | 369 return 'file:///' + self.GetTestScriptFile() |
| 379 | 370 |
| 380 def GetHtmlName(self): | 371 def GetHtmlName(self): |
| 381 path = os.path.relpath(self.test, self.root_path).replace(os.sep, '_') | 372 path = os.path.relpath(self.test, self.root_path).replace(os.sep, '_') |
| 382 return path + '.dartium.html' | 373 return path + '.dartium.html' |
| 383 | 374 |
| 384 def GetCompileCommand(self, fatal_static_type_errors=False): | 375 def GetCompileCommand(self, fatal_static_type_errors=False): |
| 385 fatal_static_type_errors = fatal_static_type_errors # shutup lint! | 376 fatal_static_type_errors = fatal_static_type_errors # shutup lint! |
| 386 return None | 377 return None |
| 387 | 378 |
| 388 def Compile(self): | 379 def Compile(self): |
| 389 return 0 | 380 return 0 |
| 390 | 381 |
| 391 | 382 |
| 392 class StandaloneArchitecture(Architecture): | 383 class StandaloneArchitecture(Architecture): |
| 393 """Base class for architectures that run tests without a browser.""" | 384 """Base class for architectures that run tests without a browser.""" |
| 394 | 385 |
| 395 def __init__(self, root_path, arch, mode, test): | 386 def __init__(self, root_path, arch, mode, FOOBAR, test): |
| 396 super(StandaloneArchitecture, self).__init__(root_path, arch, mode, test) | 387 super(StandaloneArchitecture, self).__init__(root_path, arch, mode, FOOBAR,
test) |
| 397 | 388 |
| 398 def GetCompileCommand(self, fatal_static_type_errors=False): | 389 def GetCompileCommand(self, fatal_static_type_errors=False): |
| 399 fatal_static_type_errors = fatal_static_type_errors # shutup lint! | 390 fatal_static_type_errors = fatal_static_type_errors # shutup lint! |
| 400 return None | 391 return None |
| 401 | 392 |
| 402 def GetRunCommand(self, fatal_static_type_errors=False): | 393 def GetRunCommand(self, fatal_static_type_errors=False): |
| 403 """Returns a command line to execute for the test.""" | 394 """Returns a command line to execute for the test.""" |
| 404 dart = self.GetExecutable() | 395 dart = self.GetExecutable() |
| 405 test_name = os.path.basename(self.test) | 396 test_name = os.path.basename(self.test) |
| 406 test_path = os.path.abspath(self.test) | 397 test_path = os.path.abspath(self.test) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 430 | 421 |
| 431 def Cleanup(self): | 422 def Cleanup(self): |
| 432 return | 423 return |
| 433 | 424 |
| 434 | 425 |
| 435 # Long term, we should do the running machinery that is currently in | 426 # Long term, we should do the running machinery that is currently in |
| 436 # DartRunner.java | 427 # DartRunner.java |
| 437 class DartcArchitecture(StandaloneArchitecture): | 428 class DartcArchitecture(StandaloneArchitecture): |
| 438 """Runs the Dart ->JS compiler then runs the result in a standalone JS VM.""" | 429 """Runs the Dart ->JS compiler then runs the result in a standalone JS VM.""" |
| 439 | 430 |
| 440 def __init__(self, root_path, arch, mode, test): | 431 def __init__(self, root_path, arch, mode, FOOBAR, test): |
| 441 super(DartcArchitecture, self).__init__(root_path, arch, mode, test) | 432 super(DartcArchitecture, self).__init__(root_path, arch, mode, FOOBAR, test) |
| 442 | 433 |
| 443 def GetExecutable(self): | 434 def GetExecutable(self): |
| 444 """Returns the name of the executable to run the test.""" | 435 """Returns the name of the executable to run the test.""" |
| 445 return os.path.abspath(os.path.join(self.build_root, | 436 return os.path.abspath(os.path.join(self.build_root, |
| 446 'compiler', | 437 'compiler', |
| 447 'bin', | 438 'bin', |
| 448 'dartc_test')) | 439 'dartc_test')) |
| 449 | 440 |
| 450 def GetFatalTypeErrorsFlags(self): | 441 def GetFatalTypeErrorsFlags(self): |
| 451 return ['--fatal-type-errors'] | 442 return ['--fatal-type-errors'] |
| 452 | 443 |
| 453 def HasFatalTypeErrors(self): | 444 def HasFatalTypeErrors(self): |
| 454 return True | 445 return True |
| 455 | 446 |
| 456 def GetRunCommand(self, fatal_static_type_errors=False): | 447 def GetRunCommand(self, fatal_static_type_errors=False): |
| 457 """Returns a command line to execute for the test.""" | 448 """Returns a command line to execute for the test.""" |
| 458 cmd = super(DartcArchitecture, self).GetRunCommand( | 449 cmd = super(DartcArchitecture, self).GetRunCommand( |
| 459 fatal_static_type_errors) | 450 fatal_static_type_errors) |
| 460 return cmd | 451 return cmd |
| 461 | 452 |
| 462 | 453 |
| 463 class RuntimeArchitecture(StandaloneArchitecture): | 454 class RuntimeArchitecture(StandaloneArchitecture): |
| 464 """Executes tests on the standalone VM (runtime).""" | 455 """Executes tests on the standalone VM (runtime).""" |
| 465 | 456 |
| 466 def __init__(self, root_path, arch, mode, test): | 457 def __init__(self, root_path, arch, mode, FOOBAR, test): |
| 467 super(RuntimeArchitecture, self).__init__(root_path, arch, mode, test) | 458 super(RuntimeArchitecture, self).__init__(root_path, arch, mode, FOOBAR, tes
t) |
| 468 | 459 |
| 469 def GetExecutable(self): | 460 def GetExecutable(self): |
| 470 """Returns the name of the executable to run the test.""" | 461 """Returns the name of the executable to run the test.""" |
| 471 return os.path.abspath(os.path.join(self.build_root, 'dart_bin')) | 462 return os.path.abspath(os.path.join(self.build_root, 'dart_bin')) |
| 472 | 463 |
| 473 | 464 |
| 474 def ExecutePipedCommand(cmd, verbose): | 465 def ExecutePipedCommand(cmd, verbose): |
| 475 """Execute a command in a subprocess.""" | 466 """Execute a command in a subprocess.""" |
| 476 if verbose: | 467 if verbose: |
| 477 print 'Executing: ' + ' '.join(cmd) | 468 print 'Executing: ' + ' '.join(cmd) |
| 478 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 469 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 479 (output, err) = pipe.communicate() | 470 (output, err) = pipe.communicate() |
| 480 if pipe.returncode != 0 and verbose: | 471 if pipe.returncode != 0 and verbose: |
| 481 print 'Execution failed: ' + output + '\n' + err | 472 print 'Execution failed: ' + output + '\n' + err |
| 482 print output | 473 print output |
| 483 print err | 474 print err |
| 484 return pipe.returncode, output, err | 475 return pipe.returncode, output, err |
| 485 | 476 |
| 486 | 477 |
| 487 def ExecuteCommand(cmd, verbose=False): | 478 def ExecuteCommand(cmd, verbose=False): |
| 488 """Execute a command in a subprocess.""" | 479 """Execute a command in a subprocess.""" |
| 489 if verbose: print 'Executing: ' + ' '.join(cmd) | 480 if verbose: print 'Executing: ' + ' '.join(cmd) |
| 490 return subprocess.call(cmd) | 481 return subprocess.call(cmd) |
| 491 | 482 |
| 492 | 483 |
| 493 def GetArchitecture(arch, mode, test): | 484 def GetArchitecture(arch, mode, FOOBAR, test): |
| 494 root_path = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '..')) | 485 root_path = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '..')) |
| 495 if arch == 'chromium': | 486 if FOOBAR == 'chromium': |
| 496 return ChromiumArchitecture(root_path, arch, mode, test) | 487 return ChromiumArchitecture(root_path, arch, mode, FOOBAR, test) |
| 497 | 488 |
| 498 elif arch == 'dartium': | 489 elif FOOBAR == 'dartium': |
| 499 return DartiumArchitecture(root_path, arch, mode, test) | 490 return DartiumArchitecture(root_path, arch, mode, FOOBAR, test) |
| 500 | 491 |
| 501 elif arch in ['ia32', 'x64', 'simarm', 'arm']: | 492 elif FOOBAR in ['vm']: |
| 502 return RuntimeArchitecture(root_path, arch, mode, test) | 493 return RuntimeArchitecture(root_path, arch, mode, FOOBAR, test) |
| 503 | 494 |
| 504 elif arch == 'dartc': | 495 elif FOOBAR == 'dartc': |
| 505 return DartcArchitecture(root_path, arch, mode, test) | 496 return DartcArchitecture(root_path, arch, mode, FOOBAR, test) |
| OLD | NEW |