| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/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 """Run a test. | 6 """Run a test. |
| 7 | 7 |
| 8 Sample usage: | 8 Sample usage: |
| 9 ./run.py \ | 9 ./run.py \ |
| 10 -a src/xcodebuild/Release-iphoneos/base_unittests.app \ | 10 -a src/xcodebuild/Release-iphoneos/base_unittests.app \ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 | 27 |
| 28 def main(args, test_args): | 28 def main(args, test_args): |
| 29 summary = {} | 29 summary = {} |
| 30 tr = None | 30 tr = None |
| 31 | 31 |
| 32 if not os.path.exists(args.out_dir): | 32 if not os.path.exists(args.out_dir): |
| 33 os.makedirs(args.out_dir) | 33 os.makedirs(args.out_dir) |
| 34 | 34 |
| 35 try: | 35 try: |
| 36 tr = test_runner.SimulatorTestRunner( | 36 if args.iossim and args.platform and args.version: |
| 37 args.app, | 37 tr = test_runner.SimulatorTestRunner( |
| 38 args.iossim, | 38 args.app, |
| 39 args.platform, | 39 args.iossim, |
| 40 args.version, | 40 args.platform, |
| 41 args.xcode_version, | 41 args.version, |
| 42 args.out_dir, | 42 args.xcode_version, |
| 43 test_args=test_args, | 43 args.out_dir, |
| 44 ) | 44 env_vars=args.env_var, |
| 45 test_args=test_args, |
| 46 ) |
| 47 else: |
| 48 tr = test_runner.DeviceTestRunner( |
| 49 args.app, |
| 50 args.xcode_version, |
| 51 args.out_dir, |
| 52 env_vars=args.env_var, |
| 53 test_args=test_args, |
| 54 ) |
| 45 | 55 |
| 46 return 0 if tr.launch() else 1 | 56 return 0 if tr.launch() else 1 |
| 47 except test_runner.TestRunnerError as e: | 57 except test_runner.TestRunnerError as e: |
| 48 sys.stderr.write(traceback.format_exc()) | 58 sys.stderr.write(traceback.format_exc()) |
| 49 summary['step_text'] = '%s%s' % ( | 59 summary['step_text'] = '%s%s' % ( |
| 50 e.__class__.__name__, ': %s' % e.args[0] if e.args else '') | 60 e.__class__.__name__, ': %s' % e.args[0] if e.args else '') |
| 51 | 61 |
| 52 # test_runner.Launch returns 0 on success, 1 on failure, so return 2 | 62 # test_runner.Launch returns 0 on success, 1 on failure, so return 2 |
| 53 # on exception to distinguish between a test failure, and a failure | 63 # on exception to distinguish between a test failure, and a failure |
| 54 # to launch the test at all. | 64 # to launch the test at all. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 65 parser = argparse.ArgumentParser() | 75 parser = argparse.ArgumentParser() |
| 66 | 76 |
| 67 parser.add_argument( | 77 parser.add_argument( |
| 68 '-a', | 78 '-a', |
| 69 '--app', | 79 '--app', |
| 70 help='Compiled .app to run.', | 80 help='Compiled .app to run.', |
| 71 metavar='app', | 81 metavar='app', |
| 72 required=True, | 82 required=True, |
| 73 ) | 83 ) |
| 74 parser.add_argument( | 84 parser.add_argument( |
| 85 '-e', |
| 86 '--env-var', |
| 87 action='append', |
| 88 help='Environment variable to pass to the test itself.', |
| 89 metavar='ENV=val', |
| 90 ) |
| 91 parser.add_argument( |
| 75 '-i', | 92 '-i', |
| 76 '--iossim', | 93 '--iossim', |
| 77 help='Compiled iossim to run the app on.', | 94 help='Compiled iossim to run the app on.', |
| 78 metavar='iossim', | 95 metavar='iossim', |
| 79 required=True, | |
| 80 ) | 96 ) |
| 81 parser.add_argument( | 97 parser.add_argument( |
| 82 '-o', | 98 '-o', |
| 83 '--out-dir', | 99 '--out-dir', |
| 84 help='Directory to store all test data in.', | 100 help='Directory to store all test data in.', |
| 85 metavar='dir', | 101 metavar='dir', |
| 86 required=True, | 102 required=True, |
| 87 ) | 103 ) |
| 88 parser.add_argument( | 104 parser.add_argument( |
| 89 '-p', | 105 '-p', |
| 90 '--platform', | 106 '--platform', |
| 91 help='Platform to simulate.', | 107 help='Platform to simulate.', |
| 92 metavar='sim', | 108 metavar='sim', |
| 93 required=True, | |
| 94 ) | 109 ) |
| 95 parser.add_argument( | 110 parser.add_argument( |
| 96 '-v', | 111 '-v', |
| 97 '--version', | 112 '--version', |
| 98 help='Version of iOS the simulator should run.', | 113 help='Version of iOS the simulator should run.', |
| 99 metavar='ver', | 114 metavar='ver', |
| 100 required=True, | |
| 101 ) | 115 ) |
| 102 parser.add_argument( | 116 parser.add_argument( |
| 103 '-x', | 117 '-x', |
| 104 '--xcode-version', | 118 '--xcode-version', |
| 105 help='Version of Xcode to use.', | 119 help='Version of Xcode to use.', |
| 106 metavar='ver', | 120 metavar='ver', |
| 107 required=True, | 121 required=True, |
| 108 ) | 122 ) |
| 109 | 123 |
| 110 sys.exit(main(*parser.parse_known_args())) | 124 args, test_args = parser.parse_known_args() |
| 125 if args.iossim or args.platform or args.version: |
| 126 # If any of --iossim, --platform, or --version |
| 127 # are specified then they must all be specified. |
| 128 if not (args.iossim and args.platform and args.version): |
| 129 parser.error( |
| 130 'must specify all or none of -i/--iossim, -p/--platform, -v/--version') |
| 131 |
| 132 sys.exit(main(args, test_args)) |
| OLD | NEW |