OLD | NEW |
---|---|
(Empty) | |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 import logging | |
6 import os | |
7 import sys | |
8 | |
9 from pylib import android_commands | |
10 from pylib import constants | |
11 from pylib import perf_tests_helper | |
12 from pylib.android_commands import errors | |
13 from pylib.base.base_test_runner import BaseTestRunner | |
14 from pylib.base.test_result import BaseTestResult, TestResults | |
15 from pylib.gtest.test_package_apk import TestPackageApk | |
16 from pylib.utils import run_tests_helper | |
17 | |
18 CURFILE_PATH = os.path.abspath(os.path.dirname(__file__)) | |
19 | |
20 | |
21 def _GetDataFilesForTestSuite(): | |
22 return ['content/test/data',] | |
23 | |
24 | |
25 class TestRunner(BaseTestRunner): | |
26 """Single test suite attached to a single device. | |
27 | |
28 Args: | |
29 device: Device to run the tests. | |
30 test_suite: A specific test suite to run, empty to run all. | |
31 gtest_filter: A gtest_filter flag. | |
32 test_arguments: Additional arguments to pass to the test binary. | |
33 timeout: Timeout for each test. | |
34 cleanup_test_files: Whether or not to cleanup test files on device. | |
35 tool_name: Name of the Valgrind tool. | |
36 shard_index: index number of the shard on which the test suite will run. | |
37 build_type: 'Release' or 'Debug'. | |
38 """ | |
39 | |
40 def __init__(self, device, test_suite, gtest_filter, test_arguments, timeout, | |
41 cleanup_test_files, tool_name, shard_index, build_type,): | |
42 BaseTestRunner.__init__(self, device, tool_name, shard_index, build_type) | |
43 self._gtest_filter = gtest_filter | |
44 self._test_arguments = '--single_process %s' % test_arguments | |
45 self.test_results = TestResults() | |
46 | |
47 logging.warning('Test suite: ' + test_suite) | |
48 self.test_package = TestPackageApk( | |
49 self.adb, | |
50 device, | |
51 test_suite, | |
52 timeout, | |
53 cleanup_test_files, | |
54 self.tool, | |
55 'org.chromium.content_browsertests_apk', | |
56 'org.chromium.content_browsertests_apk.ContentBrowserTestsActivity', | |
57 'content-browser-tests-command-line') | |
frankf
2013/02/15 02:10:02
Define these in constants.py
nilesh
2013/02/20 18:23:36
Done.
| |
58 | |
59 def GetDisabledTests(self): | |
60 """Returns a list of disabled tests. | |
61 | |
62 Returns: | |
63 A list of disabled tests obtained from 'filter' subdirectory. | |
64 """ | |
65 gtest_filter_base_path = os.path.join( | |
66 CURFILE_PATH, 'filter', self.test_package.test_suite_basename) | |
67 disabled_tests = run_tests_helper.GetExpectations( | |
68 gtest_filter_base_path + '_disabled') | |
69 return disabled_tests | |
70 | |
71 def LaunchHelperToolsForTestSuite(self): | |
72 """Launches helper tools for the test suite.""" | |
73 self.LaunchChromeTestServerSpawner() | |
74 | |
75 def StripAndCopyFiles(self): | |
76 """Strips and copies the required data files for the test suite.""" | |
77 self.test_package.StripAndCopyExecutable() | |
78 self.test_package.PushDataAndPakFiles() | |
79 self.tool.CopyFiles() | |
80 test_data = _GetDataFilesForTestSuite() | |
81 if test_data: | |
82 # Make sure SD card is ready. | |
83 self.adb.WaitForSdCardReady(20) | |
84 for data in test_data: | |
85 self.CopyTestData([data], self.adb.GetExternalStorage()) | |
86 | |
87 def RunTests(self): | |
88 """Runs a single test on a single device. | |
89 | |
90 Returns: | |
91 A TestResults object. | |
92 """ | |
93 if not self._gtest_filter: | |
94 raise Exception('Cannot run browser tests without a test filter.') | |
95 try: | |
96 self.test_package.CreateTestRunnerScript(self._gtest_filter, | |
97 self._test_arguments) | |
98 self.test_results = self.test_package.RunTestsAndListResults() | |
99 except errors.DeviceUnresponsiveError as e: | |
100 # Make sure this device is not attached | |
101 logging.warning(e) | |
102 if android_commands.IsDeviceAttached(self.device): | |
103 raise e | |
104 self.test_results.device_exception = device_exception | |
105 finally: | |
106 # TODO(frankf): Do not break TestResults encapsulation. | |
107 all_tests = self._gtest_filter | |
108 all_tests_ran = set([t.name for t in self.test_results.GetAll()]) | |
109 self.test_results.unknown = [] | |
110 return self.test_results | |
111 | |
112 def SetUp(self): | |
113 """Sets up necessary test enviroment for the test suite.""" | |
114 super(TestRunner, self).SetUp() | |
115 self.StripAndCopyFiles() | |
116 self.LaunchHelperToolsForTestSuite() | |
117 self.tool.SetupEnvironment() | |
118 | |
119 def TearDown(self): | |
120 """Cleans up the test enviroment for the test suite.""" | |
121 self.tool.CleanUpEnvironment() | |
122 if self.test_package.cleanup_test_files: | |
123 self.adb.RemovePushedFiles() | |
124 super(TestRunner, self).TearDown() | |
OLD | NEW |