| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 """A test runner for application tests.""" | 6 """A test runner for application tests.""" |
| 7 | 7 |
| 8 import argparse | 8 import argparse |
| 9 import logging | 9 import logging |
| 10 import os.path |
| 11 import subprocess |
| 10 import sys | 12 import sys |
| 11 | 13 |
| 12 import devtools | |
| 13 devtools.add_lib_to_path() | |
| 14 from devtoolslib.android_shell import AndroidShell | |
| 15 from devtoolslib.linux_shell import LinuxShell | |
| 16 from devtoolslib.apptest_runner import run_apptests | |
| 17 from devtoolslib import shell_arguments | |
| 18 | |
| 19 from mopy import gtest | 14 from mopy import gtest |
| 20 from mopy.config import Config | 15 from mopy.config import Config |
| 21 from mopy.gn import ConfigForGNArgs, ParseGNConfig | 16 from mopy.gn import ConfigForGNArgs, ParseGNConfig |
| 22 from mopy.log import InitLogging | 17 from mopy.log import InitLogging |
| 23 from mopy.paths import Paths | 18 from mopy.paths import Paths |
| 24 | 19 |
| 25 | 20 |
| 26 _logger = logging.getLogger() | 21 _logger = logging.getLogger() |
| 27 | 22 |
| 28 | 23 |
| 29 def main(): | 24 def main(): |
| 30 parser = argparse.ArgumentParser(description="A test runner for application " | 25 parser = argparse.ArgumentParser(description="A test runner for application " |
| 31 "tests.") | 26 "tests.") |
| 32 | 27 |
| 33 parser.add_argument("--verbose", help="be verbose (multiple times for more)", | 28 parser.add_argument("--verbose", help="be verbose (multiple times for more)", |
| 34 default=0, dest="verbose_count", action="count") | 29 default=0, dest="verbose_count", action="count") |
| 35 parser.add_argument("test_list_file", type=file, | 30 parser.add_argument("test_list_file", type=str, |
| 36 help="a file listing apptests to run") | 31 help="a file listing apptests to run") |
| 37 parser.add_argument("build_dir", type=str, | 32 parser.add_argument("build_dir", type=str, |
| 38 help="the build output directory") | 33 help="the build output directory") |
| 39 args = parser.parse_args() | 34 args = parser.parse_args() |
| 40 | 35 |
| 41 InitLogging(args.verbose_count) | 36 InitLogging(args.verbose_count) |
| 42 config = ConfigForGNArgs(ParseGNConfig(args.build_dir)) | 37 config = ConfigForGNArgs(ParseGNConfig(args.build_dir)) |
| 43 paths = Paths(config) | 38 paths = Paths(config) |
| 44 extra_args = [] | 39 command_line = [os.path.join(os.path.dirname(__file__), os.path.pardir, |
| 40 "devtools", "common", "mojo_test"), |
| 41 str(args.test_list_file)] |
| 42 if config.is_debug: |
| 43 command_line.append("--debug") |
| 44 else: |
| 45 command_line.append("--release") |
| 45 if config.target_os == Config.OS_ANDROID: | 46 if config.target_os == Config.OS_ANDROID: |
| 46 shell = AndroidShell(paths.adb_path) | 47 command_line.append("--android") |
| 47 device_status, error = shell.CheckDevice() | 48 command_line.append("--adb-path=" + paths.adb_path) |
| 48 if not device_status: | 49 command_line.append("--shell-path=" + paths.target_mojo_shell_path) |
| 49 print 'Device check failed: ' + error | 50 command_line.append("--origin-path=" + paths.build_dir) |
| 50 return 1 | |
| 51 shell.InstallApk(paths.target_mojo_shell_path) | |
| 52 extra_args.extend(shell_arguments.ConfigureLocalOrigin( | |
| 53 shell, paths.build_dir, fixed_port=True)) | |
| 54 else: | |
| 55 shell = LinuxShell(paths.mojo_shell_path) | |
| 56 | 51 |
| 57 gtest.set_color() | 52 gtest.set_color() |
| 58 | 53 print "Running " + str(command_line) |
| 59 test_list_globals = {"config": config} | 54 ret = subprocess.call(command_line) |
| 60 exec args.test_list_file in test_list_globals | 55 return ret |
| 61 apptests_result = run_apptests(shell, extra_args, test_list_globals["tests"]) | |
| 62 return 0 if apptests_result else 1 | |
| 63 | 56 |
| 64 | 57 |
| 65 if __name__ == '__main__': | 58 if __name__ == '__main__': |
| 66 sys.exit(main()) | 59 sys.exit(main()) |
| OLD | NEW |