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

Commit 0a05f5df authored by Bjorn Bringert's avatar Bjorn Bringert Committed by Android (Google) Code Review
Browse files

Merge "Clean up after failed MemoryFileTest.testPurge()"

parents 0902f02e 1017a134
Loading
Loading
Loading
Loading
+19 −16
Original line number Original line Diff line number Diff line
@@ -16,10 +16,8 @@


package android.os;
package android.os;


import android.os.MemoryFile;
import android.test.AndroidTestCase;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;
import android.test.suitebuilder.annotation.SmallTest;


import java.io.File;
import java.io.File;
@@ -44,11 +42,14 @@ public class MemoryFileTest extends AndroidTestCase {
    /**
    /**
     * Keep allocating new files till the system purges them.
     * Keep allocating new files till the system purges them.
     */
     */
    @MediumTest
    @LargeTest
    public void testPurge() throws Exception {
    public void testPurge() throws Exception {
        List<MemoryFile> files = new ArrayList<MemoryFile>();
        List<MemoryFile> files = new ArrayList<MemoryFile>();
        try {
            while (true) {
            while (true) {
            MemoryFile newFile = new MemoryFile("MemoryFileTest", 1000000);
                // This will fail if the process runs out of file descriptors before
                // the kernel starts purging ashmem areas.
                MemoryFile newFile = new MemoryFile("MemoryFileTest", 10000000);
                newFile.allowPurging(true);
                newFile.allowPurging(true);
                newFile.writeBytes(testString, 0, 0, testString.length);
                newFile.writeBytes(testString, 0, 0, testString.length);
                files.add(newFile);
                files.add(newFile);
@@ -57,13 +58,15 @@ public class MemoryFileTest extends AndroidTestCase {
                        file.readBytes(testString, 0, 0, testString.length);
                        file.readBytes(testString, 0, 0, testString.length);
                    } catch (IOException e) {
                    } catch (IOException e) {
                        // Expected
                        // Expected
                    for (MemoryFile fileToClose : files) {
                        fileToClose.close();
                    }
                        return;
                        return;
                    }
                    }
                }
                }
            }
            }
        } finally {
            for (MemoryFile fileToClose : files) {
                fileToClose.close();
            }
        }
    }
    }


    @SmallTest
    @SmallTest