[authfs][test] Run authfs host and benchmark tests in protected Vm
Test: atest AuthFsHostTest AuthFsBenchmarks
Bug: 236123069
Change-Id: Iddf0253b482bf21f0b02ce7b7df6557b8adc6a96
diff --git a/authfs/tests/benchmarks/src/java/com/android/fs/benchmarks/AuthFsBenchmarks.java b/authfs/tests/benchmarks/src/java/com/android/fs/benchmarks/AuthFsBenchmarks.java
index 5e9073a..641b566 100644
--- a/authfs/tests/benchmarks/src/java/com/android/fs/benchmarks/AuthFsBenchmarks.java
+++ b/authfs/tests/benchmarks/src/java/com/android/fs/benchmarks/AuthFsBenchmarks.java
@@ -20,6 +20,8 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assume.assumeTrue;
+
import android.platform.test.annotations.RootPermissionTest;
import com.android.fs.common.AuthFsTestRule;
@@ -71,11 +73,13 @@
@Before
public void setUp() throws Exception {
+ assumeTrue(AuthFsTestRule.getDevice().supportsMicrodroid(/*protectedVm=*/ true));
String metricsPrefix =
MetricsProcessor.getMetricPrefix(
getDevice().getProperty("debug.hypervisor.metrics_tag"));
mMetricsProcessor = new MetricsProcessor(metricsPrefix + "authfs/");
- AuthFsTestRule.startMicrodroid();
+ // TODO(b/236123069): Run benchmark tests in both protected and unprotected VMs.
+ AuthFsTestRule.startMicrodroid(/*protectedVm=*/ true);
}
@After
diff --git a/authfs/tests/common/src/java/com/android/fs/common/AuthFsTestRule.java b/authfs/tests/common/src/java/com/android/fs/common/AuthFsTestRule.java
index 994f23b..2220169 100644
--- a/authfs/tests/common/src/java/com/android/fs/common/AuthFsTestRule.java
+++ b/authfs/tests/common/src/java/com/android/fs/common/AuthFsTestRule.java
@@ -24,7 +24,6 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeTrue;
import com.android.compatibility.common.tradefed.build.CompatibilityBuildHelper;
import com.android.compatibility.common.util.PollingCheck;
@@ -131,7 +130,7 @@
return sMicrodroidDevice;
}
- public static void startMicrodroid() throws DeviceNotAvailableException {
+ public static void startMicrodroid(boolean protectedVm) throws DeviceNotAvailableException {
CLog.i("Starting the shared VM");
assertThat(sMicrodroidDevice).isNull();
sMicrodroidDevice =
@@ -139,6 +138,7 @@
findTestFile(sTestInfo.getBuildInfo(), TEST_APK_NAME),
VM_CONFIG_PATH_IN_APK)
.debugLevel("full")
+ .protectedVm(protectedVm)
.build(getDevice());
// From this point on, we need to tear down the Microdroid instance
@@ -152,10 +152,11 @@
}
public static void shutdownMicrodroid() throws DeviceNotAvailableException {
- assertNotNull(sMicrodroidDevice);
- getDevice().shutdownMicrodroid(sMicrodroidDevice);
- sMicrodroidDevice = null;
- sMicrodroid = null;
+ if (sMicrodroidDevice != null) {
+ getDevice().shutdownMicrodroid(sMicrodroidDevice);
+ sMicrodroidDevice = null;
+ sMicrodroid = null;
+ }
}
@Override
@@ -224,7 +225,7 @@
}
}
- private static TestDevice getDevice() {
+ public static TestDevice getDevice() {
return (TestDevice) sTestInfo.getDevice();
}
@@ -245,7 +246,6 @@
}
private void setUpTest() throws Exception {
- assumeTrue(getDevice().supportsMicrodroid());
sAndroid.run("mkdir -p " + TEST_OUTPUT_DIR);
}
diff --git a/authfs/tests/hosttests/java/src/com/android/fs/AuthFsHostTest.java b/authfs/tests/hosttests/java/src/com/android/fs/AuthFsHostTest.java
index 3157dfd..967d104 100644
--- a/authfs/tests/hosttests/java/src/com/android/fs/AuthFsHostTest.java
+++ b/authfs/tests/hosttests/java/src/com/android/fs/AuthFsHostTest.java
@@ -21,6 +21,7 @@
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assume.assumeTrue;
import android.platform.test.annotations.RootPermissionTest;
@@ -74,7 +75,8 @@
@BeforeClassWithInfo
public static void beforeClassWithDevice(TestInformation testInfo) throws Exception {
AuthFsTestRule.setUpAndroid(testInfo);
- AuthFsTestRule.startMicrodroid();
+ assumeTrue(AuthFsTestRule.getDevice().supportsMicrodroid(/*protectedVm=*/ true));
+ AuthFsTestRule.startMicrodroid(/*protectedVm=*/ true);
sAndroid = AuthFsTestRule.getAndroid();
sMicrodroid = AuthFsTestRule.getMicrodroid();
}