Use synchronous I/O for file preparation

Several I/O tests in the CtsFileSystemTestCases module create a very
large file as part of their test and fill it with random data.  When the
test filesystem is ext4 with journaling enabled we can hit a panic due
to a known limitation in the current ext4 journaling implementation:

https://marc.info/?l=linux-ext4&m=155290911210235&w=2

This issue is related to the ext4 journal being overwhelmed when trying
to write out a steady stream of dirty pages.

Work around this by using synchronous I/O to write the test file.  This
flushes the dirty data to media as each page is written, preventing us
from overwhelming the ext4 journal with a flood of dirty pages.

This change only affects the test setup and not the part of the test
where the disk I/O is measured.  As such it should have no impact on the
measured test results and should not affect our CDD compliance.

Bug: 126871108
Bug: 124296028
Bug: 65528573
Bug: 120237441
Bug: 126912361
Test: CtsFileSystemTestCases module passes on samus-kernelnext

Change-Id: I70660126fcdc8d263e421c36595cb3b0d1a412ab
Signed-off-by: Ross Zwisler <zwisler@google.com>
diff --git a/tests/filesystem/src/android/filesystem/cts/FileUtil.java b/tests/filesystem/src/android/filesystem/cts/FileUtil.java
index 8149105..5433f0a 100755
--- a/tests/filesystem/src/android/filesystem/cts/FileUtil.java
+++ b/tests/filesystem/src/android/filesystem/cts/FileUtil.java
@@ -143,15 +143,14 @@
     public static File createNewFilledFile(Context context, String dirName, long length)
             throws IOException {
         File file = createNewFile(context, dirName);
-        FileOutputStream out = new FileOutputStream(file);
+        final RandomAccessFile randomFile = new RandomAccessFile(file, "rwd"); // force O_SYNC
         byte[] data = generateRandomData(BUFFER_SIZE);
-        long written = 0;
-        while (written < length) {
-            out.write(data);
-            written += BUFFER_SIZE;
+
+        while (file.length() < length) {
+            randomFile.write(data);
         }
-        out.flush();
-        out.close();
+
+        randomFile.close();
         return file;
     }