| OLD | NEW |
| (Empty) |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 | |
| 6 import logging | |
| 7 import re | |
| 8 import os | |
| 9 | |
| 10 import constants | |
| 11 from perf_tests_helper import PrintPerfResult | |
| 12 from pylib import pexpect | |
| 13 from test_result import BaseTestResult, TestResults | |
| 14 | |
| 15 from android_commands import errors | |
| 16 | |
| 17 | |
| 18 class TestPackage(object): | |
| 19 """A helper base class for both APK and stand-alone executables. | |
| 20 | |
| 21 Args: | |
| 22 adb: ADB interface the tests are using. | |
| 23 device: Device to run the tests. | |
| 24 test_suite: A specific test suite to run, empty to run all. | |
| 25 timeout: Timeout for each test. | |
| 26 cleanup_test_files: Whether or not to cleanup test files on device. | |
| 27 tool: Name of the Valgrind tool. | |
| 28 dump_debug_info: A debug_info object. | |
| 29 """ | |
| 30 | |
| 31 def __init__(self, adb, device, test_suite, timeout, | |
| 32 cleanup_test_files, tool, dump_debug_info): | |
| 33 self.adb = adb | |
| 34 self.device = device | |
| 35 self.test_suite_full = test_suite | |
| 36 self.test_suite = os.path.splitext(test_suite)[0] | |
| 37 self.test_suite_basename = self._GetTestSuiteBaseName() | |
| 38 self.test_suite_dirname = os.path.dirname( | |
| 39 self.test_suite.split(self.test_suite_basename)[0]) | |
| 40 self.cleanup_test_files = cleanup_test_files | |
| 41 self.tool = tool | |
| 42 if timeout == 0: | |
| 43 timeout = 60 | |
| 44 # On a VM (e.g. chromium buildbots), this timeout is way too small. | |
| 45 if os.environ.get('BUILDBOT_SLAVENAME'): | |
| 46 timeout = timeout * 2 | |
| 47 self.timeout = timeout * self.tool.GetTimeoutScale() | |
| 48 self.dump_debug_info = dump_debug_info | |
| 49 | |
| 50 def GetDisabledPrefixes(self): | |
| 51 return ['DISABLED_', 'FLAKY_', 'FAILS_'] | |
| 52 | |
| 53 def _ParseGTestListTests(self, all_tests): | |
| 54 """Parses and filters the raw test lists. | |
| 55 | |
| 56 Args: | |
| 57 all_tests: The raw test listing with the following format: | |
| 58 | |
| 59 IPCChannelTest. | |
| 60 SendMessageInChannelConnected | |
| 61 IPCSyncChannelTest. | |
| 62 Simple | |
| 63 DISABLED_SendWithTimeoutMixedOKAndTimeout | |
| 64 | |
| 65 Returns: | |
| 66 A list of non-disabled tests. For the above raw listing: | |
| 67 | |
| 68 [IPCChannelTest.SendMessageInChannelConnected, IPCSyncChannelTest.Simple] | |
| 69 """ | |
| 70 ret = [] | |
| 71 current = '' | |
| 72 disabled_prefixes = self.GetDisabledPrefixes() | |
| 73 for test in all_tests: | |
| 74 if not test: | |
| 75 continue | |
| 76 if test[0] != ' ' and not test.endswith('.'): | |
| 77 # Ignore any lines with unexpected format. | |
| 78 continue | |
| 79 if test[0] != ' ' and test.endswith('.'): | |
| 80 current = test | |
| 81 continue | |
| 82 if 'YOU HAVE' in test: | |
| 83 break | |
| 84 test_name = test[2:] | |
| 85 if not any([test_name.startswith(x) for x in disabled_prefixes]): | |
| 86 ret += [current + test_name] | |
| 87 return ret | |
| 88 | |
| 89 def PushDataAndPakFiles(self): | |
| 90 external_storage = self.adb.GetExternalStorage() | |
| 91 if (self.test_suite_basename == 'ui_unittests' or | |
| 92 self.test_suite_basename == 'unit_tests'): | |
| 93 self.adb.PushIfNeeded( | |
| 94 self.test_suite_dirname + '/chrome.pak', | |
| 95 external_storage + '/paks/chrome.pak') | |
| 96 self.adb.PushIfNeeded( | |
| 97 self.test_suite_dirname + '/locales/en-US.pak', | |
| 98 external_storage + '/paks/en-US.pak') | |
| 99 if self.test_suite_basename == 'unit_tests': | |
| 100 self.adb.PushIfNeeded( | |
| 101 self.test_suite_dirname + '/resources.pak', | |
| 102 external_storage + '/paks/resources.pak') | |
| 103 self.adb.PushIfNeeded( | |
| 104 self.test_suite_dirname + '/chrome_100_percent.pak', | |
| 105 external_storage + '/paks/chrome_100_percent.pak') | |
| 106 self.adb.PushIfNeeded(self.test_suite_dirname + '/test_data', | |
| 107 external_storage + '/test_data') | |
| 108 if self.test_suite_basename == 'content_unittests': | |
| 109 self.adb.PushIfNeeded( | |
| 110 self.test_suite_dirname + '/content_resources.pak', | |
| 111 external_storage + '/paks/content_resources.pak') | |
| 112 if self.test_suite_basename == 'breakpad_unittests': | |
| 113 self.adb.PushIfNeeded( | |
| 114 self.test_suite_dirname + '/linux_dumper_unittest_helper', | |
| 115 constants.TEST_EXECUTABLE_DIR + '/linux_dumper_unittest_helper') | |
| 116 | |
| 117 def _WatchTestOutput(self, p): | |
| 118 """Watches the test output. | |
| 119 Args: | |
| 120 p: the process generating output as created by pexpect.spawn. | |
| 121 """ | |
| 122 ok_tests = [] | |
| 123 failed_tests = [] | |
| 124 crashed_tests = [] | |
| 125 timed_out = False | |
| 126 overall_fail = False | |
| 127 | |
| 128 # Test case statuses. | |
| 129 re_run = re.compile('\[ RUN \] ?(.*)\r\n') | |
| 130 re_fail = re.compile('\[ FAILED \] ?(.*)\r\n') | |
| 131 re_ok = re.compile('\[ OK \] ?(.*?) .*\r\n') | |
| 132 | |
| 133 # Test run statuses. | |
| 134 re_passed = re.compile('\[ PASSED \] ?(.*)\r\n') | |
| 135 re_runner_fail = re.compile('\[ RUNNER_FAILED \] ?(.*)\r\n') | |
| 136 # Signal handlers are installed before starting tests | |
| 137 # to output the CRASHED marker when a crash happens. | |
| 138 re_crash = re.compile('\[ CRASHED \](.*)\r\n') | |
| 139 | |
| 140 try: | |
| 141 while True: | |
| 142 found = p.expect([re_run, re_passed, re_runner_fail], | |
| 143 timeout=self.timeout) | |
| 144 if found == 1: # re_passed | |
| 145 break | |
| 146 elif found == 2: # re_runner_fail | |
| 147 overall_fail = True | |
| 148 break | |
| 149 else: # re_run | |
| 150 if self.dump_debug_info: | |
| 151 self.dump_debug_info.TakeScreenshot('_Test_Start_Run_') | |
| 152 | |
| 153 full_test_name = p.match.group(1).replace('\r', '') | |
| 154 found = p.expect([re_ok, re_fail, re_crash], timeout=self.timeout) | |
| 155 if found == 0: # re_ok | |
| 156 if full_test_name == p.match.group(1).replace('\r', ''): | |
| 157 ok_tests += [BaseTestResult(full_test_name, p.before)] | |
| 158 elif found == 2: # re_crash | |
| 159 crashed_tests += [BaseTestResult(full_test_name, p.before)] | |
| 160 overall_fail = True | |
| 161 break | |
| 162 else: # re_fail | |
| 163 failed_tests += [BaseTestResult(full_test_name, p.before)] | |
| 164 except pexpect.EOF: | |
| 165 logging.error('Test terminated - EOF') | |
| 166 raise errors.DeviceUnresponsiveError('Device may be offline') | |
| 167 except pexpect.TIMEOUT: | |
| 168 logging.error('Test terminated after %d second timeout.', | |
| 169 self.timeout) | |
| 170 timed_out = True | |
| 171 finally: | |
| 172 p.close() | |
| 173 | |
| 174 ret_code = self._GetGTestReturnCode() | |
| 175 if ret_code: | |
| 176 logging.critical( | |
| 177 'gtest exit code: %d\npexpect.before: %s\npexpect.after: %s', | |
| 178 ret_code, p.before, p.after) | |
| 179 overall_fail = True | |
| 180 | |
| 181 # Create TestResults and return | |
| 182 return TestResults.FromRun(ok=ok_tests, failed=failed_tests, | |
| 183 crashed=crashed_tests, timed_out=timed_out, | |
| 184 overall_fail=overall_fail) | |
| OLD | NEW |