Google is committed to advancing racial equity for Black communities. See how.

BaseDeviceMetricCollector

public class BaseDeviceMetricCollector
extends Object implements IMetricCollector

java.lang.Object
   ↳ com.android.tradefed.device.metric.BaseDeviceMetricCollector


Base implementation of IMetricCollector that allows to start and stop collection on onTestRunStart(com.android.tradefed.device.metric.DeviceMetricData) and ERROR(/#onTestRunEnd(com.android.tradefed.device.metric.DeviceMetricData,Map)).

Summary

Fields

public static final String TEST_CASE_EXCLUDE_GROUP_OPTION

public static final String TEST_CASE_INCLUDE_GROUP_OPTION

Public constructors

BaseDeviceMetricCollector()

Public methods

final getBuildInfos()

Returns the list of build information available in the invocation.

final getDevices()

Returns the list of devices available in the invocation.

File getFileFromTestArtifacts(String fileName)

Retrieve the file from the test artifacts or module artifacts and cache it in a map for the subsequent calls.

final ITestInvocationListener getInvocationListener()

Returns the original ITestInvocationListener where we are forwarding the results.

final getRealDevices()

Returns all the non-stub devices from the getDevices() list.

String getRunName()

Returns the name of test run mRunName that triggers the collector.

String getTag()

Returns the identifier mTag of the collector.

ITestInvocationListener init(IInvocationContext context, ITestInvocationListener listener)

Initialization of the collector with the current context and where to forward results.

final void invocationEnded(long elapsedTime)
final void invocationFailed(FailureDescription failure)
final void invocationFailed(Throwable cause)
final void invocationStarted(IInvocationContext context)

Invocation Listeners for forwarding

final boolean isDisabled()

Returns True if entire object disabled (skip both setup and teardown).

void onTestAssumptionFailure(DeviceMetricData testData, TestDescription test)

Callback when a test case fails with assumption failure.

void onTestEnd(DeviceMetricData testData, currentTestCaseMetrics, TestDescription test)

Callback when a test case is ended.

void onTestEnd(DeviceMetricData testData, currentTestCaseMetrics)

Callback when a test case is ended.

void onTestFail(DeviceMetricData testData, TestDescription test)

Callback when a test case fails.

void onTestRunEnd(DeviceMetricData runData, currentRunMetrics)

Callback when a test run is ended.

void onTestRunStart(DeviceMetricData runData)

Callback when a test run is started.

void onTestStart(DeviceMetricData testData)

Callback when a test case is started.

final void setDisable(boolean isDisabled)

Sets whether the object should be disabled.

void setTag(String tag)

Sets the mTag of the collector.

final void testAssumptionFailure(TestDescription test, String trace)
final void testAssumptionFailure(TestDescription test, FailureDescription failure)
final void testEnded(TestDescription test, long endTime, testMetrics)
final void testEnded(TestDescription test, testMetrics)
final void testFailed(TestDescription test, FailureDescription failure)
final void testFailed(TestDescription test, String trace)
final void testIgnored(TestDescription test)
final void testLog(String dataName, LogDataType dataType, InputStreamSource dataStream)
final void testModuleEnded()
final void testModuleStarted(IInvocationContext moduleContext)
final void testRunEnded(long elapsedTime, runMetrics)
final void testRunFailed(FailureDescription failure)
final void testRunFailed(String errorMessage)
final void testRunStarted(String runName, int testCount, int attemptNumber)
final void testRunStarted(String runName, int testCount)

Test run callbacks

final void testRunStarted(String runName, int testCount, int attemptNumber, long startTime)
final void testRunStopped(long elapsedTime)
final void testStarted(TestDescription test, long startTime)
final void testStarted(TestDescription test)

Test cases callbacks

Fields

TEST_CASE_EXCLUDE_GROUP_OPTION

public static final String TEST_CASE_EXCLUDE_GROUP_OPTION

TEST_CASE_INCLUDE_GROUP_OPTION

public static final String TEST_CASE_INCLUDE_GROUP_OPTION

Public constructors

BaseDeviceMetricCollector

public BaseDeviceMetricCollector ()

Public methods

getBuildInfos

public final  getBuildInfos ()

Returns the list of build information available in the invocation.

Returns

getDevices

public final  getDevices ()

Returns the list of devices available in the invocation.

Returns

getFileFromTestArtifacts

public File getFileFromTestArtifacts (String fileName)

Retrieve the file from the test artifacts or module artifacts and cache it in a map for the subsequent calls.

Parameters
fileName String: name of the file to look up in the artifacts.

Returns
File File from the test artifact or module artifact. Returns null if file is not found.

getInvocationListener

public final ITestInvocationListener getInvocationListener ()

Returns the original ITestInvocationListener where we are forwarding the results.

Returns
ITestInvocationListener

getRealDevices

public final  getRealDevices ()

Returns all the non-stub devices from the getDevices() list.

Returns

getRunName

public String getRunName ()

Returns the name of test run mRunName that triggers the collector.

Returns
String mRunName, the current test run name.

getTag

public String getTag ()

Returns the identifier mTag of the collector.

Returns
String mTag, the unique identifier of the collector.

init

public ITestInvocationListener init (IInvocationContext context, 
                ITestInvocationListener listener)

Initialization of the collector with the current context and where to forward results. Will only be called once per instance, and the collector is expected to update its internal context and listener. Init will never be called during a test run always before.

Do not override unless you know what you are doing.

Parameters
context IInvocationContext: the IInvocationContext for the invocation in progress.

listener ITestInvocationListener: the ITestInvocationListener where to put results.

Returns
ITestInvocationListener the new listener wrapping the original one.

invocationEnded

public final void invocationEnded (long elapsedTime)

Parameters
elapsedTime long

invocationFailed

public final void invocationFailed (FailureDescription failure)

Parameters
failure FailureDescription

invocationFailed

public final void invocationFailed (Throwable cause)

Parameters
cause Throwable

invocationStarted

public final void invocationStarted (IInvocationContext context)

Invocation Listeners for forwarding

Parameters
context IInvocationContext

isDisabled

public final boolean isDisabled ()

Returns True if entire object disabled (skip both setup and teardown). False otherwise.

Returns
boolean

onTestAssumptionFailure

public void onTestAssumptionFailure (DeviceMetricData testData, 
                TestDescription test)

Callback when a test case fails with assumption failure.

Parameters
testData DeviceMetricData: the DeviceMetricData holding the data for the test case.

test TestDescription: the TestDescription of the test case in progress.

onTestEnd

public void onTestEnd (DeviceMetricData testData, 
                 currentTestCaseMetrics, 
                TestDescription test)

Callback when a test case is ended. This should be the time for clean up.

Parameters
testData DeviceMetricData: the DeviceMetricData holding the data for the test case. Will be the same object as during onTestStart(com.android.tradefed.device.metric.DeviceMetricData).

currentTestCaseMetrics : the current map of metrics passed to ITestLifeCycleReceiver.testEnded(com.android.tradefed.result.TestDescription, Map).

test TestDescription: the TestDescription of the test case in progress.

onTestEnd

public void onTestEnd (DeviceMetricData testData, 
                 currentTestCaseMetrics)

Callback when a test case is ended. This should be the time for clean up.

Parameters
testData DeviceMetricData: the DeviceMetricData holding the data for the test case. Will be the same object as during onTestStart(com.android.tradefed.device.metric.DeviceMetricData).

currentTestCaseMetrics : the current map of metrics passed to ITestLifeCycleReceiver.testEnded(com.android.tradefed.result.TestDescription, Map).

onTestFail

public void onTestFail (DeviceMetricData testData, 
                TestDescription test)

Callback when a test case fails.

Parameters
testData DeviceMetricData: the DeviceMetricData holding the data for the test case.

test TestDescription: the TestDescription of the test case in progress.

onTestRunEnd

public void onTestRunEnd (DeviceMetricData runData, 
                 currentRunMetrics)

Callback when a test run is ended. This should be the time for clean up.

Parameters
runData DeviceMetricData: the DeviceMetricData holding the data for the run. Will be the same object as during onTestRunStart(com.android.tradefed.device.metric.DeviceMetricData).

currentRunMetrics : the current map of metrics passed to ITestLifeCycleReceiver.testRunEnded(long, Map).

onTestRunStart

public void onTestRunStart (DeviceMetricData runData)

Callback when a test run is started.

Parameters
runData DeviceMetricData: the DeviceMetricData holding the data for the run.

onTestStart

public void onTestStart (DeviceMetricData testData)

Callback when a test case is started.

Parameters
testData DeviceMetricData: the DeviceMetricData holding the data for the test case.

setDisable

public final void setDisable (boolean isDisabled)

Sets whether the object should be disabled. Disabled means that both setup and teardown steps should be skipped. Can be use to make an object disabled by default in the default constructor.

Parameters
isDisabled boolean: the state the object should be put in.

setTag

public void setTag (String tag)

Sets the mTag of the collector. It can be used to specify the interval of the collector.

Parameters
tag String: the unique identifier of the collector.

testAssumptionFailure

public final void testAssumptionFailure (TestDescription test, 
                String trace)

Parameters
test TestDescription

trace String

testAssumptionFailure

public final void testAssumptionFailure (TestDescription test, 
                FailureDescription failure)

Parameters
test TestDescription

failure FailureDescription

testEnded

public final void testEnded (TestDescription test, 
                long endTime, 
                 testMetrics)

Parameters
test TestDescription

endTime long

testMetrics

testEnded

public final void testEnded (TestDescription test, 
                 testMetrics)

Parameters
test TestDescription

testMetrics

testFailed

public final void testFailed (TestDescription test, 
                FailureDescription failure)

Parameters
test TestDescription

failure FailureDescription

testFailed

public final void testFailed (TestDescription test, 
                String trace)

Parameters
test TestDescription

trace String

testIgnored

public final void testIgnored (TestDescription test)

Parameters
test TestDescription

testLog

public final void testLog (String dataName, 
                LogDataType dataType, 
                InputStreamSource dataStream)

Parameters
dataName String

dataType LogDataType

dataStream InputStreamSource

testModuleEnded

public final void testModuleEnded ()

testModuleStarted

public final void testModuleStarted (IInvocationContext moduleContext)

Parameters
moduleContext IInvocationContext

testRunEnded

public final void testRunEnded (long elapsedTime, 
                 runMetrics)

Parameters
elapsedTime long

runMetrics

testRunFailed

public final void testRunFailed (FailureDescription failure)

Parameters
failure FailureDescription

testRunFailed

public final void testRunFailed (String errorMessage)

Parameters
errorMessage String

testRunStarted

public final void testRunStarted (String runName, 
                int testCount, 
                int attemptNumber)

Parameters
runName String

testCount int

attemptNumber int

testRunStarted

public final void testRunStarted (String runName, 
                int testCount)

Test run callbacks

Parameters
runName String

testCount int

testRunStarted

public final void testRunStarted (String runName, 
                int testCount, 
                int attemptNumber, 
                long startTime)

Parameters
runName String

testCount int

attemptNumber int

startTime long

testRunStopped

public final void testRunStopped (long elapsedTime)

Parameters
elapsedTime long

testStarted

public final void testStarted (TestDescription test, 
                long startTime)

Parameters
test TestDescription

startTime long

testStarted

public final void testStarted (TestDescription test)

Test cases callbacks

Parameters
test TestDescription