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 logging |
| 12 import shutil |
| 13 import tempfile |
| 14 from test_package import TestPackage |
| 15 |
| 16 |
| 17 class TestPackageApk(TestPackage): |
| 18 """A helper class for running APK-based native tests. |
| 19 |
| 20 Args: |
| 21 adb: ADB interface the tests are using. |
| 22 device: Device to run the tests. |
| 23 test_suite: A specific test suite to run, empty to run all. |
| 24 timeout: Timeout for each test. |
| 25 rebaseline: Whether or not to run tests in isolation and update the filter. |
| 26 performance_test: Whether or not performance test(s). |
| 27 cleanup_test_files: Whether or not to cleanup test files on device. |
| 28 tool: Name of the Valgrind tool. |
| 29 dump_debug_info: A debug_info object. |
| 30 """ |
| 31 |
| 32 APK_DATA_DIR = '/data/user/0/com.android.chrome.native_tests/files/' |
| 33 |
| 34 def __init__(self, adb, device, test_suite, timeout, rebaseline, |
| 35 performance_test, cleanup_test_files, tool, |
| 36 dump_debug_info): |
| 37 TestPackage.__init__(self, adb, device, test_suite, timeout, |
| 38 rebaseline, performance_test, cleanup_test_files, |
| 39 tool, dump_debug_info) |
| 40 |
| 41 def _CreateTestRunnerScript(self, options): |
| 42 tool_wrapper = self.tool.GetTestWrapper() |
| 43 if tool_wrapper: |
| 44 raise RuntimeError("TestPackageApk does not support custom wrappers.") |
| 45 command_line_file = tempfile.NamedTemporaryFile() |
| 46 # GTest expects argv[0] to be the executable path. |
| 47 command_line_file.write(self.test_suite_basename + ' ' + options) |
| 48 command_line_file.flush() |
| 49 self.adb.PushIfNeeded(command_line_file.name, |
| 50 TestPackageApk.APK_DATA_DIR + |
| 51 'chrome-native-tests-command-line') |
| 52 |
| 53 def _GetGTestReturnCode(self): |
| 54 return None |
| 55 |
| 56 def GetAllTests(self): |
| 57 """Returns a list of all tests available in the test suite.""" |
| 58 self._CreateTestRunnerScript('--gtest_list_tests') |
| 59 self.adb.RunShellCommand( |
| 60 'am start -n ' |
| 61 'com.android.chrome.native_tests/' |
| 62 'android.app.NativeActivity') |
| 63 stdout_file = tempfile.NamedTemporaryFile() |
| 64 ret = [] |
| 65 self.adb.Adb().Pull(TestPackageApk.APK_DATA_DIR + 'stdout.txt', |
| 66 stdout_file.name) |
| 67 ret = self._ParseGTestListTests(stdout_file) |
| 68 return ret |
| 69 |
| 70 def CreateTestRunnerScript(self, gtest_filter, test_arguments): |
| 71 self._CreateTestRunnerScript('--gtest_filter=%s %s' % (gtest_filter, |
| 72 test_arguments)) |
| 73 |
| 74 def RunTestsAndListResults(self): |
| 75 self.adb.StartMonitoringLogcat(clear=True, logfile=sys.stdout) |
| 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 # Always uninstall the previous one (by activity name); we don't |
| 84 # know what was embedded in it. |
| 85 logging.info('Uninstalling any activity with the test name') |
| 86 self.adb.Adb().SendCommand('uninstall org.chromium.native_test', |
| 87 timeout_time=60*5) |
| 88 logging.info('Installing new apk') |
| 89 self.adb.Adb().SendCommand('install -r ' + self.test_suite_full, |
| 90 timeout_time=60*5) |
| 91 logging.info('Install has completed.') |
OLD | NEW |