OLD | NEW |
| (Empty) |
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. | |
5 | |
6 """A test runner for gtest application tests.""" | |
7 | |
8 import argparse | |
9 import ast | |
10 import logging | |
11 import sys | |
12 | |
13 _logging = logging.getLogger() | |
14 | |
15 from mopy import android | |
16 from mopy import gtest | |
17 from mopy.background_app_group import BackgroundAppGroup | |
18 from mopy.config import Config | |
19 from mopy.gn import ConfigForGNArgs, ParseGNConfig | |
20 from mopy.paths import Paths | |
21 | |
22 | |
23 def main(): | |
24 logging.basicConfig() | |
25 # Uncomment to debug: | |
26 #_logging.setLevel(logging.DEBUG) | |
27 | |
28 parser = argparse.ArgumentParser(description='A test runner for gtest ' | |
29 'application tests.') | |
30 | |
31 parser.add_argument('apptest_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() | |
36 | |
37 apptest_list = ast.literal_eval(args.apptest_list_file.read()) | |
38 _logging.debug("Test list: %s" % apptest_list) | |
39 | |
40 config = ConfigForGNArgs(ParseGNConfig(args.build_dir)) | |
41 is_android = (config.target_os == Config.OS_ANDROID) | |
42 android_context = android.PrepareShellRun(config) if is_android else None | |
43 | |
44 gtest.set_color() | |
45 mojo_paths = Paths(config) | |
46 | |
47 exit_code = 0 | |
48 for apptest_dict in apptest_list: | |
49 if apptest_dict.get("disabled"): | |
50 continue | |
51 | |
52 apptest = apptest_dict["test"] | |
53 apptest_args = apptest_dict.get("test-args", []) | |
54 shell_args = apptest_dict.get("shell-args", []) | |
55 launched_services = apptest_dict.get("launched-services", []) | |
56 | |
57 print "Running " + apptest + "...", | |
58 sys.stdout.flush() | |
59 | |
60 # List the apptest fixtures so they can be run independently for isolation. | |
61 # TODO(msw): Run some apptests without fixture isolation? | |
62 fixtures = gtest.get_fixtures(config, apptest, android_context) | |
63 | |
64 if not fixtures: | |
65 print "Failed with no tests found." | |
66 exit_code = 1 | |
67 continue | |
68 | |
69 if any(not mojo_paths.IsValidAppUrl(url) for url in launched_services): | |
70 print "Failed with malformed launched-services: %r" % launched_services | |
71 exit_code = 1 | |
72 continue | |
73 | |
74 apptest_result = "Succeeded" | |
75 for fixture in fixtures: | |
76 args_for_apptest = apptest_args + ["--gtest_filter=%s" % fixture] | |
77 if launched_services: | |
78 success = RunApptestInLauncher(config, mojo_paths, apptest, | |
79 args_for_apptest, shell_args, | |
80 launched_services) | |
81 else: | |
82 success = RunApptestInShell(config, apptest, args_for_apptest, | |
83 shell_args, android_context) | |
84 | |
85 if not success: | |
86 apptest_result = "Failed test(s) in %r" % apptest_dict | |
87 exit_code = 1 | |
88 | |
89 print apptest_result | |
90 | |
91 return exit_code | |
92 | |
93 | |
94 def RunApptestInShell(config, application, application_args, shell_args, | |
95 android_context): | |
96 return gtest.run_test(config, shell_args, | |
97 {application: application_args}, android_context) | |
98 | |
99 | |
100 def RunApptestInLauncher(config, mojo_paths, application, application_args, | |
101 shell_args, launched_services): | |
102 with BackgroundAppGroup( | |
103 mojo_paths, launched_services, | |
104 gtest.build_shell_arguments(shell_args, | |
105 {application: application_args}, | |
106 run_apps=False)) as apps: | |
107 launcher_args = [ | |
108 '--shell-path=' + apps.socket_path, | |
109 '--app-url=' + application, | |
110 '--app-path=' + mojo_paths.FileFromUrl(application)] | |
111 return gtest.run_test(config, launcher_args, run_launcher=True) | |
112 | |
113 | |
114 if __name__ == '__main__': | |
115 sys.exit(main()) | |
OLD | NEW |