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 { | |
kustermann
2016/12/06 10:39:05
If you make a [VmBatchCommandOutputImpl] as well f
asgerf
2016/12/06 13:42:08
I gave this a shot but couldn't make it work. The
| |
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(Command other) { | |
386 return super._equal(other) && | |
387 other is VmBatchCommand && | |
kustermann
2016/12/06 10:39:05
The "other is VmBatchCommand" is unnecessary I thi
asgerf
2016/12/06 13:42:08
Done.
I also added 'checked' to the comparison be
| |
388 dartFile == other.dartFile; | |
389 } | |
390 | |
391 @override | |
392 void _buildHashCode(HashCodeBuilder builder) { | |
393 super._buildHashCode(builder); | |
394 builder.addJson(dartFile); | |
395 } | |
396 } | |
397 | |
365 class AdbPrecompilationCommand extends Command { | 398 class AdbPrecompilationCommand extends Command { |
366 final String precompiledRunnerFilename; | 399 final String precompiledRunnerFilename; |
367 final String processTestFilename; | 400 final String processTestFilename; |
368 final String precompiledTestDirectory; | 401 final String precompiledTestDirectory; |
369 final List<String> arguments; | 402 final List<String> arguments; |
370 final bool useBlobs; | 403 final bool useBlobs; |
371 | 404 |
372 AdbPrecompilationCommand._(this.precompiledRunnerFilename, | 405 AdbPrecompilationCommand._(this.precompiledRunnerFilename, |
373 this.processTestFilename, | 406 this.processTestFilename, |
374 this.precompiledTestDirectory, | 407 this.precompiledTestDirectory, |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
694 flavor, displayName, executable, arguments, environmentOverrides); | 727 flavor, displayName, executable, arguments, environmentOverrides); |
695 return _getUniqueCommand(command); | 728 return _getUniqueCommand(command); |
696 } | 729 } |
697 | 730 |
698 VmCommand getVmCommand(String executable, List<String> arguments, | 731 VmCommand getVmCommand(String executable, List<String> arguments, |
699 Map<String, String> environmentOverrides) { | 732 Map<String, String> environmentOverrides) { |
700 var command = new VmCommand._(executable, arguments, environmentOverrides); | 733 var command = new VmCommand._(executable, arguments, environmentOverrides); |
701 return _getUniqueCommand(command); | 734 return _getUniqueCommand(command); |
702 } | 735 } |
703 | 736 |
737 VmBatchCommand getVmBatchCommand(String executable, String tester, | |
738 List<String> arguments, Map<String, String> environmentOverrides, | |
739 {bool checked: true}) { | |
740 var command = | |
741 new VmBatchCommand._(executable, tester, arguments, environmentOverrides , | |
742 checked: checked); | |
743 return _getUniqueCommand(command); | |
744 } | |
745 | |
704 AdbPrecompilationCommand getAdbPrecompiledCommand(String precompiledRunner, | 746 AdbPrecompilationCommand getAdbPrecompiledCommand(String precompiledRunner, |
705 String processTest, | 747 String processTest, |
706 String testDirectory, | 748 String testDirectory, |
707 List<String> arguments, | 749 List<String> arguments, |
708 bool useBlobs) { | 750 bool useBlobs) { |
709 var command = new AdbPrecompilationCommand._( | 751 var command = new AdbPrecompilationCommand._( |
710 precompiledRunner, processTest, testDirectory, arguments, useBlobs); | 752 precompiledRunner, processTest, testDirectory, arguments, useBlobs); |
711 return _getUniqueCommand(command); | 753 return _getUniqueCommand(command); |
712 } | 754 } |
713 | 755 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
841 bool get isNegative => _expectations & IS_NEGATIVE != 0; | 883 bool get isNegative => _expectations & IS_NEGATIVE != 0; |
842 bool get hasRuntimeError => _expectations & HAS_RUNTIME_ERROR != 0; | 884 bool get hasRuntimeError => _expectations & HAS_RUNTIME_ERROR != 0; |
843 bool get hasStaticWarning => _expectations & HAS_STATIC_WARNING != 0; | 885 bool get hasStaticWarning => _expectations & HAS_STATIC_WARNING != 0; |
844 bool get isNegativeIfChecked => _expectations & IS_NEGATIVE_IF_CHECKED != 0; | 886 bool get isNegativeIfChecked => _expectations & IS_NEGATIVE_IF_CHECKED != 0; |
845 bool get hasCompileError => _expectations & HAS_COMPILE_ERROR != 0; | 887 bool get hasCompileError => _expectations & HAS_COMPILE_ERROR != 0; |
846 bool get hasCompileErrorIfChecked => | 888 bool get hasCompileErrorIfChecked => |
847 _expectations & HAS_COMPILE_ERROR_IF_CHECKED != 0; | 889 _expectations & HAS_COMPILE_ERROR_IF_CHECKED != 0; |
848 bool get expectCompileError => _expectations & EXPECT_COMPILE_ERROR != 0; | 890 bool get expectCompileError => _expectations & EXPECT_COMPILE_ERROR != 0; |
849 | 891 |
850 bool get unexpectedOutput { | 892 bool get unexpectedOutput { |
851 var outcome = lastCommandOutput.result(this); | 893 var outcome = this.result; |
852 return !expectedOutcomes.any((expectation) { | 894 return !expectedOutcomes.any((expectation) { |
853 return outcome.canBeOutcomeOf(expectation); | 895 return outcome.canBeOutcomeOf(expectation); |
854 }); | 896 }); |
855 } | 897 } |
856 | 898 |
857 Expectation get result => lastCommandOutput.result(this); | 899 Expectation get result => lastCommandOutput.result(this); |
858 | 900 |
859 CommandOutput get lastCommandOutput { | 901 CommandOutput get lastCommandOutput { |
860 if (commandOutputs.length == 0) { | 902 if (commandOutputs.length == 0) { |
861 throw new Exception("CommandOutputs is empty, maybe no command was run? (" | 903 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 } | 2216 } |
2175 | 2217 |
2176 void _timeoutHandler() { | 2218 void _timeoutHandler() { |
2177 _processExitHandler = makeExitHandler(">>> TEST TIMEOUT"); | 2219 _processExitHandler = makeExitHandler(">>> TEST TIMEOUT"); |
2178 _process.kill(); | 2220 _process.kill(); |
2179 } | 2221 } |
2180 | 2222 |
2181 _startProcess(callback) { | 2223 _startProcess(callback) { |
2182 assert(_command is ProcessCommand); | 2224 assert(_command is ProcessCommand); |
2183 var executable = _command.executable; | 2225 var executable = _command.executable; |
2184 var arguments = ['--batch']; | 2226 var arguments = []..addAll(_command.batchArguments)..add('--batch'); |
2185 var environment = new Map.from(io.Platform.environment); | 2227 var environment = new Map.from(io.Platform.environment); |
2186 if (_processEnvironmentOverrides != null) { | 2228 if (_processEnvironmentOverrides != null) { |
2187 for (var key in _processEnvironmentOverrides.keys) { | 2229 for (var key in _processEnvironmentOverrides.keys) { |
2188 environment[key] = _processEnvironmentOverrides[key]; | 2230 environment[key] = _processEnvironmentOverrides[key]; |
2189 } | 2231 } |
2190 } | 2232 } |
2191 Future processFuture = | 2233 Future processFuture = |
2192 io.Process.start(executable, arguments, environment: environment); | 2234 io.Process.start(executable, arguments, environment: environment); |
2193 processFuture.then((io.Process p) { | 2235 processFuture.then((io.Process p) { |
2194 _process = p; | 2236 _process = p; |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2635 } else if (command is ScriptCommand) { | 2677 } else if (command is ScriptCommand) { |
2636 return command.run(); | 2678 return command.run(); |
2637 } else if (command is AdbPrecompilationCommand) { | 2679 } else if (command is AdbPrecompilationCommand) { |
2638 assert(adbDevicePool != null); | 2680 assert(adbDevicePool != null); |
2639 return adbDevicePool.acquireDevice().then((AdbDevice device) { | 2681 return adbDevicePool.acquireDevice().then((AdbDevice device) { |
2640 return _runAdbPrecompilationCommand(device, command, timeout) | 2682 return _runAdbPrecompilationCommand(device, command, timeout) |
2641 .whenComplete(() { | 2683 .whenComplete(() { |
2642 adbDevicePool.releaseDevice(device); | 2684 adbDevicePool.releaseDevice(device); |
2643 }); | 2685 }); |
2644 }); | 2686 }); |
2687 } else if (command is VmBatchCommand) { | |
2688 var name = command.displayName; | |
2689 return _getBatchRunner(command.displayName + command.dartFile) | |
2690 .runCommand(name, command, timeout, command.arguments); | |
2645 } else { | 2691 } else { |
2646 return new RunningProcess(command, timeout).run(); | 2692 return new RunningProcess(command, timeout).run(); |
2647 } | 2693 } |
2648 } | 2694 } |
2649 | 2695 |
2650 Future<CommandOutput> _runAdbPrecompilationCommand( | 2696 Future<CommandOutput> _runAdbPrecompilationCommand( |
2651 AdbDevice device, AdbPrecompilationCommand command, int timeout) async { | 2697 AdbDevice device, AdbPrecompilationCommand command, int timeout) async { |
2652 var runner = command.precompiledRunnerFilename; | 2698 var runner = command.precompiledRunnerFilename; |
2653 var processTest = command.processTestFilename; | 2699 var processTest = command.processTestFilename; |
2654 var testdir = command.precompiledTestDirectory; | 2700 var testdir = command.precompiledTestDirectory; |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3154 } | 3200 } |
3155 } | 3201 } |
3156 | 3202 |
3157 void eventAllTestsDone() { | 3203 void eventAllTestsDone() { |
3158 for (var listener in _eventListener) { | 3204 for (var listener in _eventListener) { |
3159 listener.allDone(); | 3205 listener.allDone(); |
3160 } | 3206 } |
3161 _allDone(); | 3207 _allDone(); |
3162 } | 3208 } |
3163 } | 3209 } |
OLD | NEW |