-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Diagnostic info for when tests hang.
- Loading branch information
1 parent
c78ffbc
commit ccb1232
Showing
4 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...inventory/src/main/kotlin/net/twisterrob/inventory/build/tests/instrumentation.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.twisterrob.inventory.build.tests | ||
|
||
import com.android.build.gradle.internal.tasks.DeviceProviderInstrumentTestTask | ||
import net.twisterrob.inventory.build.tests.instrumentation.LoggingUtpTestResultListener | ||
|
||
// TODEL https://issuetracker.google.com/issues/37056080 | ||
tasks.withType<DeviceProviderInstrumentTestTask>().configureEach { | ||
setUtpTestResultListener(LoggingUtpTestResultListener(logger)) | ||
} |
42 changes: 42 additions & 0 deletions
42
...tlin/net/twisterrob/inventory/build/tests/instrumentation/LoggingUtpTestResultListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package net.twisterrob.inventory.build.tests.instrumentation | ||
|
||
import com.android.build.gradle.internal.testing.utp.UtpTestResultListener | ||
import com.android.tools.utp.plugins.result.listener.gradle.proto.GradleAndroidTestResultListenerProto.TestResultEvent | ||
import com.android.tools.utp.plugins.result.listener.gradle.proto.GradleAndroidTestResultListenerProto.TestResultEvent.StateCase | ||
import com.google.testing.platform.proto.api.core.TestCaseProto.TestCase | ||
import com.google.testing.platform.proto.api.core.TestResultProto.TestResult | ||
import com.google.testing.platform.proto.api.core.TestStatusProto.TestStatus | ||
import org.gradle.api.logging.Logger | ||
|
||
/** | ||
* See https://issuetracker.google.com/issues/37056080#comment12. | ||
*/ | ||
class LoggingUtpTestResultListener( | ||
private val logger: Logger | ||
) : UtpTestResultListener { | ||
// See com.android.build.gradle.internal.testing.utp.DdmlibTestResultAdapter.onTestResultEvent | ||
// See com.android.build.gradle.internal.testing.CustomTestRunListener.testEnded | ||
override fun onTestResultEvent(testResultEvent: TestResultEvent) { | ||
//logger.lifecycle("UTP: {}", testResultEvent) | ||
when (testResultEvent.stateCase) { | ||
StateCase.TEST_CASE_STARTED -> { | ||
val tc = testResultEvent.testCaseStarted.testCase.unpack(TestCase::class.java) | ||
logger.lifecycle("${tc.testPackage}.${tc.testClass} > ${tc.testMethod} \u001b[34mSTARTED\u001b[0m") | ||
} | ||
StateCase.TEST_CASE_FINISHED -> { | ||
val result = testResultEvent.testCaseFinished.testCaseResult.unpack(TestResult::class.java) | ||
val status = when (result.testStatus) { | ||
TestStatus.PASSED -> "\u001b[32mSUCCESS\u001b[0m" | ||
// Already handled by AGP. | ||
TestStatus.FAILED, TestStatus.ERROR, TestStatus.IGNORED -> null | ||
else -> "\u001b[31${result.testStatus.name}\u001b[0m" | ||
} | ||
if (status != null) { | ||
val tc = result.testCase | ||
logger.lifecycle("${tc.testPackage}.${tc.testClass} > ${tc.testMethod} ${status}") | ||
} | ||
} | ||
else -> {} | ||
} | ||
} | ||
} |