GTestBase

public abstract class GTestBase
extends Object implements IAbiReceiver, IConfigurationReceiver, IRemoteTest, IRuntimeHintProvider, IShardableTest, ITestCollector, ITestFilterReceiver

java.lang.Object
   ↳ com.android.tradefed.testtype.GTestBase


The base class of gTest

Summary

Fields

protected static final String FILTER_EXTENSION

protected static final String GTEST_FLAG_FILE

protected static final String GTEST_FLAG_FILTER

protected static final String GTEST_FLAG_LIST_TESTS

protected static final String GTEST_FLAG_PRINT_TIME

protected static final String GTEST_FLAG_RUN_DISABLED_TESTS

protected static final String GTEST_XML_OUTPUT

Public constructors

GTestBase()

Public methods

void addAllExcludeFilters( filters)

Adds the ERROR(/Set) of filters of which tests to exclude.

void addAllIncludeFilters( filters)

Adds the ERROR(/Set) of filters of which tests to include.

void addExcludeFilter(String filter)

Adds a filter of which tests to exclude.

void addIncludeFilter(String filter)

Adds a filter of which tests to include.

String cleanFilter(String filter)
void clearExcludeFilters()

Delete all the exclude filters currently tracked.

void clearIncludeFilters()

Delete all the include filters currently tracked.

IAbi getAbi()
getAfterTestCmd()

Gets shell command(s) to run after GTest.

getBeforeTestCmd()

Gets shell command(s) to run before GTest.

getExcludeFilters()

Returns the current ERROR(/Set) of exclude filters.

getFileExclusionFilterRegex()

Gets regex to exclude certain files from executing.

getGTestFlags()

Gets Additional flag values to pass to the native test's shell command.

getIncludeFilters()

Returns the current ERROR(/Set) of include filters.

long getMaxTestTimeMs()

Gets the max time for a gtest to run.

String getModuleName()

Get the Android native test module to run.

boolean getRunDisabledTests()

Get whether GTest should run disabled tests.

long getRuntimeHint()

Return the expected runtime of the test in milliseconds.

int getShardCount()

Returns the current shard-count.

int getShardIndex()

Gets the shard index of this test.

String getTestFilterKey()

Gets test filter key.

String getTestModule()

Gets module name.

boolean isCollectTestsOnly()

Gets only invoke the test binary to collect list of applicable test cases or not.

boolean isEnableXmlOutput()

Gets use gtest xml output for test results or not.

boolean isSharded()

Gets isSharded flag.

void notifyTestExecution(boolean incompleteTestFound, failedTests)

Notify parent of test execution, so that inclusion/exclusion filters can be handled properly for the retry attempts.

void setAbi(IAbi abi)
void setCollectTestsOnly(boolean shouldCollectTest)

Enables or disables test collection mode

void setConfiguration(IConfiguration configuration)

Injects the IConfiguration in use.

void setModuleName(String moduleName)

Set the Android native test module to run.

void setShardCount(int shardCount)

Sets the shard count of this test.

void setShardIndex(int shardIndex)

Sets the shard index of this test.

split(int shardCountHint)

Alternative version of split() which also provides the shardCount that is attempted to be run.

Protected methods

String createFlagFile(String filter)

Create a file containing the filters that will be used via --gtest_flagfile to avoid any OS limitation in args size.

void erasePrependedFileName( filters, String filename)
String getAllGTestFlags(String path)

Helper to get all the GTest flags to pass into the adb shell command.

IConfiguration getConfiguration()

Returns the test configuration.

String getExceptionMessage(Exception e)

Make a best effort attempt to retrieve a meaningful short descriptive message for given Exception

String getGTestCmdLine(String fullPath, String flags)

Helper method to build the gtest command to run.

String getGTestCmdLineWrapper(String fullPath, String flags)

Helper which allows derived classes to wrap the gtest command under some other tool (chroot, strace, gdb, and similar).

String getGTestFilters(String path)

Helper to get the g-test filter of test to run.

