GTestBase

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

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_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.

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 setCollectTestsOnly(boolean shouldCollectTest)

Enables or disables test collection mode

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

ITestInvocationListener addNativeCoverageListenerIfEnabled(ITestDevice device, ITestInvocationListener listener)

Adds a NativeCodeCoverageListener to the chain if code coverage is enabled.

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

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

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 getGTestFilters(String path)

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

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_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.

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

setCollectTestsOnly

public void setCollectTestsOnly (boolean shouldCollectTest)

Enables or disables test collection mode

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 arbitrarly 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

addNativeCoverageListenerIfEnabled

protected ITestInvocationListener addNativeCoverageListenerIfEnabled (ITestDevice device, 
                ITestInvocationListener listener)

Adds a NativeCodeCoverageListener to the chain if code coverage is enabled.

Parameters
device ITestDevice: the device to pull the coverage results from

listener ITestInvocationListener: the original listener

Returns
ITestInvocationListener a chained listener if code coverage is enabled, otherwise the original listener

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

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

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

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