BaseDeviceMetricCollector

public class BaseDeviceMetricCollector
extends Object implements IMetricCollector, IDeviceActionReceiver

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

void extraInit(IInvocationContext context, ITestInvocationListener listener)
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.

String getModuleName()
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.

final ITestInvocationListener init(IInvocationContext context, ITestInvocationListener listener)

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

final void invocationEnded(long elapsedTime)

Reports that the invocation has terminated, whether successfully or due to some error condition.

final void invocationFailed(FailureDescription failure)

Reports an incomplete invocation due to some error condition.

final void invocationFailed(Throwable cause)

Reports an incomplete invocation due to some error condition.

void invocationSkipped(SkipReason reason)

Reports an invocation as skipped

final void invocationStarted(IInvocationContext context)

Invocation Listeners for forwarding

final boolean isDisabled()

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

boolean isDisabledReceiver()

Whether the IDeviceActionReceiver is disabled or not.

final void logAssociation(String dataName, LogFile logFile)

Do not use inside metric collector implementation.

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 onTestModuleEnded()

Allows capturing the module ended event.

void onTestModuleStarted()

Allows capturing the module started event.

void onTestRunEnd(DeviceMetricData runData, currentRunMetrics)

Callback when a test run is ended.

void onTestRunFailed(DeviceMetricData testData, FailureDescription failure)

Callback for testRunFailed events

void onTestRunStart(DeviceMetricData runData)

Callback when a test run is started.

void onTestStart(DeviceMetricData testData)

Callback when a test case is started.

void rebootEnded(ITestDevice device)

Gets notification when the reboot ended in device.

void rebootStarted(ITestDevice device)

Gets notification when reboot started in device.

final void setDisable(boolean isDisabled)

Sets whether the object should be disabled.

void setDisableReceiver(boolean isDisabled)

Sets whether the IDeviceActionReceiver should be disabled.

final void setLogSaver(ILogSaver logSaver)

Do not use inside metric collector implementation.

final void testAssumptionFailure(TestDescription test, String trace)

Called when an atomic test flags that it assumes a condition that is false

final void testAssumptionFailure(TestDescription test, FailureDescription failure)

Called when an atomic test flags that it assumes a condition that is false

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

