OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 import os | 6 import os |
7 import re | |
8 import sys | |
9 | |
10 import cmd_helper | |
11 import constants | |
12 import logging | |
13 import pexpect | 7 import pexpect |
14 import shlex | 8 import shlex |
15 import shutil | 9 import sys |
16 import tempfile | 10 import tempfile |
| 11 import time |
| 12 |
| 13 import android_commands |
| 14 import constants |
17 from test_package import TestPackage | 15 from test_package import TestPackage |
18 import time | |
19 | 16 |
20 | 17 |
21 class TestPackageApk(TestPackage): | 18 class TestPackageApk(TestPackage): |
22 """A helper class for running APK-based native tests. | 19 """A helper class for running APK-based native tests. |
23 | 20 |
24 Args: | 21 Args: |
25 adb: ADB interface the tests are using. | 22 adb: ADB interface the tests are using. |
26 device: Device to run the tests. | 23 device: Device to run the tests. |
27 test_suite: A specific test suite to run, empty to run all. | 24 test_suite: A specific test suite to run, empty to run all. |
28 timeout: Timeout for each test. | 25 timeout: Timeout for each test. |
(...skipping 26 matching lines...) Expand all Loading... |
55 def _GetFifo(self): | 52 def _GetFifo(self): |
56 # The test.fifo path is determined by: | 53 # The test.fifo path is determined by: |
57 # testing/android/java/src/org/chromium/native_test/ | 54 # testing/android/java/src/org/chromium/native_test/ |
58 # ChromeNativeTestActivity.java and | 55 # ChromeNativeTestActivity.java and |
59 # testing/android/native_test_launcher.cc | 56 # testing/android/native_test_launcher.cc |
60 return '/data/data/org.chromium.native_test/files/test.fifo' | 57 return '/data/data/org.chromium.native_test/files/test.fifo' |
61 | 58 |
62 def _ClearFifo(self): | 59 def _ClearFifo(self): |
63 self.adb.RunShellCommand('rm -f ' + self._GetFifo()) | 60 self.adb.RunShellCommand('rm -f ' + self._GetFifo()) |
64 | 61 |
65 def _WatchFifo(self, timeout): | 62 def _WatchFifo(self, timeout, logfile=None): |
66 for i in range(5): | 63 for i in range(5): |
67 if self.adb.FileExistsOnDevice(self._GetFifo()): | 64 if self.adb.FileExistsOnDevice(self._GetFifo()): |
68 print 'Fifo created...' | 65 print 'Fifo created...' |
69 break | 66 break |
70 time.sleep(i) | 67 time.sleep(i) |
71 else: | 68 else: |
72 raise Exception('Unable to find fifo on device %s ' % self._GetFifo()) | 69 raise Exception('Unable to find fifo on device %s ' % self._GetFifo()) |
73 args = shlex.split(self.adb.Adb()._target_arg) | 70 args = shlex.split(self.adb.Adb()._target_arg) |
74 args += ['shell', 'cat', self._GetFifo()] | 71 args += ['shell', 'cat', self._GetFifo()] |
75 return pexpect.spawn('adb', args, timeout=timeout, logfile=sys.stdout) | 72 return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile) |
76 | 73 |
77 def GetAllTests(self): | 74 def GetAllTests(self): |
78 """Returns a list of all tests available in the test suite.""" | 75 """Returns a list of all tests available in the test suite.""" |
79 self._CreateTestRunnerScript('--gtest_list_tests') | 76 self._CreateTestRunnerScript('--gtest_list_tests') |
80 try: | 77 try: |
81 self.tool.SetupEnvironment() | 78 self.tool.SetupEnvironment() |
82 # Clear and start monitoring logcat. | 79 # Clear and start monitoring logcat. |
83 self._ClearFifo() | 80 self._ClearFifo() |
84 self.adb.RunShellCommand( | 81 self.adb.RunShellCommand( |
85 'am start -n ' | 82 'am start -n ' |
86 'org.chromium.native_test/' | 83 'org.chromium.native_test/' |
87 'org.chromium.native_test.ChromeNativeTestActivity') | 84 'org.chromium.native_test.ChromeNativeTestActivity') |
88 # Wait for native test to complete. | 85 # Wait for native test to complete. |
89 p = self._WatchFifo(timeout=30 * self.tool.GetTimeoutScale()) | 86 p = self._WatchFifo(timeout=30 * self.tool.GetTimeoutScale()) |
90 p.expect("<<ScopedMainEntryLogger") | 87 p.expect("<<ScopedMainEntryLogger") |
91 p.close() | 88 p.close() |
92 finally: | 89 finally: |
93 self.tool.CleanUpEnvironment() | 90 self.tool.CleanUpEnvironment() |
94 # We need to strip the trailing newline. | 91 # We need to strip the trailing newline. |
95 content = [line.rstrip() for line in p.before.splitlines()] | 92 content = [line.rstrip() for line in p.before.splitlines()] |
96 ret = self._ParseGTestListTests(content) | 93 ret = self._ParseGTestListTests(content) |
97 return ret | 94 return ret |
98 | 95 |
99 def CreateTestRunnerScript(self, gtest_filter, test_arguments): | 96 def CreateTestRunnerScript(self, gtest_filter, test_arguments): |
100 self._CreateTestRunnerScript('--gtest_filter=%s %s' % (gtest_filter, | 97 self._CreateTestRunnerScript('--gtest_filter=%s %s' % (gtest_filter, |
101 test_arguments)) | 98 test_arguments)) |
102 | 99 |
103 def RunTestsAndListResults(self): | 100 def RunTestsAndListResults(self): |
104 try: | 101 try: |
105 self.tool.SetupEnvironment() | 102 self.tool.SetupEnvironment() |
106 self._ClearFifo() | 103 self._ClearFifo() |
107 self.adb.RunShellCommand( | 104 self.adb.RunShellCommand( |
108 'am start -n ' | 105 'am start -n ' |
109 'org.chromium.native_test/' | 106 'org.chromium.native_test/' |
110 'org.chromium.native_test.ChromeNativeTestActivity') | 107 'org.chromium.native_test.ChromeNativeTestActivity') |
111 finally: | 108 finally: |
112 self.tool.CleanUpEnvironment() | 109 self.tool.CleanUpEnvironment() |
113 return self._WatchTestOutput(self._WatchFifo(timeout=10)) | 110 logfile = android_commands.NewLineNormalizer(sys.stdout) |
| 111 return self._WatchTestOutput(self._WatchFifo(timeout=10, logfile=logfile)) |
114 | 112 |
115 def StripAndCopyExecutable(self): | 113 def StripAndCopyExecutable(self): |
116 # Always uninstall the previous one (by activity name); we don't | 114 # Always uninstall the previous one (by activity name); we don't |
117 # know what was embedded in it. | 115 # know what was embedded in it. |
118 self.adb.ManagedInstall(self.test_suite_full, False, | 116 self.adb.ManagedInstall(self.test_suite_full, False, |
119 package_name='org.chromium.native_test') | 117 package_name='org.chromium.native_test') |
120 | 118 |
121 def _GetTestSuiteBaseName(self): | 119 def _GetTestSuiteBaseName(self): |
122 """Returns the base name of the test suite.""" | 120 """Returns the base name of the test suite.""" |
123 # APK test suite names end with '-debug.apk' | 121 # APK test suite names end with '-debug.apk' |
124 return os.path.basename(self.test_suite).rsplit('-debug', 1)[0] | 122 return os.path.basename(self.test_suite).rsplit('-debug', 1)[0] |
OLD | NEW |