ITestInvocationListener getGTestListener(ITestInvocationListener... listeners)

Returns the GTestListener that provides extra debugging info, like detects and reports duplicate tests if mDisabledDuplicateCheck is false.

abstract String loadFilter(String path)

Define get filter method.

void setRunDisabled(boolean runDisabled)

Set whether GTest should run disabled tests.

Fields

FILTER_EXTENSION

protected static final String FILTER_EXTENSION

GTEST_FLAG_FILE

protected static final String GTEST_FLAG_FILE

GTEST_FLAG_FILTER

protected static final String GTEST_FLAG_FILTER

GTEST_FLAG_LIST_TESTS

protected static final String GTEST_FLAG_LIST_TESTS

GTEST_FLAG_PRINT_TIME

protected static final String GTEST_FLAG_PRINT_TIME

GTEST_FLAG_RUN_DISABLED_TESTS

protected static final String GTEST_FLAG_RUN_DISABLED_TESTS

GTEST_XML_OUTPUT

protected static final String GTEST_XML_OUTPUT

Public constructors

GTestBase

public GTestBase ()

Public methods

addAllExcludeFilters

public void addAllExcludeFilters ( filters)

Adds the ERROR(/Set) of filters of which tests to exclude.

Parameters
filters

addAllIncludeFilters

public void addAllIncludeFilters ( filters)

Adds the ERROR(/Set) of filters of which tests to include.

Parameters
filters

addExcludeFilter

public void addExcludeFilter (String filter)

Adds a filter of which tests to exclude.

Parameters
filter String

addIncludeFilter

public void addIncludeFilter (String filter)

Adds a filter of which tests to include.

Parameters
filter String

cleanFilter

public String cleanFilter (String filter)

Parameters
filter String

Returns
String

clearExcludeFilters

public void clearExcludeFilters ()

Delete all the exclude filters currently tracked.

clearIncludeFilters

public void clearIncludeFilters ()

Delete all the include filters currently tracked.

getAbi

public IAbi getAbi ()

Returns
IAbi

getAfterTestCmd

public  getAfterTestCmd ()

Gets shell command(s) to run after GTest.

Returns

getBeforeTestCmd

public  getBeforeTestCmd ()

Gets shell command(s) to run before GTest.

Returns

getExcludeFilters

public  getExcludeFilters ()

Returns the current ERROR(/Set) of exclude filters.

Returns

getFileExclusionFilterRegex

public  getFileExclusionFilterRegex ()

Gets regex to exclude certain files from executing.

Returns

getGTestFlags

public  getGTestFlags ()

Gets Additional flag values to pass to the native test's shell command.

Returns

getIncludeFilters

public  getIncludeFilters ()

Returns the current ERROR(/Set) of include filters.

Returns

getMaxTestTimeMs

public long getMaxTestTimeMs ()

Gets the max time for a gtest to run.

Returns
long

getModuleName

public String getModuleName ()

Get the Android native test module to run.

Returns
String the name of the native test module to run, or null if not set

getRunDisabledTests

public boolean getRunDisabledTests ()

Get whether GTest should run disabled tests.

Returns
boolean True if disabled tests should be run, false otherwise

getRuntimeHint

public long getRuntimeHint ()

Return the expected runtime of the test in milliseconds. The time is used to load balance sharded execution

Returns
long

getShardCount

public int getShardCount ()

Returns the current shard-count.

Returns
int

getShardIndex

public int getShardIndex ()

Gets the shard index of this test.

Returns
int

getTestFilterKey

public String getTestFilterKey ()

Gets test filter key.

Returns
String

getTestModule

public String getTestModule ()

Gets module name.

Returns
String

isCollectTestsOnly

public boolean isCollectTestsOnly ()

Gets only invoke the test binary to collect list of applicable test cases or not.

Returns
boolean

isEnableXmlOutput

public boolean isEnableXmlOutput ()

Gets use gtest xml output for test results or not.

Returns
boolean

isSharded

public boolean isSharded ()

