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

Commit 6452c259 authored by Elliott Hughes's avatar Elliott Hughes Committed by Android (Google) Code Review
Browse files

Merge "Remove tests for dead API." into honeycomb

parents eb97c0dd ffcac1a1
Loading
Loading
Loading
Loading
+0 −90
Original line number Diff line number Diff line
@@ -540,94 +540,4 @@ public class HeapTest extends TestCase {
            objSize = (objSize * 4) / 5;
        }
    }

    // TODO: flaky test
    //@SmallTest
    public void testExternalOomeLarge() {
        /* Just shy of the typical max heap size so that it will actually
         * try to allocate it instead of short-circuiting.
         */
        final int HUGE_SIZE = (16 * 1024 * 1024 - 32);

        assertFalse(VMRuntime.getRuntime().trackExternalAllocation(HUGE_SIZE));
    }

    /**
     * "Allocates" external memory in progressively smaller chunks until there's
     * only roughly 16 bytes left.
     *
     * @return the number of bytes allocated
     */
    private long allocateMaxExternal() {
        final VMRuntime runtime = VMRuntime.getRuntime();
        final int SIXTEEN_MB = (16 * 1024 * 1024);
        final int MIN_SIZE = 16;
        long totalAllocated = 0;
        boolean success;

        success = false;
        try {
            /* "Allocate" progressively smaller chunks to "fill up" the entire heap.
             */
            int objSize = 1 * 1024 * 1024;
            while (objSize >= MIN_SIZE) {
                boolean sawFailure = false;
                for (int i = 0; i < SIXTEEN_MB / objSize; i++) {
                    if (runtime.trackExternalAllocation(objSize)) {
                        totalAllocated += objSize;
                    } else {
                        sawFailure = true;
                        break;
                    }
                }

                if (!sawFailure) {
                    throw new RuntimeException("Test failed: " +
                            "no failure while filling heap");
                }

                objSize = (objSize * 4) / 5;
            }
            success = true;
        } finally {
            if (!success) {
                runtime.trackExternalFree(totalAllocated);
                totalAllocated = 0;
            }
        }
        return totalAllocated;
    }

    public void xxtest00ExternalOomeSmall() {
        VMRuntime.getRuntime().trackExternalFree(allocateMaxExternal());
    }

    /**
     * Allocates as much external memory as possible, then allocates from the heap
     * until an OOME is caught.
     *
     * It's nice to run this test while the real heap is small, hence the '00' in its
     * name to force it to run before testOomeSmall().
     */
    public void xxtest00CombinedOomeSmall() {
        long totalAllocated = 0;
        boolean sawEx = false;
        try {
            totalAllocated = allocateMaxExternal();
            LinkedList<Object> list = new LinkedList<Object>();
            try {
                while (true) {
                    list.add((Object)new byte[8192]);
                }
                /*NOTREACHED*/
            } catch (OutOfMemoryError oom) {
                sawEx = true;
            }
        } finally {
            VMRuntime.getRuntime().trackExternalFree(totalAllocated);
        }
        assertTrue(sawEx);
    }

    //TODO: test external alloc debugging/inspection
}