Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library test_progress; | 5 library test_progress; |
| 6 | 6 |
| 7 import "dart:io"; | 7 import "dart:io"; |
| 8 import "dart:io" as io; | 8 import "dart:io" as io; |
| 9 import "http_server.dart" as http_server; | 9 import "http_server.dart" as http_server; |
| 10 import "status_file_parser.dart"; | 10 import "status_file_parser.dart"; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 List<String> output = new List<String>(); | 70 List<String> output = new List<String>(); |
| 71 output.add(''); | 71 output.add(''); |
| 72 output.add(formatter.failed('FAILED: ${test.configurationString}' | 72 output.add(formatter.failed('FAILED: ${test.configurationString}' |
| 73 ' ${test.displayName}')); | 73 ' ${test.displayName}')); |
| 74 StringBuffer expected = new StringBuffer(); | 74 StringBuffer expected = new StringBuffer(); |
| 75 expected.write('Expected: '); | 75 expected.write('Expected: '); |
| 76 for (var expectation in test.expectedOutcomes) { | 76 for (var expectation in test.expectedOutcomes) { |
| 77 expected.write('$expectation '); | 77 expected.write('$expectation '); |
| 78 } | 78 } |
| 79 output.add(expected.toString()); | 79 output.add(expected.toString()); |
| 80 output.add('Actual: ${test.lastCommandOutput.result}'); | 80 output.add('Actual: ${test.result}'); |
| 81 if (!test.lastCommandOutput.hasTimedOut && test.info != null) { | 81 if (!test.lastCommandOutput.hasTimedOut && test.info != null) { |
| 82 if (test.lastCommandOutput.incomplete && !test.info.hasCompileError) { | 82 if (test.commandOutputs.length != test.commands.length |
| 83 && !test.info.hasCompileError) { | |
| 83 output.add('Unexpected compile-time error.'); | 84 output.add('Unexpected compile-time error.'); |
| 84 } else { | 85 } else { |
| 85 if (test.info.hasCompileError) { | 86 if (test.info.hasCompileError) { |
| 86 output.add('Compile-time error expected.'); | 87 output.add('Compile-time error expected.'); |
| 87 } | 88 } |
| 88 if (test.info.hasRuntimeError) { | 89 if (test.info.hasRuntimeError) { |
| 89 output.add('Runtime error expected.'); | 90 output.add('Runtime error expected.'); |
| 90 } | 91 } |
| 91 } | 92 } |
| 92 } | 93 } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 123 // Additional command for rerunning the steps locally after the fact. | 124 // Additional command for rerunning the steps locally after the fact. |
| 124 var command = | 125 var command = |
| 125 test.configuration["_servers_"].httpServerCommandline(); | 126 test.configuration["_servers_"].httpServerCommandline(); |
| 126 output.add(''); | 127 output.add(''); |
| 127 output.add('To retest, run: $command'); | 128 output.add('To retest, run: $command'); |
| 128 } | 129 } |
| 129 for (var i = 0; i < test.commands.length; i++) { | 130 for (var i = 0; i < test.commands.length; i++) { |
| 130 var command = test.commands[i]; | 131 var command = test.commands[i]; |
| 131 var commandOutput = test.commandOutputs[command]; | 132 var commandOutput = test.commandOutputs[command]; |
| 132 output.add(''); | 133 output.add(''); |
| 133 output.add('Command[$i]: $command'); | 134 output.add('Command[${command.displayName}}]: $command'); |
|
ricow1
2013/08/01 18:23:52
extra }
kustermann
2013/08/05 07:29:17
Done.
| |
| 134 if (commandOutput != null) { | 135 if (commandOutput != null) { |
| 135 output.add('Took ${commandOutput.time}'); | 136 output.add('Took ${commandOutput.time}'); |
| 136 } else { | 137 } else { |
| 137 output.add('Did not run'); | 138 output.add('Did not run'); |
| 138 } | 139 } |
| 139 } | 140 } |
| 140 | 141 |
| 141 var arguments = ['python', 'tools/test.py']; | 142 var arguments = ['python', 'tools/test.py']; |
| 142 arguments.addAll(test.configuration['_reproducing_arguments_']); | 143 arguments.addAll(test.configuration['_reproducing_arguments_']); |
| 143 arguments.add(test.displayName); | 144 arguments.add(test.displayName); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 154 return '\n===\n=== All tests succeeded\n===\n'; | 155 return '\n===\n=== All tests succeeded\n===\n'; |
| 155 } else { | 156 } else { |
| 156 var pluralSuffix = failedTests != 1 ? 's' : ''; | 157 var pluralSuffix = failedTests != 1 ? 's' : ''; |
| 157 return '\n===\n=== ${failedTests} test$pluralSuffix failed\n===\n'; | 158 return '\n===\n=== ${failedTests} test$pluralSuffix failed\n===\n'; |
| 158 } | 159 } |
| 159 } | 160 } |
| 160 | 161 |
| 161 | 162 |
| 162 class EventListener { | 163 class EventListener { |
| 163 void testAdded() { } | 164 void testAdded() { } |
| 164 void start(TestCase test) { } | |
| 165 void done(TestCase test) { } | 165 void done(TestCase test) { } |
| 166 void allTestsKnown() { } | 166 void allTestsKnown() { } |
| 167 void allDone() { } | 167 void allDone() { } |
| 168 } | 168 } |
| 169 | 169 |
| 170 class ExitCodeSetter extends EventListener { | 170 class ExitCodeSetter extends EventListener { |
| 171 void done(TestCase test) { | 171 void done(TestCase test) { |
| 172 if (test.lastCommandOutput.unexpectedOutput) { | 172 if (test.unexpectedOutput) { |
| 173 io.exitCode = 1; | 173 io.exitCode = 1; |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| 178 class FlakyLogWriter extends EventListener { | 178 class FlakyLogWriter extends EventListener { |
| 179 void done(TestCase test) { | 179 void done(TestCase test) { |
| 180 if (test.isFlaky && test.lastCommandOutput.result != PASS) { | 180 if (test.isFlaky && test.result != PASS) { |
| 181 var buf = new StringBuffer(); | 181 var buf = new StringBuffer(); |
| 182 for (var l in _buildFailureOutput(test)) { | 182 for (var l in _buildFailureOutput(test)) { |
| 183 buf.write("$l\n"); | 183 buf.write("$l\n"); |
| 184 } | 184 } |
| 185 _appendToFlakyFile(buf.toString()); | 185 _appendToFlakyFile(buf.toString()); |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 | 188 |
| 189 void _appendToFlakyFile(String msg) { | 189 void _appendToFlakyFile(String msg) { |
| 190 var file = new File(TestUtils.flakyFileName()); | 190 var file = new File(TestUtils.flakyFileName()); |
| 191 var fd = file.openSync(mode: FileMode.APPEND); | 191 var fd = file.openSync(mode: FileMode.APPEND); |
| 192 fd.writeStringSync(msg); | 192 fd.writeStringSync(msg); |
| 193 fd.closeSync(); | 193 fd.closeSync(); |
| 194 } | 194 } |
| 195 } | 195 } |
| 196 | 196 |
| 197 class SummaryPrinter extends EventListener { | 197 class SummaryPrinter extends EventListener { |
| 198 void allTestsKnown() { | 198 void allTestsKnown() { |
| 199 if (SummaryReport.total > 0) { | 199 if (SummaryReport.total > 0) { |
| 200 SummaryReport.printReport(); | 200 SummaryReport.printReport(); |
| 201 } | 201 } |
| 202 } | 202 } |
| 203 } | 203 } |
| 204 | 204 |
| 205 class TimingPrinter extends EventListener { | 205 class TimingPrinter extends EventListener { |
| 206 List<CommandOutput> _commandOutputs = <CommandOutput>[]; | 206 final _command2testCases = new Map<Command, List<TestCase>>(); |
| 207 final _commandOutputs = new Set<CommandOutput>(); | |
| 207 DateTime _startTime; | 208 DateTime _startTime; |
| 208 | 209 |
| 209 TimingPrinter(this._startTime); | 210 TimingPrinter(this._startTime); |
| 210 | 211 |
| 211 void done(TestCase testCase) { | 212 void done(TestCase testCase) { |
| 212 for (var commandOutput in testCase.commandOutputs.values) { | 213 for (var commandOutput in testCase.commandOutputs.values) { |
| 214 var command = commandOutput.command; | |
| 213 _commandOutputs.add(commandOutput); | 215 _commandOutputs.add(commandOutput); |
| 216 _command2testCases.putIfAbsent(command, () => <TestCase>[]); | |
| 217 _command2testCases[command].add(testCase); | |
| 214 } | 218 } |
| 215 } | 219 } |
| 216 | 220 |
| 217 void allDone() { | 221 void allDone() { |
| 218 Duration d = (new DateTime.now()).difference(_startTime); | 222 Duration d = (new DateTime.now()).difference(_startTime); |
| 219 print('\n--- Total time: ${_timeString(d)} ---'); | 223 print('\n--- Total time: ${_timeString(d)} ---'); |
| 220 _commandOutputs.sort((a, b) { | 224 var outputs = _commandOutputs.toList(); |
| 225 outputs.sort((a, b) { | |
| 221 return b.time.inMilliseconds - a.time.inMilliseconds; | 226 return b.time.inMilliseconds - a.time.inMilliseconds; |
| 222 }); | 227 }); |
| 223 for (int i = 0; i < 20 && i < _commandOutputs.length; i++) { | 228 for (int i = 0; i < 20 && i < outputs.length; i++) { |
| 224 var commandOutput = _commandOutputs[i]; | 229 var commandOutput = outputs[i]; |
| 225 var command = commandOutput.command; | 230 var command = commandOutput.command; |
| 226 var testCase = commandOutput.testCase; | 231 var testCases = _command2testCases[command]; |
| 227 var duration = commandOutput.time; | 232 var duration = commandOutput.time; |
| 228 var configuration = testCase.configurationString; | 233 |
| 229 print('${commandOutput.time} - $configuration' | 234 var testCasesDescription = testCases.map((testCase) { |
| 230 ' - ${testCase.displayName} (${command.displayName})'); | 235 return "${testCase.configurationString}/${testCase.displayName}"; |
| 236 }).join(', '); | |
| 237 | |
| 238 print('${commandOutput.time} - ' | |
| 239 '${command.displayName} - ' | |
| 240 '$testCasesDescription'); | |
| 231 } | 241 } |
| 232 } | 242 } |
| 233 } | 243 } |
| 234 | 244 |
| 235 class StatusFileUpdatePrinter extends EventListener { | 245 class StatusFileUpdatePrinter extends EventListener { |
| 236 var statusToConfigs = new Map<String, List<String>>(); | 246 var statusToConfigs = new Map<String, List<String>>(); |
| 237 var _failureSummary = <String>[]; | 247 var _failureSummary = <String>[]; |
| 238 | 248 |
| 239 void done(TestCase test) { | 249 void done(TestCase test) { |
| 240 if (test.lastCommandOutput.unexpectedOutput) { | 250 if (test.unexpectedOutput) { |
| 241 _printFailureOutput(test); | 251 _printFailureOutput(test); |
| 242 } | 252 } |
| 243 } | 253 } |
| 244 | 254 |
| 245 void allDone() { | 255 void allDone() { |
| 246 _printFailureSummary(); | 256 _printFailureSummary(); |
| 247 } | 257 } |
| 248 | 258 |
| 249 | 259 |
| 250 void _printFailureOutput(TestCase test) { | 260 void _printFailureOutput(TestCase test) { |
| 251 String status = '${test.displayName}: ${test.lastCommandOutput.result}'; | 261 String status = '${test.displayName}: ${test.result}'; |
| 252 List<String> configs = | 262 List<String> configs = |
| 253 statusToConfigs.putIfAbsent(status, () => <String>[]); | 263 statusToConfigs.putIfAbsent(status, () => <String>[]); |
| 254 configs.add(test.configurationString); | 264 configs.add(test.configurationString); |
| 255 if (test.lastCommandOutput.hasTimedOut) { | 265 if (test.lastCommandOutput.hasTimedOut) { |
| 256 print('\n${test.displayName} timed out on ${test.configurationString}'); | 266 print('\n${test.displayName} timed out on ${test.configurationString}'); |
| 257 } | 267 } |
| 258 } | 268 } |
| 259 | 269 |
| 260 String _extractRuntime(String configuration) { | 270 String _extractRuntime(String configuration) { |
| 261 // Extract runtime from a configuration, for example, | 271 // Extract runtime from a configuration, for example, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 "in the system tempdir ('$systemTempDir')! " | 351 "in the system tempdir ('$systemTempDir')! " |
| 342 "Maybe left over directories?\n"); | 352 "Maybe left over directories?\n"); |
| 343 } | 353 } |
| 344 }); | 354 }); |
| 345 } | 355 } |
| 346 } | 356 } |
| 347 | 357 |
| 348 class LineProgressIndicator extends EventListener { | 358 class LineProgressIndicator extends EventListener { |
| 349 void done(TestCase test) { | 359 void done(TestCase test) { |
| 350 var status = 'pass'; | 360 var status = 'pass'; |
| 351 if (test.lastCommandOutput.unexpectedOutput) { | 361 if (test.unexpectedOutput) { |
| 352 status = 'fail'; | 362 status = 'fail'; |
| 353 } | 363 } |
| 354 print('Done ${test.configurationString} ${test.displayName}: $status'); | 364 print('Done ${test.configurationString} ${test.displayName}: $status'); |
| 355 } | 365 } |
| 356 } | 366 } |
| 357 | 367 |
| 358 class TestFailurePrinter extends EventListener { | 368 class TestFailurePrinter extends EventListener { |
| 359 bool _printSummary; | 369 bool _printSummary; |
| 360 var _formatter; | 370 var _formatter; |
| 361 var _failureSummary = <String>[]; | 371 var _failureSummary = <String>[]; |
| 362 var _failedTests= 0; | 372 var _failedTests= 0; |
| 363 | 373 |
| 364 TestFailurePrinter(this._printSummary, | 374 TestFailurePrinter(this._printSummary, |
| 365 [this._formatter = const Formatter()]); | 375 [this._formatter = const Formatter()]); |
| 366 | 376 |
| 367 void done(TestCase test) { | 377 void done(TestCase test) { |
| 368 if (test.lastCommandOutput.unexpectedOutput) { | 378 if (test.unexpectedOutput) { |
| 369 _failedTests++; | 379 _failedTests++; |
| 370 var lines = _buildFailureOutput(test, _formatter); | 380 var lines = _buildFailureOutput(test, _formatter); |
| 371 for (var line in lines) { | 381 for (var line in lines) { |
| 372 print(line); | 382 print(line); |
| 373 } | 383 } |
| 374 print(''); | 384 print(''); |
| 375 if (_printSummary) { | 385 if (_printSummary) { |
| 376 _failureSummary.addAll(lines); | 386 _failureSummary.addAll(lines); |
| 377 _failureSummary.add(''); | 387 _failureSummary.add(''); |
| 378 } | 388 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 393 } | 403 } |
| 394 } | 404 } |
| 395 } | 405 } |
| 396 | 406 |
| 397 class ProgressIndicator extends EventListener { | 407 class ProgressIndicator extends EventListener { |
| 398 ProgressIndicator(this._startTime); | 408 ProgressIndicator(this._startTime); |
| 399 | 409 |
| 400 | 410 |
| 401 void testAdded() { _foundTests++; } | 411 void testAdded() { _foundTests++; } |
| 402 | 412 |
| 403 void start(TestCase test) { | |
| 404 _printStartProgress(test); | |
| 405 } | |
| 406 | |
| 407 void done(TestCase test) { | 413 void done(TestCase test) { |
| 408 if (test.lastCommandOutput.unexpectedOutput) { | 414 if (test.unexpectedOutput) { |
| 409 _failedTests++; | 415 _failedTests++; |
| 410 } else { | 416 } else { |
| 411 _passedTests++; | 417 _passedTests++; |
| 412 } | 418 } |
| 413 _printDoneProgress(test); | 419 _printDoneProgress(test); |
| 414 } | 420 } |
| 415 | 421 |
| 416 void allTestsKnown() { | 422 void allTestsKnown() { |
| 417 _allTestsKnown = true; | 423 _allTestsKnown = true; |
| 418 } | 424 } |
| 419 | 425 |
| 420 void _printStartProgress(TestCase test) {} | |
| 421 void _printDoneProgress(TestCase test) {} | 426 void _printDoneProgress(TestCase test) {} |
| 422 | 427 |
| 423 int _completedTests() => _passedTests + _failedTests; | 428 int _completedTests() => _passedTests + _failedTests; |
| 424 | 429 |
| 425 int _foundTests = 0; | 430 int _foundTests = 0; |
| 426 int _passedTests = 0; | 431 int _passedTests = 0; |
| 427 int _failedTests = 0; | 432 int _failedTests = 0; |
| 428 bool _allTestsKnown = false; | 433 bool _allTestsKnown = false; |
| 429 DateTime _startTime; | 434 DateTime _startTime; |
| 430 } | 435 } |
| 431 | 436 |
| 432 abstract class CompactIndicator extends ProgressIndicator { | 437 abstract class CompactIndicator extends ProgressIndicator { |
| 433 CompactIndicator(DateTime startTime) | 438 CompactIndicator(DateTime startTime) |
| 434 : super(startTime); | 439 : super(startTime); |
| 435 | 440 |
| 436 void allDone() { | 441 void allDone() { |
| 437 if (_failedTests > 0) { | 442 if (_failedTests > 0) { |
| 438 // We may have printed many failure logs, so reprint the summary data. | 443 // We may have printed many failure logs, so reprint the summary data. |
| 439 _printProgress(); | 444 _printProgress(); |
| 440 } | 445 } |
| 441 print(''); | 446 print(''); |
| 442 } | 447 } |
| 443 | 448 |
| 444 void _printStartProgress(TestCase test) => _printProgress(); | |
| 445 void _printDoneProgress(TestCase test) => _printProgress(); | 449 void _printDoneProgress(TestCase test) => _printProgress(); |
| 446 | 450 |
| 447 void _printProgress(); | 451 void _printProgress(); |
| 448 } | 452 } |
| 449 | 453 |
| 450 | 454 |
| 451 class CompactProgressIndicator extends CompactIndicator { | 455 class CompactProgressIndicator extends CompactIndicator { |
| 452 Formatter _formatter; | 456 Formatter _formatter; |
| 453 | 457 |
| 454 CompactProgressIndicator(DateTime startTime, this._formatter) | 458 CompactProgressIndicator(DateTime startTime, this._formatter) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 466 '-${_formatter.failed(failedPadded)}]'; | 470 '-${_formatter.failed(failedPadded)}]'; |
| 467 stdout.write(progressLine); | 471 stdout.write(progressLine); |
| 468 } | 472 } |
| 469 } | 473 } |
| 470 | 474 |
| 471 | 475 |
| 472 class VerboseProgressIndicator extends ProgressIndicator { | 476 class VerboseProgressIndicator extends ProgressIndicator { |
| 473 VerboseProgressIndicator(DateTime startTime) | 477 VerboseProgressIndicator(DateTime startTime) |
| 474 : super(startTime); | 478 : super(startTime); |
| 475 | 479 |
| 476 void _printStartProgress(TestCase test) { | |
| 477 print('Starting ${test.configurationString} ${test.displayName}...'); | |
| 478 } | |
| 479 | |
| 480 void _printDoneProgress(TestCase test) { | 480 void _printDoneProgress(TestCase test) { |
| 481 var status = 'pass'; | 481 var status = 'pass'; |
| 482 if (test.lastCommandOutput.unexpectedOutput) { | 482 if (test.unexpectedOutput) { |
| 483 status = 'fail'; | 483 status = 'fail'; |
| 484 } | 484 } |
| 485 print('Done ${test.configurationString} ${test.displayName}: $status'); | 485 print('Done ${test.configurationString} ${test.displayName}: $status'); |
| 486 } | 486 } |
| 487 } | 487 } |
| 488 | 488 |
| 489 | 489 |
| 490 class BuildbotProgressIndicator extends ProgressIndicator { | 490 class BuildbotProgressIndicator extends ProgressIndicator { |
| 491 static String stepName; | 491 static String stepName; |
| 492 var _failureSummary = <String>[]; | 492 var _failureSummary = <String>[]; |
| 493 | 493 |
| 494 BuildbotProgressIndicator(DateTime startTime) : super(startTime); | 494 BuildbotProgressIndicator(DateTime startTime) : super(startTime); |
| 495 | 495 |
| 496 void done(TestCase test) { | 496 void done(TestCase test) { |
| 497 super.done(test); | 497 super.done(test); |
| 498 if (test.lastCommandOutput.unexpectedOutput) { | 498 if (test.unexpectedOutput) { |
| 499 _failureSummary.addAll(_buildFailureOutput(test)); | 499 _failureSummary.addAll(_buildFailureOutput(test)); |
| 500 } | 500 } |
| 501 } | 501 } |
| 502 | 502 |
| 503 void _printDoneProgress(TestCase test) { | 503 void _printDoneProgress(TestCase test) { |
| 504 var status = 'pass'; | 504 var status = 'pass'; |
| 505 if (test.lastCommandOutput.unexpectedOutput) { | 505 if (test.unexpectedOutput) { |
| 506 status = 'fail'; | 506 status = 'fail'; |
| 507 } | 507 } |
| 508 var percent = ((_completedTests() / _foundTests) * 100).toInt().toString(); | 508 var percent = ((_completedTests() / _foundTests) * 100).toInt().toString(); |
| 509 print('Done ${test.configurationString} ${test.displayName}: $status'); | 509 print('Done ${test.configurationString} ${test.displayName}: $status'); |
| 510 print('@@@STEP_CLEAR@@@'); | 510 print('@@@STEP_CLEAR@@@'); |
| 511 print('@@@STEP_TEXT@ $percent% +$_passedTests -$_failedTests @@@'); | 511 print('@@@STEP_TEXT@ $percent% +$_passedTests -$_failedTests @@@'); |
| 512 } | 512 } |
| 513 | 513 |
| 514 void allDone() { | 514 void allDone() { |
| 515 if (!_failureSummary.isEmpty) { | 515 if (!_failureSummary.isEmpty) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 539 return new VerboseProgressIndicator(startTime); | 539 return new VerboseProgressIndicator(startTime); |
| 540 case 'status': | 540 case 'status': |
| 541 return new ProgressIndicator(startTime); | 541 return new ProgressIndicator(startTime); |
| 542 case 'buildbot': | 542 case 'buildbot': |
| 543 return new BuildbotProgressIndicator(startTime); | 543 return new BuildbotProgressIndicator(startTime); |
| 544 default: | 544 default: |
| 545 assert(false); | 545 assert(false); |
| 546 break; | 546 break; |
| 547 } | 547 } |
| 548 } | 548 } |
| OLD | NEW |