Skip to content

Commit 4647370

Browse files
OmniLab Teamcopybara-github
authored andcommitted
Internal change
PiperOrigin-RevId: 935921835
1 parent 9e0a154 commit 4647370

4 files changed

Lines changed: 28 additions & 2 deletions

File tree

src/devtools/mobileharness/platform/android/instrumentation/result/proto/test_suite_result.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ message TestSuiteMetaData {
4747

4848
// Number of test cases scheduled to be run.
4949
int32 scheduled_test_case_count = 2;
50+
51+
// Start time of the test suite execution.
52+
google.protobuf.Timestamp start_time = 3;
53+
54+
// End time of the test suite execution.
55+
google.protobuf.Timestamp end_time = 4;
5056
}
5157

5258
// Test status of a test suite or test case

src/java/com/google/devtools/mobileharness/platform/android/instrumentation/parser/AmInstrumentationParser.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,15 @@ import java.time.Instant
4242
* INSTRUMENTATION_CODE: -1
4343
* ```
4444
*/
45-
class AmInstrumentationParser(
45+
class AmInstrumentationParser
46+
@JvmOverloads
47+
constructor(
4648
private val listeners: Set<AmInstrumentationListener> = emptySet(),
4749
private val testTimeTrackerFactory: () -> TestTimeTracker = { TestTimeTracker() },
50+
private val systemClock: () -> Instant = { Instant.now() },
4851
) {
52+
private val startTime = systemClock()
53+
4954
/** The result of the Instrumentation, available after parse completion. */
5055
var result: InstrumentationResult? = null
5156
private set
@@ -262,7 +267,14 @@ class AmInstrumentationParser(
262267
reportInstrumentationFailed("Test run failed to complete. $error")
263268
}
264269
val result =
265-
InstrumentationResult(code, bundle.toMutableMap().also { knownStatus.forEach(it::remove) })
270+
InstrumentationResult(
271+
code = code,
272+
bundle = bundle.toMutableMap().also { knownStatus.forEach(it::remove) },
273+
)
274+
.apply {
275+
startTime = this@AmInstrumentationParser.startTime
276+
endTime = systemClock()
277+
}
266278
this.result = result
267279
reportInstrumentationEnded(result)
268280
}

src/java/com/google/devtools/mobileharness/platform/android/instrumentation/parser/AmInstrumentationResultBuilder.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,8 @@ class AmInstrumentationResultBuilder(private val testSuiteResultBuilder: TestSui
6161
} else {
6262
ProtoTestStatus.FAILED
6363
}
64+
val metaDataBuilder = testSuiteResultBuilder.testSuiteMetaDataBuilder
65+
instrumentationResult.startTime?.let { metaDataBuilder.startTime = it.toProtoTimestamp() }
66+
instrumentationResult.endTime?.let { metaDataBuilder.endTime = it.toProtoTimestamp() }
6467
}
6568
}

src/java/com/google/devtools/mobileharness/platform/android/instrumentation/parser/InstrumentationResult.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.google.devtools.mobileharness.platform.android.instrumentation.parser
22

3+
import java.time.Instant
4+
35
/**
46
* Results reported at the end of an `am instrument` command.
57
*
@@ -9,6 +11,9 @@ package com.google.devtools.mobileharness.platform.android.instrumentation.parse
911
* * other: Failure
1012
*/
1113
data class InstrumentationResult(val code: Int? = null, val bundle: Map<String, String> = mapOf()) {
14+
var startTime: Instant? = null
15+
var endTime: Instant? = null
16+
1217
val success
1318
get() = code == -1
1419
}

0 commit comments

Comments
 (0)