• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"""Base class representing GTest test packages."""
6# pylint: disable=R0201
7
8
9class TestPackage(object):
10
11  """A helper base class for both APK and stand-alone executables.
12
13  Args:
14    suite_name: Name of the test suite (e.g. base_unittests).
15  """
16  def __init__(self, suite_name):
17    self.suite_name = suite_name
18
19  def ClearApplicationState(self, device):
20    """Clears the application state.
21
22    Args:
23      device: Instance of DeviceUtils.
24    """
25    raise NotImplementedError('Method must be overriden.')
26
27  def CreateCommandLineFileOnDevice(self, device, test_filter, test_arguments):
28    """Creates a test runner script and pushes to the device.
29
30    Args:
31      device: Instance of DeviceUtils.
32      test_filter: A test_filter flag.
33      test_arguments: Additional arguments to pass to the test binary.
34    """
35    raise NotImplementedError('Method must be overriden.')
36
37  def GetAllTests(self, device):
38    """Returns a list of all tests available in the test suite.
39
40    Args:
41      device: Instance of DeviceUtils.
42    """
43    raise NotImplementedError('Method must be overriden.')
44
45  def GetGTestReturnCode(self, _device):
46    return None
47
48  def SpawnTestProcess(self, device):
49    """Spawn the test process.
50
51    Args:
52      device: Instance of DeviceUtils.
53
54    Returns:
55      An instance of pexpect spawn class.
56    """
57    raise NotImplementedError('Method must be overriden.')
58
59  def Install(self, device):
60    """Install the test package to the device.
61
62    Args:
63      device: Instance of DeviceUtils.
64    """
65    raise NotImplementedError('Method must be overriden.')
66
67  @staticmethod
68  def _ParseGTestListTests(raw_list):
69    """Parses a raw test list as provided by --gtest_list_tests.
70
71    Args:
72      raw_list: The raw test listing with the following format:
73
74      IPCChannelTest.
75        SendMessageInChannelConnected
76      IPCSyncChannelTest.
77        Simple
78        DISABLED_SendWithTimeoutMixedOKAndTimeout
79
80    Returns:
81      A list of all tests. For the above raw listing:
82
83      [IPCChannelTest.SendMessageInChannelConnected, IPCSyncChannelTest.Simple,
84       IPCSyncChannelTest.DISABLED_SendWithTimeoutMixedOKAndTimeout]
85    """
86    ret = []
87    current = ''
88    for test in raw_list:
89      if not test:
90        continue
91      if test[0] != ' ':
92        test_case = test.split()[0]
93        if test_case.endswith('.'):
94          current = test_case
95      elif not 'YOU HAVE' in test:
96        test_name = test.split()[0]
97        ret += [current + test_name]
98    return ret
99