Add test to verify page size of Microdroid VM
Also fix the x86_64 microdroid_16k. Unfortunately passing the
`page_shift = 14` option in the bootconfig doesn't enable 16k emulation,
so we need to pass the option in the kernel cmdline until support for
bootconfig is implemented in the kernel.
Bug: 333730505
Test: atest MicrodroidTests
Change-Id: I35375ad272b4ff91c37a9a69658a17045a4a7ac8
diff --git a/tests/testapk/src/java/com/android/microdroid/test/MicrodroidTests.java b/tests/testapk/src/java/com/android/microdroid/test/MicrodroidTests.java
index 53fc819..917a027 100644
--- a/tests/testapk/src/java/com/android/microdroid/test/MicrodroidTests.java
+++ b/tests/testapk/src/java/com/android/microdroid/test/MicrodroidTests.java
@@ -2511,6 +2511,30 @@
assertThat(testResults.mMountFlags & expectedFlags).isEqualTo(expectedFlags);
}
+ @Test
+ public void pageSize() throws Exception {
+ assumeSupportedDevice();
+
+ VirtualMachineConfig config =
+ newVmConfigBuilderWithPayloadBinary("MicrodroidTestNativeLib.so")
+ .setDebugLevel(DEBUG_LEVEL_FULL)
+ .build();
+
+ VirtualMachine vm = forceCreateNewVirtualMachine("test_page_size", config);
+
+ TestResults testResults =
+ runVmTestService(
+ TAG,
+ vm,
+ (ts, tr) -> {
+ tr.mPageSize = ts.getPageSize();
+ });
+
+ assertThat(testResults.mException).isNull();
+ int expectedPageSize = mOs.endsWith("_16k") ? 16384 : 4096;
+ assertThat(testResults.mPageSize).isEqualTo(expectedPageSize);
+ }
+
private static class VmShareServiceConnection implements ServiceConnection {
private final CountDownLatch mLatch = new CountDownLatch(1);
diff --git a/tests/testapk/src/native/testbinary.cpp b/tests/testapk/src/native/testbinary.cpp
index 1a75102..632f648 100644
--- a/tests/testapk/src/native/testbinary.cpp
+++ b/tests/testapk/src/native/testbinary.cpp
@@ -34,6 +34,7 @@
#include <vm_main.h>
#include <vm_payload_restricted.h>
+#include <cstdint>
#include <string>
#include <thread>
@@ -311,6 +312,11 @@
return ScopedAStatus::ok();
}
+ ScopedAStatus getPageSize(int32_t* out) override {
+ *out = getpagesize();
+ return ScopedAStatus::ok();
+ }
+
ScopedAStatus requestCallback(const std::shared_ptr<IAppCallback>& appCallback) {
auto vmCallback = ndk::SharedRefBase::make<VmCallbackImpl>(appCallback);
std::thread callback_thread{[=] { appCallback->setVmCallback(vmCallback); }};
diff --git a/tests/testapk/src/native/testbinary.rs b/tests/testapk/src/native/testbinary.rs
index 85b411e..e479342 100644
--- a/tests/testapk/src/native/testbinary.rs
+++ b/tests/testapk/src/native/testbinary.rs
@@ -123,6 +123,9 @@
fn getMountFlags(&self, _: &str) -> BinderResult<i32> {
unimplemented()
}
+ fn getPageSize(&self) -> BinderResult<i32> {
+ unimplemented()
+ }
fn requestCallback(&self, _: &Strong<dyn IAppCallback + 'static>) -> BinderResult<()> {
unimplemented()
}