| 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 """Base class representing GTest test packages.""" | 5 """Base class representing GTest test packages.""" |
| 6 | 6 |
| 7 import os | 7 import logging |
| 8 | |
| 9 from pylib import constants | |
| 10 | 8 |
| 11 | 9 |
| 12 class TestPackage(object): | 10 class TestPackage(object): |
| 11 |
| 13 """A helper base class for both APK and stand-alone executables. | 12 """A helper base class for both APK and stand-alone executables. |
| 14 | 13 |
| 15 Args: | 14 Args: |
| 16 adb: ADB interface the tests are using. | 15 suite_name: Name of the test suite (e.g. base_unittests). |
| 17 device: Device to run the tests. | |
| 18 suite_path_full: Absolute path to a specific test suite to run, | |
| 19 empty to run all. | |
| 20 Ex: '/foo/bar/base_unittests-debug.apk', for which | |
| 21 self.suite_path_full = '/foo/bar/base_unittests-debug.apk' | |
| 22 self.suite_path = '/foo/bar/base_unittests-debug' | |
| 23 self.suite_basename = 'base_unittests' | |
| 24 self.suite_dirname = '/foo/bar' | |
| 25 tool: Name of the Valgrind tool. | |
| 26 """ | 16 """ |
| 17 def __init__(self, suite_name): |
| 18 self.suite_name = suite_name |
| 27 | 19 |
| 28 def __init__(self, adb, device, suite_path_full, tool): | 20 def ClearApplicationState(self, adb): |
| 29 self.adb = adb | 21 """Clears the application state. |
| 30 self.device = device | |
| 31 self.suite_path_full = suite_path_full | |
| 32 self.suite_path = os.path.splitext(suite_path_full)[0] | |
| 33 self.suite_basename = self._GetTestSuiteBaseName() | |
| 34 self.suite_dirname = os.path.dirname( | |
| 35 self.suite_path.split(self.suite_basename)[0]) | |
| 36 self.tool = tool | |
| 37 | 22 |
| 38 def ClearApplicationState(self): | 23 Args: |
| 39 """Clears the application state.""" | 24 adb: Instance of AndroidCommands. |
| 25 """ |
| 40 raise NotImplementedError('Method must be overriden.') | 26 raise NotImplementedError('Method must be overriden.') |
| 41 | 27 |
| 42 def CreateCommandLineFileOnDevice(self, test_filter, test_arguments): | 28 def CreateCommandLineFileOnDevice(self, adb, test_filter, test_arguments): |
| 43 """Creates a test runner script and pushes to the device. | 29 """Creates a test runner script and pushes to the device. |
| 44 | 30 |
| 45 Args: | 31 Args: |
| 32 adb: Instance of AndroidCommands. |
| 46 test_filter: A test_filter flag. | 33 test_filter: A test_filter flag. |
| 47 test_arguments: Additional arguments to pass to the test binary. | 34 test_arguments: Additional arguments to pass to the test binary. |
| 48 """ | 35 """ |
| 49 raise NotImplementedError('Method must be overriden.') | 36 raise NotImplementedError('Method must be overriden.') |
| 50 | 37 |
| 51 def GetAllTests(self): | 38 def GetAllTests(self, adb): |
| 52 """Returns a list of all tests available in the test suite.""" | 39 """Returns a list of all tests available in the test suite. |
| 40 |
| 41 Args: |
| 42 adb: Instance of AndroidCommands. |
| 43 """ |
| 53 raise NotImplementedError('Method must be overriden.') | 44 raise NotImplementedError('Method must be overriden.') |
| 54 | 45 |
| 55 def GetGTestReturnCode(self): | 46 def GetGTestReturnCode(self, adb): |
| 56 return None | 47 return None |
| 57 | 48 |
| 58 def SpawnTestProcess(self): | 49 def SpawnTestProcess(self, adb): |
| 59 """Spawn the test process. | 50 """Spawn the test process. |
| 60 | 51 |
| 52 Args: |
| 53 adb: Instance of AndroidCommands. |
| 54 |
| 61 Returns: | 55 Returns: |
| 62 An instance of pexpect spawn class. | 56 An instance of pexpect spawn class. |
| 63 """ | 57 """ |
| 64 raise NotImplementedError('Method must be overriden.') | 58 raise NotImplementedError('Method must be overriden.') |
| 65 | 59 |
| 66 def Install(self): | 60 def Install(self, adb): |
| 67 """Install the test package to the device.""" | 61 """Install the test package to the device. |
| 62 |
| 63 Args: |
| 64 adb: Instance of AndroidCommands. |
| 65 """ |
| 68 raise NotImplementedError('Method must be overriden.') | 66 raise NotImplementedError('Method must be overriden.') |
| 69 | 67 |
| 70 def _ParseGTestListTests(self, raw_list): | 68 def _ParseGTestListTests(self, raw_list): |
| 71 """Parses a raw test list as provided by --gtest_list_tests. | 69 """Parses a raw test list as provided by --gtest_list_tests. |
| 72 | 70 |
| 73 Args: | 71 Args: |
| 74 raw_list: The raw test listing with the following format: | 72 raw_list: The raw test listing with the following format: |
| 75 | 73 |
| 76 IPCChannelTest. | 74 IPCChannelTest. |
| 77 SendMessageInChannelConnected | 75 SendMessageInChannelConnected |
| (...skipping 16 matching lines...) Expand all Loading... |
| 94 # Ignore any lines with unexpected format. | 92 # Ignore any lines with unexpected format. |
| 95 continue | 93 continue |
| 96 if test[0] != ' ' and test.endswith('.'): | 94 if test[0] != ' ' and test.endswith('.'): |
| 97 current = test | 95 current = test |
| 98 continue | 96 continue |
| 99 if 'YOU HAVE' in test: | 97 if 'YOU HAVE' in test: |
| 100 break | 98 break |
| 101 test_name = test[2:] | 99 test_name = test[2:] |
| 102 ret += [current + test_name] | 100 ret += [current + test_name] |
| 103 return ret | 101 return ret |
| OLD | NEW |