OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/python | |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
bulach
2012/03/23 10:30:48
nit:2012
John Grabowski
2012/03/24 01:59:18
Done.
| |
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('am start -n ' | |
59 'com.android.chrome.native_tests/' | |
60 'android.app.NativeActivity') | |
61 stdout_file = tempfile.NamedTemporaryFile() | |
62 ret = [] | |
63 self.adb.Adb().Pull(TestPackageApk.APK_DATA_DIR + 'stdout.txt', | |
64 stdout_file.name) | |
65 ret = self._ParseGTestListTests(stdout_file) | |
66 return ret | |
67 | |
68 def CreateTestRunnerScript(self, gtest_filter, test_arguments): | |
69 self._CreateTestRunnerScript('--gtest_filter=%s %s' % (gtest_filter, | |
70 test_arguments)) | |
71 | |
72 def RunTestsAndListResults(self): | |
73 self.adb.StartMonitoringLogcat(clear=True, logfile=sys.stdout) | |
74 # TODO(jrg): make the activity name a function of the test. | |
75 self.adb.RunShellCommand('am start -n ' | |
76 'org.chromium.native_test/' | |
77 'org.chromium.native_test.ChromeNativeTestActivity' ) | |
bulach
2012/03/23 10:30:48
nit: >80cols
John Grabowski
2012/03/24 01:59:18
Done.
| |
78 return self._WatchTestOutput(self.adb.GetMonitoredLogCat()) | |
79 | |
80 def StripAndCopyExecutable(self): | |
81 # TODO(jrg): downstream we would package up the .so into the apk | |
82 # and rebuild. (Yikes!) We need to do something more kosher, | |
83 # such as assembly at build time. E.g. building base_unittests | |
84 # will build a libbase_unittests.apk that contains | |
85 # libbbase_unittests.so, and avoid a "naked" ChromeNativeTests.apk. | |
86 self.adb.Adb().SendCommand('install -r ' + self.test_suite_full, | |
87 timeout_time=60*5) | |
OLD | NEW |