InstrumentationProtoResultParser

public class InstrumentationProtoResultParser
extends Object implements IInstrumentationResultParser

java.lang.Object
   ↳ com.android.tradefed.result.ddmlib.InstrumentationProtoResultParser


Parses the 'protoStd output mode' results of an instrumentation test run from shell and informs a ITestRunListener of the results.

Am instrument command with "-m" option outputs test execution status in binary protobuf format incrementally. The output protobuf message is InstrumentationData.Session, which has two fields: 1) a repeated field of InstrumentationData.TestStatus, 2) InstrumentationData.SessionStatus. The am instrument command outputs test status message before/after each test execution. addOutput(byte, int, int) is invoked with a data argument which is a serialized bytes of TestStatus(es). When all tests are done, the command outputs SessionStatus at last.

See https://cs.android.com/android/platform/superproject/+/master:frameworks/base/cmds/am/proto/instrumentation_data.proto for a complete protobuf definition.

InstrumentationProtoResultParser is a state-machine and states are defined in ERROR(InstrumentationProtoResultParserState/com.android.tradefed.result.ddmlib.InstrumentationProtoResultParser.InstrumentationProtoResultParserState InstrumentationProtoResultParserState). The state begins with ERROR(/com.android.tradefed.result.ddmlib.InstrumentationProtoResultParser.InstrumentationProtoResultParserState#NOT_STARTED). When it sees a first test case status, it moves to ERROR(InstrumentationProtoResultParserState.RUNNING/com.android.tradefed.result.ddmlib.InstrumentationProtoResultParser.InstrumentationProtoResultParserState#RUNNING InstrumentationProtoResultParserState.RUNNING). The state changes to ERROR(/com.android.tradefed.result.ddmlib.InstrumentationProtoResultParser.InstrumentationProtoResultParserState#FINISHED) if all tests are done or ERROR(/com.android.tradefed.result.ddmlib.InstrumentationProtoResultParser.InstrumentationProtoResultParserState#CANCELLED) if it is requested by calling cancel().

Every time a new test status is available, it will be informed to the registered listeners.

Summary

Public constructors

InstrumentationProtoResultParser(String runName, listeners)

Constructs InstrumentationProtoResultParser.

Public methods

void addOutput(byte[] data, int offset, int length)

This method is called every time some new data is available.

void cancel()

Requests cancellation of test run.

void flush()

Called at the end of the process execution (unless the process was canceled).

void handleTestRunFailed(String errorMsg)

This method is called when "am instrument" command crashes with an exception.

boolean isCancelled()

Cancel method to stop the execution of the remote shell command.

Public constructors

InstrumentationProtoResultParser

public InstrumentationProtoResultParser (String runName, 
                 listeners)

Constructs InstrumentationProtoResultParser.

Parameters
runName String: the test run name to provide to ITestRunListener.testRunStarted

listeners : informed of test results as the tests are executing

Public methods

addOutput

public void addOutput (byte[] data, 
                int offset, 
                int length)

This method is called every time some new data is available.

Parameters
data byte: a serialized data of InstrumentationData.Session message. If data is an incomplete chunk, they are added into an internal buffer and will be processed in the next addOutput(byte, int, int) call.

offset int: an offset of the new data stored in data

length int: bytes of a new data in data to be processed.

cancel

public void cancel ()

Requests cancellation of test run.

flush

public void flush ()

Called at the end of the process execution (unless the process was canceled). This allows the receiver to terminate and flush whatever data was not yet processed.

handleTestRunFailed

public void handleTestRunFailed (String errorMsg)

This method is called when "am instrument" command crashes with an exception. All registered listeners should be notified ITestRunListener.testRunFailed followed by ITestRunListener.testRunEnded(long, ) if the crash happens during the test execution.

Parameters
errorMsg String

isCancelled

public boolean isCancelled ()

Cancel method to stop the execution of the remote shell command.

Returns
boolean true to cancel the execution of the command.