MicrodroidHostTestCases: Add testHugePages
This test intends to verify if a VM can boot with THPs enabled. This
test is part of the MicrodroidHostTests suite as root is required to
enable THPs.
Bug: 278011447
Change-Id: I3819b85108bd514982002bc12517ddb26206831c
diff --git a/tests/hostside/java/com/android/microdroid/test/MicrodroidHostTests.java b/tests/hostside/java/com/android/microdroid/test/MicrodroidHostTests.java
index 18dc219..eb456f2 100644
--- a/tests/hostside/java/com/android/microdroid/test/MicrodroidHostTests.java
+++ b/tests/hostside/java/com/android/microdroid/test/MicrodroidHostTests.java
@@ -1174,6 +1174,40 @@
}
}
+ @Test
+ public void testHugePages() throws Exception {
+ ITestDevice device = getDevice();
+ boolean disableRoot = !device.isAdbRoot();
+ CommandRunner android = new CommandRunner(device);
+
+ final String SHMEM_ENABLED_PATH = "/sys/kernel/mm/transparent_hugepage/shmem_enabled";
+ String thpShmemStr = android.run("cat", SHMEM_ENABLED_PATH);
+
+ assumeFalse("shmem already enabled, skip", thpShmemStr.contains("[advise]"));
+ assumeTrue("Unsupported shmem, skip", thpShmemStr.contains("[never]"));
+
+ device.enableAdbRoot();
+ assumeTrue("adb root is not enabled", device.isAdbRoot());
+ android.run("echo advise > " + SHMEM_ENABLED_PATH);
+
+ final String configPath = "assets/vm_config.json";
+ mMicrodroidDevice =
+ MicrodroidBuilder.fromDevicePath(getPathForPackage(PACKAGE_NAME), configPath)
+ .debugLevel("full")
+ .memoryMib(minMemorySize())
+ .cpuTopology("match_host")
+ .protectedVm(mProtectedVm)
+ .gki(mGki)
+ .hugePages(true)
+ .build(getAndroidDevice());
+ mMicrodroidDevice.waitForBootComplete(BOOT_COMPLETE_TIMEOUT);
+
+ android.run("echo never >" + SHMEM_ENABLED_PATH);
+ if (disableRoot) {
+ device.disableAdbRoot();
+ }
+ }
+
@Before
public void setUp() throws Exception {
assumeDeviceIsCapable(getDevice());