| 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 os | |
| 7 import sys | |
| 8 | |
| 9 import cmd_helper | |
| 10 import logging | |
| 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/org.chromium.native_test/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 '/data/local/tmp/' + | |
| 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 self.adb.RunShellCommand( | |
| 76 'am start -n ' | |
| 77 'org.chromium.native_test/' | |
| 78 'org.chromium.native_test.ChromeNativeTestActivity') | |
| 79 return self._WatchTestOutput(self.adb.GetMonitoredLogCat()) | |
| 80 | |
| 81 def StripAndCopyExecutable(self): | |
| 82 # Always uninstall the previous one (by activity name); we don't | |
| 83 # know what was embedded in it. | |
| 84 logging.info('Uninstalling any activity with the test name') | |
| 85 self.adb.Adb().SendCommand('uninstall org.chromium.native_test', | |
| 86 timeout_time=60*5) | |
| 87 logging.info('Installing new apk') | |
| 88 self.adb.Adb().SendCommand('install -r ' + self.test_suite_full, | |
| 89 timeout_time=60*5) | |
| 90 logging.info('Install has completed.') | |
| 91 | |
| 92 def _GetTestSuiteBaseName(self): | |
| 93 """Returns the base name of the test suite.""" | |
| 94 # APK test suite names end with '-debug.apk' | |
| 95 return os.path.basename(self.test_suite).rsplit('-debug', 1)[0] | |
| OLD | NEW |