Merge "Fix incorrect tests Bug #7262921 Bug #7198966 Bug #7203333" into jb-mr1-dev
diff --git a/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/AlmostFullTest.java b/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/AlmostFullTest.java
new file mode 100644
index 0000000..1735ea3
--- /dev/null
+++ b/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/AlmostFullTest.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.pts.filesystemperf;
+
+import android.cts.util.TimeoutReq;
+import com.android.pts.util.MeasureRun;
+import com.android.pts.util.MeasureTime;
+import com.android.pts.util.PtsAndroidTestCase;
+import com.android.pts.util.ReportLog;
+import com.android.pts.util.Stat;
+import com.android.pts.util.SystemUtil;
+
+import android.util.Log;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class AlmostFullTest extends PtsAndroidTestCase {
+
+    private static final String DIR_INITIAL_FILL = "INITIAL_FILL";
+    private static final String DIR_SEQ_UPDATE = "SEQ_UPDATE";
+    private static final String DIR_RANDOM_WR = "RANDOM_WR";
+    private static final String DIR_RANDOM_RD = "RANDOM_RD";
+    private static final String TAG = "AlmostFullTest";
+
+    private static final long FREE_SPACE_FINAL = 1000L * 1024 * 1024L;
+
+    // test runner creates multiple instances at the begging.
+    // use that to fill disk only once.
+    private static AtomicInteger mRefCounter = new AtomicInteger(0);
+    private static AtomicBoolean mDiskFilled = new AtomicBoolean(false);
+
+    public AlmostFullTest() {
+        int currentCounter = mRefCounter.incrementAndGet();
+        Log.i(TAG, "++currentCounter: " + currentCounter);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        if (mDiskFilled.compareAndSet(false, true)) {
+            Log.i(TAG, "Filling disk");
+            // initial fill done in two stage as disk can be filled by other components
+            long freeDisk = SystemUtil.getFreeDiskSize(getContext());
+            long diskToFill = freeDisk - FREE_SPACE_FINAL;
+            Log.i(TAG, "free disk " + freeDisk + ", to fill " + diskToFill);
+            final long MAX_FILE_SIZE_TO_FILL = 1024L * 1024L * 1024L;
+            long filled = 0;
+            while (filled < diskToFill) {
+                long toFill = diskToFill - filled;
+                if (toFill > MAX_FILE_SIZE_TO_FILL) {
+                    toFill = MAX_FILE_SIZE_TO_FILL;
+                }
+                Log.i(TAG, "Generating file " + toFill);
+                FileUtil.createNewFilledFile(getContext(),
+                        DIR_INITIAL_FILL, toFill);
+                filled += toFill;
+            }
+        }
+        Log.i(TAG, "free disk " + SystemUtil.getFreeDiskSize(getContext()));
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        Log.i(TAG, "tearDown free disk " + SystemUtil.getFreeDiskSize(getContext()));
+        int currentCounter = mRefCounter.decrementAndGet();
+        Log.i(TAG, "--currentCounter: " + currentCounter);
+        if (currentCounter == 0) {
+            FileUtil.removeFileOrDir(getContext(), DIR_INITIAL_FILL);
+        }
+        FileUtil.removeFileOrDir(getContext(), DIR_SEQ_UPDATE);
+        FileUtil.removeFileOrDir(getContext(), DIR_RANDOM_WR);
+        FileUtil.removeFileOrDir(getContext(), DIR_RANDOM_RD);
+        Log.i(TAG, "tearDown free disk " + SystemUtil.getFreeDiskSize(getContext()));
+        super.tearDown();
+    }
+
+    @TimeoutReq(minutes = 30)
+    public void testSequentialUpdate() throws IOException {
+        // now about freeSpaceToLeave should be left
+        // and try updating exceeding the free space size
+        final long FILE_SIZE = 400L * 1024L * 1024L;
+        long freeDisk = SystemUtil.getFreeDiskSize(getContext());
+        Log.i(TAG, "Now free space is " + freeDisk);
+        assertTrue(freeDisk > FILE_SIZE);
+        final int BUFFER_SIZE = 10 * 1024 * 1024;
+        final int NUMBER_REPETITION = 10;
+        FileUtil.doSequentialUpdateTest(getContext(), DIR_SEQ_UPDATE, getReportLog(), FILE_SIZE,
+                BUFFER_SIZE, NUMBER_REPETITION);
+    }
+
+    //TODO: file size too small and caching will give wrong better result.
+    //      needs to flush cache by reading big files per each read.
+    @TimeoutReq(minutes = 60)
+    public void testRandomRead() throws IOException {
+        final int BUFFER_SIZE = 4 * 1024;
+        final long fileSize = 400L * 1024L * 1024L;
+        FileUtil.doRandomReadTest(getContext(), DIR_RANDOM_RD, getReportLog(), fileSize,
+                BUFFER_SIZE);
+    }
+
+    @TimeoutReq(minutes = 60)
+    public void testRandomUpdate() throws IOException {
+        final int BUFFER_SIZE = 4 * 1024;
+        final long fileSize = 400L * 1024L * 1024L;
+        FileUtil.doRandomWriteTest(getContext(), DIR_RANDOM_WR, getReportLog(), fileSize,
+                BUFFER_SIZE);
+    }
+}
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 906d831..3399a5b 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
@@ -19,12 +19,17 @@
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.io.RandomAccessFile;
 import java.util.Random;
 
 import com.android.pts.util.MeasureRun;
