Enable testSdkData_IsAttributedToApp_DisableQuota test
Test was failing since manual app size calculation exceeded the margin
of error we had previously.
Updated the test to write bigger file and set the margin to 5%.
Bug: 246954235
Test: atest SdkSandboxStorageHostTest
Test: presubmit
Change-Id: Id908e16942973f5dd80c73c619c43b77502600c1
diff --git a/sdksandbox/tests/hostsidetests/SdkSandboxStorageHostTest/app/src/com/android/tests/sdksandbox/SdkSandboxStorageTestApp.java b/sdksandbox/tests/hostsidetests/SdkSandboxStorageHostTest/app/src/com/android/tests/sdksandbox/SdkSandboxStorageTestApp.java
index a358a54..487547b 100644
--- a/sdksandbox/tests/hostsidetests/SdkSandboxStorageHostTest/app/src/com/android/tests/sdksandbox/SdkSandboxStorageTestApp.java
+++ b/sdksandbox/tests/hostsidetests/SdkSandboxStorageHostTest/app/src/com/android/tests/sdksandbox/SdkSandboxStorageTestApp.java
@@ -126,27 +126,32 @@
final StorageStats initialAppStats = stats.queryStatsForUid(UUID_DEFAULT, uid);
final StorageStats initialUserStats = stats.queryStatsForUser(UUID_DEFAULT, user);
- mSdk.createFilesInSharedStorage();
+ final int sizeInBytes = 10000000; // 10 MB
+ mSdk.createFilesInSharedStorage(sizeInBytes, /*inCacheDir*/ false);
+ mSdk.createFilesInSharedStorage(sizeInBytes, /*inCacheDir*/ true);
final StorageStats finalAppStats = stats.queryStatsForUid(UUID_DEFAULT, uid);
final StorageStats finalUserStats = stats.queryStatsForUser(UUID_DEFAULT, user);
- // Verify the space used with a few hundred kilobytes error margin
- long deltaAppSize = 2000000;
- long deltaCacheSize = 1000000;
- long errorMarginSize = 100000;
- assertMostlyEquals(deltaAppSize,
- finalAppStats.getDataBytes() - initialAppStats.getDataBytes(),
- errorMarginSize);
- assertMostlyEquals(deltaAppSize,
- finalUserStats.getDataBytes() - initialUserStats.getDataBytes(),
- errorMarginSize);
- assertMostlyEquals(deltaCacheSize,
- finalAppStats.getCacheBytes() - initialAppStats.getCacheBytes(),
- errorMarginSize);
- assertMostlyEquals(deltaCacheSize,
- finalUserStats.getCacheBytes() - initialUserStats.getCacheBytes(),
- errorMarginSize);
+ // Verify the space used with a 5% error margin
+ long deltaAppSize = 2 * sizeInBytes;
+ long deltaCacheSize = sizeInBytes;
+ long errorMarginSize = sizeInBytes / 20; // 0.5 MB
+
+ // Assert app size is same
+ final long appSizeAppStats = finalAppStats.getDataBytes() - initialAppStats.getDataBytes();
+ final long appSizeUserStats =
+ finalUserStats.getDataBytes() - initialUserStats.getDataBytes();
+ assertMostlyEquals(deltaAppSize, appSizeAppStats, errorMarginSize);
+ assertMostlyEquals(deltaAppSize, appSizeUserStats, errorMarginSize);
+
+ // Assert cache size is same
+ final long cacheSizeAppStats =
+ finalAppStats.getCacheBytes() - initialAppStats.getCacheBytes();
+ final long cacheSizeUserStats =
+ finalUserStats.getCacheBytes() - initialUserStats.getCacheBytes();
+ assertMostlyEquals(deltaCacheSize, cacheSizeAppStats, errorMarginSize);
+ assertMostlyEquals(deltaCacheSize, cacheSizeUserStats, errorMarginSize);
}
@Test
diff --git a/sdksandbox/tests/hostsidetests/SdkSandboxStorageHostTest/codeprovider/src/com/android/tests/codeprovider/storagetest_1/IStorageTestSdk1Api.aidl b/sdksandbox/tests/hostsidetests/SdkSandboxStorageHostTest/codeprovider/src/com/android/tests/codeprovider/storagetest_1/IStorageTestSdk1Api.aidl
index 12a9390..f59414a 100644
--- a/sdksandbox/tests/hostsidetests/SdkSandboxStorageHostTest/codeprovider/src/com/android/tests/codeprovider/storagetest_1/IStorageTestSdk1Api.aidl
+++ b/sdksandbox/tests/hostsidetests/SdkSandboxStorageHostTest/codeprovider/src/com/android/tests/codeprovider/storagetest_1/IStorageTestSdk1Api.aidl
@@ -17,6 +17,6 @@
interface IStorageTestSdk1Api {
void verifySharedStorageIsUsable();
void verifyPerSdkStorageIsUsable();
- void createFilesInSharedStorage();
+ void createFilesInSharedStorage(int sizeInBytes, boolean inCacheDir);
String getSyncedSharedPreferencesString(in String key);
}
diff --git a/sdksandbox/tests/hostsidetests/SdkSandboxStorageHostTest/codeprovider/src/com/android/tests/codeprovider/storagetest_1/StorageTestSdk1ApiImpl.java b/sdksandbox/tests/hostsidetests/SdkSandboxStorageHostTest/codeprovider/src/com/android/tests/codeprovider/storagetest_1/StorageTestSdk1ApiImpl.java
index 3afb5ad..d8cf7cb 100644
--- a/sdksandbox/tests/hostsidetests/SdkSandboxStorageHostTest/codeprovider/src/com/android/tests/codeprovider/storagetest_1/StorageTestSdk1ApiImpl.java
+++ b/sdksandbox/tests/hostsidetests/SdkSandboxStorageHostTest/codeprovider/src/com/android/tests/codeprovider/storagetest_1/StorageTestSdk1ApiImpl.java
@@ -68,21 +68,15 @@
}
@Override
- public void createFilesInSharedStorage() {
+ public void createFilesInSharedStorage(int sizeInBytes, boolean inCacheDir) {
try {
- final byte[] buffer = new byte[1000000];
- String sharedPath = getSharedStoragePath();
- String sharedCachePath = getSharedStorageCachePath();
+ final byte[] buffer = new byte[sizeInBytes];
+ final String path = inCacheDir ? getSharedStorageCachePath() : getSharedStoragePath();
- Files.createDirectory(Paths.get(sharedPath, "attribution"));
- Path filepath = Paths.get(sharedPath, "attribution", "file");
+ Files.createDirectory(Paths.get(path, "attribution"));
+ final Path filepath = Paths.get(path, "attribution", "file");
Files.createFile(filepath);
Files.write(filepath, buffer);
-
- Files.createDirectory(Paths.get(sharedCachePath, "attribution"));
- Path cacheFilepath = Paths.get(sharedCachePath, "attribution", "file");
- Files.createFile(cacheFilepath);
- Files.write(cacheFilepath, buffer);
} catch (Exception e) {
throw new IllegalStateException(e);
}
diff --git a/sdksandbox/tests/hostsidetests/SdkSandboxStorageHostTest/src/com/android/tests/sdksandbox/host/SdkSandboxStorageHostTest.java b/sdksandbox/tests/hostsidetests/SdkSandboxStorageHostTest/src/com/android/tests/sdksandbox/host/SdkSandboxStorageHostTest.java
index 46eac07..709a069 100644
--- a/sdksandbox/tests/hostsidetests/SdkSandboxStorageHostTest/src/com/android/tests/sdksandbox/host/SdkSandboxStorageHostTest.java
+++ b/sdksandbox/tests/hostsidetests/SdkSandboxStorageHostTest/src/com/android/tests/sdksandbox/host/SdkSandboxStorageHostTest.java
@@ -36,7 +36,6 @@
import org.junit.After;
import org.junit.AssumptionViolatedException;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -1026,8 +1025,6 @@
runPhase("testSdkDataIsAttributedToApp");
}
- // TODO(b/246954235): Manual calcualtions have bigger margin of error
- @Ignore
@Test
public void testSdkData_IsAttributedToApp_DisableQuota() throws Exception {
installPackage(TEST_APP_STORAGE_APK);