Chromium Code Reviews| 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..b4564e3b9247eb0c1e9797ab980ba3282acb88ee |
| --- /dev/null |
| +++ b/tools/execute_recorded_testcases.py |
| @@ -0,0 +1,68 @@ |
| +#!/usr/bin/env python |
| + |
| +import sys |
| +import json |
| +import subprocess |
| +import time |
| +import threading |
| + |
| +did_timeout = False |
|
ricow1
2013/05/27 09:05:17
Write the usage pattern in a comment here.
kustermann
2013/05/27 11:11:37
Done.
|
| + |
| +def run_command(name, executable, arguments, timeout_in_seconds): |
| + print "Running %s: '%s'" % (name, [executable] + arguments) |
| + global did_timeout |
|
ricow1
2013/05/27 09:05:17
why don't you send this back in the tuple like the
kustermann
2013/05/27 11:11:37
I think we need to make it global. Otherwise 'time
|
| + did_timeout = False |
| + start = time.time() |
| + |
| + process = subprocess.Popen([executable] + arguments, |
| + stdout=subprocess.PIPE, |
| + stderr=subprocess.PIPE) |
| + def timeout_handler(): |
| + global did_timeout |
|
ricow1
2013/05/27 09:05:17
this is already global
kustermann
2013/05/27 11:11:37
I think global has to be set on every new scope. B
|
| + 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) |
| + |
| +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 = ( |
| + 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:])) |
| + |