Call callback asynchronously for device reboot command
[chromium-blink-merge.git] / mojo / tools / apptest_runner.py
blobddc0830712a2bc03919ea534181a273b91254d66
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
6 """A test runner for gtest application tests."""
8 import argparse
9 import logging
10 import sys
12 from mopy import dart_apptest
13 from mopy import gtest
14 # TODO(msw): Mojo's script pulls in android.py via mojo/devtools/common/pylib.
15 from mopy.android import AndroidShell
16 from mopy.config import Config
17 from mopy.gn import ConfigForGNArgs, ParseGNConfig
18 from mopy.log import InitLogging
19 from mopy.paths import Paths
22 _logger = logging.getLogger()
25 def main():
26 parser = argparse.ArgumentParser(description="A test runner for application "
27 "tests.")
29 parser.add_argument("--verbose", help="be verbose (multiple times for more)",
30 default=0, dest="verbose_count", action="count")
31 parser.add_argument("test_list_file", type=file,
32 help="a file listing apptests to run")
33 parser.add_argument("build_dir", type=str,
34 help="the build output directory")
35 args = parser.parse_args()
37 InitLogging(args.verbose_count)
38 config = ConfigForGNArgs(ParseGNConfig(args.build_dir))
40 _logger.debug("Test list file: %s", args.test_list_file)
41 execution_globals = {"config": config}
42 exec args.test_list_file in execution_globals
43 test_list = execution_globals["tests"]
44 _logger.debug("Test list: %s" % test_list)
46 extra_args = []
47 if config.target_os == Config.OS_ANDROID:
48 paths = Paths(config)
49 shell = AndroidShell(paths.target_mojo_shell_path, paths.build_dir,
50 paths.adb_path)
51 extra_args.extend(shell.PrepareShellRun(fixed_port=False))
52 else:
53 shell = None
55 gtest.set_color()
57 exit_code = 0
58 for test_dict in test_list:
59 test = test_dict["test"]
60 test_name = test_dict.get("name", test)
61 test_type = test_dict.get("type", "gtest")
62 test_args = test_dict.get("test-args", [])
63 shell_args = test_dict.get("shell-args", []) + extra_args
65 _logger.info("Will start: %s" % test_name)
66 print "Running %s...." % test_name,
67 sys.stdout.flush()
69 if test_type == "dart":
70 apptest_result = dart_apptest.run_test(config, shell, test_dict,
71 shell_args, {test: test_args})
72 elif test_type == "gtest":
73 apptest_result = gtest.run_fixtures(config, shell, test_dict,
74 test, False,
75 test_args, shell_args)
76 elif test_type == "gtest_isolated":
77 apptest_result = gtest.run_fixtures(config, shell, test_dict,
78 test, True, test_args, shell_args)
79 else:
80 apptest_result = "Invalid test type in %r" % test_dict
82 if apptest_result != "Succeeded":
83 exit_code = 1
84 print apptest_result
85 _logger.info("Completed: %s" % test_name)
87 return exit_code
90 if __name__ == '__main__':
91 sys.exit(main())