+import com.android.pts.util.MeasureTime;
+import com.android.pts.util.ReportLog;
+import com.android.pts.util.Stat;
 import com.android.pts.util.SystemUtil;
 
 import android.content.Context;
@@ -162,6 +167,7 @@
                 removeEntry(new File(entry, child));
             }
         }
+        Log.i(TAG, "delete file " + entry.getAbsolutePath());
         entry.delete();
     }
 
@@ -243,4 +249,150 @@
         }
         return diskSizeTarget;
     }
+
+    /**
+     *
+     * @param context
+     * @param dirName
+     * @param report
+     * @param fileSize
+     * @param bufferSize should be power of two
+     * @throws IOException
+     */
+    public static void doRandomReadTest(Context context, String dirName, ReportLog report,
+            long fileSize, int bufferSize) throws IOException {
+        File file = FileUtil.createNewFilledFile(context,
+                dirName, fileSize);
+
+        final byte[] data = FileUtil.generateRandomData(bufferSize);
+        Random random = new Random(0);
+        final int totalReadCount = (int)(fileSize / bufferSize);
+        final int[] readOffsets = new int[totalReadCount];
+        for (int i = 0; i < totalReadCount; i++) {
+            // align in buffer size
+            readOffsets[i] = (int)(random.nextFloat() * (fileSize - bufferSize)) &
+                    ~(bufferSize - 1);
+        }
+        final int runsInOneGo = 16;
+        final int readsInOneMeasure = totalReadCount / runsInOneGo;
+
+
+        final RandomAccessFile randomFile = new RandomAccessFile(file, "rw");
+        double[] rdAmount = new double[runsInOneGo];
+        double[] wrAmount = new double[runsInOneGo];
+        double[] times = FileUtil.measureIO(runsInOneGo, rdAmount, wrAmount, new MeasureRun() {
+
+            @Override
+            public void run(int i) throws IOException {
+                int start = i * readsInOneMeasure;
+                int end = (i + 1) * readsInOneMeasure;
+                for (int j = start; j < end; j++) {
+                    randomFile.seek(readOffsets[j]);
+                    randomFile.read(data);
+                }
+            }
+        });
+        randomFile.close();
+        double[] mbps = ReportLog.calcRatePerSecArray((double)fileSize / runsInOneGo / 1024 / 1024,
+                times);
+        report.printArray("MB/s",
+                mbps, true);
+        report.printArray("Rd amount", rdAmount, true);
+        Stat.StatResult stat = Stat.getStat(mbps);
+
+        report.printSummary("MB/s", stat.mMin, stat.mAverage);
+    }
+
+    /**
+     *
+     * @param context
+     * @param dirName
+     * @param report
+     * @param fileSize
+     * @param bufferSize should be power of two
+     * @throws IOException
+     */
+    public static void doRandomWriteTest(Context context, String dirName, ReportLog report,
+            long fileSize, int bufferSize) throws IOException {
+        File file = FileUtil.createNewFilledFile(context,
+                dirName, fileSize);
+        final byte[] data = FileUtil.generateRandomData(bufferSize);
+        Random random = new Random(0);
+        final int totalWriteCount = (int)(fileSize / bufferSize);
+        final int[] writeOffsets = new int[totalWriteCount];
+        for (int i = 0; i < totalWriteCount; i++) {
+            writeOffsets[i] = (int)(random.nextFloat() * (fileSize - bufferSize)) &
+                    ~(bufferSize - 1);
+        }
+        final int runsInOneGo = 16;
+        final int writesInOneMeasure = totalWriteCount / runsInOneGo; // 32MB at a time
+
+
+        final RandomAccessFile randomFile = new RandomAccessFile(file, "rw");
+        double[] rdAmount = new double[runsInOneGo];
+        double[] wrAmount = new double[runsInOneGo];
+        double[] times = FileUtil.measureIO(runsInOneGo, rdAmount, wrAmount, new MeasureRun() {
+
+            @Override
+            public void run(int i) throws IOException {
+                int start = i * writesInOneMeasure;
+                int end = (i + 1) * writesInOneMeasure;
+                for (int j = start; j < end; j++) {
+                    randomFile.seek(writeOffsets[j]);
+                    randomFile.write(data);
+                }
+            }
+        });
+        randomFile.close();
+        double[] mbps = ReportLog.calcRatePerSecArray((double)fileSize / runsInOneGo / 1024 / 1024,
+                times);
+        report.printArray("MB/s",
+                mbps, true);
+        report.printArray("Wr amount", wrAmount, true);
+        Stat.StatResult stat = Stat.getStat(mbps);
+
+        report.printSummary("MB/s", stat.mMin, stat.mAverage);
+    }
+
+    /**
+     *
+     * @param context
+     * @param dirName
+     * @param report
+     * @param fileSize fileSize should be multiple of bufferSize.
+     * @param bufferSize
+     * @param numberRepetition
+     * @throws IOException
+     */
+    public static void doSequentialUpdateTest(Context context, String dirName, ReportLog report,
+            long fileSize, int bufferSize, int numberRepetition) throws IOException {
+        File file = FileUtil.createNewFilledFile(context,
+                dirName, fileSize);
+        final byte[] data = FileUtil.generateRandomData(bufferSize);
+        double[] worsts = new double[numberRepetition];
+        double[] averages = new double[numberRepetition];
+        for (int i = 0; i < numberRepetition; i++) {
+            final FileOutputStream out = new FileOutputStream(file);
+            int numberRepeat = (int)(fileSize / bufferSize);
+            double[] times = MeasureTime.measure(numberRepeat, new MeasureRun() {
+
+                @Override
+                public void run(int i) throws IOException {
+                    out.write(data);
+                    out.flush();
+                }
+            });
+            out.close();
+            double[] mbps = ReportLog.calcRatePerSecArray((double)bufferSize / 1024 / 1024,
+                    times);
+            report.printArray(i + "-th round MB/s",
+                    mbps, true);
+            Stat.StatResult stat = Stat.getStat(mbps);
+            worsts[i] = stat.mMin;
+            averages[i] = stat.mAverage;
+        }
+        Stat.StatResult statWorsts = Stat.getStat(worsts);
+        Stat.StatResult statAverages = Stat.getStat(averages);
+        report.printSummary("MB/s", statWorsts.mMin, statAverages.mAverage);
+    }
 }
