OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 |
| 7 import os |
| 8 import sys |
| 9 |
| 10 import cmd_helper |
| 11 import shutil |
| 12 import tempfile |
| 13 from test_package import TestPackage |
| 14 |
| 15 |
| 16 class TestPackageApk(TestPackage): |
| 17 """A helper class for running APK-based native tests. |
| 18 |
| 19 Args: |
| 20 adb: ADB interface the tests are using. |
| 21 device: Device to run the tests. |
| 22 test_suite: A specific test suite to run, empty to run all. |
| 23 timeout: Timeout for each test. |
| 24 rebaseline: Whether or not to run tests in isolation and update the filter. |
| 25 performance_test: Whether or not performance test(s). |
| 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 APK_DATA_DIR = '/data/user/0/com.android.chrome.native_tests/files/' |
| 32 |
| 33 def __init__(self, adb, device, test_suite, timeout, rebaseline, |
| 34 performance_test, cleanup_test_files, tool, |
| 35 dump_debug_info): |
| 36 TestPackage.__init__(self, adb, device, test_suite, timeout, |
| 37 rebaseline, performance_test, cleanup_test_files, |
| 38 tool, dump_debug_info) |
| 39 |
| 40 def _CreateTestRunnerScript(self, options): |
| 41 tool_wrapper = self.tool.GetTestWrapper() |
| 42 if tool_wrapper: |
| 43 raise RuntimeError("TestPackageApk does not support custom wrappers.") |
| 44 command_line_file = tempfile.NamedTemporaryFile() |
| 45 # GTest expects argv[0] to be the executable path. |
| 46 command_line_file.write(self.test_suite_basename + ' ' + options) |
| 47 command_line_file.flush() |
| 48 self.adb.PushIfNeeded(command_line_file.name, |
| 49 TestPackageApk.APK_DATA_DIR + |
| 50 'chrome-native-tests-command-line') |
| 51 |
| 52 def _GetGTestReturnCode(self): |
| 53 return None |
| 54 |
| 55 def GetAllTests(self): |
| 56 """Returns a list of all tests available in the test suite.""" |
| 57 self._CreateTestRunnerScript('--gtest_list_tests') |
| 58 self.adb.RunShellCommand( |
| 59 'am start -n ' |
| 60 'com.android.chrome.native_tests/' |
| 61 'android.app.NativeActivity') |
| 62 stdout_file = tempfile.NamedTemporaryFile() |
| 63 ret = [] |
| 64 self.adb.Adb().Pull(TestPackageApk.APK_DATA_DIR + 'stdout.txt', |
| 65 stdout_file.name) |
| 66 ret = self._ParseGTestListTests(stdout_file) |
| 67 return ret |
| 68 |
| 69 def CreateTestRunnerScript(self, gtest_filter, test_arguments): |
| 70 self._CreateTestRunnerScript('--gtest_filter=%s %s' % (gtest_filter, |
| 71 test_arguments)) |
| 72 |
| 73 def RunTestsAndListResults(self): |
| 74 self.adb.StartMonitoringLogcat(clear=True, logfile=sys.stdout) |
| 75 # TODO(jrg): make the activity name a function of the test. |
| 76 self.adb.RunShellCommand( |
| 77 'am start -n ' |
| 78 'org.chromium.native_test/' |
| 79 'org.chromium.native_test.ChromeNativeTestActivity') |
| 80 return self._WatchTestOutput(self.adb.GetMonitoredLogCat()) |
| 81 |
| 82 def StripAndCopyExecutable(self): |
| 83 # TODO(jrg): downstream we would package up the .so into the apk |
| 84 # and rebuild. (Yikes!) We need to do something more kosher, |
| 85 # such as assembly at build time. E.g. building base_unittests |
| 86 # will build a libbase_unittests.apk that contains |
| 87 # libbbase_unittests.so, and avoid a "naked" ChromeNativeTests.apk. |
| 88 self.adb.Adb().SendCommand('install -r ' + self.test_suite_full, |
| 89 timeout_time=60*5) |
OLD | NEW |