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(DeviceMetricData) and onTestRunEnd(DeviceMetricData, Map).

Summary

Constants

String TEST_CASE_EXCLUDE_GROUP_OPTION

String TEST_CASE_INCLUDE_GROUP_OPTION

Public constructors

BaseDeviceMetricCollector()

Public methods

final List<IBuildInfo> getBuildInfos()

Returns the list of build information available in the invocation.

final List<ITestDevice> getDevices()

Returns the list of devices available in the invocation.

final ITestInvocationListener getInvocationListener()

Returns the original ITestInvocationListener where we are forwarding the results.

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)

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

final void invocationFailed(Throwable cause)

Reports an incomplete invocation due to some error condition.

final void invocationStarted(IInvocationContext context)

Invocation Listeners for forwarding

void onTestEnd(DeviceMetricData testData, Map<String, MetricMeasurement.Metric> currentTestCaseMetrics)

Callback when a test case is ended.

void onTestRunEnd(DeviceMetricData runData, Map<String, MetricMeasurement.Metric> 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.

void setTag(String tag)

Sets the mTag of the collector.

final void testAssumptionFailure(TestDescription test, String trace)

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

final void testEnded(TestDescription test, HashMap<String, MetricMeasurement.Metric> testMetrics)

Reports the execution end of an individual test case.

final void testEnded(TestDescription test, long endTime, HashMap<String, MetricMeasurement.Metric> testMetrics)

Alternative to testEnded(TestDescription, Map) where we can specify the end time directly.

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 testRunEnded(long elapsedTime, HashMap<String, MetricMeasurement.Metric> runMetrics)

Reports end of test run.

final void testRunFailed(String errorMessage)

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

final void testRunStarted(String runName, int testCount)

Test run callbacks

final void testRunStopped(long elapsedTime)

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

final void testStarted(TestDescription test, long startTime)

Alternative to testStarted(TestDescription) where we also specify when the test was started, combined with testEnded(TestDescription, long, Map) for accurate measure.

final void testStarted(TestDescription test)

Test cases callbacks

Constants

TEST_CASE_EXCLUDE_GROUP_OPTION

public static final String TEST_CASE_EXCLUDE_GROUP_OPTION

Constant Value: "test-case-exclude-group"

TEST_CASE_INCLUDE_GROUP_OPTION

public static final String TEST_CASE_INCLUDE_GROUP_OPTION

Constant Value: "test-case-include-group"

Public constructors

BaseDeviceMetricCollector

public BaseDeviceMetricCollector ()

Public methods

getBuildInfos

public final List<IBuildInfo> getBuildInfos ()

Returns the list of build information available in the invocation.

Returns
List<IBuildInfo>

getDevices

public final List<ITestDevice> getDevices ()

Returns the list of devices available in the invocation.

Returns
List<ITestDevice>

getInvocationListener

public final ITestInvocationListener getInvocationListener ()

Returns the original ITestInvocationListener where we are forwarding the results.

Returns
ITestInvocationListener

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)

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

invocationStarted

public final void invocationStarted (IInvocationContext context)

Invocation Listeners for forwarding

Parameters
context IInvocationContext: information about the invocation

onTestEnd

public void onTestEnd (DeviceMetricData testData, 
                Map<String, MetricMeasurement.Metric> 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(DeviceMetricData).

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

onTestRunEnd

public void onTestRunEnd (DeviceMetricData runData, 
                Map<String, MetricMeasurement.Metric> 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(DeviceMetricData).

currentRunMetrics Map: 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.

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)

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

testEnded

public final void testEnded (TestDescription test, 
                HashMap<String, MetricMeasurement.Metric> testMetrics)

Reports the execution end of an individual test case.

If testFailed(TestDescription, String) 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 HashMap: a Map of the metrics emitted

testEnded

public final void testEnded (TestDescription test, 
                long endTime, 
                HashMap<String, MetricMeasurement.Metric> testMetrics)

Alternative to testEnded(TestDescription, Map) where we can specify the end time directly. Combine with testStarted(TestDescription, long) for accurate measure.

Parameters
test TestDescription: identifies the test

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

testMetrics HashMap: a Map of the metrics emitted

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 ITestInvocationListener.invocationFailed(Throwable) or 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.

testRunEnded

public final void testRunEnded (long elapsedTime, 
                HashMap<String, MetricMeasurement.Metric> 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 HashMap: key-value pairs reported at the end of a test run with MetricMeasurement.Metric.

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)

Test run callbacks

Parameters
runName String: the test run name

testCount int: total number of tests in test run

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

testStarted

public final void testStarted (TestDescription test, 
                long startTime)

Alternative to testStarted(TestDescription) where we also specify when the test was started, combined with testEnded(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