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

Side by Side Diff: build/android/pylib/host_driven/test_case.py

Issue 23295006: [Android] Changes _RunJavaTests to accept filters (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 """Base class for host-driven test cases. 5 """Base class for host-driven test cases.
6 6
7 This test case is intended to serve as the base class for any host-driven 7 This test case is intended to serve as the base class for any host-driven
8 test cases. It is similar to the Python unitttest module in that test cases 8 test cases. It is similar to the Python unitttest module in that test cases
9 inherit from this class and add methods which will be run as tests. 9 inherit from this class and add methods which will be run as tests.
10 10
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 def GetOutDir(self): 70 def GetOutDir(self):
71 return os.path.join(os.environ['CHROME_SRC'], 'out', 71 return os.path.join(os.environ['CHROME_SRC'], 'out',
72 constants.GetBuildType()) 72 constants.GetBuildType())
73 73
74 def Run(self): 74 def Run(self):
75 logging.info('Running host-driven test: %s', self.tagged_name) 75 logging.info('Running host-driven test: %s', self.tagged_name)
76 # Get the test method on the derived class and execute it 76 # Get the test method on the derived class and execute it
77 return getattr(self, self.test_name)() 77 return getattr(self, self.test_name)()
78 78
79 def __RunJavaTest(self, package_name, test_case, test_method): 79 def __RunJavaTest(self, test, test_pkg):
80 """Runs a single Java test method with a Java TestRunner. 80 """Runs a single Java test in a Java TestRunner.
81 81
82 Args: 82 Args:
83 package_name: Package name in which the java tests live 83 test: Fully qualified test name (ex. foo.bar.TestClass#testMethod)
84 (e.g. foo.bar.baz.tests) 84 test_pkg: TestPackage object.
85 test_case: Name of the Java test case (e.g. FooTest)
86 test_method: Name of the test method to run (e.g. testFooBar)
87 85
88 Returns: 86 Returns:
89 TestRunResults object with a single test result. 87 TestRunResults object with a single test result.
90 """ 88 """
91 test = '%s.%s#%s' % (package_name, test_case, test_method)
92 test_pkg = test_package.TestPackage(
93 self.instrumentation_options.test_apk_path,
94 self.instrumentation_options.test_apk_jar_path)
95 java_test_runner = test_runner.TestRunner(self.instrumentation_options, 89 java_test_runner = test_runner.TestRunner(self.instrumentation_options,
96 self.device_id, 90 self.device_id,
97 self.shard_index, test_pkg, 91 self.shard_index, test_pkg,
98 self.ports_to_forward) 92 self.ports_to_forward)
99 try: 93 try:
100 java_test_runner.SetUp() 94 java_test_runner.SetUp()
101 return java_test_runner.RunTest(test)[0] 95 return java_test_runner.RunTest(test)[0]
102 finally: 96 finally:
103 java_test_runner.TearDown() 97 java_test_runner.TearDown()
104 98
105 def _RunJavaTests(self, package_name, tests): 99 def _RunJavaTests(self, test_filters):
bulach 2013/08/20 11:08:07 we should probably do this two-sided? keep the oth
gkanwar1 2013/08/20 15:45:33 By two-sided do you mean: * Upstream: Create a new
bulach 2013/08/20 15:53:10 the former :) requires less coordination between y
gkanwar 2013/08/20 16:01:57 Yeah, the only other problem I had with the former
106 """Calls a list of tests and stops at the first test failure. 100 """Calls a list of tests and stops at the first test failure.
107 101
108 This method iterates until either it encounters a non-passing test or it 102 This method iterates until either it encounters a non-passing test or it
109 exhausts the list of tests. Then it returns the appropriate overall result. 103 exhausts the list of tests. Then it returns the appropriate overall result.
110 104
111 Test cases may make use of this method internally to assist in running 105 Test cases may make use of this method internally to assist in running
112 instrumentation tests. This function relies on instrumentation_options 106 instrumentation tests. This function relies on instrumentation_options
113 being defined. 107 being defined.
114 108
115 Args: 109 Args:
116 package_name: Package name in which the java tests live 110 test_filters: A list of Java test filters.
117 (e.g. foo.bar.baz.tests)
118 tests: A list of Java test names which will be run
119 111
120 Returns: 112 Returns:
121 A TestRunResults object containing an overall result for this set of Java 113 A TestRunResults object containing an overall result for this set of Java
122 tests. If any Java tests do not pass, this is a fail overall. 114 tests. If any Java tests do not pass, this is a fail overall.
123 """ 115 """
124 test_type = base_test_result.ResultType.PASS 116 test_type = base_test_result.ResultType.PASS
125 log = '' 117 log = ''
126 118
119 test_pkg = test_package.TestPackage(
120 self.instrumentation_options.test_apk_path,
121 self.instrumentation_options.test_apk_jar_path)
122
127 start_ms = int(time.time()) * 1000 123 start_ms = int(time.time()) * 1000
128 for test in tests: 124 done = False
129 # We're only running one test at a time, so this TestRunResults object 125 for test_filter in test_filters:
130 # will hold only one result. 126 tests = test_pkg._GetAllMatchingTests(None, None, test_filter)
131 suite, test_name = test.split('.') 127 # Filters should always result in >= 1 test.
132 java_result = self.__RunJavaTest(package_name, suite, test_name) 128 if len(tests) == 0:
133 assert len(java_result.GetAll()) == 1 129 raise Exception('Java test filter "%s" returned no tests.'
134 if not java_result.DidRunPass(): 130 % test_filter)
135 result = java_result.GetNotPass().pop() 131 for test in tests:
136 log = result.GetLog() 132 # We're only running one test at a time, so this TestRunResults object
137 test_type = result.GetType() 133 # will hold only one result.
134 java_result = self.__RunJavaTest(test, test_pkg)
135 assert len(java_result.GetAll()) == 1
136 if not java_result.DidRunPass():
137 result = java_result.GetNotPass().pop()
138 log = result.GetLog()
139 test_type = result.GetType()
140 done = True
141 break
142 if done:
138 break 143 break
139 duration_ms = int(time.time()) * 1000 - start_ms 144 duration_ms = int(time.time()) * 1000 - start_ms
140 145
141 overall_result = base_test_result.TestRunResults() 146 overall_result = base_test_result.TestRunResults()
142 overall_result.AddResult( 147 overall_result.AddResult(
143 test_result.InstrumentationTestResult( 148 test_result.InstrumentationTestResult(
144 self.tagged_name, test_type, start_ms, duration_ms, log=log)) 149 self.tagged_name, test_type, start_ms, duration_ms, log=log))
145 return overall_result 150 return overall_result
146 151
147 def __str__(self): 152 def __str__(self):
148 return self.tagged_name 153 return self.tagged_name
149 154
150 def __repr__(self): 155 def __repr__(self):
151 return self.tagged_name 156 return self.tagged_name
OLDNEW
« no previous file with comments | « no previous file | chrome/android/host_driven_tests/DummyTest.py » ('j') | chrome/android/host_driven_tests/DummyTest.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698