ResultDBUtil

public final class ResultDBUtil
extends Object

java.lang.Object
   ↳ com.android.tradefed.result.resultdb.ResultDBUtil


Utility class for ResultDB reporter.

Summary

Public constructors

ResultDBUtil()

Public methods

static String bytesToHex(byte[] bytes)

Converts a byte array to a hexadecimal string.

static String makeValidKey(String key)

Ensure the key is valid for ResultDB.

static String testSkipReasonToSummaryHtml(SkipReason reason, String skipReasonType)

Converts a test skip reason to a summary HTML string.

static TestIdentifier toTestIdentifier(String moduleName, Variant moduleVariant, TestDescription testDescription)

Converts a TestDescription to a TestIdentifier.

static String truncateString(String input, int maxBytes)

Truncates the string to the given max bytes, avoiding breaking up a multi-byte character.

Public constructors

ResultDBUtil

public ResultDBUtil ()

Public methods

bytesToHex

public static String bytesToHex (byte[] bytes)

Converts a byte array to a hexadecimal string.

Parameters
bytes byte

Returns
String

makeValidKey

public static String makeValidKey (String key)

Ensure the key is valid for ResultDB.

The key must match the regex: ^[a-z][a-z0-9_]*(/[a-z][a-z0-9_]*)*$

Parameters
key String

Returns
String

testSkipReasonToSummaryHtml

public static String testSkipReasonToSummaryHtml (SkipReason reason, 
                String skipReasonType)

Converts a test skip reason to a summary HTML string. ResultDB does not yet have a skip reason field, we put them in the summary HTML field and test artifact for now. The return string can be longer than the summary HTML field limit, caller should truncate it if needed.

Parameters
reason SkipReason

skipReasonType String

Returns
String

toTestIdentifier

public static TestIdentifier toTestIdentifier (String moduleName, 
                Variant moduleVariant, 
                TestDescription testDescription)

Converts a TestDescription to a TestIdentifier.

Parameters
moduleName String: the module name

moduleVariant Variant: the module variant

testDescription TestDescription: the test description

Returns
TestIdentifier the ResultDB test identifier. This test identifier is not guaranteed to be valid (i.e. ResultDB may reject it, returning a invalid_argument error). This is because ResultDB has more strict requirements on the test identifier, such as the field length and character set.

truncateString

public static String truncateString (String input, 
                int maxBytes)

Truncates the string to the given max bytes, avoiding breaking up a multi-byte character.

Parameters
input String: the string to truncate

maxBytes int: the maximum number of bytes (in utf-8 encoding) to truncate to

Returns
String the truncated string