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

Unified Diff: tools/execute_recorded_testcases.py

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 | « no previous file | tools/test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/execute_recorded_testcases.py
diff --git a/tools/execute_recorded_testcases.py b/tools/execute_recorded_testcases.py
new file mode 100755
index 0000000000000000000000000000000000000000..f30727779f02cb850b2a07d93d2d4f324c415ac0
--- /dev/null
+++ b/tools/execute_recorded_testcases.py
@@ -0,0 +1,67 @@
+#!/usr/bin/env python
+
+import sys
+import json
+import subprocess
+import time
+import threading
+
+def run_command(name, executable, arguments, timeout_in_seconds):
+ print "Running %s: '%s'" % (name, [executable] + arguments)
+
+ # The timeout_handler will set this to True if the command times out.
+ timeout_value = {'did_timeout' : False}
+
+ start = time.time()
+
+ process = subprocess.Popen([executable] + arguments,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ def timeout_handler():
+ timeout_value['did_timeout'] = True
+ process.kill()
+ timer = threading.Timer(timeout_in_seconds, timeout_handler)
+ timer.start()
+
+ stdout, stderr = process.communicate()
+ exit_code = process.wait()
+ timer.cancel()
+
+ end = time.time()
+
+ return (exit_code, stdout, stderr, end - start, timeout_value['did_timeout'])
+
+def main(args):
+ recording_file = args[0]
+ result_file = args[1]
+
+ with open(recording_file) as fd:
+ test_cases = json.load(fd)
+
+ for test_case in test_cases:
+ name = test_case['name']
+ command = test_case['command']
+ executable = command['executable']
+ arguments = command['arguments']
+ timeout_limit = command['timeout_limit']
+
+ exit_code, stdout, stderr, duration, did_timeout = (
+ run_command(name, executable, arguments, timeout_limit))
+
+ test_case['command_output'] = {
+ 'exit_code' : exit_code,
+ 'stdout' : stdout,
+ 'stderr' : stderr,
+ 'duration' : duration,
+ 'did_timeout' : did_timeout,
+ }
+ with open(result_file, 'w') as fd:
+ json.dump(test_cases, fd)
+
+if __name__ == '__main__':
+ if len(sys.argv) != 3:
+ print >> sys.stderr, ("Usage: %s <input-file.json> <output-file.json>"
+ % sys.argv[0])
+ sys.exit(1)
+ sys.exit(main(sys.argv[1:]))
+
« no previous file with comments | « no previous file | tools/test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698