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

Side by Side Diff: tools/testing/dart/test_runner.dart

Issue 8440066: Add test_runner.dart to Dart version of test scripts. Include TestRunnerTest unit test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Skip TimeoutTest on dartium Created 9 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
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.
4
5 #library("test_runner");
6
7
8 #import("status_file_parser.dart");
9 // #import("test_configuration.dart");
Søren Gjesse 2011/11/04 09:05:34 "Code" in comments.
Mads Ager (google) 2011/11/04 09:06:13 Remove commented out code.
Bill Hesse 2011/11/04 14:49:22 Done.
10
11 /**
12 * Classes and methods for executing tests.
13 *
14 * This module includes:
15 * - Managing parallel execution of tests, including timeout checks.
16 * - Evaluating the output of each test as pass/fail/crash/timeout.
17 */
18
19 // Possible outcomes of running a test.
20 final CRASH = "Crash";
21 final TIMEOUT = "Timeout";
22 final FAIL = "Fail";
23 final PASS = "Pass";
24 // An indication to skip the test. The caller is responsible for skipping it.
25 final SKIP = "Skip";
26
27 class TestCase {
28 String executablePath;
29 List<String> arguments;
30 String commandLine;
31 TestOutput output;
32 Set<String> expectedOutcomes;
33 Function completedHandler;
34
35 TestCase(this.executablePath, this.arguments,
36 this.completedHandler, this.expectedOutcomes) {
37 commandLine = executablePath;
38 for (var arg in arguments) {
39 commandLine += " " + arg;
40 }
41 }
42
43 bool get isNegative() => false;
44
45 void completed() { completedHandler(this); }
46 }
47
Søren Gjesse 2011/11/04 09:05:34 Add empty line.
Bill Hesse 2011/11/04 14:49:22 Done.
48 class TestOutput {
49 TestCase testCase; // The TestCase this is the output for.
Mads Ager (google) 2011/11/04 09:06:13 I would add the comment above the line instead.
Bill Hesse 2011/11/04 14:49:22 Done.
50 int exitCode;
51 bool timedOut;
52 bool failed = false;
53 List<String> stdout;
54 List<String> stderr;
55 Duration time;
56
57 TestOutput(this.testCase, this.exitCode, this.timedOut, this.stdout,
58 this.stderr, this.time) {
59 testCase.output = this;
60 }
61
Mads Ager (google) 2011/11/04 09:06:13 Remove extra blank?
Bill Hesse 2011/11/04 14:49:22 Done.
62
63 String get result() =>
64 hasCrashed ? CRASH : (hasTimedOut ? TIMEOUT : (hasFailed ? FAIL : PASS));
65
66 bool get unexpectedOutput() => !testCase.expectedOutcomes.contains(result);
67
68 bool get hasCrashed() =>
Mads Ager (google) 2011/11/04 09:06:13 This will fit on one line I think?
Bill Hesse 2011/11/04 14:49:22 Done.
69 !timedOut && exitCode != 255 && exitCode != 0;
70
71 bool get hasTimedOut() => timedOut;
72
73 bool get didFail() => exitCode != 0 && !hasCrashed;
74
75 bool get hasFailed() => // Reverse result of a negative test.
Mads Ager (google) 2011/11/04 09:06:13 Please move this comment to the line above and mak
76 (testCase.isNegative ? !didFail : didFail);
77 }
78
79
80 class RunningProcess {
81 Process process;
82 TestCase testCase;
83 String executablePath;
Mads Ager (google) 2011/11/04 09:06:13 Isn't the executablePath and the arguments also in
Bill Hesse 2011/11/04 14:49:22 Done.
84 List<String> arguments;
85 int timeout;
86 bool timedOut = false;
87 int timerKey; // Running processes have a timeout check callback in a map.
Mads Ager (google) 2011/11/04 09:06:13 Move comment above the field instead?
Bill Hesse 2011/11/04 14:49:22 Why? I have gotten rid of this anyway, by creating
88 Date startTime;
89 List<String> output;
Søren Gjesse 2011/11/04 09:05:34 Use names stdout and stderr as on TestOutput class
Bill Hesse 2011/11/04 14:49:22 Done.
90 List<String> errorOutput;
91 List<Function> handlers;
92
93 static final int NO_TIMEOUT = 0;
94
95 RunningProcess(this.testCase,
Mads Ager (google) 2011/11/04 09:06:13 One line?
Bill Hesse 2011/11/04 14:49:22 Done.
96 [this.timeout = NO_TIMEOUT]);
97
98 void exitHandler(int exitCode) {
Søren Gjesse 2011/11/04 09:05:34 When we get the stream close handling working corr
99 new TestOutput(testCase, exitCode, timedOut, output,
100 errorOutput, new Date.now().difference(startTime));
101 process.close();
102 TimerChecks.remove(timerKey);
103 testCase.completed();
104 }
105
Mads Ager (google) 2011/11/04 09:06:13 Either consistently use two new lines or one.
106
Søren Gjesse 2011/11/04 09:05:34 Only one empty line between methods for consistenc
Bill Hesse 2011/11/04 14:49:22 Done.
107 void makeReadHandler(StringInputStream source, List<String> destination) {
108 return () {
109 var line = source.readLine();
110 while (null != line) {
111 destination.add(line);
112 line = source.readLine();
113 }
114 };
115 }
116
117
Søren Gjesse 2011/11/04 09:05:34 Ditto.
118 void start() {
119 Expect.isFalse(testCase.expectedOutcomes.contains(SKIP));
120 process = new Process(testCase.executablePath, testCase.arguments);
121 process.exitHandler = exitHandler;
122 startTime = new Date.now();
123 process.start();
124
125 InputStream stdout = process.stdout;
126 InputStream stderr = process.stderr;
127 output = new List<String>();
128 errorOutput = new List<String>();
129 StringInputStream stdoutStringStream = new StringInputStream(stdout);
130 StringInputStream stderrStringStream = new StringInputStream(stderr);
131 stdoutStringStream.dataHandler =
132 makeReadHandler(stdoutStringStream, output);
133 stderrStringStream.dataHandler =
134 makeReadHandler(stderrStringStream, errorOutput);
135 timerKey = TimerChecks.add(checkTimeout);
136 }
137
138 void checkTimeout(Date currentTime) {
139 if (timeout != NO_TIMEOUT &&
140 currentTime.difference(startTime).inSeconds >= timeout) {
141 timedOut = true;
142 process.kill();
143 }
144 }
145 }
146
147
148 class TimerChecks {
Mads Ager (google) 2011/11/04 09:06:13 I'm not sure I like this approach. This means that
149 static int key = 1;
150 static Map<int, Function> timers;
151 static Timer timer;
152
153 static int add(Function callback) {
154 if (timers == null) initialize();
155 timers[key] = callback;
156 return key++;
157 }
158
159 static void remove(int key) => timers.remove(key);
160
161 static void initialize() {
162 timers = new Map<int, Function>();
163 timer = new Timer(callback, 1000, true);
164 }
165
166 static void callback(Timer unused) {
167 Date current = new Date.now();
168 timers.forEach((key, callback_value) => callback_value(current));
169 }
170 }
OLDNEW
« tests/standalone/standalone.status ('K') | « tests/standalone/standalone.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698