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

Commit 686333ca authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "fs-verity: fix broken testFsverityFailToReadModifiedBlockAtFront/Back"

parents cc1ce346 8c0d57a6
Loading
Loading
Loading
Loading
+26 −23
Original line number Diff line number Diff line
@@ -408,8 +408,7 @@ public class ApkVerityTest extends BaseHostJUnit4Test {
        damageFileAgainstBlockDevice(apkPath, offsetFirstByte);

        // Expect actual read from disk to fail but only at damaged page.
        BlockDeviceWriter.dropCaches(mDevice);
        assertFalse(BlockDeviceWriter.canReadByte(mDevice, apkPath, offsetFirstByte));
        expectReadFromBlockDeviceToFail(apkPath, offsetFirstByte);
        if (apkSize > offsetFirstByte + FSVERITY_PAGE_SIZE) {
            long lastByteOfTheSamePage =
                    offsetFirstByte % FSVERITY_PAGE_SIZE + FSVERITY_PAGE_SIZE - 1;
@@ -437,8 +436,7 @@ public class ApkVerityTest extends BaseHostJUnit4Test {
        damageFileAgainstBlockDevice(apkPath, offsetOfLastByte);

        // Expect actual read from disk to fail but only at damaged page.
        BlockDeviceWriter.dropCaches(mDevice);
        assertFalse(BlockDeviceWriter.canReadByte(mDevice, apkPath, offsetOfLastByte));
        expectReadFromBlockDeviceToFail(apkPath, offsetOfLastByte);
        if (offsetOfLastByte - FSVERITY_PAGE_SIZE > 0) {
            long firstByteOfTheSamePage = offsetOfLastByte - offsetOfLastByte % FSVERITY_PAGE_SIZE;
            assertFalse(BlockDeviceWriter.canReadByte(mDevice, apkPath, firstByteOfTheSamePage));
@@ -456,17 +454,23 @@ public class ApkVerityTest extends BaseHostJUnit4Test {
            String path = appDir + "/" + basename;
            damageFileAgainstBlockDevice(path, kTargetOffset);

            expectReadFromBlockDeviceToFail(path, kTargetOffset);
        }
    }

    private void expectReadFromBlockDeviceToFail(String readPath, long offset)
            throws DeviceNotAvailableException {
        // Retry is sometimes needed to pass the test. Package manager may have FD leaks
        // (see b/122744005 as example) that prevents the file in question to be evicted
        // from filesystem cache. Forcing GC workarounds the problem.
        int retry = 5;
        for (; retry > 0; retry--) {
            BlockDeviceWriter.dropCaches(mDevice);
                if (!BlockDeviceWriter.canReadByte(mDevice, path, kTargetOffset)) {
            if (!BlockDeviceWriter.canReadByte(mDevice, readPath, offset)) {
                break;
            }
            try {
                    String openFiles = expectRemoteCommandToSucceed("lsof " + apkPath);
                String openFiles = expectRemoteCommandToSucceed("lsof " + readPath);
                CLog.d("lsof: " + openFiles);
                Thread.sleep(1000);
                forceGCOnOpenFilesProcess(getOpenFilesPIDs(openFiles));
@@ -475,8 +479,7 @@ public class ApkVerityTest extends BaseHostJUnit4Test {
                return;
            }
        }
            assertTrue("Read from " + path + " should fail", retry > 0);
        }
        assertTrue("Read from " + readPath + " should fail", retry > 0);
    }

    /**