change all file writes to random access with O_SYNC

- for giving the same result for all write tests

Change-Id: I630cfb8712bf0b130cb97f42b8c1708cfa0a1358
diff --git a/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/FileUtil.java b/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/FileUtil.java
index 2cb3854..14fc45a 100644
--- a/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/FileUtil.java
+++ b/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/FileUtil.java
@@ -118,10 +118,14 @@
      * @throws IOException
      */
     public static void writeFile(File file, byte[] data, boolean append) throws IOException {
-        FileOutputStream out = new FileOutputStream(file, append);
-        out.write(data);
-        out.flush();
-        out.close();
+        final RandomAccessFile randomFile = new RandomAccessFile(file, "rwd"); // force O_SYNC
+        if (append) {
+            randomFile.seek(randomFile.length());
+        } else {
+            randomFile.seek(0L);
+        }
+        randomFile.write(data);
+        randomFile.close();
     }
 
     /**
@@ -276,7 +280,7 @@
         final int runsInOneGo = 16;
         final int readsInOneMeasure = totalReadCount / runsInOneGo;
 
-        final RandomAccessFile randomFile = new RandomAccessFile(file, "rw");
+        final RandomAccessFile randomFile = new RandomAccessFile(file, "rw"); // do not need O_SYNC
         double[] rdAmount = new double[runsInOneGo];
         double[] wrAmount = new double[runsInOneGo];
         double[] times = FileUtil.measureIO(runsInOneGo, rdAmount, wrAmount, new MeasureRun() {
@@ -326,7 +330,7 @@
         final int runsInOneGo = 16;
         final int writesInOneMeasure = totalWriteCount / runsInOneGo; // 32MB at a time
 
-        final RandomAccessFile randomFile = new RandomAccessFile(file, "rw");
+        final RandomAccessFile randomFile = new RandomAccessFile(file, "rwd"); // force O_SYNC
         double[] rdAmount = new double[runsInOneGo];
         double[] wrAmount = new double[runsInOneGo];
         double[] times = FileUtil.measureIO(runsInOneGo, rdAmount, wrAmount, new MeasureRun() {
@@ -370,16 +374,16 @@
         int numberRepeatInOneRun = (int)(fileSize / bufferSize);
         double[] mbpsAll = new double[numberRepetition * numberRepeatInOneRun];
         for (int i = 0; i < numberRepetition; i++) {
-            final FileOutputStream out = new FileOutputStream(file);
+            final RandomAccessFile randomFile = new RandomAccessFile(file, "rwd");  // force O_SYNC
+            randomFile.seek(0L);
             double[] times = MeasureTime.measure(numberRepeatInOneRun, new MeasureRun() {
 
                 @Override
                 public void run(int i) throws IOException {
-                    out.write(data);
-                    out.flush();
+                    randomFile.write(data);
                 }
             });
-            out.close();
+            randomFile.close();
             double[] mbps = ReportLog.calcRatePerSecArray((double)bufferSize / 1024 / 1024,
                     times);
             report.printArray(i + "-th round MB/s",
diff --git a/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/TestTest.java b/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/TestTest.java
index 6800d6f..e333200 100644
--- a/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/TestTest.java
+++ b/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/TestTest.java
@@ -31,7 +31,7 @@
     protected void tearDown() throws Exception {
         super.tearDown();
     }
-
+/* code for testing PTS logging. Disabled.
     @TimeoutReq(minutes = 15)
     public void testPass() {
         double[] array = new double[] {1.0, 2.0, 3.0};
@@ -49,4 +49,5 @@
         getReportLog().printSummary("This should not be shown", 0, 0);
         throw new Exception("failed");
     }
+*/
 }