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

Unified Diff: utils/testrunner/run_process_task.dart

Issue 10897016: Testrunner for 3rd parties. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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
Index: utils/testrunner/run_process_task.dart
===================================================================
--- utils/testrunner/run_process_task.dart (revision 0)
+++ utils/testrunner/run_process_task.dart (revision 0)
@@ -0,0 +1,64 @@
+// 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.
+
+// A pipeline task to run a process and capture the output.
+class RunProcessTask extends PipelineTask {
+ String commandTemplate;
+ List argumentTemplates;
+ int timeout;
+
+ RunProcessTask(this.commandTemplate, this.argumentTemplates, this.timeout);
+
+ void execute(Path testfile, List stdout, List stderr, bool verboseLogging,
+ Function exitHandler) {
+ var cmd = concretize(commandTemplate, testfile);
+ List args = new List();
+ for (var i = 0; i < argumentTemplates.length; i++) {
+ args.add(concretize(argumentTemplates[i], testfile));
+ }
+
+ if (verboseLogging) {
+ stdout.add('Running $cmd ${Strings.join(args, " ")}');
+ }
+ var timer = null;
+ var process = Process.start(cmd, args);
+ process.onStart = () {
+ timer = new Timer(1000 * timeout, (t) {
+ timer = null;
+ process.kill();
+ });
+ };
+ process.onExit = (exitCode) {
+ if (timer != null) {
+ timer.cancel();
+ }
+ process.close();
+ exitHandler(exitCode);
+ };
+ process.onError = (e) {
+ print("Error starting process:");
+ print(" Command: $cmd");
+ print(" Error: $e");
+ exitHandler(-1);
+ };
+
+ StringInputStream stdoutStringStream =
+ new StringInputStream(process.stdout);
+ StringInputStream stderrStringStream =
+ new StringInputStream(process.stderr);
+ stdoutStringStream.onLine = makeReadHandler(stdoutStringStream, stdout);
+ stderrStringStream.onLine = makeReadHandler(stderrStringStream, stderr);
+ }
+
+ Function makeReadHandler(StringInputStream source, List<String> destination) {
+ return () {
+ if (source.closed) return;
+ var line = source.readLine();
+ while (null != line) {
+ destination.add(line);
+ line = source.readLine();
+ }
+ };
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698