| OLD | NEW |
| 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 """Class for running instrumentation tests on a single device.""" | 5 """Class for running instrumentation tests on a single device.""" |
| 6 | 6 |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import re | 9 import re |
| 10 import sys | 10 import sys |
| 11 import time | 11 import time |
| 12 | 12 |
| 13 |
| 14 sys.path.append(os.path.join(sys.path[0], |
| 15 os.pardir, os.pardir, 'build', 'util', 'lib', |
| 16 'common')) |
| 17 import perf_tests_results_helper |
| 18 |
| 13 from pylib import android_commands | 19 from pylib import android_commands |
| 14 from pylib import constants | 20 from pylib import constants |
| 15 from pylib import flag_changer | 21 from pylib import flag_changer |
| 16 from pylib import valgrind_tools | 22 from pylib import valgrind_tools |
| 17 from pylib.base import base_test_result | 23 from pylib.base import base_test_result |
| 18 from pylib.base import base_test_runner | 24 from pylib.base import base_test_runner |
| 19 from pylib.instrumentation import json_perf_parser | 25 from pylib.instrumentation import json_perf_parser |
| 20 from pylib.instrumentation import test_result | |
| 21 | 26 |
| 22 sys.path.append(os.path.join(sys.path[0], | 27 import test_result |
| 23 os.pardir, os.pardir, 'build', 'util', 'lib', | |
| 24 'common')) | |
| 25 import perf_tests_results_helper # pylint: disable=F0401 | |
| 26 | 28 |
| 27 | 29 |
| 28 _PERF_TEST_ANNOTATION = 'PerfTest' | 30 _PERF_TEST_ANNOTATION = 'PerfTest' |
| 29 | 31 |
| 30 | 32 |
| 31 def _GetDataFilesForTestSuite(suite_basename): | 33 def _GetDataFilesForTestSuite(suite_basename): |
| 32 """Returns a list of data files/dirs needed by the test suite. | 34 """Returns a list of data files/dirs needed by the test suite. |
| 33 | 35 |
| 34 Args: | 36 Args: |
| 35 suite_basename: The test suite basename for which to return file paths. | 37 suite_basename: The test suite basename for which to return file paths. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 64 device: Attached android device. | 66 device: Attached android device. |
| 65 shard_index: Shard index. | 67 shard_index: Shard index. |
| 66 test_pkg: A TestPackage object. | 68 test_pkg: A TestPackage object. |
| 67 additional_flags: A list of additional flags to add to the command line. | 69 additional_flags: A list of additional flags to add to the command line. |
| 68 """ | 70 """ |
| 69 super(TestRunner, self).__init__(device, test_options.tool, | 71 super(TestRunner, self).__init__(device, test_options.tool, |
| 70 test_options.push_deps, | 72 test_options.push_deps, |
| 71 test_options.cleanup_test_files) | 73 test_options.cleanup_test_files) |
| 72 self._lighttp_port = constants.LIGHTTPD_RANDOM_PORT_FIRST + shard_index | 74 self._lighttp_port = constants.LIGHTTPD_RANDOM_PORT_FIRST + shard_index |
| 73 | 75 |
| 74 self.coverage_device_file = None | |
| 75 self.coverage_dir = test_options.coverage_dir | |
| 76 self.coverage_host_file = None | |
| 77 self.options = test_options | 76 self.options = test_options |
| 78 self.test_pkg = test_pkg | 77 self.test_pkg = test_pkg |
| 78 self.coverage_dir = test_options.coverage_dir |
| 79 # Use the correct command line file for the package under test. | 79 # Use the correct command line file for the package under test. |
| 80 cmdline_file = [a.cmdline_file for a in constants.PACKAGE_INFO.itervalues() | 80 cmdline_file = [a.cmdline_file for a in constants.PACKAGE_INFO.itervalues() |
| 81 if a.test_package == self.test_pkg.GetPackageName()] | 81 if a.test_package == self.test_pkg.GetPackageName()] |
| 82 assert len(cmdline_file) < 2, 'Multiple packages have the same test package' | 82 assert len(cmdline_file) < 2, 'Multiple packages have the same test package' |
| 83 if len(cmdline_file) and cmdline_file[0]: | 83 if len(cmdline_file) and cmdline_file[0]: |
| 84 self.flags = flag_changer.FlagChanger(self.adb, cmdline_file[0]) | 84 self.flags = flag_changer.FlagChanger(self.adb, cmdline_file[0]) |
| 85 if additional_flags: | 85 if additional_flags: |
| 86 self.flags.AddFlags(additional_flags) | 86 self.flags.AddFlags(additional_flags) |
| 87 else: | 87 else: |
| 88 self.flags = None | 88 self.flags = None |
| (...skipping 16 matching lines...) Expand all Loading... |
| 105 # Make sure SD card is ready. | 105 # Make sure SD card is ready. |
| 106 self.adb.WaitForSdCardReady(20) | 106 self.adb.WaitForSdCardReady(20) |
| 107 for p in test_data: | 107 for p in test_data: |
| 108 self.adb.PushIfNeeded( | 108 self.adb.PushIfNeeded( |
| 109 os.path.join(constants.DIR_SOURCE_ROOT, p), | 109 os.path.join(constants.DIR_SOURCE_ROOT, p), |
| 110 os.path.join(self.adb.GetExternalStorage(), p)) | 110 os.path.join(self.adb.GetExternalStorage(), p)) |
| 111 | 111 |
| 112 # TODO(frankf): Specify test data in this file as opposed to passing | 112 # TODO(frankf): Specify test data in this file as opposed to passing |
| 113 # as command-line. | 113 # as command-line. |
| 114 for dest_host_pair in self.options.test_data: | 114 for dest_host_pair in self.options.test_data: |
| 115 dst_src = dest_host_pair.split(':', 1) | 115 dst_src = dest_host_pair.split(':',1) |
| 116 dst_layer = dst_src[0] | 116 dst_layer = dst_src[0] |
| 117 host_src = dst_src[1] | 117 host_src = dst_src[1] |
| 118 host_test_files_path = '%s/%s' % (constants.DIR_SOURCE_ROOT, host_src) | 118 host_test_files_path = '%s/%s' % (constants.DIR_SOURCE_ROOT, host_src) |
| 119 if os.path.exists(host_test_files_path): | 119 if os.path.exists(host_test_files_path): |
| 120 self.adb.PushIfNeeded(host_test_files_path, '%s/%s/%s' % ( | 120 self.adb.PushIfNeeded(host_test_files_path, '%s/%s/%s' % ( |
| 121 self.adb.GetExternalStorage(), TestRunner._DEVICE_DATA_DIR, | 121 self.adb.GetExternalStorage(), TestRunner._DEVICE_DATA_DIR, |
| 122 dst_layer)) | 122 dst_layer)) |
| 123 self.tool.CopyFiles() | 123 self.tool.CopyFiles() |
| 124 TestRunner._DEVICE_HAS_TEST_FILES[self.device] = True | 124 TestRunner._DEVICE_HAS_TEST_FILES[self.device] = True |
| 125 | 125 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 145 if not self.adb.IsRootEnabled(): | 145 if not self.adb.IsRootEnabled(): |
| 146 logging.warning('Unable to enable java asserts for %s, non rooted device', | 146 logging.warning('Unable to enable java asserts for %s, non rooted device', |
| 147 self.device) | 147 self.device) |
| 148 else: | 148 else: |
| 149 if self.adb.SetJavaAssertsEnabled(True): | 149 if self.adb.SetJavaAssertsEnabled(True): |
| 150 self.adb.Reboot(full_reboot=False) | 150 self.adb.Reboot(full_reboot=False) |
| 151 | 151 |
| 152 # We give different default value to launch HTTP server based on shard index | 152 # We give different default value to launch HTTP server based on shard index |
| 153 # because it may have race condition when multiple processes are trying to | 153 # because it may have race condition when multiple processes are trying to |
| 154 # launch lighttpd with same port at same time. | 154 # launch lighttpd with same port at same time. |
| 155 self.LaunchTestHttpServer( | 155 http_server_ports = self.LaunchTestHttpServer( |
| 156 os.path.join(constants.DIR_SOURCE_ROOT), self._lighttp_port) | 156 os.path.join(constants.DIR_SOURCE_ROOT), self._lighttp_port) |
| 157 if self.flags: | 157 if self.flags: |
| 158 self.flags.AddFlags(['--disable-fre', '--enable-test-intents']) | 158 self.flags.AddFlags(['--disable-fre', '--enable-test-intents']) |
| 159 | 159 |
| 160 def TearDown(self): | 160 def TearDown(self): |
| 161 """Cleans up the test harness and saves outstanding data from test run.""" | 161 """Cleans up the test harness and saves outstanding data from test run.""" |
| 162 if self.flags: | 162 if self.flags: |
| 163 self.flags.Restore() | 163 self.flags.Restore() |
| 164 super(TestRunner, self).TearDown() | 164 super(TestRunner, self).TearDown() |
| 165 | 165 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 self._GetInstrumentationArgs(), timeout) | 325 self._GetInstrumentationArgs(), timeout) |
| 326 except android_commands.errors.WaitForResponseTimedOutError: | 326 except android_commands.errors.WaitForResponseTimedOutError: |
| 327 logging.info('Ran the test with timeout of %ds.' % timeout) | 327 logging.info('Ran the test with timeout of %ds.' % timeout) |
| 328 raise | 328 raise |
| 329 | 329 |
| 330 #override | 330 #override |
| 331 def RunTest(self, test): | 331 def RunTest(self, test): |
| 332 raw_result = None | 332 raw_result = None |
| 333 start_date_ms = None | 333 start_date_ms = None |
| 334 results = base_test_result.TestRunResults() | 334 results = base_test_result.TestRunResults() |
| 335 timeout = (self._GetIndividualTestTimeoutSecs(test) * | 335 timeout=(self._GetIndividualTestTimeoutSecs(test) * |
| 336 self._GetIndividualTestTimeoutScale(test) * | 336 self._GetIndividualTestTimeoutScale(test) * |
| 337 self.tool.GetTimeoutScale()) | 337 self.tool.GetTimeoutScale()) |
| 338 try: | 338 try: |
| 339 self.TestSetup(test) | 339 self.TestSetup(test) |
| 340 start_date_ms = int(time.time()) * 1000 | 340 start_date_ms = int(time.time()) * 1000 |
| 341 raw_result = self._RunTest(test, timeout) | 341 raw_result = self._RunTest(test, timeout) |
| 342 duration_ms = int(time.time()) * 1000 - start_date_ms | 342 duration_ms = int(time.time()) * 1000 - start_date_ms |
| 343 status_code = raw_result.GetStatusCode() | 343 status_code = raw_result.GetStatusCode() |
| 344 if status_code: | 344 if status_code: |
| 345 if self.options.screenshot_failures: | 345 if self.options.screenshot_failures: |
| 346 self._TakeScreenshot(test) | 346 self._TakeScreenshot(test) |
| 347 log = raw_result.GetFailureReason() | 347 log = raw_result.GetFailureReason() |
| (...skipping 22 matching lines...) Expand all Loading... |
| 370 duration_ms = 0 | 370 duration_ms = 0 |
| 371 message = str(e) | 371 message = str(e) |
| 372 if not message: | 372 if not message: |
| 373 message = 'No information.' | 373 message = 'No information.' |
| 374 results.AddResult(test_result.InstrumentationTestResult( | 374 results.AddResult(test_result.InstrumentationTestResult( |
| 375 test, base_test_result.ResultType.CRASH, start_date_ms, duration_ms, | 375 test, base_test_result.ResultType.CRASH, start_date_ms, duration_ms, |
| 376 log=message)) | 376 log=message)) |
| 377 raw_result = None | 377 raw_result = None |
| 378 self.TestTeardown(test, raw_result) | 378 self.TestTeardown(test, raw_result) |
| 379 return (results, None if results.DidRunPass() else test) | 379 return (results, None if results.DidRunPass() else test) |
| OLD | NEW |