| 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 gtest application tests.""" | 6 """A test runner for gtest application tests.""" |
| 7 | 7 |
| 8 import argparse | 8 import argparse |
| 9 import logging | 9 import logging |
| 10 import sys | 10 import sys |
| 11 | 11 |
| 12 from mopy import dart_apptest | |
| 13 from mopy import gtest | 12 from mopy import gtest |
| 14 from mopy.android import AndroidShell | 13 from mopy.android import AndroidShell |
| 15 from mopy.config import Config | 14 from mopy.config import Config |
| 16 from mopy.gn import ConfigForGNArgs, ParseGNConfig | |
| 17 from mopy.log import InitLogging | 15 from mopy.log import InitLogging |
| 18 from mopy.paths import Paths | 16 from mopy.paths import Paths |
| 19 | 17 |
| 20 | 18 |
| 21 _logger = logging.getLogger() | 19 _logger = logging.getLogger() |
| 22 | 20 |
| 23 | 21 |
| 24 def main(): | 22 def main(): |
| 25 parser = argparse.ArgumentParser(description="A test runner for application " | 23 parser = argparse.ArgumentParser(description="An application test runner.") |
| 26 "tests.") | |
| 27 | |
| 28 parser.add_argument("--verbose", help="be verbose (multiple times for more)", | 24 parser.add_argument("--verbose", help="be verbose (multiple times for more)", |
| 29 default=0, dest="verbose_count", action="count") | 25 default=0, dest="verbose_count", action="count") |
| 30 parser.add_argument("test_list_file", type=file, | 26 parser.add_argument("test_list_file", type=file, |
| 31 help="a file listing apptests to run") | 27 help="a file listing apptests to run") |
| 32 parser.add_argument("build_dir", type=str, | 28 parser.add_argument("build_dir", type=str, help="the build output directory") |
| 33 help="the build output directory") | |
| 34 args = parser.parse_args() | 29 args = parser.parse_args() |
| 35 | 30 |
| 36 InitLogging(args.verbose_count) | 31 InitLogging(args.verbose_count) |
| 37 config = ConfigForGNArgs(ParseGNConfig(args.build_dir)) | 32 config = Config(args.build_dir) |
| 38 | 33 |
| 39 _logger.debug("Test list file: %s", args.test_list_file) | 34 _logger.debug("Test list file: %s", args.test_list_file) |
| 40 execution_globals = {"config": config} | 35 execution_globals = {"config": config} |
| 41 exec args.test_list_file in execution_globals | 36 exec args.test_list_file in execution_globals |
| 42 test_list = execution_globals["tests"] | 37 test_list = execution_globals["tests"] |
| 43 _logger.debug("Test list: %s" % test_list) | 38 _logger.debug("Test list: %s" % test_list) |
| 44 | 39 |
| 45 extra_args = [] | 40 extra_args = [] |
| 46 if config.target_os == Config.OS_ANDROID: | 41 if config.target_os == Config.OS_ANDROID: |
| 47 paths = Paths(config) | 42 paths = Paths(config) |
| 48 shell = AndroidShell(paths.target_mojo_shell_path, paths.build_dir, | 43 shell = AndroidShell(paths.mojo_runner, paths.build_dir, paths.adb_path) |
| 49 paths.adb_path) | |
| 50 extra_args.extend(shell.PrepareShellRun('localhost')) | 44 extra_args.extend(shell.PrepareShellRun('localhost')) |
| 51 else: | 45 else: |
| 52 shell = None | 46 shell = None |
| 53 | 47 |
| 54 gtest.set_color() | 48 gtest.set_color() |
| 55 | 49 |
| 56 exit_code = 0 | 50 exit_code = 0 |
| 57 for test_dict in test_list: | 51 for test_dict in test_list: |
| 58 test = test_dict["test"] | 52 test = test_dict["test"] |
| 59 test_name = test_dict.get("name", test) | 53 test_name = test_dict.get("name", test) |
| 60 test_type = test_dict.get("type", "gtest") | 54 test_type = test_dict.get("type", "gtest") |
| 61 test_args = test_dict.get("test-args", []) | 55 test_args = test_dict.get("test-args", []) |
| 62 shell_args = test_dict.get("shell-args", []) + extra_args | 56 shell_args = test_dict.get("shell-args", []) + extra_args |
| 63 | 57 |
| 64 _logger.info("Will start: %s" % test_name) | 58 _logger.info("Will start: %s" % test_name) |
| 65 print "Running %s...." % test_name, | 59 print "Running %s...." % test_name, |
| 66 sys.stdout.flush() | 60 sys.stdout.flush() |
| 67 | 61 |
| 68 if test_type == "dart": | 62 if test_type == "gtest": |
| 69 apptest_result = dart_apptest.run_test(config, shell, test_dict, | |
| 70 shell_args, {test: test_args}) | |
| 71 elif test_type == "gtest": | |
| 72 apptest_result = gtest.run_fixtures(config, shell, test_dict, | 63 apptest_result = gtest.run_fixtures(config, shell, test_dict, |
| 73 test, False, | 64 test, False, |
| 74 test_args, shell_args) | 65 test_args, shell_args) |
| 75 elif test_type == "gtest_isolated": | 66 elif test_type == "gtest_isolated": |
| 76 apptest_result = gtest.run_fixtures(config, shell, test_dict, | 67 apptest_result = gtest.run_fixtures(config, shell, test_dict, |
| 77 test, True, test_args, shell_args) | 68 test, True, test_args, shell_args) |
| 78 else: | 69 else: |
| 79 apptest_result = "Invalid test type in %r" % test_dict | 70 apptest_result = "Invalid test type in %r" % test_dict |
| 80 | 71 |
| 81 if apptest_result != "Succeeded": | 72 if apptest_result != "Succeeded": |
| 82 exit_code = 1 | 73 exit_code = 1 |
| 83 print apptest_result | 74 print apptest_result |
| 84 _logger.info("Completed: %s" % test_name) | 75 _logger.info("Completed: %s" % test_name) |
| 85 | 76 |
| 86 return exit_code | 77 return exit_code |
| 87 | 78 |
| 88 | 79 |
| 89 if __name__ == '__main__': | 80 if __name__ == '__main__': |
| 90 sys.exit(main()) | 81 sys.exit(main()) |
| OLD | NEW |