diff options
author | android-build-prod (mdb) <android-build-team-robot@google.com> | 2018-01-13 00:12:55 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-01-13 00:12:55 +0000 |
commit | 000a8beb97821fc5b0c50953e12cec73aace0b9b (patch) | |
tree | f51f339bed9b6050f637c9e3b894a927bc0d5fac | |
parent | d562ecb764ae51fc07b28a0ac61998bb233d0dbc (diff) | |
parent | 75bfe31dbea9af2ae6c40c27381a437fb8a7ce4c (diff) | |
download | libcore-nougat-cts-release.tar.gz |
Merge "Snap for 4539635 from 65e0e6e2254eab162d9d8d4e05f598cefef10c5b to nougat-cts-release" into nougat-cts-releaseandroid-cts-7.0_r33android-cts-7.0_r32android-cts-7.0_r31android-cts-7.0_r30android-cts-7.0_r29android-cts-7.0_r28android-cts-7.0_r27android-cts-7.0_r26android-cts-7.0_r25android-cts-7.0_r24android-cts-7.0_r23android-cts-7.0_r22android-cts-7.0_r21android-cts-7.0_r20android-cts-7.0_r19android-cts-7.0_r18nougat-cts-release
-rw-r--r-- | luni/src/test/java/libcore/java/io/FileInputStreamTest.java | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/luni/src/test/java/libcore/java/io/FileInputStreamTest.java b/luni/src/test/java/libcore/java/io/FileInputStreamTest.java index 74432e5e000..7ff4684b8c3 100644 --- a/luni/src/test/java/libcore/java/io/FileInputStreamTest.java +++ b/luni/src/test/java/libcore/java/io/FileInputStreamTest.java @@ -26,7 +26,9 @@ import java.util.ArrayList; import java.util.List; import android.system.ErrnoException; +import android.system.Os; import android.system.OsConstants; +import android.system.StructStatVfs; import junit.framework.TestCase; import libcore.io.IoUtils; @@ -226,23 +228,36 @@ public final class FileInputStreamTest extends TestCase { // http://b/28192631 public void testSkipOnLargeFiles() throws Exception { File largeFile = File.createTempFile("FileInputStreamTest_testSkipOnLargeFiles", ""); - FileOutputStream fos = new FileOutputStream(largeFile); + + // Required space is 3.1 GB: 3GB for file plus 100M headroom. + final long requiredFreeSpaceBytes = 3172L * 1024 * 1024; + + // If system doesn't have enough space free for this test, skip it. + final StructStatVfs statVfs = Os.statvfs(largeFile.getPath()); + final long freeSpaceAvailableBytes = statVfs.f_bsize * statVfs.f_bavail; + if (freeSpaceAvailableBytes < requiredFreeSpaceBytes) { + return; + } + try { - byte[] buffer = new byte[1024 * 1024]; // 1 MB - for (int i = 0; i < 3 * 1024; i++) { // 3 GB - fos.write(buffer); + FileOutputStream fos = new FileOutputStream(largeFile); + try { + byte[] buffer = new byte[1024 * 1024]; // 1 MB + for (int i = 0; i < 3 * 1024; i++) { // 3 GB + fos.write(buffer); + } + } finally { + fos.close(); } + + FileInputStream fis = new FileInputStream(largeFile); + long lastByte = 3 * 1024 * 1024 * 1024L - 1; + assertEquals(0, Libcore.os.lseek(fis.getFD(), 0, OsConstants.SEEK_CUR)); + assertEquals(lastByte, fis.skip(lastByte)); } finally { - fos.close(); + // Proactively cleanup - it's a pretty large file. + assertTrue(largeFile.delete()); } - - FileInputStream fis = new FileInputStream(largeFile); - long lastByte = 3 * 1024 * 1024 * 1024L - 1; - assertEquals(0, Libcore.os.lseek(fis.getFD(), 0, OsConstants.SEEK_CUR)); - assertEquals(lastByte, fis.skip(lastByte)); - - // Proactively cleanup - it's a pretty large file. - assertTrue(largeFile.delete()); } private static List<Integer> getOpenFdsForPrefix(String path) throws Exception { |