1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.filesystem.cts; 18 19 import android.os.Environment; 20 21 import com.android.compatibility.common.util.CddTest; 22 import com.android.compatibility.common.util.CtsAndroidTestCase; 23 import com.android.compatibility.common.util.DeviceReportLog; 24 25 public class RandomRWTest extends CtsAndroidTestCase { 26 private static final String DIR_RANDOM_WR = "RANDOM_WR"; 27 private static final String DIR_RANDOM_RD = "RANDOM_RD"; 28 private static final String REPORT_LOG_NAME = "CtsFileSystemTestCases"; 29 30 @Override tearDown()31 protected void tearDown() throws Exception { 32 FileUtil.removeFileOrDir(getContext(), DIR_RANDOM_WR); 33 FileUtil.removeFileOrDir(getContext(), DIR_RANDOM_RD); 34 super.tearDown(); 35 } 36 37 @CddTest(requirement="8.2") testRandomRead()38 public void testRandomRead() throws Exception { 39 final int READ_BUFFER_SIZE = 4 * 1024; 40 final long fileSize = FileUtil.getFileSizeExceedingMemory(getContext(), READ_BUFFER_SIZE); 41 if (fileSize == 0) { // not enough space, give up 42 return; 43 } 44 String streamName = "test_random_read"; 45 DeviceReportLog report = new DeviceReportLog(REPORT_LOG_NAME, streamName); 46 FileUtil.doRandomReadTest(getContext(), DIR_RANDOM_RD, report, fileSize, 47 READ_BUFFER_SIZE); 48 report.submit(getInstrumentation()); 49 } 50 51 // It is taking too long in some device, and thus cannot run multiple times 52 @CddTest(requirement="8.2") testRandomUpdate()53 public void testRandomUpdate() throws Exception { 54 final int WRITE_BUFFER_SIZE = 4 * 1024; 55 final long usableSpace = Environment.getDataDirectory().getUsableSpace(); 56 long fileSize = 256 * 1024 * 1024; 57 while (usableSpace < fileSize) { 58 fileSize = fileSize / 2; 59 } 60 String streamName = "test_random_update"; 61 DeviceReportLog report = new DeviceReportLog(REPORT_LOG_NAME, streamName); 62 if (fileSize > FileUtil.BUFFER_SIZE) { 63 FileUtil.doRandomWriteTest(getContext(), DIR_RANDOM_WR, report, fileSize, 64 WRITE_BUFFER_SIZE); 65 } 66 report.submit(getInstrumentation()); 67 } 68 } 69