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

Commit af7a818c authored by Kean Mariotti's avatar Kean Mariotti
Browse files

Extend BugreportManagerTest

Test scenario where dumpstate ignores the "use predump" flag
because no pre-dumped data is available on disk.

Bug: 327322141
Test: atest com.android.os.bugreports.tests.BugreportManagerTest
Change-Id: I8c3f74ad8c96cb10cd3cd3ae89f34b01a22737db
parent 26f7a914
Loading
Loading
Loading
Loading
+40 −5
Original line number Diff line number Diff line
@@ -110,8 +110,6 @@ public class BugreportManagerTest {
            Paths.get("/data/misc/wmtrace/ime_trace_service.winscope"),
            Paths.get("/data/misc/wmtrace/wm_trace.winscope"),
            Paths.get("/data/misc/wmtrace/wm_log.winscope"),
            Paths.get("/data/misc/wmtrace/wm_transition_trace.winscope"),
            Paths.get("/data/misc/wmtrace/shell_transition_trace.winscope"),
    };

    private Handler mHandler;
@@ -257,6 +255,38 @@ public class BugreportManagerTest {
        assertThatAllFileContentsAreDifferent(preDumpedTraceFiles, actualTraceFiles);
    }

    @LargeTest
    @Test
    public void noPreDumpData_then_fullWithUsePreDumpFlag_ignoresFlag() throws Exception {
        startPreDumpedUiTraces();

        mBrm.preDumpUiData();
        waitTillDumpstateExitedOrTimeout();

        // Simulate lost of pre-dumped data.
        // For example it can happen in this scenario:
        // 1. Pre-dump data
        // 2. Start bugreport + "use pre-dump" flag (USE AND REMOVE THE PRE-DUMP FROM DISK)
        // 3. Start bugreport + "use pre-dump" flag (NO PRE-DUMP AVAILABLE ON DISK)
        removeFilesIfNeeded(UI_TRACES_PREDUMPED);

        // Start bugreport with "use predump" flag. Because the pre-dumped data is not available
        // the flag will be ignored and data will be dumped as in normal flow.
        BugreportCallbackImpl callback = new BugreportCallbackImpl();
        mBrm.startBugreport(mBugreportFd, null, fullWithUsePreDumpFlag(), mExecutor,
                callback);
        shareConsentDialog(ConsentReply.ALLOW);
        waitTillDoneOrTimeout(callback);

        stopPreDumpedUiTraces();

        assertThat(callback.isDone()).isTrue();
        assertThat(mBugreportFile.length()).isGreaterThan(0L);
        assertFdsAreClosed(mBugreportFd);

        assertThatBugreportContainsFiles(UI_TRACES_PREDUMPED);
    }

    @Test
    public void simultaneousBugreportsNotAllowed() throws Exception {
        // Start bugreport #1
@@ -506,9 +536,6 @@ public class BugreportManagerTest {
        InstrumentationRegistry.getInstrumentation().getUiAutomation().executeShellCommand(
                "cmd window tracing start"
        );
        InstrumentationRegistry.getInstrumentation().getUiAutomation().executeShellCommand(
                "service call SurfaceFlinger 1025 i32 1"
        );
    }

    private static void stopPreDumpedUiTraces() {
@@ -611,6 +638,14 @@ public class BugreportManagerTest {
        return files;
    }

    private static void removeFilesIfNeeded(Path[] paths) throws Exception {
        for (Path path : paths) {
            InstrumentationRegistry.getInstrumentation().getUiAutomation().executeShellCommand(
                    "rm -f " + path.toString()
            );
        }
    }

    private static ParcelFileDescriptor parcelFd(File file) throws Exception {
        return ParcelFileDescriptor.open(file,
                ParcelFileDescriptor.MODE_WRITE_ONLY | ParcelFileDescriptor.MODE_APPEND);