Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3c712594 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Take timestamp before causing ANR in the test

Before this CL, the test failed on a hwasan device with the following
exception:

STACKTRACE:
java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
	at jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
	at jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
	at jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
	at java.util.Objects.checkIndex(Objects.java:359)
	at java.util.ArrayList.get(ArrayList.java:434)
	at com.android.test.input.AnrTest.clickCloseAppOnAnrDialog(AnrTest.kt:119)
	at com.android.test.input.AnrTest.testGestureMonitorAnr_Close(AnrTest.kt:89)

To fix this, stop collecting initial reasons before running the test.
Instead, just take a timestamp.

That said, this failure has not yet been reported by our automated
tools. This might be due to the use of hwasan on the local development
device.

Bug: 288343153
Test: atest com.android.test.input.AnrTest#testGestureMonitorAnr_Close --rerun-until-failure 10
Test: atest InputTests --rerun-until-failure 10
Change-Id: Ia62f7161211392f9c63092ff271b394c4ff76e48
parent 5a726914
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@ class AnrTest {

    private fun clickCloseAppOnAnrDialog() {
        // Find anr dialog and kill app
        val timestamp = System.currentTimeMillis()
        val uiDevice: UiDevice = UiDevice.getInstance(instrumentation)
        val closeAppButton: UiObject2? =
                uiDevice.wait(Until.findObject(By.res("android:id/aerr_close")), 20000)
@@ -107,7 +108,6 @@ class AnrTest {
            fail("Could not find anr dialog")
            return
        }
        val initialReasons = getExitReasons()
        closeAppButton.click()
        /**
         * We must wait for the app to be fully closed before exiting this test. This is because
@@ -116,7 +116,7 @@ class AnrTest {
         * the killing logic will apply to the newly launched 'am start' instance, and the second
         * test will fail because the unresponsive activity will never be launched.
         */
        waitForNewExitReason(initialReasons[0].timestamp)
        waitForNewExitReasonAfter(timestamp)
    }

    private fun clickWaitOnAnrDialog() {
@@ -140,12 +140,13 @@ class AnrTest {
        return infos
    }

    private fun waitForNewExitReason(previousExitTimestamp: Long) {
    private fun waitForNewExitReasonAfter(timestamp: Long) {
        PollingCheck.waitFor {
            getExitReasons()[0].timestamp > previousExitTimestamp
            val reasons = getExitReasons()
            !reasons.isEmpty() && reasons[0].timestamp >= timestamp
        }
        val reasons = getExitReasons()
        assertTrue(reasons[0].timestamp > previousExitTimestamp)
        assertTrue(reasons[0].timestamp > timestamp)
        assertEquals(ApplicationExitInfo.REASON_ANR, reasons[0].reason)
    }