GTest

public class GTest
extends Object implements IDeviceTest, IRemoteTest, ITestFilterReceiver, IRuntimeHintProvider, ITestCollector, IStrictShardableTest

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


A Test that runs a native test package on given device.

Summary

Constants

String DEFAULT_NATIVETEST_PATH

String FILTER_EXTENSION

Public constructors

GTest()

Public methods

void addAllExcludeFilters(Set<String> filters)

Adds the Set of filters of which tests to exclude.

void addAllIncludeFilters(Set<String> filters)

Adds the 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.

ITestDevice getDevice()

Get the device under test.

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.

IRemoteTest getTestShard(int shardCount, int shardIndex)

Returns a IRemoteTest for a single shard.

void run(ITestInvocationListener listener)

Runs the tests, and reports result to the listener.

void setCollectTestsOnly(boolean shouldCollectTest)

Enables or disables test collection mode

void setDevice(ITestDevice device)

Inject the device under test.

void setEnableXmlOutput(boolean b)
void setModuleName(String moduleName)

Set the Android native test module to run.

void setRunDisabled(boolean runDisabled)

Set whether GTest should run disabled tests.

Protected methods

void executeCommandByScript(ITestDevice testDevice, String cmd, IShellOutputReceiver resultParser)

Helper method to run a gtest command from a temporary script, in the case that the command is too long to be run directly by adb.

String getGTestCmdLine(String fullPath, String flags)

Helper method to build the gtest command to run.

boolean isDeviceFileExecutable(String fullPath)
void setLoadFilterFromFile(String loadFilterFromFile)
boolean shouldSkipFile(String fullPath)

Helper method to determine if we should skip the execution of a given file.

Constants

DEFAULT_NATIVETEST_PATH

String DEFAULT_NATIVETEST_PATH

Constant Value: "/data/nativetest"

FILTER_EXTENSION

String FILTER_EXTENSION

Constant Value: ".filter"

Public constructors

GTest

GTest ()

Public methods

addAllExcludeFilters

void addAllExcludeFilters (Set<String> filters)

Adds the Set of filters of which tests to exclude.

Parameters
filters Set

addAllIncludeFilters

void addAllIncludeFilters (Set<String> filters)

Adds the Set of filters of which tests to include.

Parameters
filters Set

addExcludeFilter

void addExcludeFilter (String filter)

Adds a filter of which tests to exclude.

Parameters
filter String

addIncludeFilter

void addIncludeFilter (String filter)

Adds a filter of which tests to include.

Parameters
filter String

getDevice

ITestDevice getDevice ()

Get the device under test.

Returns
ITestDevice the ITestDevice

getModuleName

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

boolean getRunDisabledTests ()

Get whether GTest should run disabled tests.

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

getRuntimeHint

long getRuntimeHint ()

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

Returns
long

getTestShard

IRemoteTest getTestShard (int shardCount, 
                int shardIndex)

Returns a IRemoteTest for a single shard. This must be deterministic and always return the same IRemoteTest for the same input.

Parameters
shardCount int: the number of total shards
shardIndex int: the index of a test shard to return. The value is in range [0, shardCount).
Returns
IRemoteTest a IRemoteTest

run

void run (ITestInvocationListener listener)

Runs the tests, and reports result to the listener.

Parameters
listener ITestInvocationListener: the ITestInvocationListener of test results
Throws
DeviceNotAvailableException

setCollectTestsOnly

void setCollectTestsOnly (boolean shouldCollectTest)

Enables or disables test collection mode

setDevice

void setDevice (ITestDevice device)

Inject the device under test.

Parameters
device ITestDevice: the ITestDevice to use

setEnableXmlOutput

void setEnableXmlOutput (boolean b)

Parameters
b boolean

setModuleName

void setModuleName (String moduleName)

Set the Android native test module to run.

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

setRunDisabled

void setRunDisabled (boolean runDisabled)

Set whether GTest should run disabled tests.

Parameters
runDisabled boolean

Protected methods

executeCommandByScript

void executeCommandByScript (ITestDevice testDevice, 
                String cmd, 
                IShellOutputReceiver resultParser)

Helper method to run a gtest command from a temporary script, in the case that the command is too long to be run directly by adb.

Parameters
testDevice ITestDevice: the device on which to run the command
cmd String: the command string to run
resultParser IShellOutputReceiver: the output receiver for reading test results
Throws
DeviceNotAvailableException

getGTestCmdLine

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

isDeviceFileExecutable

boolean isDeviceFileExecutable (String fullPath)

Parameters
fullPath String
Returns
boolean
Throws
DeviceNotAvailableException

setLoadFilterFromFile

void setLoadFilterFromFile (String loadFilterFromFile)

Parameters
loadFilterFromFile String

shouldSkipFile

boolean shouldSkipFile (String fullPath)

Helper method to determine if we should skip the execution of a given file.

Parameters
fullPath String: the full path of the file in question
Returns
boolean true if we should skip the said file.
Throws
DeviceNotAvailableException