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

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

Issue 12256021: [Android] Split out the instrumentation test runner, sharder, and dispatcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix some host_driven imports Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 Android Python-driven tests. 5 """Base class for Android Python-driven tests.
6 6
7 This test case is intended to serve as the base class for any Python-driven 7 This test case is intended to serve as the base class for any Python-driven
8 tests. It is similar to the Python unitttest module in that the user's tests 8 tests. It is similar to the Python unitttest module in that the user's tests
9 inherit from this case and add their tests in that case. 9 inherit from this case and add their tests in that case.
10 10
11 When a PythonTestBase object is instantiated, its purpose is to run only one of 11 When a PythonTestBase object is instantiated, its purpose is to run only one of
12 its tests. The test runner gives it the name of the test the instance will 12 its tests. The test runner gives it the name of the test the instance will
13 run. The test runner calls SetUp with the Android device ID which the test will 13 run. The test runner calls SetUp with the Android device ID which the test will
14 run against. The runner runs the test method itself, collecting the result, 14 run against. The runner runs the test method itself, collecting the result,
15 and calls TearDown. 15 and calls TearDown.
16 16
17 Tests can basically do whatever they want in the test methods, such as call 17 Tests can basically do whatever they want in the test methods, such as call
18 Java tests using _RunJavaTests. Those methods have the advantage of massaging 18 Java tests using _RunJavaTests. Those methods have the advantage of massaging
19 the Java test results into Python test results. 19 the Java test results into Python test results.
20 """ 20 """
21 21
22 import logging 22 import logging
23 import os 23 import os
24 import time 24 import time
25 25
26 from pylib import android_commands 26 from pylib import android_commands
27 from pylib.base.test_result import SingleTestResult, TestResults 27 from pylib.base.test_result import SingleTestResult, TestResults
28 from pylib.instrumentation import apk_info 28 from pylib.instrumentation import apk_info
29 from pylib.instrumentation.run_java_tests import TestRunner 29 from pylib.instrumentation import test_runner
30 30
31 31
32 # aka the parent of com.google.android 32 # aka the parent of com.google.android
33 BASE_ROOT = 'src' + os.sep 33 BASE_ROOT = 'src' + os.sep
34 34
35 35
36 class PythonTestBase(object): 36 class PythonTestBase(object):
37 """Base class for Python-driven tests.""" 37 """Base class for Python-driven tests."""
38 38
39 def __init__(self, test_name): 39 def __init__(self, test_name):
(...skipping 30 matching lines...) Expand all
70 fname: filename for the test (e.g. foo/bar/baz/tests/FooTest.py) 70 fname: filename for the test (e.g. foo/bar/baz/tests/FooTest.py)
71 suite: name of the Java test suite (e.g. FooTest) 71 suite: name of the Java test suite (e.g. FooTest)
72 test: name of the test method to run (e.g. testFooBar) 72 test: name of the test method to run (e.g. testFooBar)
73 73
74 Returns: 74 Returns:
75 TestResults object with a single test result. 75 TestResults object with a single test result.
76 """ 76 """
77 test = self._ComposeFullTestName(fname, suite, test) 77 test = self._ComposeFullTestName(fname, suite, test)
78 apks = [apk_info.ApkInfo(self.options.test_apk_path, 78 apks = [apk_info.ApkInfo(self.options.test_apk_path,
79 self.options.test_apk_jar_path)] 79 self.options.test_apk_jar_path)]
80 java_test_runner = TestRunner(self.options, self.device_id, [test], False, 80 java_test_runner = test_runner.TestRunner(self.options, self.device_id,
81 self.shard_index, 81 [test], False, self.shard_index,
82 apks, 82 apks, self.ports_to_forward)
83 self.ports_to_forward)
84 return java_test_runner.Run() 83 return java_test_runner.Run()
85 84
86 def _RunJavaTests(self, fname, tests): 85 def _RunJavaTests(self, fname, tests):
87 """Calls a list of tests and stops at the first test failure. 86 """Calls a list of tests and stops at the first test failure.
88 87
89 This method iterates until either it encounters a non-passing test or it 88 This method iterates until either it encounters a non-passing test or it
90 exhausts the list of tests. Then it returns the appropriate Python result. 89 exhausts the list of tests. Then it returns the appropriate Python result.
91 90
92 Args: 91 Args:
93 fname: filename for the Python test 92 fname: filename for the Python test
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 162
164 def _ComposeFullTestName(self, fname, suite, test): 163 def _ComposeFullTestName(self, fname, suite, test):
165 package_name = self._GetPackageName(fname) 164 package_name = self._GetPackageName(fname)
166 return package_name + '.' + suite + '#' + test 165 return package_name + '.' + suite + '#' + test
167 166
168 def _GetPackageName(self, fname): 167 def _GetPackageName(self, fname):
169 """Extracts the package name from the test file path.""" 168 """Extracts the package name from the test file path."""
170 dirname = os.path.dirname(fname) 169 dirname = os.path.dirname(fname)
171 package = dirname[dirname.rfind(BASE_ROOT) + len(BASE_ROOT):] 170 package = dirname[dirname.rfind(BASE_ROOT) + len(BASE_ROOT):]
172 return package.replace(os.sep, '.') 171 return package.replace(os.sep, '.')
OLDNEW
« no previous file with comments | « build/android/pylib/host_driven/java_unittest_utils.py ('k') | build/android/pylib/host_driven/python_test_sharder.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698