Merge "Suppress AppCacheTest tests that cause am instrument failure." into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
cd32b42e1c
@@ -25,11 +25,11 @@ import android.os.RemoteException;
|
|||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.StatFs;
|
import android.os.StatFs;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
|
import android.support.test.filters.LargeTest;
|
||||||
|
import android.support.test.filters.MediumTest;
|
||||||
|
import android.support.test.filters.SmallTest;
|
||||||
|
import android.support.test.filters.Suppress;
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
import android.test.suitebuilder.annotation.LargeTest;
|
|
||||||
import android.test.suitebuilder.annotation.MediumTest;
|
|
||||||
import android.test.suitebuilder.annotation.SmallTest;
|
|
||||||
import android.test.suitebuilder.annotation.Suppress;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -48,14 +48,14 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
public final long WAIT_TIME_INCR=10*1000;
|
public final long WAIT_TIME_INCR=10*1000;
|
||||||
private static final long THRESHOLD=5;
|
private static final long THRESHOLD=5;
|
||||||
private static final long ACTUAL_THRESHOLD=10;
|
private static final long ACTUAL_THRESHOLD=10;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
if(localLOGV) Log.i(TAG, "Cleaning up cache directory first");
|
if(localLOGV) Log.i(TAG, "Cleaning up cache directory first");
|
||||||
cleanUpCacheDirectory();
|
cleanUpCacheDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanUpDirectory(File pDir, String dirName) {
|
void cleanUpDirectory(File pDir, String dirName) {
|
||||||
File testDir = new File(pDir, dirName);
|
File testDir = new File(pDir, dirName);
|
||||||
if(!testDir.exists()) {
|
if(!testDir.exists()) {
|
||||||
@@ -72,13 +72,13 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
}
|
}
|
||||||
testDir.delete();
|
testDir.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanUpCacheDirectory() {
|
void cleanUpCacheDirectory() {
|
||||||
File testDir = mContext.getCacheDir();
|
File testDir = mContext.getCacheDir();
|
||||||
if(!testDir.exists()) {
|
if(!testDir.exists()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String fList[] = testDir.list();
|
String fList[] = testDir.list();
|
||||||
if(fList == null) {
|
if(fList == null) {
|
||||||
testDir.delete();
|
testDir.delete();
|
||||||
@@ -93,7 +93,7 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
public void testDeleteAllCacheFiles() {
|
public void testDeleteAllCacheFiles() {
|
||||||
String testName="testDeleteAllCacheFiles";
|
String testName="testDeleteAllCacheFiles";
|
||||||
@@ -160,9 +160,9 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
+(blks1-blks3));
|
+(blks1-blks3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method opens an output file writes to it, opens the same file as an input
|
* This method opens an output file writes to it, opens the same file as an input
|
||||||
* stream, reads the contents and verifies the data that was written earlier can be read
|
* stream, reads the contents and verifies the data that was written earlier can be read
|
||||||
*/
|
*/
|
||||||
public void openOutFileInAppFilesDir(File pFile, String pFileOut) {
|
public void openOutFileInAppFilesDir(File pFile, String pFileOut) {
|
||||||
@@ -180,7 +180,7 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
failStr(e.getMessage());
|
failStr(e.getMessage());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
failStr(e.getMessage());
|
failStr(e.getMessage());
|
||||||
}
|
}
|
||||||
int count = pFileOut.getBytes().length;
|
int count = pFileOut.getBytes().length;
|
||||||
byte[] buffer = new byte[count];
|
byte[] buffer = new byte[count];
|
||||||
try {
|
try {
|
||||||
@@ -194,8 +194,8 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
}
|
}
|
||||||
String str = new String(buffer);
|
String str = new String(buffer);
|
||||||
assertEquals(str, pFileOut);
|
assertEquals(str, pFileOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This test case verifies that output written to a file
|
* This test case verifies that output written to a file
|
||||||
* using Context.openFileOutput has executed successfully.
|
* using Context.openFileOutput has executed successfully.
|
||||||
@@ -215,7 +215,7 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
failStr(e);
|
failStr(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
public void testAppCacheCreateFile() {
|
public void testAppCacheCreateFile() {
|
||||||
String fileName = "testFile1.txt";
|
String fileName = "testFile1.txt";
|
||||||
@@ -225,7 +225,7 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
openOutFileInAppFilesDir(file, fileOut);
|
openOutFileInAppFilesDir(file, fileOut);
|
||||||
cleanUpCacheDirectory();
|
cleanUpCacheDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@MediumTest
|
@MediumTest
|
||||||
public void testAppCreateCacheFiles() {
|
public void testAppCreateCacheFiles() {
|
||||||
File cacheDir = mContext.getCacheDir();
|
File cacheDir = mContext.getCacheDir();
|
||||||
@@ -261,7 +261,7 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] getBuffer() {
|
byte[] getBuffer() {
|
||||||
String sbuffer = "a";
|
String sbuffer = "a";
|
||||||
for(int i = 0; i < 10; i++) {
|
for(int i = 0; i < 10; i++) {
|
||||||
@@ -360,7 +360,7 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
}
|
}
|
||||||
assertTrue("Files should have been removed", removedFlag);
|
assertTrue("Files should have been removed", removedFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
//createTestFiles(new File(super.getContext().getCacheDir(), "testtmp", "dir", 3)
|
//createTestFiles(new File(super.getContext().getCacheDir(), "testtmp", "dir", 3)
|
||||||
void createTestFiles1(File cacheDir, String testFilePrefix, int numTestFiles) {
|
void createTestFiles1(File cacheDir, String testFilePrefix, int numTestFiles) {
|
||||||
byte buffer[] = getBuffer();
|
byte buffer[] = getBuffer();
|
||||||
@@ -439,7 +439,7 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PackageDataObserver extends IPackageDataObserver.Stub {
|
class PackageDataObserver extends IPackageDataObserver.Stub {
|
||||||
public boolean retValue = false;
|
public boolean retValue = false;
|
||||||
private boolean doneFlag = false;
|
private boolean doneFlag = false;
|
||||||
@@ -455,11 +455,11 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
return doneFlag;
|
return doneFlag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IPackageManager getPm() {
|
IPackageManager getPm() {
|
||||||
return IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
|
return IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean invokePMDeleteAppCacheFiles() throws Exception {
|
boolean invokePMDeleteAppCacheFiles() throws Exception {
|
||||||
try {
|
try {
|
||||||
String packageName = mContext.getPackageName();
|
String packageName = mContext.getPackageName();
|
||||||
@@ -485,7 +485,7 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean invokePMFreeApplicationCache(long idealStorageSize) throws Exception {
|
boolean invokePMFreeApplicationCache(long idealStorageSize) throws Exception {
|
||||||
try {
|
try {
|
||||||
String packageName = mContext.getPackageName();
|
String packageName = mContext.getPackageName();
|
||||||
@@ -512,7 +512,7 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean invokePMFreeStorage(long idealStorageSize, FreeStorageReceiver r,
|
boolean invokePMFreeStorage(long idealStorageSize, FreeStorageReceiver r,
|
||||||
PendingIntent pi) throws Exception {
|
PendingIntent pi) throws Exception {
|
||||||
try {
|
try {
|
||||||
// Spin lock waiting for call back
|
// Spin lock waiting for call back
|
||||||
@@ -536,7 +536,7 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@LargeTest
|
@LargeTest
|
||||||
public void testDeleteAppCacheFiles() throws Exception {
|
public void testDeleteAppCacheFiles() throws Exception {
|
||||||
String testName="testDeleteAppCacheFiles";
|
String testName="testDeleteAppCacheFiles";
|
||||||
@@ -551,7 +551,7 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
public boolean retValue = false;
|
public boolean retValue = false;
|
||||||
public PackageStats stats;
|
public PackageStats stats;
|
||||||
private boolean doneFlag = false;
|
private boolean doneFlag = false;
|
||||||
|
|
||||||
public void onGetStatsCompleted(PackageStats pStats, boolean succeeded)
|
public void onGetStatsCompleted(PackageStats pStats, boolean succeeded)
|
||||||
throws RemoteException {
|
throws RemoteException {
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
@@ -565,7 +565,7 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
return doneFlag;
|
return doneFlag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PackageStats invokePMGetPackageSizeInfo() throws Exception {
|
public PackageStats invokePMGetPackageSizeInfo() throws Exception {
|
||||||
try {
|
try {
|
||||||
String packageName = mContext.getPackageName();
|
String packageName = mContext.getPackageName();
|
||||||
@@ -593,7 +593,7 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
public void testGetPackageSizeInfo() throws Exception {
|
public void testGetPackageSizeInfo() throws Exception {
|
||||||
String testName="testGetPackageSizeInfo";
|
String testName="testGetPackageSizeInfo";
|
||||||
@@ -603,7 +603,7 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
if(localLOGV) Log.i(TAG, "code="+stats.codeSize+", data="+stats.dataSize+
|
if(localLOGV) Log.i(TAG, "code="+stats.codeSize+", data="+stats.dataSize+
|
||||||
", cache="+stats.cacheSize);
|
", cache="+stats.cacheSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
public void testGetSystemSharedLibraryNames() throws Exception {
|
public void testGetSystemSharedLibraryNames() throws Exception {
|
||||||
try {
|
try {
|
||||||
@@ -615,17 +615,17 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
fail("Failed invoking getSystemSharedLibraryNames with exception:" + e);
|
fail("Failed invoking getSystemSharedLibraryNames with exception:" + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FreeStorageReceiver extends BroadcastReceiver {
|
class FreeStorageReceiver extends BroadcastReceiver {
|
||||||
public static final String ACTION_FREE = "com.android.unit_tests.testcallback";
|
public static final String ACTION_FREE = "com.android.unit_tests.testcallback";
|
||||||
private boolean doneFlag = false;
|
private boolean doneFlag = false;
|
||||||
|
|
||||||
public boolean isDone() {
|
public boolean isDone() {
|
||||||
return doneFlag;
|
return doneFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if(intent.getAction().equalsIgnoreCase(ACTION_FREE)) {
|
if(intent.getAction().equalsIgnoreCase(ACTION_FREE)) {
|
||||||
@@ -637,7 +637,7 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: flaky test, omit from LargeTest for now
|
// TODO: flaky test, omit from LargeTest for now
|
||||||
//@LargeTest
|
//@LargeTest
|
||||||
public void testFreeStorage() throws Exception {
|
public void testFreeStorage() throws Exception {
|
||||||
@@ -664,10 +664,10 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
if(localLOGV || TRACKING) Log.i(TAG, "Available blocks after freeing cache"+blks3);
|
if(localLOGV || TRACKING) Log.i(TAG, "Available blocks after freeing cache"+blks3);
|
||||||
assertEquals(receiver.getResultCode(), 1);
|
assertEquals(receiver.getResultCode(), 1);
|
||||||
mContext.unregisterReceiver(receiver);
|
mContext.unregisterReceiver(receiver);
|
||||||
// Verify result
|
// Verify result
|
||||||
verifyTestFiles1(cacheDir, "testtmpdir", 5);
|
verifyTestFiles1(cacheDir, "testtmpdir", 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* utility method used to create observer and check async call back from PackageManager.
|
/* utility method used to create observer and check async call back from PackageManager.
|
||||||
* ClearApplicationUserData
|
* ClearApplicationUserData
|
||||||
*/
|
*/
|
||||||
@@ -696,7 +696,7 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void verifyUserDataCleared(File pDir) {
|
void verifyUserDataCleared(File pDir) {
|
||||||
if(localLOGV) Log.i(TAG, "Verifying "+pDir);
|
if(localLOGV) Log.i(TAG, "Verifying "+pDir);
|
||||||
if(pDir == null) {
|
if(pDir == null) {
|
||||||
@@ -717,7 +717,7 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
fail(pDir+" should be empty or contain only lib subdirectory. Found "+fileList[i]);
|
fail(pDir+" should be empty or contain only lib subdirectory. Found "+fileList[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
File getDataDir() {
|
File getDataDir() {
|
||||||
try {
|
try {
|
||||||
ApplicationInfo appInfo = getPm().getApplicationInfo(mContext.getPackageName(), 0,
|
ApplicationInfo appInfo = getPm().getApplicationInfo(mContext.getPackageName(), 0,
|
||||||
@@ -727,7 +727,8 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
throw new RuntimeException("Pacakge manager dead", e);
|
throw new RuntimeException("Pacakge manager dead", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress
|
||||||
@LargeTest
|
@LargeTest
|
||||||
public void testClearApplicationUserDataWithTestData() throws Exception {
|
public void testClearApplicationUserDataWithTestData() throws Exception {
|
||||||
File cacheDir = mContext.getCacheDir();
|
File cacheDir = mContext.getCacheDir();
|
||||||
@@ -740,14 +741,16 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
//confirm files dont exist
|
//confirm files dont exist
|
||||||
verifyUserDataCleared(getDataDir());
|
verifyUserDataCleared(getDataDir());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress
|
||||||
@SmallTest
|
@SmallTest
|
||||||
public void testClearApplicationUserDataWithNoTestData() throws Exception {
|
public void testClearApplicationUserDataWithNoTestData() throws Exception {
|
||||||
assertTrue(invokePMClearApplicationUserData());
|
assertTrue(invokePMClearApplicationUserData());
|
||||||
//confirm files dont exist
|
//confirm files dont exist
|
||||||
verifyUserDataCleared(getDataDir());
|
verifyUserDataCleared(getDataDir());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress
|
||||||
@LargeTest
|
@LargeTest
|
||||||
public void testClearApplicationUserDataNoObserver() throws Exception {
|
public void testClearApplicationUserDataNoObserver() throws Exception {
|
||||||
getPm().clearApplicationUserData(mContext.getPackageName(), null, UserHandle.myUserId());
|
getPm().clearApplicationUserData(mContext.getPackageName(), null, UserHandle.myUserId());
|
||||||
@@ -756,5 +759,5 @@ public class AppCacheTest extends AndroidTestCase {
|
|||||||
//confirm files dont exist
|
//confirm files dont exist
|
||||||
verifyUserDataCleared(getDataDir());
|
verifyUserDataCleared(getDataDir());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user