BasePostProcessor

public abstract class BasePostProcessor
extends Object implements IPostProcessor

java.lang.Object
   ↳ com.android.tradefed.postprocessor.BasePostProcessor


The base IPostProcessor that every implementation should extend. Ensure that the post processing methods are called before the final result reporters.

Summary

Public constructors

BasePostProcessor()

Public methods

final ITestInvocationListener init(ITestInvocationListener listener)

Initialization step of the post processor.

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).

final void logAssociation(String dataName, LogFile logFile)

In some cases, log must be strongly associated with a test cases, but the opportunity to do so on the direct testLogSaved(String, com.android.tradefed.result.LogDataType, com.android.tradefed.result.InputStreamSource, com.android.tradefed.result.LogFile) callback is not possible.

Updates the log-to-test assocation.

processAllTestMetricsAndLogs(ListMultimap<String, MetricMeasurement.Metric> allTestMetrics, allTestLogs)

Implement this method to aggregate metrics and logs across all tests.

abstract processRunMetricsAndLogs( rawMetrics, runLogs)

Implement this method in order to generate a set of new metrics from the existing metrics and logs.

processTestMetricsAndLogs(TestDescription testDescription, testMetrics, testLogs)

Implement this method to post process metrics and logs from each test.

final void setLogSaver(ILogSaver logSaver)

Set the ILogSaver to allow the implementor to save files.

void setUp()

Override this method in the child post processors to initialize before the test runs.

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)

Use this method to log a file from the PostProcessor implementation.

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

Called when the test log is saved.

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

Protected methods

void cleanUp()
MetricMeasurement.DataType getMetricType()

Override this method to change the metric type if needed.

String getRunName()

Public constructors

BasePostProcessor

public BasePostProcessor ()

Public methods

init

public final ITestInvocationListener init (ITestInvocationListener listener)

Initialization step of the post processor. Ensured to be called before any of the tests callbacks.

Parameters
listener ITestInvocationListener

Returns
ITestInvocationListener

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

logAssociation

public final void logAssociation (String dataName, 
                LogFile logFile)

In some cases, log must be strongly associated with a test cases, but the opportunity to do so on the direct testLogSaved(String, com.android.tradefed.result.LogDataType, com.android.tradefed.result.InputStreamSource, com.android.tradefed.result.LogFile) callback is not possible. Thus, this callback allows to provide a strong association explicitly.

Updates the log-to-test assocation. If this method is called during a test, then the log belongs to the test; otherwise it will be a run log.

Parameters
dataName String: The name of the data

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

processAllTestMetricsAndLogs

public  processAllTestMetricsAndLogs (ListMultimap<String, MetricMeasurement.Metric> allTestMetrics, 
                 allTestLogs)

Implement this method to aggregate metrics and logs across all tests. Metrics coming out of this method will be reporter as run metrics. Only the newly generated metrics should be returned, and with unique key name (no collision with existing keys are allowed).

Parameters
allTestMetrics ListMultimap: A HashMultimap storing the metrics from each test grouped by metric names.

allTestLogs : A map storing each test's map of log files keyed by their data names, using the each test's TestDescription as keys.

Returns
The set of newly generated metrics from all test metrics.

processRunMetricsAndLogs

public abstract  processRunMetricsAndLogs ( rawMetrics, 
                 runLogs)

Implement this method in order to generate a set of new metrics from the existing metrics and logs. Only the newly generated metrics should be returned, and with unique key name (no collision with existing keys are allowed).

Parameters
rawMetrics : The set of raw metrics available for the run.

runLogs : The set of log files for the test run.

Returns
The set of newly generated metrics from the run metrics.

processTestMetricsAndLogs

public  processTestMetricsAndLogs (TestDescription testDescription, 
                 testMetrics, 
                 testLogs)

Implement this method to post process metrics and logs from each test. Only the newly generated metrics should be returned, and with unique key name (no collision with existing keys are allowed).

Parameters
testDescription TestDescription: The TestDescription object describing the test.

testMetrics : The set of metrics from the test.

testLogs : The set of files logged during the test.

Returns
The set of newly generated metrics from the test metrics.

setLogSaver

public final void setLogSaver (ILogSaver logSaver)

Set the ILogSaver to allow the implementor to save files.

Parameters
logSaver ILogSaver: the ILogSaver

setUp

public void setUp ()

Override this method in the child post processors to initialize before the test runs.

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)

Use this method to log a file from the PostProcessor implementation.

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)

Called when the test log is saved.

Should be used in place of ITestInvocationListener#testLog(String, LogDataType, InputStreamSource).

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

Protected methods

cleanUp

protected void cleanUp ()

getMetricType

protected MetricMeasurement.DataType getMetricType ()

Override this method to change the metric type if needed. By default metric is set to processed type.

Returns
MetricMeasurement.DataType

getRunName

protected String getRunName ()

Returns
String