Move isCuttlefish() to helper classes
We skip some tests when running on Cuttlefish, typically because nested
virtualization is too slow and the tests time out, but logic has been
duplicated across multiple test files. Clean things up by adding a new
common host/device helper VirtualizationTestHelper and make both the
MicrodroidHostTestCaseBase and MicrodroidDeviceTestBase share the same
logic.
Test: m MicrodroidTestApp ComposBenchmarkApp MicrodroidHostTestCases
Change-Id: Ibb9d25fc40818ffeb971d366dea409f8ee55ef48
diff --git a/tests/helper/Android.bp b/tests/helper/Android.bp
index 679fbfe..e7760e2 100644
--- a/tests/helper/Android.bp
+++ b/tests/helper/Android.bp
@@ -3,11 +3,18 @@
}
java_library_static {
+ name: "VirtualizationTestHelper",
+ srcs: ["src/java/com/android/virt/**/*.java"],
+ host_supported: true,
+}
+
+java_library_static {
name: "MicroroidDeviceTestHelper",
- srcs: ["src/java/**/*.java"],
+ srcs: ["src/java/com/android/microdroid/**/*.java"],
static_libs: [
"androidx.test.runner",
"androidx.test.ext.junit",
+ "VirtualizationTestHelper",
"truth-prebuilt",
],
libs: ["android.system.virtualmachine"],
diff --git a/tests/helper/src/java/com/android/microdroid/test/MicrodroidDeviceTestBase.java b/tests/helper/src/java/com/android/microdroid/test/MicrodroidDeviceTestBase.java
index 4d38f1f..a2c43d7 100644
--- a/tests/helper/src/java/com/android/microdroid/test/MicrodroidDeviceTestBase.java
+++ b/tests/helper/src/java/com/android/microdroid/test/MicrodroidDeviceTestBase.java
@@ -21,6 +21,7 @@
import android.content.Context;
import android.os.ParcelFileDescriptor;
+import android.os.SystemProperties;
import android.sysprop.HypervisorProperties;
import android.system.virtualizationservice.DeathReason;
import android.system.virtualmachine.VirtualMachine;
@@ -33,6 +34,8 @@
import androidx.annotation.CallSuper;
import androidx.test.core.app.ApplicationProvider;
+import com.android.virt.VirtualizationTestHelper;
+
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -60,6 +63,10 @@
}).start();
}
+ public static boolean isCuttlefish() {
+ return VirtualizationTestHelper.isCuttlefish(SystemProperties.get("ro.product.name"));
+ }
+
// TODO(b/220920264): remove Inner class; this is a hack to hide virt APEX types
protected static class Inner {
private final boolean mProtectedVm;
diff --git a/tests/helper/src/java/com/android/virt/VirtualizationTestHelper.java b/tests/helper/src/java/com/android/virt/VirtualizationTestHelper.java
new file mode 100644
index 0000000..c6c0ad0
--- /dev/null
+++ b/tests/helper/src/java/com/android/virt/VirtualizationTestHelper.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2022 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.virt;
+
+public abstract class VirtualizationTestHelper {
+ public static boolean isCuttlefish(String productName) {
+ return (null != productName)
+ && (productName.startsWith("aosp_cf_x86")
+ || productName.startsWith("aosp_cf_arm")
+ || productName.startsWith("cf_x86")
+ || productName.startsWith("cf_arm"));
+ }
+}