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

Commit f6d0d2c1 authored by Connor O'Brien's avatar Connor O'Brien
Browse files

KernelCpuUidBpfMapReaderTest: test UID removal with absent UIDs



The original implementation of
KernelCpuUidBpfMapReader.removeUidsInRange did not work unless data
was present for the first & last UIDs in the range. Add a test case to
verify the fix for this issue & prevent regressions

Test: confirm test passes with fix & fails without it
Bug: 157887803
Change-Id: Icfabb7298dbfb1a7f1b89dadbe33bae0492922b6
Signed-off-by: default avatarConnor O'Brien <connoro@google.com>
parent b3bd77fc
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -179,6 +179,21 @@ public class KernelCpuUidBpfMapReaderTest {
        testOpenAndReadData(changedData);
    }

    @Test
    public void testRemoveUidsInRange_firstAndLastAbsent() {
        final SparseArray<long[]> data = getTestSparseArray(200, 50);
        data.delete(0);
        data.delete(5);
        mReader.setData(data);
        testOpenAndReadData(data);
        SparseArray<long[]> changedData = new SparseArray<>();
        for (int i = 6; i < 200; i++) {
            changedData.put(i, data.get(i));
        }
        mReader.removeUidsInRange(0, 5);
        testOpenAndReadData(changedData);
    }

    private void testOpenAndReadData(SparseArray<long[]> expectedData) {
        try (BpfMapIterator iter = mReader.open()) {
            long[] actual;