aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-prod (mdb) <android-build-team-robot@google.com>2018-01-13 00:12:55 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2018-01-13 00:12:55 +0000
commit000a8beb97821fc5b0c50953e12cec73aace0b9b (patch)
treef51f339bed9b6050f637c9e3b894a927bc0d5fac
parentd562ecb764ae51fc07b28a0ac61998bb233d0dbc (diff)
parent75bfe31dbea9af2ae6c40c27381a437fb8a7ce4c (diff)
downloadlibcore-nougat-cts-release.tar.gz
-rw-r--r--luni/src/test/java/libcore/java/io/FileInputStreamTest.java41
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 {