Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Side by Side Diff: mojo/tools/apptest_runner.py

Issue 971083002: Create an apptesting framework for dart. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: msw comments Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
18 from mopy import test_util
17 from mopy.background_app_group import BackgroundAppGroup 19 from mopy.background_app_group import BackgroundAppGroup
18 from mopy.config import Config 20 from mopy.config import Config
19 from mopy.gn import ConfigForGNArgs, ParseGNConfig 21 from mopy.gn import ConfigForGNArgs, ParseGNConfig
20 from mopy.paths import Paths 22 from mopy.paths import Paths
21 23
22 24
23 def main(): 25 def main():
24 logging.basicConfig() 26 logging.basicConfig()
25 # Uncomment to debug: 27 # Uncomment to debug:
26 #_logging.setLevel(logging.DEBUG) 28 #_logging.setLevel(logging.DEBUG)
(...skipping 28 matching lines...) Expand all
55 apptest = apptest_dict["test"] 57 apptest = apptest_dict["test"]
56 test_args = apptest_dict.get("test-args", []) 58 test_args = apptest_dict.get("test-args", [])
57 shell_args = apptest_dict.get("shell-args", []) 59 shell_args = apptest_dict.get("shell-args", [])
58 if android_origin_argument: 60 if android_origin_argument:
59 shell_args.append(android_origin_argument) 61 shell_args.append(android_origin_argument)
60 launched_services = apptest_dict.get("launched-services", []) 62 launched_services = apptest_dict.get("launched-services", [])
61 63
62 print "Running " + apptest + "...", 64 print "Running " + apptest + "...",
63 sys.stdout.flush() 65 sys.stdout.flush()
64 66
65 # List the apptest fixtures so they can be run independently for isolation. 67 if apptest_dict.get("type", "gtest") == "dart":
66 # TODO(msw): Run some apptests without fixture isolation? 68 # TODO(erg): Support android and external and fixture isolation.
msw 2015/03/04 21:04:31 nit: s/external/launched services/
67 fixtures = gtest.get_fixtures(config, shell_args, apptest) 69 apptest_result = "Succeeded"
68 70 success = dart_apptest.run_test(config, shell_args, {apptest: test_args})
69 if not fixtures:
70 print "Failed with no tests found."
71 exit_code = 1
72 continue
73
74 if any(not mojo_paths.IsValidAppUrl(url) for url in launched_services):
75 print "Failed with malformed launched-services: %r" % launched_services
76 exit_code = 1
77 continue
78
79 apptest_result = "Succeeded"
80 for fixture in fixtures:
81 apptest_args = test_args + ["--gtest_filter=%s" % fixture]
82 if launched_services:
83 success = RunApptestInLauncher(config, mojo_paths, apptest,
84 apptest_args, shell_args,
85 launched_services)
86 else:
87 success = RunApptestInShell(config, apptest, apptest_args, shell_args)
88
89 if not success: 71 if not success:
90 apptest_result = "Failed test(s) in %r" % apptest_dict 72 apptest_result = "Failed test(s) in %r" % apptest_dict
91 exit_code = 1 73 exit_code = 1
74 else:
msw 2015/03/04 21:04:31 nit: maybe this could be extracted to a gtest.py f
Elliot Glaysher 2015/03/04 22:20:59 Done. Moves this (and code only called from this c
75 # List the apptest fixtures so they can be run independently for
76 # isolation. TODO(msw): Run some apptests without fixture isolation?
77 fixtures = gtest.get_fixtures(config, shell_args, apptest)
78
79 if not fixtures:
80 print "Failed with no tests found."
81 exit_code = 1
82 continue
83
84 if any(not mojo_paths.IsValidAppUrl(url) for url in launched_services):
85 print "Failed with malformed launched-services: %r" % launched_services
86 exit_code = 1
87 continue
88
89 apptest_result = "Succeeded"
90 for fixture in fixtures:
91 apptest_args = test_args + ["--gtest_filter=%s" % fixture]
92 if launched_services:
93 success = RunApptestInLauncher(config, mojo_paths, apptest,
94 apptest_args, shell_args,
95 launched_services)
96 else:
97 success = RunApptestInShell(config, apptest, apptest_args, shell_args)
98
99 if not success:
100 apptest_result = "Failed test(s) in %r" % apptest_dict
101 exit_code = 1
92 102
93 print apptest_result 103 print apptest_result
94 104
95 return exit_code 105 return exit_code
96 106
97 107
98 def RunApptestInShell(config, application, application_args, shell_args): 108 def RunApptestInShell(config, application, application_args, shell_args):
99 return gtest.run_test(config, shell_args, {application: application_args}) 109 return gtest.run_test(config, shell_args, {application: application_args})
100 110
101 111
102 def RunApptestInLauncher(config, mojo_paths, application, application_args, 112 def RunApptestInLauncher(config, mojo_paths, application, application_args,
103 shell_args, launched_services): 113 shell_args, launched_services):
104 with BackgroundAppGroup( 114 with BackgroundAppGroup(
105 mojo_paths, launched_services, 115 mojo_paths, launched_services,
106 gtest.build_shell_arguments(shell_args)) as apps: 116 test_util.build_shell_arguments(shell_args)) as apps:
107 launcher_args = [ 117 launcher_args = [
108 '--shell-path=' + apps.socket_path, 118 '--shell-path=' + apps.socket_path,
109 '--app-url=' + application, 119 '--app-url=' + application,
110 '--app-path=' + mojo_paths.FileFromUrl(application), 120 '--app-path=' + mojo_paths.FileFromUrl(application),
111 '--app-args=' + " ".join(application_args)] 121 '--app-args=' + " ".join(application_args)]
112 return gtest.run_test(config, launcher_args, run_launcher=True) 122 return gtest.run_test(config, launcher_args, run_launcher=True)
113 123
114 124
115 if __name__ == '__main__': 125 if __name__ == '__main__':
116 sys.exit(main()) 126 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698