Chromium Code Reviews| Index: build/android/pylib/browsertests/test_runner.py |
| diff --git a/build/android/pylib/browsertests/test_runner.py b/build/android/pylib/browsertests/test_runner.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fe6931ae4519c3e54c4c2fe7855b7b65173a9498 |
| --- /dev/null |
| +++ b/build/android/pylib/browsertests/test_runner.py |
| @@ -0,0 +1,124 @@ |
| +# Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import logging |
| +import os |
| +import sys |
| + |
| +from pylib import android_commands |
| +from pylib import constants |
| +from pylib import perf_tests_helper |
| +from pylib.android_commands import errors |
| +from pylib.base.base_test_runner import BaseTestRunner |
| +from pylib.base.test_result import BaseTestResult, TestResults |
| +from pylib.gtest.test_package_apk import TestPackageApk |
| +from pylib.utils import run_tests_helper |
| + |
| +CURFILE_PATH = os.path.abspath(os.path.dirname(__file__)) |
| + |
| + |
| +def _GetDataFilesForTestSuite(): |
| + return ['content/test/data',] |
| + |
| + |
| +class TestRunner(BaseTestRunner): |
| + """Single test suite attached to a single device. |
| + |
| + Args: |
| + device: Device to run the tests. |
| + test_suite: A specific test suite to run, empty to run all. |
| + gtest_filter: A gtest_filter flag. |
| + test_arguments: Additional arguments to pass to the test binary. |
| + timeout: Timeout for each test. |
| + cleanup_test_files: Whether or not to cleanup test files on device. |
| + tool_name: Name of the Valgrind tool. |
| + shard_index: index number of the shard on which the test suite will run. |
| + build_type: 'Release' or 'Debug'. |
| + """ |
| + |
| + def __init__(self, device, test_suite, gtest_filter, test_arguments, timeout, |
| + cleanup_test_files, tool_name, shard_index, build_type,): |
| + BaseTestRunner.__init__(self, device, tool_name, shard_index, build_type) |
| + self._gtest_filter = gtest_filter |
| + self._test_arguments = '--single_process %s' % test_arguments |
| + self.test_results = TestResults() |
| + |
| + logging.warning('Test suite: ' + test_suite) |
| + self.test_package = TestPackageApk( |
| + self.adb, |
| + device, |
| + test_suite, |
| + timeout, |
| + cleanup_test_files, |
| + self.tool, |
| + 'org.chromium.content_browsertests_apk', |
| + 'org.chromium.content_browsertests_apk.ContentBrowserTestsActivity', |
| + '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.
|
| + |
| + def GetDisabledTests(self): |
| + """Returns a list of disabled tests. |
| + |
| + Returns: |
| + A list of disabled tests obtained from 'filter' subdirectory. |
| + """ |
| + gtest_filter_base_path = os.path.join( |
| + CURFILE_PATH, 'filter', self.test_package.test_suite_basename) |
| + disabled_tests = run_tests_helper.GetExpectations( |
| + gtest_filter_base_path + '_disabled') |
| + return disabled_tests |
| + |
| + def LaunchHelperToolsForTestSuite(self): |
| + """Launches helper tools for the test suite.""" |
| + self.LaunchChromeTestServerSpawner() |
| + |
| + def StripAndCopyFiles(self): |
| + """Strips and copies the required data files for the test suite.""" |
| + self.test_package.StripAndCopyExecutable() |
| + self.test_package.PushDataAndPakFiles() |
| + self.tool.CopyFiles() |
| + test_data = _GetDataFilesForTestSuite() |
| + if test_data: |
| + # Make sure SD card is ready. |
| + self.adb.WaitForSdCardReady(20) |
| + for data in test_data: |
| + self.CopyTestData([data], self.adb.GetExternalStorage()) |
| + |
| + def RunTests(self): |
| + """Runs a single test on a single device. |
| + |
| + Returns: |
| + A TestResults object. |
| + """ |
| + if not self._gtest_filter: |
| + raise Exception('Cannot run browser tests without a test filter.') |
| + try: |
| + self.test_package.CreateTestRunnerScript(self._gtest_filter, |
| + self._test_arguments) |
| + self.test_results = self.test_package.RunTestsAndListResults() |
| + except errors.DeviceUnresponsiveError as e: |
| + # Make sure this device is not attached |
| + logging.warning(e) |
| + if android_commands.IsDeviceAttached(self.device): |
| + raise e |
| + self.test_results.device_exception = device_exception |
| + finally: |
| + # TODO(frankf): Do not break TestResults encapsulation. |
| + all_tests = self._gtest_filter |
| + all_tests_ran = set([t.name for t in self.test_results.GetAll()]) |
| + self.test_results.unknown = [] |
| + return self.test_results |
| + |
| + def SetUp(self): |
| + """Sets up necessary test enviroment for the test suite.""" |
| + super(TestRunner, self).SetUp() |
| + self.StripAndCopyFiles() |
| + self.LaunchHelperToolsForTestSuite() |
| + self.tool.SetupEnvironment() |
| + |
| + def TearDown(self): |
| + """Cleans up the test enviroment for the test suite.""" |
| + self.tool.CleanUpEnvironment() |
| + if self.test_package.cleanup_test_files: |
| + self.adb.RemovePushedFiles() |
| + super(TestRunner, self).TearDown() |