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

Commit 7b8808b6 authored by Lee Shombert's avatar Lee Shombert
Browse files

Make AnrTimerTest.testDumpOutput hermetic

testDumpOuput() calls the AnrTimer dumpsys routine and verifies that
the expected timers are present, or not.  It was originally written on
the assumption that the only timers in the process would be those
created in AnrTimerTest, but this is not true: other ActivityManager
tests also create timers that are immortal and thus appear in the
dumpsys output.

This change gives unique names to the timers created in AnrTimerTest
and checks that those timers are present, or not.

Tested by manually modifying the code to inject a random timer name:
verified that the test still produced the correct result.

Test: atest
 * FrameworksServicesTests

Bug: 326043049
Change-Id: I93ea43236b4f9f5f2f9c2e5bd7276459d9bee3d2
parent ecffed7d
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -147,7 +147,7 @@ public class AnrTimerTest {
            final int n = 4;
            StackTraceElement[] stack = Thread.currentThread().getStackTrace();
            if (stack.length < n+1) return "test";
            return stack[n].getMethodName();
            return stack[n].getClassName() + "." + stack[n].getMethodName();
        }
    }

@@ -318,8 +318,11 @@ public class AnrTimerTest {
    public void testDumpOutput() throws Exception {
        if (!AnrTimer.nativeTimersSupported()) return;

        // The timers in this class are named "class.method".
        final String timerName = "timer: com.android.server.utils.AnrTimerTest";

        String r1 = getDumpOutput();
        assertThat(r1).doesNotContain("timer:");
        assertThat(r1).doesNotContain(timerName);

        Helper helper = new Helper(2);
        TestArg t1 = new TestArg(1, 1);
@@ -333,14 +336,14 @@ public class AnrTimerTest {
            String r2 = getDumpOutput();
            // There are timers in the list if and only if the feature is enabled.
            if (mEnabled) {
              assertThat(r2).contains("timer:");
                assertThat(r2).contains(timerName);
            } else {
              assertThat(r2).doesNotContain("timer:");
                assertThat(r2).doesNotContain(timerName);
            }
        }

        String r3 = getDumpOutput();
        assertThat(r3).doesNotContain("timer:");
        assertThat(r3).doesNotContain(timerName);
    }

    /**