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 /** | 5 /** |
6 * Classes and methods for executing tests. | 6 * Classes and methods for executing tests. |
7 * | 7 * |
8 * This module includes: | 8 * This module includes: |
9 * - Managing parallel execution of tests, including timeout checks. | 9 * - Managing parallel execution of tests, including timeout checks. |
10 * - Evaluating the output of each test as pass/fail/crash/timeout. | 10 * - Evaluating the output of each test as pass/fail/crash/timeout. |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 deepJsonCompare(arguments, other.arguments) && | 132 deepJsonCompare(arguments, other.arguments) && |
133 workingDirectory == other.workingDirectory && | 133 workingDirectory == other.workingDirectory && |
134 deepJsonCompare(environmentOverrides, other.environmentOverrides); | 134 deepJsonCompare(environmentOverrides, other.environmentOverrides); |
135 | 135 |
136 String get reproductionCommand { | 136 String get reproductionCommand { |
137 var env = new StringBuffer(); | 137 var env = new StringBuffer(); |
138 environmentOverrides?.forEach((key, value) => | 138 environmentOverrides?.forEach((key, value) => |
139 (io.Platform.operatingSystem == 'windows') | 139 (io.Platform.operatingSystem == 'windows') |
140 ? env.write('set $key=${escapeCommandLineArgument(value)} & ') | 140 ? env.write('set $key=${escapeCommandLineArgument(value)} & ') |
141 : env.write('$key=${escapeCommandLineArgument(value)} ')); | 141 : env.write('$key=${escapeCommandLineArgument(value)} ')); |
142 var command = ([executable]..addAll(arguments)) | 142 var command = ([executable]..addAll(batchArguments)..addAll(arguments)) |
143 .map(escapeCommandLineArgument) | 143 .map(escapeCommandLineArgument) |
144 .join(' '); | 144 .join(' '); |
145 if (workingDirectory != null) { | 145 if (workingDirectory != null) { |
146 command = "$command (working directory: $workingDirectory)"; | 146 command = "$command (working directory: $workingDirectory)"; |
147 } | 147 } |
148 return "$env$command"; | 148 return "$env$command"; |
149 } | 149 } |
150 | 150 |
151 Future<bool> get outputIsUpToDate => new Future.value(false); | 151 Future<bool> get outputIsUpToDate => new Future.value(false); |
| 152 |
| 153 /// Arguments that are passed to the process when starting batch mode. |
| 154 /// |
| 155 /// In non-batch mode, they should be passed before [arguments]. |
| 156 List<String> get batchArguments => const []; |
152 } | 157 } |
153 | 158 |
154 class CompilationCommand extends ProcessCommand { | 159 class CompilationCommand extends ProcessCommand { |
155 final String _outputFile; | 160 final String _outputFile; |
156 final bool _neverSkipCompilation; | 161 final bool _neverSkipCompilation; |
157 final List<Uri> _bootstrapDependencies; | 162 final List<Uri> _bootstrapDependencies; |
158 | 163 |
159 CompilationCommand._( | 164 CompilationCommand._( |
160 String displayName, | 165 String displayName, |
161 this._outputFile, | 166 this._outputFile, |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 bool _equal(AnalysisCommand other) => | 360 bool _equal(AnalysisCommand other) => |
356 super._equal(other) && flavor == other.flavor; | 361 super._equal(other) && flavor == other.flavor; |
357 } | 362 } |
358 | 363 |
359 class VmCommand extends ProcessCommand { | 364 class VmCommand extends ProcessCommand { |
360 VmCommand._(String executable, List<String> arguments, | 365 VmCommand._(String executable, List<String> arguments, |
361 Map<String, String> environmentOverrides) | 366 Map<String, String> environmentOverrides) |
362 : super._("vm", executable, arguments, environmentOverrides); | 367 : super._("vm", executable, arguments, environmentOverrides); |
363 } | 368 } |
364 | 369 |
| 370 class VmBatchCommand extends ProcessCommand implements VmCommand { |
| 371 final String dartFile; |
| 372 final bool checked; |
| 373 |
| 374 VmBatchCommand._(String executable, String dartFile, List<String> arguments, |
| 375 Map<String, String> environmentOverrides, {this.checked: true}) |
| 376 : this.dartFile = dartFile, |
| 377 super._('vm-batch', executable, arguments, environmentOverrides); |
| 378 |
| 379 @override |
| 380 List<String> get batchArguments => checked |
| 381 ? ['--checked', dartFile] |
| 382 : [dartFile]; |
| 383 |
| 384 @override |
| 385 bool _equal(VmBatchCommand other) { |
| 386 return super._equal(other) && |
| 387 dartFile == other.dartFile && |
| 388 checked == other.checked; |
| 389 } |
| 390 |
| 391 @override |
| 392 void _buildHashCode(HashCodeBuilder builder) { |
| 393 super._buildHashCode(builder); |
| 394 builder.addJson(dartFile); |
| 395 builder.addJson(checked); |
| 396 } |
| 397 } |
| 398 |
365 class AdbPrecompilationCommand extends Command { | 399 class AdbPrecompilationCommand extends Command { |
366 final String precompiledRunnerFilename; | 400 final String precompiledRunnerFilename; |
367 final String processTestFilename; | 401 final String processTestFilename; |
368 final String precompiledTestDirectory; | 402 final String precompiledTestDirectory; |
369 final List<String> arguments; | 403 final List<String> arguments; |
370 final bool useBlobs; | 404 final bool useBlobs; |
371 | 405 |
372 AdbPrecompilationCommand._(this.precompiledRunnerFilename, | 406 AdbPrecompilationCommand._(this.precompiledRunnerFilename, |
373 this.processTestFilename, | 407 this.processTestFilename, |
374 this.precompiledTestDirectory, | 408 this.precompiledTestDirectory, |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 flavor, displayName, executable, arguments, environmentOverrides); | 728 flavor, displayName, executable, arguments, environmentOverrides); |
695 return _getUniqueCommand(command); | 729 return _getUniqueCommand(command); |
696 } | 730 } |
697 | 731 |
698 VmCommand getVmCommand(String executable, List<String> arguments, | 732 VmCommand getVmCommand(String executable, List<String> arguments, |
699 Map<String, String> environmentOverrides) { | 733 Map<String, String> environmentOverrides) { |
700 var command = new VmCommand._(executable, arguments, environmentOverrides); | 734 var command = new VmCommand._(executable, arguments, environmentOverrides); |
701 return _getUniqueCommand(command); | 735 return _getUniqueCommand(command); |
702 } | 736 } |
703 | 737 |
| 738 VmBatchCommand getVmBatchCommand(String executable, String tester, |
| 739 List<String> arguments, Map<String, String> environmentOverrides, |
| 740 {bool checked: true}) { |
| 741 var command = |
| 742 new VmBatchCommand._(executable, tester, arguments, environmentOverrides
, |
| 743 checked: checked); |
| 744 return _getUniqueCommand(command); |
| 745 } |
| 746 |
704 AdbPrecompilationCommand getAdbPrecompiledCommand(String precompiledRunner, | 747 AdbPrecompilationCommand getAdbPrecompiledCommand(String precompiledRunner, |
705 String processTest, | 748 String processTest, |
706 String testDirectory, | 749 String testDirectory, |
707 List<String> arguments, | 750 List<String> arguments, |
708 bool useBlobs) { | 751 bool useBlobs) { |
709 var command = new AdbPrecompilationCommand._( | 752 var command = new AdbPrecompilationCommand._( |
710 precompiledRunner, processTest, testDirectory, arguments, useBlobs); | 753 precompiledRunner, processTest, testDirectory, arguments, useBlobs); |
711 return _getUniqueCommand(command); | 754 return _getUniqueCommand(command); |
712 } | 755 } |
713 | 756 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 bool get isNegative => _expectations & IS_NEGATIVE != 0; | 884 bool get isNegative => _expectations & IS_NEGATIVE != 0; |
842 bool get hasRuntimeError => _expectations & HAS_RUNTIME_ERROR != 0; | 885 bool get hasRuntimeError => _expectations & HAS_RUNTIME_ERROR != 0; |
843 bool get hasStaticWarning => _expectations & HAS_STATIC_WARNING != 0; | 886 bool get hasStaticWarning => _expectations & HAS_STATIC_WARNING != 0; |
844 bool get isNegativeIfChecked => _expectations & IS_NEGATIVE_IF_CHECKED != 0; | 887 bool get isNegativeIfChecked => _expectations & IS_NEGATIVE_IF_CHECKED != 0; |
845 bool get hasCompileError => _expectations & HAS_COMPILE_ERROR != 0; | 888 bool get hasCompileError => _expectations & HAS_COMPILE_ERROR != 0; |
846 bool get hasCompileErrorIfChecked => | 889 bool get hasCompileErrorIfChecked => |
847 _expectations & HAS_COMPILE_ERROR_IF_CHECKED != 0; | 890 _expectations & HAS_COMPILE_ERROR_IF_CHECKED != 0; |
848 bool get expectCompileError => _expectations & EXPECT_COMPILE_ERROR != 0; | 891 bool get expectCompileError => _expectations & EXPECT_COMPILE_ERROR != 0; |
849 | 892 |
850 bool get unexpectedOutput { | 893 bool get unexpectedOutput { |
851 var outcome = lastCommandOutput.result(this); | 894 var outcome = this.result; |
852 return !expectedOutcomes.any((expectation) { | 895 return !expectedOutcomes.any((expectation) { |
853 return outcome.canBeOutcomeOf(expectation); | 896 return outcome.canBeOutcomeOf(expectation); |
854 }); | 897 }); |
855 } | 898 } |
856 | 899 |
857 Expectation get result => lastCommandOutput.result(this); | 900 Expectation get result => lastCommandOutput.result(this); |
858 | 901 |
859 CommandOutput get lastCommandOutput { | 902 CommandOutput get lastCommandOutput { |
860 if (commandOutputs.length == 0) { | 903 if (commandOutputs.length == 0) { |
861 throw new Exception("CommandOutputs is empty, maybe no command was run? (" | 904 throw new Exception("CommandOutputs is empty, maybe no command was run? (" |
(...skipping 1312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2174 } | 2217 } |
2175 | 2218 |
2176 void _timeoutHandler() { | 2219 void _timeoutHandler() { |
2177 _processExitHandler = makeExitHandler(">>> TEST TIMEOUT"); | 2220 _processExitHandler = makeExitHandler(">>> TEST TIMEOUT"); |
2178 _process.kill(); | 2221 _process.kill(); |
2179 } | 2222 } |
2180 | 2223 |
2181 _startProcess(callback) { | 2224 _startProcess(callback) { |
2182 assert(_command is ProcessCommand); | 2225 assert(_command is ProcessCommand); |
2183 var executable = _command.executable; | 2226 var executable = _command.executable; |
2184 var arguments = ['--batch']; | 2227 var arguments = []..addAll(_command.batchArguments)..add('--batch'); |
2185 var environment = new Map.from(io.Platform.environment); | 2228 var environment = new Map.from(io.Platform.environment); |
2186 if (_processEnvironmentOverrides != null) { | 2229 if (_processEnvironmentOverrides != null) { |
2187 for (var key in _processEnvironmentOverrides.keys) { | 2230 for (var key in _processEnvironmentOverrides.keys) { |
2188 environment[key] = _processEnvironmentOverrides[key]; | 2231 environment[key] = _processEnvironmentOverrides[key]; |
2189 } | 2232 } |
2190 } | 2233 } |
2191 Future processFuture = | 2234 Future processFuture = |
2192 io.Process.start(executable, arguments, environment: environment); | 2235 io.Process.start(executable, arguments, environment: environment); |
2193 processFuture.then((io.Process p) { | 2236 processFuture.then((io.Process p) { |
2194 _process = p; | 2237 _process = p; |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2635 } else if (command is ScriptCommand) { | 2678 } else if (command is ScriptCommand) { |
2636 return command.run(); | 2679 return command.run(); |
2637 } else if (command is AdbPrecompilationCommand) { | 2680 } else if (command is AdbPrecompilationCommand) { |
2638 assert(adbDevicePool != null); | 2681 assert(adbDevicePool != null); |
2639 return adbDevicePool.acquireDevice().then((AdbDevice device) { | 2682 return adbDevicePool.acquireDevice().then((AdbDevice device) { |
2640 return _runAdbPrecompilationCommand(device, command, timeout) | 2683 return _runAdbPrecompilationCommand(device, command, timeout) |
2641 .whenComplete(() { | 2684 .whenComplete(() { |
2642 adbDevicePool.releaseDevice(device); | 2685 adbDevicePool.releaseDevice(device); |
2643 }); | 2686 }); |
2644 }); | 2687 }); |
| 2688 } else if (command is VmBatchCommand) { |
| 2689 var name = command.displayName; |
| 2690 return _getBatchRunner(command.displayName + command.dartFile) |
| 2691 .runCommand(name, command, timeout, command.arguments); |
2645 } else { | 2692 } else { |
2646 return new RunningProcess(command, timeout).run(); | 2693 return new RunningProcess(command, timeout).run(); |
2647 } | 2694 } |
2648 } | 2695 } |
2649 | 2696 |
2650 Future<CommandOutput> _runAdbPrecompilationCommand( | 2697 Future<CommandOutput> _runAdbPrecompilationCommand( |
2651 AdbDevice device, AdbPrecompilationCommand command, int timeout) async { | 2698 AdbDevice device, AdbPrecompilationCommand command, int timeout) async { |
2652 var runner = command.precompiledRunnerFilename; | 2699 var runner = command.precompiledRunnerFilename; |
2653 var processTest = command.processTestFilename; | 2700 var processTest = command.processTestFilename; |
2654 var testdir = command.precompiledTestDirectory; | 2701 var testdir = command.precompiledTestDirectory; |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3154 } | 3201 } |
3155 } | 3202 } |
3156 | 3203 |
3157 void eventAllTestsDone() { | 3204 void eventAllTestsDone() { |
3158 for (var listener in _eventListener) { | 3205 for (var listener in _eventListener) { |
3159 listener.allDone(); | 3206 listener.allDone(); |
3160 } | 3207 } |
3161 _allDone(); | 3208 _allDone(); |
3162 } | 3209 } |
3163 } | 3210 } |
OLD | NEW |