Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Unified Diff: tools/testing/dart/record_and_replay.dart

Issue 15944005: Record/replay support to test.py (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/test.dart ('k') | tools/testing/dart/test_options.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/testing/dart/record_and_replay.dart
diff --git a/tools/testing/dart/record_and_replay.dart b/tools/testing/dart/record_and_replay.dart
new file mode 100644
index 0000000000000000000000000000000000000000..fd5df685908f78409e881cf8064ec9358061a9b4
--- /dev/null
+++ b/tools/testing/dart/record_and_replay.dart
@@ -0,0 +1,126 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library record_and_replay;
+
+import 'dart:io';
+import 'dart:json' as json;
+import 'dart:utf';
+
+import 'test_runner.dart';
+
+/*
+ * Json files look like this:
+ *
+ * [
+ * {
+ * 'name' : '...',
+ * 'configuration' : '...',
+ * 'command' : {
+ * 'timeout_limit' : 60,
+ * 'executable' : '...',
+ * 'arguments' : ['arg1, 'arg2', '...'],
+ * },
+ * 'command_output' : {
+ * 'exit_code' : 42,
+ * 'stdout' : '...',
+ * 'stderr' : '...',
+ * 'duration' : 1.5,
+ * 'did_timeout' : false,
+ * },
+ * },
+ * ....
+ * ]
+ */
+
+
+class TestCaseRecorder {
+ Path _outputPath;
+ List<Map> _recordedCommandInvocations = [];
+ var _cwd;
+
+ TestCaseRecorder(this._outputPath) {
+ _cwd = new Directory.current().path;
+ }
+
+ void nextTestCase(TestCase testCase) {
+ assert(testCase.commands.length == 1);
+
+ var command = testCase.commands[0];
+ assert(command.environment == null);
+
+ var arguments = [];
+ for (var rawArgument in command.arguments) {
+ if (rawArgument.startsWith(_cwd)) {
+ var relative = new Path(rawArgument).relativeTo(new Path(_cwd));
+ arguments.add(relative.toNativePath());
+ } else {
+ arguments.add(rawArgument);
+ }
+ }
+
+ var commandExecution = {
+ 'name' : testCase.displayName,
+ 'configuration' : testCase.configurationString,
+ 'command' : {
+ 'timeout_limit' : testCase.timeout,
+ 'executable' : command.executable,
+ 'arguments' : arguments,
+ },
+ };
+ _recordedCommandInvocations.add(commandExecution);
+ }
+
+ void finish() {
+ var file = new File.fromPath(_outputPath);
+ var jsonString = json.stringify(_recordedCommandInvocations);
+ file.writeAsStringSync(jsonString);
+ print("TestCaseRecorder: written all TestCases to ${_outputPath}");
+ }
+}
+
+class TestCaseOutputArchive {
+ Map<String, Map> _testCaseOutputRecords;
+
+ void loadFromPath(Path recordingPath) {
+ var file = new File.fromPath(recordingPath);
+ var testCases = json.parse(file.readAsStringSync());
+ _testCaseOutputRecords = {};
+ for (var testCase in testCases) {
+ var key = _indexKey(testCase['configuration'], testCase['name']);
+ _testCaseOutputRecords[key] = testCase['command_output'];
+ }
+ }
+
+ CommandOutput outputOf(TestCase testCase) {
+ var key = _indexKey(testCase.configurationString, testCase.displayName);
+ var command_output = _testCaseOutputRecords[key];
+ if (command_output == null) {
+ print("Sorry, but there is no command output for "
+ "${testCase.displayName}");
+
+ exit(42);
+ }
+
+ double seconds = command_output['duration'];
+ var duration = new Duration(seconds: seconds.round(),
+ milliseconds: (seconds/1000).round());
+ var commandOutput = new CommandOutput.fromCase(
+ testCase,
+ testCase.commands.first,
+ command_output['exit_code'],
+ false,
+ command_output['did_timeout'],
+ encodeUtf8(command_output['stdout']),
+ encodeUtf8(command_output['stderr']),
+ duration,
+ false);
+ return commandOutput;
+ }
+
+ String _indexKey(String configuration, String name) {
+ return "${configuration}__$name";
+ }
+}
+
« no previous file with comments | « tools/test.dart ('k') | tools/testing/dart/test_options.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698