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

Side by Side Diff: mojo/devtools/common/devtoolslib/apptest_gtest.py

Issue 1266623002: Impose max running time for apptests. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Indicate time unit when printing out the time out value. Created 5 years, 4 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 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Apptest runner specific to the particular gtest-based apptest framework in 5 """Apptest runner specific to the particular gtest-based apptest framework in
6 /mojo/public/cpp/application/tests/, built on top of the general apptest 6 /mojo/public/cpp/application/tests/, built on top of the general apptest
7 runner.""" 7 runner."""
8 8
9 import logging 9 import logging
10 import re 10 import re
11 11
12 from devtoolslib.apptest import run_apptest 12 from devtoolslib.apptest import run_apptest
13 13
14 14
15 _logger = logging.getLogger() 15 _logger = logging.getLogger()
16 16
17 17
18 def _gtest_apptest_output_test(output): 18 def _gtest_apptest_output_test(output):
19 # Fail on output with gtest's "[ FAILED ]" or a lack of "[ PASSED ]". 19 # Fail on output with gtest's "[ FAILED ]" or a lack of "[ PASSED ]".
20 # The latter condition ensures failure on broken command lines or output. 20 # The latter condition ensures failure on broken command lines or output.
21 # Check output instead of exit codes because mojo_shell always exits with 0. 21 # Check output instead of exit codes because mojo_shell always exits with 0.
22 if (output is None or 22 if (output is None or
23 (output.find("[ FAILED ]") != -1 or output.find("[ PASSED ]") == -1)): 23 (output.find("[ FAILED ]") != -1 or output.find("[ PASSED ]") == -1)):
24 return False 24 return False
25 return True 25 return True
26 26
27 27
28 def run_gtest_apptest(shell, shell_args, apptest_url, apptest_args, isolate): 28 def run_gtest_apptest(shell, shell_args, apptest_url, apptest_args, timeout,
29 isolate):
29 """Runs a gtest apptest. 30 """Runs a gtest apptest.
30 31
31 Args: 32 Args:
32 shell: Wrapper around concrete Mojo shell, implementing devtools Shell 33 shell: Wrapper around concrete Mojo shell, implementing devtools Shell
33 interface. 34 interface.
34 shell_args: The arguments for mojo_shell. 35 shell_args: The arguments for mojo_shell.
35 apptest_url: Url of the apptest app to run. 36 apptest_url: Url of the apptest app to run.
36 apptest_args: Parameters to be passed to the apptest app. 37 apptest_args: Parameters to be passed to the apptest app.
37 isolate: Iff True, each test in the app will be run in a separate shell run. 38 isolate: Iff True, each test in the app will be run in a separate shell run.
38 39
39 Returns: 40 Returns:
40 True iff the test succeeded, False otherwise. 41 True iff the test succeeded, False otherwise.
41 """ 42 """
42 43
43 if not isolate: 44 if not isolate:
44 return run_apptest(shell, shell_args, apptest_url, apptest_args, 45 return run_apptest(shell, shell_args, apptest_url, apptest_args, timeout,
45 _gtest_apptest_output_test) 46 _gtest_apptest_output_test)
46 47
47 # List the apptest fixtures so they can be run independently for isolation. 48 # List the apptest fixtures so they can be run independently for isolation.
48 fixtures = get_fixtures(shell, shell_args, apptest_url) 49 fixtures = get_fixtures(shell, shell_args, apptest_url)
49 if not fixtures: 50 if not fixtures:
50 print "No tests to run found in %s." % apptest_url 51 print "No tests to run found in %s." % apptest_url
51 return False 52 return False
52 53
53 apptest_result = True 54 apptest_result = True
54 for fixture in fixtures: 55 for fixture in fixtures:
55 isolated_apptest_args = apptest_args + ["--gtest_filter=%s" % fixture] 56 isolated_apptest_args = apptest_args + ["--gtest_filter=%s" % fixture]
56 success = run_apptest(shell, shell_args, apptest_url, isolated_apptest_args, 57 success = run_apptest(shell, shell_args, apptest_url, isolated_apptest_args,
57 _gtest_apptest_output_test) 58 timeout, _gtest_apptest_output_test)
58 59
59 if not success: 60 if not success:
60 apptest_result = False 61 apptest_result = False
61 62
62 return apptest_result 63 return apptest_result
63 64
64 65
65 def get_fixtures(shell, shell_args, apptest): 66 def get_fixtures(shell, shell_args, apptest):
66 """Returns the "Test.Fixture" list from an apptest using mojo_shell. 67 """Returns the "Test.Fixture" list from an apptest using mojo_shell.
67 68
68 Tests are listed by running the given apptest in mojo_shell and passing 69 Tests are listed by running the given apptest in mojo_shell and passing
69 --gtest_list_tests. The output is parsed and reformatted into a list like 70 --gtest_list_tests. The output is parsed and reformatted into a list like
70 [TestSuite.TestFixture, ... ] 71 [TestSuite.TestFixture, ... ]
71 An empty list is returned on failure, with errors logged. 72 An empty list is returned on failure, with errors logged.
72 73
73 Args: 74 Args:
74 apptest: The URL of the test application to run. 75 apptest: The URL of the test application to run.
75 """ 76 """
76 arguments = [] 77 arguments = []
77 arguments.extend(shell_args) 78 arguments.extend(shell_args)
78 arguments.append("--args-for=%s %s" % (apptest, "--gtest_list_tests")) 79 arguments.append("--args-for=%s %s" % (apptest, "--gtest_list_tests"))
79 arguments.append(apptest) 80 arguments.append(apptest)
80 81
81 (exit_code, output) = shell.RunAndGetOutput(arguments) 82 (exit_code, output, did_time_out) = shell.RunAndGetOutput(arguments)
82 if exit_code: 83 if exit_code or did_time_out:
83 command_line = "mojo_shell " + " ".join(["%r" % x for x in arguments]) 84 command_line = "mojo_shell " + " ".join(["%r" % x for x in arguments])
84 print "Failed to get test fixtures: %r" % command_line 85 print "Failed to get test fixtures: %r" % command_line
85 print 72 * '-' 86 print 72 * '-'
86 print output 87 print output
87 print 72 * '-' 88 print 72 * '-'
88 return [] 89 return []
89 90
90 _logger.debug("Tests listed:\n%s" % output) 91 _logger.debug("Tests listed:\n%s" % output)
91 return _gtest_list_tests(output) 92 return _gtest_list_tests(output)
92 93
(...skipping 17 matching lines...) Expand all
110 test_list = [] 111 test_list = []
111 for line in output_lines: 112 for line in output_lines:
112 if not line: 113 if not line:
113 continue 114 continue
114 if line[0] != " ": 115 if line[0] != " ":
115 suite = line.strip() 116 suite = line.strip()
116 continue 117 continue
117 test_list.append(suite + line.strip()) 118 test_list.append(suite + line.strip())
118 119
119 return test_list 120 return test_list
OLDNEW
« no previous file with comments | « mojo/devtools/common/devtoolslib/apptest_dart.py ('k') | mojo/devtools/common/devtoolslib/linux_shell.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698