diff --git a/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/FullUpdateTest.java b/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/FullUpdateTest.java
deleted file mode 100644
index b6da646..0000000
--- a/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/FullUpdateTest.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.pts.filesystemperf;
-
-import android.cts.util.TimeoutReq;
-import com.android.pts.util.MeasureRun;
-import com.android.pts.util.MeasureTime;
-import com.android.pts.util.PtsAndroidTestCase;
-import com.android.pts.util.ReportLog;
-import com.android.pts.util.Stat;
-import com.android.pts.util.SystemUtil;
-
-import android.util.Log;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-public class FullUpdateTest extends PtsAndroidTestCase {
-    private static final String DIR_INITIAL_FILL = "INITIAL_FILL";
-    private static final String DIR_WORK = "WORK";
-    private static final String TAG = "FullUpdateTest";
-
-    @Override
-    protected void tearDown() throws Exception {
-        FileUtil.removeFileOrDir(getContext(), DIR_INITIAL_FILL);
-        FileUtil.removeFileOrDir(getContext(), DIR_WORK);
-        super.tearDown();
-    }
-
-    // fill disk almost, update exceeding free space, then update some amount
-    // idea is to drain all free blocks and measure update performance
-    @TimeoutReq(minutes = 30)
-    public void testAlmostFilledUpdate() throws IOException {
-        long freeDisk = SystemUtil.getFreeDiskSize(getContext());
-        final long FREE_SPACE_TO_LEAVE = 400L * 1024L * 1024L; // leave this much
-        long diskToFill = freeDisk - FREE_SPACE_TO_LEAVE;
-        Log.i(TAG, "free disk " + freeDisk + ", to fill " + diskToFill);
-        final long MAX_FILE_SIZE_TO_FILL = 1024L * 1024L * 1024L;
-        long filled = 0;
-        while (filled < diskToFill) {
-            long toFill = diskToFill - filled;
-            if (toFill > MAX_FILE_SIZE_TO_FILL) {
-                toFill = MAX_FILE_SIZE_TO_FILL;
-            }
-            Log.i(TAG, "Generating file " + toFill);
-            FileUtil.createNewFilledFile(getContext(),
-                    DIR_INITIAL_FILL, toFill);
-            filled += toFill;
-        }
-
-        // now about freeSpaceToLeave should be left
-        // and try updating exceeding the free space size
-        final long FILE_SIZE = 300L * 1024L * 1024L;
-        File file = FileUtil.createNewFilledFile(getContext(),
-                DIR_WORK, FILE_SIZE);
-        final int BUFFER_SIZE = 10 * 1024 * 1024;
-        final byte[] data = FileUtil.generateRandomData(BUFFER_SIZE);
-        final int NUMBER_REPETITION = 10;
-        double[] worsts = new double[NUMBER_REPETITION];
-        double[] averages = new double[NUMBER_REPETITION];
-        for (int i = 0; i < NUMBER_REPETITION; i++) {
-            final FileOutputStream out = new FileOutputStream(file);
-            int numberRepeat = (int)(FILE_SIZE / BUFFER_SIZE);
-            double[] times = MeasureTime.measure(numberRepeat, new MeasureRun() {
-
-                @Override
-                public void run(int i) throws IOException {
-                    out.write(data);
-                    out.flush();
-                }
-            });
-            out.close();
-            double[] mbps = ReportLog.calcRatePerSecArray((double)BUFFER_SIZE / 1024 / 1024,
-                    times);
-            getReportLog().printArray(i + "-th round MB/s",
-                    mbps, true);
-            Stat.StatResult stat = Stat.getStat(mbps);
-            worsts[i] = stat.mMin;
-            averages[i] = stat.mAverage;
-        }
-        Stat.StatResult statWorsts = Stat.getStat(worsts);
-        Stat.StatResult statAverages = Stat.getStat(averages);
-        getReportLog().printSummary("MB/s", statWorsts.mMin, statAverages.mAverage);
-    }
-}
diff --git a/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/RandomRWTest.java b/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/RandomRWTest.java
index 4f8aad4..e9eb25b 100644
--- a/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/RandomRWTest.java
+++ b/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/RandomRWTest.java
@@ -36,98 +36,24 @@
     @Override
     protected void tearDown() throws Exception {
         FileUtil.removeFileOrDir(getContext(), DIR_RANDOM_WR);
+        FileUtil.removeFileOrDir(getContext(), DIR_RANDOM_RD);
         super.tearDown();
     }
 
