Simplify use of config files
Since the exposed API won't support config files:
- Don't use a config file for the demo app.
- Don't use config files for tests that don't need one.
Also, in preparation for removing command line argument support
entirely, remove all arguments from config files. Where we were using
arguments to specify behavior, use different binaries instead.
Tweak: Improve error reporting in the benchmark after I got a (sadly
non-reproducible) failure.
Bug: 250876593
Bug: 243513572
Test: atest MicrodroidTests MicrodroidHostTestCases
Test: atest MicrodroidBenchmarkApp
Test: manual - install & run demo app
Change-Id: I4332b2340bf2e18cdaee5acd9ef3277766b1c0b5
diff --git a/tests/testapk/Android.bp b/tests/testapk/Android.bp
index 47116eb..4dff0a2 100644
--- a/tests/testapk/Android.bp
+++ b/tests/testapk/Android.bp
@@ -20,7 +20,10 @@
"compatibility-common-util-devicesidelib",
],
libs: ["android.system.virtualmachine"],
- jni_libs: ["MicrodroidTestNativeLib"],
+ jni_libs: [
+ "MicrodroidTestNativeLib",
+ "MicrodroidTestNativeCrashLib",
+ ],
platform_apis: true,
use_embedded_native_libs: true,
// We only support 64-bit ABI, but CTS demands all APKs to be multi-ABI.
@@ -48,6 +51,11 @@
}
cc_library_shared {
+ name: "MicrodroidTestNativeCrashLib",
+ srcs: ["src/native/crashbinary.cpp"],
+}
+
+cc_library_shared {
name: "MicrodroidTestNativeLibSub",
srcs: ["src/native/testlib.cpp"],
}
diff --git a/tests/testapk/assets/vm_config.json b/tests/testapk/assets/vm_config.json
index da420ff..d12eb5c 100644
--- a/tests/testapk/assets/vm_config.json
+++ b/tests/testapk/assets/vm_config.json
@@ -4,11 +4,7 @@
},
"task": {
"type": "microdroid_launcher",
- "command": "MicrodroidTestNativeLib.so",
- "args": [
- "hello",
- "microdroid"
- ]
+ "command": "MicrodroidTestNativeLib.so"
},
"export_tombstones": true
}
diff --git a/tests/testapk/assets/vm_config_apex.json b/tests/testapk/assets/vm_config_apex.json
index 0f100aa..c00787f 100644
--- a/tests/testapk/assets/vm_config_apex.json
+++ b/tests/testapk/assets/vm_config_apex.json
@@ -4,11 +4,7 @@
},
"task": {
"type": "microdroid_launcher",
- "command": "MicrodroidTestNativeLib.so",
- "args": [
- "hello",
- "microdroid"
- ]
+ "command": "MicrodroidTestNativeLib.so"
},
"apexes": [
{
diff --git a/tests/testapk/assets/vm_config_crash.json b/tests/testapk/assets/vm_config_crash.json
index 282f25c..2951fdf 100644
--- a/tests/testapk/assets/vm_config_crash.json
+++ b/tests/testapk/assets/vm_config_crash.json
@@ -4,10 +4,7 @@
},
"task": {
"type": "microdroid_launcher",
- "command": "MicrodroidTestNativeLib.so",
- "args": [
- "crash"
- ]
+ "command": "MicrodroidTestNativeCrashLib.so"
},
"export_tombstones": true
}
diff --git a/tests/testapk/assets/vm_config_crash_no_tombstone.json b/tests/testapk/assets/vm_config_crash_no_tombstone.json
index be0983d..583f87b 100644
--- a/tests/testapk/assets/vm_config_crash_no_tombstone.json
+++ b/tests/testapk/assets/vm_config_crash_no_tombstone.json
@@ -4,10 +4,7 @@
},
"task": {
"type": "microdroid_launcher",
- "command": "MicrodroidTestNativeLib.so",
- "args": [
- "crash"
- ]
+ "command": "MicrodroidTestNativeCrashLib.so"
},
"export_tombstones": false
}
diff --git a/tests/testapk/assets/vm_config_extra_apk.json b/tests/testapk/assets/vm_config_extra_apk.json
index d7d3dd7..b45e57d 100644
--- a/tests/testapk/assets/vm_config_extra_apk.json
+++ b/tests/testapk/assets/vm_config_extra_apk.json
@@ -4,11 +4,7 @@
},
"task": {
"type": "microdroid_launcher",
- "command": "MicrodroidTestNativeLib.so",
- "args": [
- "hello",
- "microdroid"
- ]
+ "command": "MicrodroidTestNativeLib.so"
},
"extra_apks": [
{
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 b0ec359..3681348 100644
--- a/tests/testapk/src/java/com/android/microdroid/test/MicrodroidTests.java
+++ b/tests/testapk/src/java/com/android/microdroid/test/MicrodroidTests.java
@@ -122,7 +122,8 @@
@Test
public void bootFailsWhenLowMem() throws Exception {
for (int memMib : new int[]{ 10, 20, 40 }) {
- VirtualMachineConfig lowMemConfig = mInner.newVmConfigBuilder("assets/vm_config.json")
+ VirtualMachineConfig lowMemConfig = mInner.newVmConfigBuilder()
+ .setPayloadBinaryPath("MicrodroidTestNativeLib.so")
.setMemoryMib(memMib)
.setDebugLevel(DEBUG_LEVEL_NONE)
.build();
@@ -157,8 +158,10 @@
public void changingDebugLevelInvalidatesVmIdentity() throws Exception {
assumeSupportedKernel();
- VirtualMachineConfig.Builder builder = mInner.newVmConfigBuilder("assets/vm_config.json");
- VirtualMachineConfig normalConfig = builder.setDebugLevel(DEBUG_LEVEL_NONE).build();
+ VirtualMachineConfig.Builder builder = mInner.newVmConfigBuilder()
+ .setPayloadBinaryPath("MicrodroidTestNativeLib.so")
+ .setDebugLevel(DEBUG_LEVEL_NONE);
+ VirtualMachineConfig normalConfig = builder.build();
mInner.forceCreateNewVirtualMachine("test_vm", normalConfig);
assertThat(tryBootVm(TAG, "test_vm").payloadStarted).isTrue();
@@ -219,7 +222,8 @@
public void instancesOfSameVmHaveDifferentCdis() throws Exception {
assumeSupportedKernel();
- VirtualMachineConfig normalConfig = mInner.newVmConfigBuilder("assets/vm_config.json")
+ VirtualMachineConfig normalConfig = mInner.newVmConfigBuilder()
+ .setPayloadBinaryPath("MicrodroidTestNativeLib.so")
.setDebugLevel(DEBUG_LEVEL_FULL)
.build();
mInner.forceCreateNewVirtualMachine("test_vm_a", normalConfig);
@@ -243,7 +247,8 @@
public void sameInstanceKeepsSameCdis() throws Exception {
assumeSupportedKernel();
- VirtualMachineConfig normalConfig = mInner.newVmConfigBuilder("assets/vm_config.json")
+ VirtualMachineConfig normalConfig = mInner.newVmConfigBuilder()
+ .setPayloadBinaryPath("MicrodroidTestNativeLib.so")
.setDebugLevel(DEBUG_LEVEL_FULL)
.build();
mInner.forceCreateNewVirtualMachine("test_vm", normalConfig);
@@ -264,7 +269,8 @@
public void bccIsSuperficiallyWellFormed() throws Exception {
assumeSupportedKernel();
- VirtualMachineConfig normalConfig = mInner.newVmConfigBuilder("assets/vm_config.json")
+ VirtualMachineConfig normalConfig = mInner.newVmConfigBuilder()
+ .setPayloadBinaryPath("MicrodroidTestNativeLib.so")
.setDebugLevel(DEBUG_LEVEL_FULL)
.build();
VirtualMachine vm = mInner.forceCreateNewVirtualMachine("bcc_vm", normalConfig);
@@ -338,7 +344,8 @@
}
private RandomAccessFile prepareInstanceImage(String vmName) throws Exception {
- VirtualMachineConfig config = mInner.newVmConfigBuilder("assets/vm_config.json")
+ VirtualMachineConfig config = mInner.newVmConfigBuilder()
+ .setPayloadBinaryPath("MicrodroidTestNativeLib.so")
.setDebugLevel(DEBUG_LEVEL_FULL)
.build();
@@ -411,14 +418,16 @@
@Test
public void sameInstancesShareTheSameVmObject() throws Exception {
- VirtualMachineConfig.Builder builder =
- mInner.newVmConfigBuilder("assets/vm_config.json");
- VirtualMachineConfig normalConfig = builder.setDebugLevel(DEBUG_LEVEL_NONE).build();
- VirtualMachine vm = mInner.forceCreateNewVirtualMachine("test_vm", normalConfig);
+ VirtualMachineConfig config = mInner.newVmConfigBuilder()
+ .setPayloadBinaryPath("MicrodroidTestNativeLib.so")
+ .setDebugLevel(DEBUG_LEVEL_NONE)
+ .build();
+
+ VirtualMachine vm = mInner.forceCreateNewVirtualMachine("test_vm", config);
VirtualMachine vm2 = mInner.getVirtualMachineManager().get("test_vm");
assertThat(vm).isEqualTo(vm2);
- VirtualMachine newVm = mInner.forceCreateNewVirtualMachine("test_vm", normalConfig);
+ VirtualMachine newVm = mInner.forceCreateNewVirtualMachine("test_vm", config);
VirtualMachine newVm2 = mInner.getVirtualMachineManager().get("test_vm");
assertThat(newVm).isEqualTo(newVm2);
diff --git a/tests/testapk/src/native/crashbinary.cpp b/tests/testapk/src/native/crashbinary.cpp
new file mode 100644
index 0000000..9f80fd0
--- /dev/null
+++ b/tests/testapk/src/native/crashbinary.cpp
@@ -0,0 +1,24 @@
+/*
+ * Copyright 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+// A VM payload that crashes as soon as it starts, to allow us to exercise that error path.
+extern "C" int android_native_main(int /* argc */, char* /* argv */[]) {
+ printf("test crash!!!!\n");
+ abort();
+}
diff --git a/tests/testapk/src/native/testbinary.cpp b/tests/testapk/src/native/testbinary.cpp
index c8d07a3..422afca 100644
--- a/tests/testapk/src/native/testbinary.cpp
+++ b/tests/testapk/src/native/testbinary.cpp
@@ -181,11 +181,6 @@
setvbuf(stdout, nullptr, _IONBF, 0);
setvbuf(stderr, nullptr, _IONBF, 0);
- if (argc >= 2 && strcmp(argv[1], "crash") == 0) {
- printf("test crash!!!!\n");
- abort();
- }
-
printf("Hello Microdroid ");
for (int i = 0; i < argc; i++) {
printf("%s", argv[i]);