Home | History | Annotate | Download | only in gtest
      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 
      7 import logging
      8 
      9 
     10 class TestPackage(object):
     11 
     12   """A helper base class for both APK and stand-alone executables.
     13 
     14   Args:
     15     suite_name: Name of the test suite (e.g. base_unittests).
     16   """
     17   def __init__(self, suite_name):
     18     self.suite_name = suite_name
     19 
     20   def ClearApplicationState(self, adb):
     21     """Clears the application state.
     22 
     23     Args:
     24       adb: Instance of AndroidCommands.
     25     """
     26     raise NotImplementedError('Method must be overriden.')
     27 
     28   def CreateCommandLineFileOnDevice(self, adb, test_filter, test_arguments):
     29     """Creates a test runner script and pushes to the device.
     30 
     31     Args:
     32       adb: Instance of AndroidCommands.
     33       test_filter: A test_filter flag.
     34       test_arguments: Additional arguments to pass to the test binary.
     35     """
     36     raise NotImplementedError('Method must be overriden.')
     37 
     38   def GetAllTests(self, adb):
     39     """Returns a list of all tests available in the test suite.
     40 
     41     Args:
     42       adb: Instance of AndroidCommands.
     43     """
     44     raise NotImplementedError('Method must be overriden.')
     45 
     46   def GetGTestReturnCode(self, adb):
     47     return None
     48 
     49   def SpawnTestProcess(self, adb):
     50     """Spawn the test process.
     51 
     52     Args:
     53       adb: Instance of AndroidCommands.
     54 
     55     Returns:
     56       An instance of pexpect spawn class.
     57     """
     58     raise NotImplementedError('Method must be overriden.')
     59 
     60   def Install(self, adb):
     61     """Install the test package to the device.
     62 
     63     Args:
     64       adb: Instance of AndroidCommands.
     65     """
     66     raise NotImplementedError('Method must be overriden.')
     67 
     68   def _ParseGTestListTests(self, 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] != ' ' and not test.endswith('.'):
     92         # Ignore any lines with unexpected format.
     93         continue
     94       if test[0] != ' ' and test.endswith('.'):
     95         current = test
     96         continue
     97       if 'YOU HAVE' in test:
     98         break
     99       test_name = test[2:]
    100       ret += [current + test_name]
    101     return ret
    102