-
     @TimeoutReq(minutes = 60)
     public void testRandomRead() throws IOException {
         final int READ_BUFFER_SIZE = 4 * 1024;
         final long fileSize = FileUtil.getFileSizeExceedingMemory(getContext(), READ_BUFFER_SIZE);
-        File file = FileUtil.createNewFilledFile(getContext(),
-                DIR_RANDOM_RD, fileSize);
-
-        final byte[] data = FileUtil.generateRandomData(READ_BUFFER_SIZE);
-        Random random = new Random(0);
-        final int totalReadCount = (int)(fileSize / READ_BUFFER_SIZE);
-        final int[] readOffsets = new int[totalReadCount];
-        for (int i = 0; i < totalReadCount; i++) {
-            // align in buffer size
-            readOffsets[i] = (int)(random.nextFloat() * (fileSize - READ_BUFFER_SIZE)) &
-                    ~(READ_BUFFER_SIZE - 1);
-        }
-        final int runsInOneGo = 16;
-        final int readsInOneMeasure = totalReadCount / runsInOneGo;
-
-
-        final RandomAccessFile randomFile = new RandomAccessFile(file, "rw");
-        double[] rdAmount = new double[runsInOneGo];
-        double[] wrAmount = new double[runsInOneGo];
-        double[] times = FileUtil.measureIO(runsInOneGo, rdAmount, wrAmount, new MeasureRun() {
-
-            @Override
-            public void run(int i) throws IOException {
-                int start = i * readsInOneMeasure;
-                int end = (i + 1) * readsInOneMeasure;
-                for (int j = start; j < end; j++) {
-                    randomFile.seek(readOffsets[j]);
-                    randomFile.read(data);
-                }
-            }
-        });
-        randomFile.close();
-        double[] mbps = ReportLog.calcRatePerSecArray((double)fileSize / runsInOneGo / 1024 / 1024,
-                times);
-        getReportLog().printArray("MB/s",
-                mbps, true);
-        getReportLog().printArray("Rd amount", rdAmount, true);
-        Stat.StatResult stat = Stat.getStat(mbps);
-
-        getReportLog().printSummary("MB/s", stat.mMin, stat.mAverage);
+        FileUtil.doRandomReadTest(getContext(), DIR_RANDOM_RD, getReportLog(), fileSize,
+                READ_BUFFER_SIZE);
     }
 
     // It is taking too long in tuna, and thus cannot run multiple times
     @TimeoutReq(minutes = 60)
     public void testRandomUpdate() throws IOException {
-        final int fileSize = 512 * 1024 * 1024;
-        File file = FileUtil.createNewFilledFile(getContext(),
-                DIR_RANDOM_WR, fileSize);
         final int WRITE_BUFFER_SIZE = 4 * 1024;
-        final byte[] data = FileUtil.generateRandomData(WRITE_BUFFER_SIZE);
-        Random random = new Random(0);
-        final int totalWriteCount = fileSize / WRITE_BUFFER_SIZE;
-        final int[] writeOffsets = new int[totalWriteCount];
-        for (int i = 0; i < totalWriteCount; i++) {
-            writeOffsets[i] = (int)(random.nextFloat() * (fileSize - WRITE_BUFFER_SIZE)) &
-                    ~(WRITE_BUFFER_SIZE - 1);
-        }
-        final int runsInOneGo = 16;
-        final int writesInOneMeasure = totalWriteCount / runsInOneGo; // 32MB at a time
-
-
-        final RandomAccessFile randomFile = new RandomAccessFile(file, "rw");
-        double[] rdAmount = new double[runsInOneGo];
-        double[] wrAmount = new double[runsInOneGo];
-        double[] times = FileUtil.measureIO(runsInOneGo, rdAmount, wrAmount, new MeasureRun() {
-
-            @Override
-            public void run(int i) throws IOException {
-                int start = i * writesInOneMeasure;
-                int end = (i + 1) * writesInOneMeasure;
-                for (int j = start; j < end; j++) {
-                    randomFile.seek(writeOffsets[j]);
-                    randomFile.write(data);
-                }
-            }
-        });
-        randomFile.close();
-        double[] mbps = ReportLog.calcRatePerSecArray((double)fileSize / runsInOneGo / 1024 / 1024,
-                times);
-        getReportLog().printArray("MB/s",
-                mbps, true);
-        getReportLog().printArray("Wr amount", wrAmount, true);
-        Stat.StatResult stat = Stat.getStat(mbps);
-
-        getReportLog().printSummary("MB/s", stat.mMin, stat.mAverage);
+        final long fileSize = 512 * 1024 * 1024;
+        FileUtil.doRandomWriteTest(getContext(), DIR_RANDOM_WR, getReportLog(), fileSize,
+                WRITE_BUFFER_SIZE);
     }
 }