Alternative to ERROR(/#testEnded(com.android.tradefed.result.TestDescription,Map)) where we can specify the end time directly.

final void testEnded(TestDescription test, testMetrics)

Reports the execution end of an individual test case.

final void testFailed(TestDescription test, FailureDescription failure)

Reports the failure of a individual test case.

final void testFailed(TestDescription test, String trace)

Reports the failure of a individual test case.

final void testIgnored(TestDescription test)

Called when a test will not be run, generally because a test method is annotated with org.junit.Ignore.

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

Provides the associated log or debug data from the test invocation.

final void testLogSaved(String dataName, LogDataType dataType, InputStreamSource dataStream, LogFile logFile)

Do not use inside metric collector implementation.

final void testModuleEnded()

Reports the end of a module run.

final void testModuleStarted(IInvocationContext moduleContext)

Reports the beginning of a module running.

final void testRunEnded(long elapsedTime, runMetrics)

Reports end of test run.

final void testRunFailed(FailureDescription failure)

Reports test run failed to complete due to a failure described by FailureDescription.

final void testRunFailed(String errorMessage)

Reports test run failed to complete due to a fatal error.

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

Reports the start of a test run.

final void testRunStarted(String runName, int testCount)

Test run callbacks

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

Reports the start of a test run.

final void testRunStopped(long elapsedTime)

Reports test run stopped before completion due to a user request.

final void testSkipped(TestDescription test, SkipReason reason)

Called when a test is skipped and did not execute for a reason that is not usually expected.

final void testStarted(TestDescription test, long startTime)

Alternative to testStarted(com.android.tradefed.result.TestDescription) where we also specify when the test was started, combined with ERROR(/#testEnded(com.android.tradefed.result.TestDescription,long,Map)) for accurate measure.

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

extraInit

public void extraInit (IInvocationContext context, 
                ITestInvocationListener listener)

Throws
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

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

getModuleName

public String getModuleName ()

Returns
String

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.

init

public final 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.

Throws
DeviceNotAvailableException

invocationEnded

public final void invocationEnded (long elapsedTime)

Reports that the invocation has terminated, whether successfully or due to some error condition.

Will be automatically called by the TradeFederation framework.

Parameters
elapsedTime long: the elapsed time of the invocation in ms

invocationFailed

public final void invocationFailed (FailureDescription failure)

Reports an incomplete invocation due to some error condition.

Will be automatically called by the TradeFederation framework.

Parameters
failure FailureDescription: the FailureDescription describing the cause of the failure

invocationFailed

public final void invocationFailed (Throwable cause)

Reports an incomplete invocation due to some error condition.

Will be automatically called by the TradeFederation framework.

Parameters
cause Throwable: the Throwable cause of the failure

invocationSkipped

public void invocationSkipped (SkipReason reason)

Reports an invocation as skipped

Parameters
reason SkipReason

invocationStarted

public final void invocationStarted (IInvocationContext context)

Invocation Listeners for forwarding

Parameters
context IInvocationContext: information about the invocation

isDisabled

public final boolean isDisabled ()

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

Returns
boolean

isDisabledReceiver

public boolean isDisabledReceiver ()

Whether the IDeviceActionReceiver is disabled or not.

Returns
boolean return true if disabled, false otherwise.

logAssociation

public final void logAssociation (String dataName, 
                LogFile logFile)

Do not use inside metric collector implementation. This is pure forwarding.

Parameters
dataName String: The name of the data

logFile LogFile: the LogFile that was logged before and should be associated with the test case.

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.

Throws
DeviceNotAvailableException

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 ERROR(/#testEnded(com.android.tradefed.result.TestDescription,Map)).

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

Throws
DeviceNotAvailableException

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 ERROR(/#testEnded(com.android.tradefed.result.TestDescription,Map)).

Throws
DeviceNotAvailableException

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.

Throws
DeviceNotAvailableException

onTestModuleEnded

public void onTestModuleEnded ()

Allows capturing the module ended event.

Throws
DeviceNotAvailableException

onTestModuleStarted

public void onTestModuleStarted ()

Allows capturing the module started event.

Throws
DeviceNotAvailableException

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 ERROR(/#testRunEnded(long,Map)).

Throws
DeviceNotAvailableException

onTestRunFailed

public void onTestRunFailed (DeviceMetricData testData, 
                FailureDescription failure)

Callback for testRunFailed events

Throws
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

onTestRunStart

public void onTestRunStart (DeviceMetricData runData)

Callback when a test run is started.

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

Throws
DeviceNotAvailableException

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.

Throws
DeviceNotAvailableException

rebootEnded

public void rebootEnded (ITestDevice device)

Gets notification when the reboot ended in device.

NOTE: Receivers should avoid rebooting during this callback. Any reboot attempt will be ignored.

Parameters
device ITestDevice: ITestDevice where the reboot ended.

Throws
DeviceNotAvailableException

rebootStarted

public void rebootStarted (ITestDevice device)

Gets notification when reboot started in device.

NOTE: Receivers should avoid rebooting during this callback. Any reboot attempt will be ignored.

Parameters
device ITestDevice: ITestDevice where the reboot started.

Throws
DeviceNotAvailableException

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.

setDisableReceiver

public void setDisableReceiver (boolean isDisabled)

Sets whether the IDeviceActionReceiver should be disabled. Disabling means it will not be registered to the device for receiving device action events.

Parameters
isDisabled boolean

setLogSaver

public final void setLogSaver (ILogSaver logSaver)

Do not use inside metric collector implementation. This is pure forwarding.

Parameters
logSaver ILogSaver: the ILogSaver

testAssumptionFailure

public final void testAssumptionFailure (TestDescription test, 
                String trace)

Called when an atomic test flags that it assumes a condition that is false

Parameters
test TestDescription: identifies the test

trace String: stack trace of failure

testAssumptionFailure

public final void testAssumptionFailure (TestDescription test, 
                FailureDescription failure)

Called when an atomic test flags that it assumes a condition that is false

Parameters
test TestDescription: identifies the test

failure FailureDescription: FailureDescription describing the failure and its context.

testEnded

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

Alternative to ERROR(/#testEnded(com.android.tradefed.result.TestDescription,Map)) where we can specify the end time directly. Combine with testStarted(com.android.tradefed.result.TestDescription, long) for accurate measure.

Parameters
test TestDescription: identifies the test

endTime long: the time the test ended, measured via System.currentTimeMillis()

testMetrics : a ERROR(/Map) of the metrics emitted

testEnded

public final void testEnded (TestDescription test, 
                 testMetrics)

Reports the execution end of an individual test case.

If testFailed(TestDescription, FailureDescription) was not invoked, this test passed. Also returns any key/value metrics which may have been emitted during the test case's execution.

Parameters
test TestDescription: identifies the test

testMetrics : a ERROR(/Map) of the metrics emitted

testFailed

public final void testFailed (TestDescription test, 
                FailureDescription failure)

Reports the failure of a individual test case.

Will be called between testStarted and testEnded.

Parameters
test TestDescription: identifies the test

failure FailureDescription: FailureDescription describing the failure and its context.

testFailed

public final void testFailed (TestDescription test, 
                String trace)

Reports the failure of a individual test case.

Will be called between testStarted and testEnded.

Parameters
test TestDescription: identifies the test

trace String: stack trace of failure

testIgnored

public final void testIgnored (TestDescription test)

Called when a test will not be run, generally because a test method is annotated with org.junit.Ignore.

Parameters
test TestDescription: identifies the test

testLog

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

Provides the associated log or debug data from the test invocation.

Must be called before ERROR(/ITestInvocationListener#invocationFailed(Throwable)) or ERROR(/ITestInvocationListener#invocationEnded(long))

The TradeFederation framework will automatically call this method, providing the host log and if applicable, the device logcat.

Parameters
dataName String: a String descriptive name of the data. e.g. "device_logcat". Note dataName may not be unique per invocation. ie implementers must be able to handle multiple calls with same dataName

dataType LogDataType: the LogDataType of the data

dataStream InputStreamSource: the InputStreamSource of the data. Implementers should call createInputStream to start reading the data, and ensure to close the resulting InputStream when complete. Callers should ensure the source of the data remains present and accessible until the testLog method completes.

testLogSaved

public final void testLogSaved (String dataName, 
                LogDataType dataType, 
                InputStreamSource dataStream, 
                LogFile logFile)

Do not use inside metric collector implementation. This is pure forwarding.

Parameters
dataName String: a String descriptive name of the data. e.g. "device_logcat". Note dataName may not be unique per invocation. ie implementers must be able to handle multiple calls with same dataName

dataType LogDataType: the LogDataType of the data

dataStream InputStreamSource: the InputStreamSource of the data. Implementers should call createInputStream to start reading the data, and ensure to close the resulting InputStream when complete.

logFile LogFile: the LogFile containing the meta data of the saved file.

testModuleEnded

public final void testModuleEnded ()

Reports the end of a module run.

testModuleStarted

public final void testModuleStarted (IInvocationContext moduleContext)

Reports the beginning of a module running. This callback is associated with testModuleEnded() and is optional in the sequence. It is only used during a run that uses modules: suite based runners.

Parameters
moduleContext IInvocationContext: the IInvocationContext of the module.

testRunEnded

public final void testRunEnded (long elapsedTime, 
                 runMetrics)

Reports end of test run. FIXME: We cannot have two Map<> interfaces with different type, so we have to use HashMap here.

Parameters
elapsedTime long: device reported elapsed time, in milliseconds

runMetrics : key-value pairs reported at the end of a test run with Metric.

testRunFailed

public final void testRunFailed (FailureDescription failure)

Reports test run failed to complete due to a failure described by FailureDescription.

Parameters
failure FailureDescription: FailureDescription describing the failure and its context.

testRunFailed

public final void testRunFailed (String errorMessage)

Reports test run failed to complete due to a fatal error.

Parameters
errorMessage String: String describing reason for run failure.

testRunStarted

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

Reports the start of a test run.

Parameters
runName String: the test run name

testCount int: total number of tests in test run

attemptNumber int: order number, identifying the different attempts of the same runName that run multiple times. The attemptNumber is 0-indexed and should increment everytime a new run happens. e.g. A test is granular retried 3 times, it should have 4 total runs under the same runName and the attemptNumber is from 0 to 3.

testRunStarted

public final void testRunStarted (String runName, 
                int testCount)

Test run callbacks

Parameters
runName String: the test run name

testCount int: total number of tests in test run

testRunStarted

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

Reports the start of a test run.

Parameters
runName String: the test run name

testCount int: total number of tests in test run

attemptNumber int: order number, identifying the different attempts of the same runName that run multiple times. The attemptNumber is 0-indexed and should increment everytime a new run happens. e.g. A test is granular retried 3 times, it should have 4 total runs under the same runName and the attemptNumber is from 0 to 3.

startTime long: the time the run started, measured via System.currentTimeMillis()

testRunStopped

public final void testRunStopped (long elapsedTime)

Reports test run stopped before completion due to a user request.

TODO: currently unused, consider removing

Parameters
elapsedTime long: device reported elapsed time, in milliseconds

testSkipped

public final void testSkipped (TestDescription test, 
                SkipReason reason)

Called when a test is skipped and did not execute for a reason that is not usually expected. These tests will be attempted to be retried to attempt to get a proper execution.

Parameters
test TestDescription: identifies the test

reason SkipReason: SkipReason

testStarted

public final void testStarted (TestDescription test, 
                long startTime)

Alternative to testStarted(com.android.tradefed.result.TestDescription) where we also specify when the test was started, combined with ERROR(/#testEnded(com.android.tradefed.result.TestDescription,long,Map)) for accurate measure.

Parameters
test TestDescription: identifies the test

startTime long: the time the test started, measured via System.currentTimeMillis()

testStarted

public final void testStarted (TestDescription test)

Test cases callbacks

Parameters
test TestDescription: identifies the test