BugreportCollector

public class BugreportCollector
extends Object implements ITestInvocationListener

java.lang.Object
   ↳ com.android.tradefed.result.BugreportCollector


A pass-through ITestInvocationListener that collects bugreports when configurable events occur and then calls ITestInvocationListener#testLog on its children after each bugreport is collected.

Behaviors: (FIXME: finish this)

  • Capture after each if any testcases failed
  • Capture after each testcase
  • Capture after each failed testcase
  • Capture

Summary

Nested classes

class BugreportCollector.Predicate

A full predicate describing when to capture a bugreport. 

interface BugreportCollector.SubPredicate

 

Fields

public static final BugreportCollector.Predicate AFTER_FAILED_TESTCASES

A predefined predicate which fires after each failed testcase

public static final BugreportCollector.Predicate AT_START

A predefined predicate which fires as the first invocation begins

Public constructors

BugreportCollector(ITestInvocationListener listener, ITestDevice testDevice)

Public methods

void addPredicate(BugreportCollector.Predicate p)
void blockUntilIdle()

Block until the collector is not collecting any bugreports.

TestSummary getSummary()

Allows the InvocationListener to return a summary.

void invocationEnded(long elapsedTime)

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

void invocationFailed(Throwable cause)

Reports an incomplete invocation due to some error condition.

void invocationStarted(IInvocationContext context)

Reports the start of the test invocation.

void setAsynchronous(boolean asynchronous)

Set whether bugreport collection should collect the bugreport in a different thread (asynchronous = true), or block the caller until the bugreport is captured (asynchronous = false).

void setDescriptiveName(String name)

Set the descriptive name to use when recording bugreports.

void setDeviceWaitTime(int waitTime)

Set the time (in seconds) to wait for the device to be Online before we try to capture a bugreport.

void testAssumptionFailure(TestDescription test, String trace)

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

void testEnded(TestDescription test, testMetrics)

Reports the execution end of an individual test case.

void testFailed(TestDescription test, String trace)

Reports the failure of a individual test case.

void testIgnored(TestDescription test)

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

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

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

void testRunEnded(long elapsedTime, runMetrics)

Reports end of test run.

void testRunFailed(String errorMessage)

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

void testRunStarted(String runName, int testCount)

Reports the start of a test run.

void testRunStopped(long elapsedTime)

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

void testStarted(TestDescription test)

Reports the start of an individual test case.

Fields

AFTER_FAILED_TESTCASES

public static final BugreportCollector.Predicate AFTER_FAILED_TESTCASES

A predefined predicate which fires after each failed testcase

AT_START

public static final BugreportCollector.Predicate AT_START

A predefined predicate which fires as the first invocation begins

Public constructors

BugreportCollector

public BugreportCollector (ITestInvocationListener listener, 
                ITestDevice testDevice)

Parameters
listener ITestInvocationListener

testDevice ITestDevice

Public methods

addPredicate

public void addPredicate (BugreportCollector.Predicate p)

Parameters
p BugreportCollector.Predicate

blockUntilIdle

public void blockUntilIdle ()

Block until the collector is not collecting any bugreports. If the collector isn't actively collecting a bugreport, return immediately

getSummary

public TestSummary getSummary ()

Allows the InvocationListener to return a summary.

Returns
TestSummary A TestSummary summarizing the run, or null

invocationEnded

public 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 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 void invocationStarted (IInvocationContext context)

Reports the start of the test invocation.

Will be automatically called by the TradeFederation framework. Reporters need to override this method to support multiple devices reporting.

Parameters
context IInvocationContext: information about the invocation

setAsynchronous

public void setAsynchronous (boolean asynchronous)

Set whether bugreport collection should collect the bugreport in a different thread (asynchronous = true), or block the caller until the bugreport is captured (asynchronous = false).

Parameters
asynchronous boolean

setDescriptiveName

public void setDescriptiveName (String name)

Set the descriptive name to use when recording bugreports. If null, BugreportCollector will fall back to the default behavior of serializing the name of the event that caused the bugreport to be collected.

Parameters
name String

setDeviceWaitTime

public void setDeviceWaitTime (int waitTime)

Set the time (in seconds) to wait for the device to be Online before we try to capture a bugreport. If negative, no check will be performed. Any DeviceNotAvailableException encountered during this check will be logged and ignored.

Parameters
waitTime int

testAssumptionFailure

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

testRunEnded

public 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 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 void testRunStarted (String runName, 
                int testCount)

Reports the start of a test run.

Parameters
runName String: the test run name

testCount int: total number of tests in test run

testRunStopped

public 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 void testStarted (TestDescription test)

Reports the start of an individual test case. Older interface, should use testStarted(com.android.tradefed.result.TestDescription) whenever possible.

Parameters
test TestDescription: identifies the test