Gets isSharded flag.

Returns
boolean

notifyTestExecution

public void notifyTestExecution (boolean incompleteTestFound, 
                 failedTests)

Notify parent of test execution, so that inclusion/exclusion filters can be handled properly for the retry attempts.

Parameters
incompleteTestFound boolean

failedTests

setAbi

public void setAbi (IAbi abi)

Parameters
abi IAbi

setCollectTestsOnly

public void setCollectTestsOnly (boolean shouldCollectTest)

Enables or disables test collection mode

setConfiguration

public void setConfiguration (IConfiguration configuration)

Injects the IConfiguration in use.

Parameters
configuration IConfiguration

setModuleName

public void setModuleName (String moduleName)

Set the Android native test module to run.

Parameters
moduleName String: The name of the native test module to run

setShardCount

public void setShardCount (int shardCount)

Sets the shard count of this test.

Parameters
shardCount int

setShardIndex

public void setShardIndex (int shardIndex)

Sets the shard index of this test.

Parameters
shardIndex int

split

public  split (int shardCountHint)

Alternative version of split() which also provides the shardCount that is attempted to be run. This is useful for some test runner that cannot arbitrarily decide sometimes.

Parameters
shardCountHint int: the attempted shard count.

Returns
a collection of subtests to be executed separately or null if test is not currently shardable

Protected methods

createFlagFile

protected String createFlagFile (String filter)

Create a file containing the filters that will be used via --gtest_flagfile to avoid any OS limitation in args size.

Parameters
filter String: The filter string

Returns
String The path to the file containing the filter.

Throws
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

erasePrependedFileName

protected void erasePrependedFileName ( filters, 
                String filename)

Parameters
filters

filename String

getAllGTestFlags

protected String getAllGTestFlags (String path)

Helper to get all the GTest flags to pass into the adb shell command.

Parameters
path String: the full path of the binary on the device.

Returns
String the String of all the GTest flags that should be passed to the GTest

Throws
DeviceNotAvailableException

getConfiguration

protected IConfiguration getConfiguration ()

Returns the test configuration.

Returns
IConfiguration an IConfiguration

getExceptionMessage

protected String getExceptionMessage (Exception e)

Make a best effort attempt to retrieve a meaningful short descriptive message for given Exception

Parameters
e Exception: the Exception

Returns
String a short message

getGTestCmdLine

protected String getGTestCmdLine (String fullPath, 
                String flags)

Helper method to build the gtest command to run.

Parameters
fullPath String: absolute file system path to gtest binary on device

flags String: gtest execution flags

Returns
String the shell command line to run for the gtest

getGTestCmdLineWrapper

protected String getGTestCmdLineWrapper (String fullPath, 
                String flags)

Helper which allows derived classes to wrap the gtest command under some other tool (chroot, strace, gdb, and similar).

Parameters
fullPath String

flags String

Returns
String

getGTestFilters

protected String getGTestFilters (String path)

Helper to get the g-test filter of test to run.

Note that filters filter on the function name only (eg: Google Test "Test"); all Google Test "Test Cases" will be considered.

Parameters
path String: the full path of the binary on the device.

Returns
String the full filter flag to pass to the g-test, or an empty string if none have been specified

Throws
DeviceNotAvailableException

getGTestListener

protected ITestInvocationListener getGTestListener (ITestInvocationListener... listeners)

Returns the GTestListener that provides extra debugging info, like detects and reports duplicate tests if mDisabledDuplicateCheck is false. Otherwise, returns the passed-in listener.

Parameters
listeners ITestInvocationListener

Returns
ITestInvocationListener

loadFilter

protected abstract String loadFilter (String path)

Define get filter method.

Sub class must implement how to get it's own filter.

Parameters
path String: the full path of the filter file.

Returns
String filter string.

Throws
DeviceNotAvailableException

setRunDisabled

protected void setRunDisabled (boolean runDisabled)

Set whether GTest should run disabled tests.

Parameters
runDisabled boolean