| 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 import 'dart:convert' show JSON; | 5 import 'dart:convert'; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 | 7 |
| 8 import "package:status_file/expectation.dart"; | 8 import "package:status_file/expectation.dart"; |
| 9 | 9 |
| 10 import 'command.dart'; | 10 import 'command.dart'; |
| 11 import 'command_output.dart'; | 11 import 'command_output.dart'; |
| 12 import 'configuration.dart'; | 12 import 'configuration.dart'; |
| 13 import 'path.dart'; | 13 import 'path.dart'; |
| 14 import 'summary_report.dart'; | 14 import 'summary_report.dart'; |
| 15 import 'test_runner.dart'; | 15 import 'test_runner.dart'; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 * duration: 200.2, | 133 * duration: 200.2, |
| 134 * }, | 134 * }, |
| 135 * ], | 135 * ], |
| 136 * } | 136 * } |
| 137 * }, | 137 * }, |
| 138 */ | 138 */ |
| 139 IOSink _sink; | 139 IOSink _sink; |
| 140 | 140 |
| 141 void done(TestCase test) { | 141 void done(TestCase test) { |
| 142 var name = test.displayName; | 142 var name = test.displayName; |
| 143 var configuration = { | |
| 144 'mode': test.configuration.mode.name, | |
| 145 'arch': test.configuration.architecture.name, | |
| 146 'compiler': test.configuration.compiler.name, | |
| 147 'runtime': test.configuration.runtime.name, | |
| 148 'checked': test.configuration.isChecked, | |
| 149 'strong': test.configuration.isStrong, | |
| 150 'host_checked': test.configuration.isHostChecked, | |
| 151 'minified': test.configuration.isMinified, | |
| 152 'csp': test.configuration.isCsp, | |
| 153 'system': test.configuration.system.name, | |
| 154 'vm_options': test.configuration.vmOptions, | |
| 155 'use_sdk': test.configuration.useSdk, | |
| 156 'builder_tag': test.configuration.builderTag | |
| 157 }; | |
| 158 | |
| 159 var outcome = '${test.lastCommandOutput.result(test)}'; | 143 var outcome = '${test.lastCommandOutput.result(test)}'; |
| 160 var expectations = | 144 var expectations = |
| 161 test.expectedOutcomes.map((expectation) => "$expectation").toList(); | 145 test.expectedOutcomes.map((expectation) => "$expectation").toList(); |
| 162 | 146 |
| 163 var commandResults = []; | 147 var commandResults = []; |
| 164 double totalDuration = 0.0; | 148 double totalDuration = 0.0; |
| 165 for (var command in test.commands) { | 149 for (var command in test.commands) { |
| 166 var output = test.commandOutputs[command]; | 150 var output = test.commandOutputs[command]; |
| 167 if (output != null) { | 151 if (output != null) { |
| 168 double duration = output.time.inMicroseconds / 1000.0; | 152 double duration = output.time.inMicroseconds / 1000.0; |
| 169 totalDuration += duration; | 153 totalDuration += duration; |
| 170 commandResults.add({ | 154 commandResults.add({ |
| 171 'name': command.displayName, | 155 'name': command.displayName, |
| 172 'duration': duration, | 156 'duration': duration, |
| 173 }); | 157 }); |
| 174 } | 158 } |
| 175 } | 159 } |
| 176 _writeTestOutcomeRecord({ | 160 _writeTestOutcomeRecord({ |
| 177 'name': name, | 161 'name': name, |
| 178 'configuration': configuration, | 162 'configuration': test.configuration.toSummaryMap(), |
| 179 'test_result': { | 163 'test_result': { |
| 180 'outcome': outcome, | 164 'outcome': outcome, |
| 181 'expected_outcomes': expectations, | 165 'expected_outcomes': expectations, |
| 182 'duration': totalDuration, | 166 'duration': totalDuration, |
| 183 'command_results': commandResults, | 167 'command_results': commandResults, |
| 184 }, | 168 }, |
| 185 }); | 169 }); |
| 186 } | 170 } |
| 187 | 171 |
| 188 void allDone() { | 172 void allDone() { |
| 189 if (_sink != null) _sink.close(); | 173 if (_sink != null) _sink.close(); |
| 190 } | 174 } |
| 191 | 175 |
| 192 void _writeTestOutcomeRecord(Map record) { | 176 void _writeTestOutcomeRecord(Map record) { |
| 177 // TODO(mkroghj) change the location of this file |
| 178 // to be in the debug_output_directory |
| 179 // if the current location is not used. |
| 193 if (_sink == null) { | 180 if (_sink == null) { |
| 194 _sink = new File(TestUtils.testOutcomeFileName) | 181 _sink = new File(TestUtils.testOutcomeFileName) |
| 195 .openWrite(mode: FileMode.APPEND); | 182 .openWrite(mode: FileMode.APPEND); |
| 196 } | 183 } |
| 197 _sink.write("${JSON.encode(record)}\n"); | 184 _sink.write("${JSON.encode(record)}\n"); |
| 198 } | 185 } |
| 199 } | 186 } |
| 200 | 187 |
| 201 class UnexpectedCrashLogger extends EventListener { | 188 class UnexpectedCrashLogger extends EventListener { |
| 202 final archivedBinaries = <String, String>{}; | 189 final archivedBinaries = <String, String>{}; |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 } | 658 } |
| 672 | 659 |
| 673 String _buildSummaryEnd(int failedTests) { | 660 String _buildSummaryEnd(int failedTests) { |
| 674 if (failedTests == 0) { | 661 if (failedTests == 0) { |
| 675 return '\n===\n=== All tests succeeded\n===\n'; | 662 return '\n===\n=== All tests succeeded\n===\n'; |
| 676 } else { | 663 } else { |
| 677 var pluralSuffix = failedTests != 1 ? 's' : ''; | 664 var pluralSuffix = failedTests != 1 ? 's' : ''; |
| 678 return '\n===\n=== ${failedTests} test$pluralSuffix failed\n===\n'; | 665 return '\n===\n=== ${failedTests} test$pluralSuffix failed\n===\n'; |
| 679 } | 666 } |
| 680 } | 667 } |
| 668 |
| 669 class ResultLogWriter extends EventListener { |
| 670 Map<String, Map> _configurations = {}; |
| 671 List<Map> _results = []; |
| 672 String _outputDirectory; |
| 673 |
| 674 void done(TestCase test) { |
| 675 // We try to find an existing configuration, so as to not duplicate this |
| 676 // for each test. |
| 677 var thisConf = test.configuration.toSummaryMap(); |
| 678 String key = _configurations.keys.firstWhere( |
| 679 (key) => identical(_configurations[key], thisConf), orElse: () { |
| 680 var newKey = "conf${_configurations.length + 1}"; |
| 681 _configurations[newKey] = thisConf; |
| 682 return newKey; |
| 683 }); |
| 684 var commands = test.commands.map((command) { |
| 685 var output = test.commandOutputs[command]; |
| 686 if (output != null) { |
| 687 return { |
| 688 'name': command.displayName, |
| 689 'exitCode': output.exitCode, |
| 690 'compilationSkipped': output.compilationSkipped, |
| 691 'timeout': output.hasTimedOut, |
| 692 'duration': output.time.inMilliseconds |
| 693 }; |
| 694 } else { |
| 695 return {'name': command.displayName}; |
| 696 } |
| 697 }).toList(); |
| 698 _results.add( |
| 699 {'configuration': key, 'name': test.displayName, 'commands': commands}); |
| 700 _outputDirectory ??= test.configuration.outputDirectory; |
| 701 } |
| 702 |
| 703 void allDone() { |
| 704 if (_outputDirectory != null) { |
| 705 var path = new Path(_outputDirectory); |
| 706 var file = |
| 707 new File(path.append(TestUtils.resultLogFileName).toNativePath()); |
| 708 file.createSync(recursive: true); |
| 709 file.writeAsStringSync(JSON |
| 710 .encode({'configurations': _configurations, 'results': _results})); |
| 711 } |
| 712 } |
| 713 } |
| OLD | NEW |