OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2016 The Chromium Authors. All rights reserved. | 2 # Copyright 2016 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Wrapper for adding logdog streaming support to swarming tasks.""" | 6 """Wrapper for adding logdog streaming support to swarming tasks.""" |
7 | 7 |
8 import argparse | 8 import argparse |
9 import logging | 9 import logging |
10 import os | 10 import os |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 def CommandParser(): | 30 def CommandParser(): |
31 # Parses the command line arguments being passed in | 31 # Parses the command line arguments being passed in |
32 parser = argparse.ArgumentParser() | 32 parser = argparse.ArgumentParser() |
33 parser.add_argument('--target', required=True, | 33 parser.add_argument('--target', required=True, |
34 help='The test target to be run.') | 34 help='The test target to be run.') |
35 parser.add_argument('--logdog-bin-cmd', required=True, | 35 parser.add_argument('--logdog-bin-cmd', required=True, |
36 help='The logdog bin cmd.') | 36 help='The logdog bin cmd.') |
37 parser.add_argument('--target-devices-file', required=False, | 37 parser.add_argument('--target-devices-file', required=False, |
38 help='The target devices file.') | 38 help='The target devices file.') |
| 39 parser.add_argument('--logcat-output-file', |
| 40 help='The logcat output file.') |
39 return parser | 41 return parser |
40 | 42 |
41 def CreateStopTestsMethod(proc): | 43 def CreateStopTestsMethod(proc): |
42 def StopTests(signum, _frame): | 44 def StopTests(signum, _frame): |
43 logging.error('Forwarding signal %s to test process', str(signum)) | 45 logging.error('Forwarding signal %s to test process', str(signum)) |
44 proc.send_signal(signum) | 46 proc.send_signal(signum) |
45 return StopTests | 47 return StopTests |
46 | 48 |
47 def main(): | 49 def main(): |
48 parser = CommandParser() | 50 parser = CommandParser() |
49 args, extra_cmd_args = parser.parse_known_args(sys.argv[1:]) | 51 args, extra_cmd_args = parser.parse_known_args(sys.argv[1:]) |
50 | 52 |
51 logging.basicConfig(level=logging.INFO) | 53 logging.basicConfig(level=logging.INFO) |
52 with tempfile_ext.NamedTemporaryDirectory() as logcat_output_dir: | 54 with tempfile_ext.NamedTemporaryDirectory() as logcat_output_dir: |
53 test_cmd = [ | 55 test_cmd = [ |
54 os.path.join('bin', 'run_%s' % args.target), | 56 os.path.join('bin', 'run_%s' % args.target), |
55 '--logcat-output-file', os.path.join(logcat_output_dir, 'logcats'), | 57 '--logcat-output-file', |
| 58 (args.logcat_output_file if args.logcat_output_file |
| 59 else os.path.join(logcat_output_dir, 'logcats')), |
56 '--upload-logcats-file', | 60 '--upload-logcats-file', |
57 '--target-devices-file', args.target_devices_file, | 61 '--target-devices-file', args.target_devices_file, |
58 '-v'] + extra_cmd_args | 62 '-v'] + extra_cmd_args |
59 | 63 |
60 with tempfile_ext.NamedTemporaryDirectory( | 64 with tempfile_ext.NamedTemporaryDirectory( |
61 prefix='tmp_android_logdog_wrapper') as temp_directory: | 65 prefix='tmp_android_logdog_wrapper') as temp_directory: |
62 if not os.path.exists(args.logdog_bin_cmd): | 66 if not os.path.exists(args.logdog_bin_cmd): |
63 logging.error( | 67 logging.error( |
64 'Logdog binary %s unavailable. Unable to create logdog client', | 68 'Logdog binary %s unavailable. Unable to create logdog client', |
65 args.logdog_bin_cmd) | 69 args.logdog_bin_cmd) |
(...skipping 13 matching lines...) Expand all Loading... |
79 'run', '-streamserver-uri', streamserver_uri, '--'] + test_cmd | 83 'run', '-streamserver-uri', streamserver_uri, '--'] + test_cmd |
80 | 84 |
81 test_proc = subprocess.Popen(test_cmd) | 85 test_proc = subprocess.Popen(test_cmd) |
82 with signal_handler.SignalHandler(signal.SIGTERM, | 86 with signal_handler.SignalHandler(signal.SIGTERM, |
83 CreateStopTestsMethod(test_proc)): | 87 CreateStopTestsMethod(test_proc)): |
84 result = test_proc.wait() | 88 result = test_proc.wait() |
85 return result | 89 return result |
86 | 90 |
87 if __name__ == '__main__': | 91 if __name__ == '__main__': |
88 sys.exit(main()) | 92 sys.exit(main()) |
OLD | NEW |