RandomRWTest now checks for usable space before running
Bug: 30151120
Test: cts-tradefed run cts -m CtsFileSystemTestCases -t android.filesystem.cts.RandomRWTest#testRandomUpdate
Change-Id: I655b1b56f0f708d4d15e1b7330483e7cd50047ed
diff --git a/tests/filesystem/src/android/filesystem/cts/FileUtil.java b/tests/filesystem/src/android/filesystem/cts/FileUtil.java
index fc8eee0..8149105 100755
--- a/tests/filesystem/src/android/filesystem/cts/FileUtil.java
+++ b/tests/filesystem/src/android/filesystem/cts/FileUtil.java
@@ -41,6 +41,8 @@
private static final String TAG = "FileUtil";
private static final Random mRandom = new Random(0);
private static long mFileId = 0;
+
+ public static final int BUFFER_SIZE = 10 * 1024 * 1024;
/**
* create array with different data per each call
*
@@ -140,7 +142,6 @@
*/
public static File createNewFilledFile(Context context, String dirName, long length)
throws IOException {
- final int BUFFER_SIZE = 10 * 1024 * 1024;
File file = createNewFile(context, dirName);
FileOutputStream out = new FileOutputStream(file);
byte[] data = generateRandomData(BUFFER_SIZE);
diff --git a/tests/filesystem/src/android/filesystem/cts/RandomRWTest.java b/tests/filesystem/src/android/filesystem/cts/RandomRWTest.java
index a2df743..7b97f8f 100644
--- a/tests/filesystem/src/android/filesystem/cts/RandomRWTest.java
+++ b/tests/filesystem/src/android/filesystem/cts/RandomRWTest.java
@@ -17,7 +17,7 @@
package android.filesystem.cts;
import android.cts.util.CtsAndroidTestCase;
-
+import android.os.Environment;
import com.android.compatibility.common.util.CddTest;
import com.android.compatibility.common.util.DeviceReportLog;
@@ -51,11 +51,17 @@
@CddTest(requirement="8.2")
public void testRandomUpdate() throws Exception {
final int WRITE_BUFFER_SIZE = 4 * 1024;
- final long fileSize = 256 * 1024 * 1024;
+ final long usableSpace = Environment.getDataDirectory().getUsableSpace();
+ long fileSize = 256 * 1024 * 1024;
+ while (usableSpace < fileSize) {
+ fileSize = fileSize / 2;
+ }
String streamName = "test_random_update";
DeviceReportLog report = new DeviceReportLog(REPORT_LOG_NAME, streamName);
- FileUtil.doRandomWriteTest(getContext(), DIR_RANDOM_WR, report, fileSize,
+ if (fileSize > FileUtil.BUFFER_SIZE) {
+ FileUtil.doRandomWriteTest(getContext(), DIR_RANDOM_WR, report, fileSize,
WRITE_BUFFER_SIZE);
+ }
report.submit(getInstrumentation());
}
}