diff --git a/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/SequentialRWTest.java b/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/SequentialRWTest.java
index 2a750b1..a68ac4e 100644
--- a/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/SequentialRWTest.java
+++ b/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/SequentialRWTest.java
@@ -71,39 +71,9 @@
     @TimeoutReq(minutes = 60)
     public void testSingleSequentialUpdate() throws IOException {
         final long fileSize = FileUtil.getFileSizeExceedingMemory(getContext(), BUFFER_SIZE);
-        File file = FileUtil.createNewFilledFile(getContext(),
-                DIR_SEQ_UPD, fileSize);
-        final byte[] data = FileUtil.generateRandomData(BUFFER_SIZE);
         final int NUMBER_REPETITION = 6;
-        double[] worsts = new double[NUMBER_REPETITION];
-        double[] averages = new double[NUMBER_REPETITION];
-        for (int i = 0; i < NUMBER_REPETITION; i++) {
-            final FileOutputStream out = new FileOutputStream(file);
-            int numberRepeat = (int)(fileSize / BUFFER_SIZE);
-            double[] rdAmount = new double[numberRepeat];
-            double[] wrAmount = new double[numberRepeat];
-            double[] times = FileUtil.measureIO(numberRepeat, rdAmount, wrAmount,
-                    new MeasureRun() {
-
-                @Override
-                public void run(int i) throws IOException {
-                    out.write(data);
-                    out.flush();
-                }
-            });
-            out.close();
-            double[] mbps = ReportLog.calcRatePerSecArray((double)BUFFER_SIZE / 1024 / 1024,
-                    times);
-            getReportLog().printArray(i + "-th round MB/s",
-                    mbps, true);
-            getReportLog().printArray("Wr amount", wrAmount, true);
-            Stat.StatResult stat = Stat.getStat(mbps);
-            worsts[i] = stat.mMin;
-            averages[i] = stat.mAverage;
-        }
-        Stat.StatResult statWorsts = Stat.getStat(worsts);
-        Stat.StatResult statAverages = Stat.getStat(averages);
-        getReportLog().printSummary("MB/s", statWorsts.mMin, statAverages.mAverage);
+        FileUtil.doSequentialUpdateTest(getContext(), DIR_SEQ_UPD, getReportLog(), fileSize,
+                BUFFER_SIZE, NUMBER_REPETITION);
     }
 
     @TimeoutReq(minutes = 30)
