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