GranularRetriableTestWrapper

public class GranularRetriableTestWrapper
extends Object implements IRemoteTest, ITestCollector

java.lang.Object
   ↳ com.android.tradefed.testtype.suite.GranularRetriableTestWrapper


A wrapper class works on the IRemoteTest to granulate the IRemoteTest in testcase level. An IRemoteTest can contain multiple testcases. Previously, these testcases are treated as a whole: When IRemoteTest runs, all testcases will run. Some IRemoteTest (The ones that implements ITestFilterReceiver) can accept an allowlist of testcases and only run those testcases. This class takes advantage of the existing feature and provides a more flexible way to run test suite.

  • Single testcase can be retried multiple times (within the same IRemoteTest run) to reduce the non-test-error failure rates.
  • The retried testcases are dynamically collected from previous run failures.

Note:

  • The prerequisite to run a subset of test cases is that the test type should implement the interface ITestFilterReceiver.
  • X is customized max retry number.

Summary

Nested classes

class GranularRetriableTestWrapper.StartEndCollector

Class helper to catch missing run start and end. 

Public constructors

GranularRetriableTestWrapper(IRemoteTest test, ITestInvocationListener mainListener, moduleLevelListeners, int maxRunLimit)
GranularRetriableTestWrapper(IRemoteTest test, ModuleDefinition module, ITestInvocationListener mainListener, moduleLevelListeners, int maxRunLimit)

Public methods

final int getExpectedTestsCount()

Calculate the number of testcases in the IRemoteTest.

final getFinalTestRunResults()

Get the merged TestRunResults from each IRemoteTest run.

final getPassedTests()
ModuleListener getResultListener()

Returns the listener containing all the results.

int getRetryCount()
void run(TestInformation testInfo, ITestInvocationListener listener)

Schedule a series of IRemoteTest#run(TestInformation, ITestInvocationListener).

void setCollectTestsOnly(boolean shouldCollectTest)

Enables or disables test collection mode

void setInvocationContext(IInvocationContext moduleInvocationContext)

Set the IInvocationContext as a GranularRetriableTestWrapper attribute.

void setLogSaver(ILogSaver logSaver)

Set the Module's ILogSaver as a GranularRetriableTestWrapper attribute.

void setMarkTestsSkipped(boolean skipTestCases)

Set the ModuleDefinition RunStrategy as a GranularRetriableTestWrapper attribute.

void setMetricCollectors( runMetricCollectors)

Set the ModuleDefinition's runMetricCollector as a GranularRetriableTestWrapper attribute.

void setModuleConfig(IConfiguration moduleConfiguration)

Set the ModuleDefinition's ModuleConfig as a GranularRetriableTestWrapper attribute.

void setModuleId(String moduleId)

Set the ModuleDefinition name as a GranularRetriableTestWrapper attribute.

void setRetryDecision(IRetryDecision decision)

Sets the IRetryDecision to be used.

Public constructors

GranularRetriableTestWrapper

public GranularRetriableTestWrapper (IRemoteTest test, 
                ITestInvocationListener mainListener, 
                 moduleLevelListeners, 
                int maxRunLimit)

Parameters
test IRemoteTest

mainListener ITestInvocationListener

moduleLevelListeners

maxRunLimit int

GranularRetriableTestWrapper

public GranularRetriableTestWrapper (IRemoteTest test, 
                ModuleDefinition module, 
                ITestInvocationListener mainListener, 
                 moduleLevelListeners, 
                int maxRunLimit)

Parameters
test IRemoteTest

module ModuleDefinition

mainListener ITestInvocationListener

moduleLevelListeners

maxRunLimit int

Public methods

getExpectedTestsCount

public final int getExpectedTestsCount ()

Calculate the number of testcases in the IRemoteTest. This value distincts the same testcases that are rescheduled multiple times.

Returns
int

getFinalTestRunResults

public final  getFinalTestRunResults ()

Get the merged TestRunResults from each IRemoteTest run.

Returns

getPassedTests

public final  getPassedTests ()

Returns

getResultListener

public ModuleListener getResultListener ()

Returns the listener containing all the results.

Returns
ModuleListener

getRetryCount

public int getRetryCount ()

Returns
int

run

public void run (TestInformation testInfo, 
                ITestInvocationListener listener)

Schedule a series of IRemoteTest#run(TestInformation, ITestInvocationListener).

Parameters
testInfo TestInformation: The TestInformation object containing useful information to run tests.

listener ITestInvocationListener: The ResultForwarder listener which contains a new moduleListener for each run.

Throws
DeviceNotAvailableException

setCollectTestsOnly

public void setCollectTestsOnly (boolean shouldCollectTest)

Enables or disables test collection mode

setInvocationContext

public void setInvocationContext (IInvocationContext moduleInvocationContext)

Set the IInvocationContext as a GranularRetriableTestWrapper attribute.

Parameters
moduleInvocationContext IInvocationContext: The wrapper uses the InvocationContext to initialize the MetricCollector when necessary.

setLogSaver

public void setLogSaver (ILogSaver logSaver)

Set the Module's ILogSaver as a GranularRetriableTestWrapper attribute.

Parameters
logSaver ILogSaver: The listeners for each test run should save the logs.

setMarkTestsSkipped

public void setMarkTestsSkipped (boolean skipTestCases)

Set the ModuleDefinition RunStrategy as a GranularRetriableTestWrapper attribute.

Parameters
skipTestCases boolean: whether the testcases should be skipped.

setMetricCollectors

public void setMetricCollectors ( runMetricCollectors)

Set the ModuleDefinition's runMetricCollector as a GranularRetriableTestWrapper attribute.

Parameters
runMetricCollectors : A list of MetricCollector for the module.

setModuleConfig

public void setModuleConfig (IConfiguration moduleConfiguration)

Set the ModuleDefinition's ModuleConfig as a GranularRetriableTestWrapper attribute.

Parameters
moduleConfiguration IConfiguration: Provide the module metrics.

setModuleId

public void setModuleId (String moduleId)

Set the ModuleDefinition name as a GranularRetriableTestWrapper attribute.

Parameters
moduleId String: the name of the moduleDefinition.

setRetryDecision

public void setRetryDecision (IRetryDecision decision)

Sets the IRetryDecision to be used.

Parameters
decision IRetryDecision