diff --git a/tests/tests/dpi/src/android/dpi/cts/ConfigurationScreenLayoutTest.java b/tests/tests/dpi/src/android/dpi/cts/ConfigurationScreenLayoutTest.java
index f0372e9..45418cf 100644
--- a/tests/tests/dpi/src/android/dpi/cts/ConfigurationScreenLayoutTest.java
+++ b/tests/tests/dpi/src/android/dpi/cts/ConfigurationScreenLayoutTest.java
@@ -46,9 +46,6 @@
         int expectedSize = expectedScreenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
         int expectedLong = expectedScreenLayout & Configuration.SCREENLAYOUT_LONG_MASK;
 
-        // Check if the device has the navigation bar.
-        boolean navigationBar = hasNavigationBar();
-
         // Check that all four orientations report the same configuration value.
         for (int i = 0; i < ORIENTATIONS.length; i++) {
             Activity activity = startOrientationActivity(ORIENTATIONS[i]);
@@ -56,15 +53,6 @@
             int actualSize = mConfig.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
             int actualLong = mConfig.screenLayout & Configuration.SCREENLAYOUT_LONG_MASK;
 
-            if (navigationBar) {
-                // Update screenLayout value if the device has the navigation bar.
-                expectedScreenLayout = reduceScreenLayout(activity,
-                        Configuration.SCREENLAYOUT_SIZE_XLARGE
-                        | Configuration.SCREENLAYOUT_LONG_YES);
-                expectedSize = expectedScreenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
-                expectedLong = expectedScreenLayout & Configuration.SCREENLAYOUT_LONG_MASK;
-            }
-
             assertEquals("Expected screen size value of " + expectedSize + " but got " + actualSize
                     + " for orientation " + ORIENTATIONS[i], expectedSize, actualSize);
             assertEquals("Expected screen long value of " + expectedLong + " but got " + actualLong
@@ -93,11 +81,6 @@
         return screenLayout;
     }
 
-    private boolean hasNavigationBar() {
-        // Check if the device has a permanent menu key available.
-        return !ViewConfiguration.get(getActivity()).hasPermanentMenuKey();
-    }
-
     private Activity startOrientationActivity(int orientation) {
         Intent intent = new Intent();
         intent.putExtra(OrientationActivity.EXTRA_ORIENTATION, orientation);
diff --git a/tests/tests/permission/src/android/permission/cts/NoLocationPermissionTest.java b/tests/tests/permission/src/android/permission/cts/NoLocationPermissionTest.java
index fbf8d2c..b3cf682 100644
--- a/tests/tests/permission/src/android/permission/cts/NoLocationPermissionTest.java
+++ b/tests/tests/permission/src/android/permission/cts/NoLocationPermissionTest.java
@@ -312,6 +312,7 @@
     @SmallTest
     public void testSetTestProviderLocation() {
         Location location = new Location(TEST_PROVIDER_NAME);
+        location.makeComplete();
 
         try {
             mLocationManager.setTestProviderLocation(TEST_PROVIDER_NAME, location);