| 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 shlex | 7 import shlex |
| 8 import sys | 8 import sys |
| 9 import tempfile | 9 import tempfile |
| 10 import time | 10 import time |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 Args: | 23 Args: |
| 24 adb: ADB interface the tests are using. | 24 adb: ADB interface the tests are using. |
| 25 device: Device to run the tests. | 25 device: Device to run the tests. |
| 26 test_suite: A specific test suite to run, empty to run all. | 26 test_suite: A specific test suite to run, empty to run all. |
| 27 timeout: Timeout for each test. | 27 timeout: Timeout for each test. |
| 28 cleanup_test_files: Whether or not to cleanup test files on device. | 28 cleanup_test_files: Whether or not to cleanup test files on device. |
| 29 tool: Name of the Valgrind tool. | 29 tool: Name of the Valgrind tool. |
| 30 """ | 30 """ |
| 31 | 31 |
| 32 def __init__(self, adb, device, test_suite, timeout, | 32 def __init__(self, adb, device, test_suite, timeout, |
| 33 cleanup_test_files, tool): | 33 cleanup_test_files, tool, apk_package_name, |
| 34 test_activity_name, command_line_file): |
| 34 TestPackage.__init__(self, adb, device, test_suite, timeout, | 35 TestPackage.__init__(self, adb, device, test_suite, timeout, |
| 35 cleanup_test_files, tool) | 36 cleanup_test_files, tool) |
| 37 self._apk_package_name = apk_package_name |
| 38 self._test_activity_name = test_activity_name |
| 39 self._command_line_file = command_line_file |
| 36 | 40 |
| 37 def _CreateTestRunnerScript(self, options): | 41 def _CreateTestRunnerScript(self, options): |
| 38 command_line_file = tempfile.NamedTemporaryFile() | 42 command_line_file = tempfile.NamedTemporaryFile() |
| 39 # GTest expects argv[0] to be the executable path. | 43 # GTest expects argv[0] to be the executable path. |
| 40 command_line_file.write(self.test_suite_basename + ' ' + options) | 44 command_line_file.write(self.test_suite_basename + ' ' + options) |
| 41 command_line_file.flush() | 45 command_line_file.flush() |
| 42 self.adb.PushIfNeeded(command_line_file.name, | 46 self.adb.PushIfNeeded(command_line_file.name, |
| 43 constants.TEST_EXECUTABLE_DIR + | 47 constants.TEST_EXECUTABLE_DIR + '/' + |
| 44 '/chrome-native-tests-command-line') | 48 self._command_line_file) |
| 45 | 49 |
| 46 def _GetGTestReturnCode(self): | 50 def _GetGTestReturnCode(self): |
| 47 return None | 51 return None |
| 48 | 52 |
| 49 def _GetFifo(self): | 53 def _GetFifo(self): |
| 50 # The test.fifo path is determined by: | 54 # The test.fifo path is determined by: |
| 51 # testing/android/java/src/org/chromium/native_test/ | 55 # testing/android/java/src/org/chromium/native_test/ |
| 52 # ChromeNativeTestActivity.java and | 56 # ChromeNativeTestActivity.java and |
| 53 # testing/android/native_test_launcher.cc | 57 # testing/android/native_test_launcher.cc |
| 54 return '/data/data/org.chromium.native_test/files/test.fifo' | 58 return '/data/data/' + self._apk_package_name + '/files/test.fifo' |
| 55 | 59 |
| 56 def _ClearFifo(self): | 60 def _ClearFifo(self): |
| 57 self.adb.RunShellCommand('rm -f ' + self._GetFifo()) | 61 self.adb.RunShellCommand('rm -f ' + self._GetFifo()) |
| 58 | 62 |
| 59 def _WatchFifo(self, timeout, logfile=None): | 63 def _WatchFifo(self, timeout, logfile=None): |
| 60 for i in range(10): | 64 for i in range(10): |
| 61 if self.adb.FileExistsOnDevice(self._GetFifo()): | 65 if self.adb.FileExistsOnDevice(self._GetFifo()): |
| 62 print 'Fifo created...' | 66 print 'Fifo created...' |
| 63 break | 67 break |
| 64 time.sleep(i) | 68 time.sleep(i) |
| 65 else: | 69 else: |
| 66 raise errors.DeviceUnresponsiveError( | 70 raise errors.DeviceUnresponsiveError( |
| 67 'Unable to find fifo on device %s ' % self._GetFifo()) | 71 'Unable to find fifo on device %s ' % self._GetFifo()) |
| 68 args = shlex.split(self.adb.Adb()._target_arg) | 72 args = shlex.split(self.adb.Adb()._target_arg) |
| 69 args += ['shell', 'cat', self._GetFifo()] | 73 args += ['shell', 'cat', self._GetFifo()] |
| 70 return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile) | 74 return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile) |
| 71 | 75 |
| 72 def GetAllTests(self): | 76 def GetAllTests(self): |
| 73 """Returns a list of all tests available in the test suite.""" | 77 """Returns a list of all tests available in the test suite.""" |
| 74 self._CreateTestRunnerScript('--gtest_list_tests') | 78 self._CreateTestRunnerScript('--gtest_list_tests') |
| 75 try: | 79 try: |
| 76 self.tool.SetupEnvironment() | 80 self.tool.SetupEnvironment() |
| 77 # Clear and start monitoring logcat. | 81 # Clear and start monitoring logcat. |
| 78 self._ClearFifo() | 82 self._ClearFifo() |
| 79 self.adb.RunShellCommand( | 83 self.adb.RunShellCommand( |
| 80 'am start -n ' | 84 'am start -n ' + self._apk_package_name + '/' + |
| 81 'org.chromium.native_test/' | 85 self._test_activity_name) |
| 82 'org.chromium.native_test.ChromeNativeTestActivity') | |
| 83 # Wait for native test to complete. | 86 # Wait for native test to complete. |
| 84 p = self._WatchFifo(timeout=30 * self.tool.GetTimeoutScale()) | 87 p = self._WatchFifo(timeout=30 * self.tool.GetTimeoutScale()) |
| 85 p.expect("<<ScopedMainEntryLogger") | 88 p.expect("<<ScopedMainEntryLogger") |
| 86 p.close() | 89 p.close() |
| 87 finally: | 90 finally: |
| 88 self.tool.CleanUpEnvironment() | 91 self.tool.CleanUpEnvironment() |
| 89 # We need to strip the trailing newline. | 92 # We need to strip the trailing newline. |
| 90 content = [line.rstrip() for line in p.before.splitlines()] | 93 content = [line.rstrip() for line in p.before.splitlines()] |
| 91 ret = self._ParseGTestListTests(content) | 94 ret = self._ParseGTestListTests(content) |
| 92 return ret | 95 return ret |
| 93 | 96 |
| 94 def CreateTestRunnerScript(self, gtest_filter, test_arguments): | 97 def CreateTestRunnerScript(self, gtest_filter, test_arguments): |
| 95 self._CreateTestRunnerScript('--gtest_filter=%s %s' % (gtest_filter, | 98 self._CreateTestRunnerScript('--gtest_filter=%s %s' % (gtest_filter, |
| 96 test_arguments)) | 99 test_arguments)) |
| 97 | 100 |
| 98 def RunTestsAndListResults(self): | 101 def RunTestsAndListResults(self): |
| 99 try: | 102 try: |
| 100 self.tool.SetupEnvironment() | 103 self.tool.SetupEnvironment() |
| 101 self._ClearFifo() | 104 self._ClearFifo() |
| 102 self.adb.RunShellCommand( | 105 self.adb.RunShellCommand( |
| 103 'am start -n ' | 106 'am start -n ' + self._apk_package_name + '/' + |
| 104 'org.chromium.native_test/' | 107 self._test_activity_name) |
| 105 'org.chromium.native_test.ChromeNativeTestActivity') | |
| 106 finally: | 108 finally: |
| 107 self.tool.CleanUpEnvironment() | 109 self.tool.CleanUpEnvironment() |
| 108 logfile = android_commands.NewLineNormalizer(sys.stdout) | 110 logfile = android_commands.NewLineNormalizer(sys.stdout) |
| 109 return self._WatchTestOutput(self._WatchFifo(timeout=10, logfile=logfile)) | 111 return self._WatchTestOutput(self._WatchFifo(timeout=10, logfile=logfile)) |
| 110 | 112 |
| 111 def StripAndCopyExecutable(self): | 113 def StripAndCopyExecutable(self): |
| 112 self.tool.CopyFiles() | 114 self.tool.CopyFiles() |
| 113 # Always uninstall the previous one (by activity name); we don't | 115 # Always uninstall the previous one (by activity name); we don't |
| 114 # know what was embedded in it. | 116 # know what was embedded in it. |
| 115 self.adb.ManagedInstall(self.test_suite_full, False, | 117 self.adb.ManagedInstall(self.test_suite_full, False, |
| 116 package_name='org.chromium.native_test') | 118 package_name=self._apk_package_name) |
| 117 | 119 |
| 118 def _GetTestSuiteBaseName(self): | 120 def _GetTestSuiteBaseName(self): |
| 119 """Returns the base name of the test suite.""" | 121 """Returns the base name of the test suite.""" |
| 120 # APK test suite names end with '-debug.apk' | 122 # APK test suite names end with '-debug.apk' |
| 121 return os.path.basename(self.test_suite).rsplit('-debug', 1)[0] | 123 return os.path.basename(self.test_suite).rsplit('-debug', 1)[0] |
| OLD | NEW |