Pass "shared libs" apexes
Signing key tests rely on "raw configs" and custom-built payload image. When passing "adbd" and "statsd" apexes to VM, "shared libs" apexes should be passed together but the custom-built payload image was missing "shared libs" apexes. This fixes the test by passing "shared libs" apexes to VM. Note that virtualizationservice handles this already. Bug: 243460563 Test: atest MicrodroidHostTestCases Change-Id: I4208c9d117f5cb996d511d8fd47da73c134ed0f7
This commit is contained in:
parent
61c6fd7921
commit
70225b3297
|
@ -90,11 +90,3 @@ android_filesystem {
|
||||||
],
|
],
|
||||||
type: "cpio",
|
type: "cpio",
|
||||||
}
|
}
|
||||||
|
|
||||||
genrule {
|
|
||||||
name: "test-payload-metadata",
|
|
||||||
tools: ["mk_payload"],
|
|
||||||
cmd: "$(location mk_payload) --metadata-only $(in) $(out)",
|
|
||||||
srcs: ["test-payload-metadata-config.json"],
|
|
||||||
out: ["test-payload-metadata.img"],
|
|
||||||
}
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ java_test_host {
|
||||||
":microdroid_general_sepolicy.conf",
|
":microdroid_general_sepolicy.conf",
|
||||||
":test.com.android.virt.pem",
|
":test.com.android.virt.pem",
|
||||||
":test2.com.android.virt.pem",
|
":test2.com.android.virt.pem",
|
||||||
":test-payload-metadata",
|
|
||||||
],
|
],
|
||||||
data_native_bins: [
|
data_native_bins: [
|
||||||
"sepolicy-analyze",
|
"sepolicy-analyze",
|
||||||
|
@ -32,6 +31,7 @@ java_test_host {
|
||||||
"img2simg",
|
"img2simg",
|
||||||
"lpmake",
|
"lpmake",
|
||||||
"lpunpack",
|
"lpunpack",
|
||||||
|
"mk_payload",
|
||||||
"sign_virt_apex",
|
"sign_virt_apex",
|
||||||
"simg2img",
|
"simg2img",
|
||||||
],
|
],
|
||||||
|
|
|
@ -32,6 +32,8 @@ import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.junit.Assume.assumeTrue;
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
import android.cts.statsdatom.lib.ConfigUtils;
|
import android.cts.statsdatom.lib.ConfigUtils;
|
||||||
import android.cts.statsdatom.lib.ReportUtils;
|
import android.cts.statsdatom.lib.ReportUtils;
|
||||||
|
|
||||||
|
@ -139,6 +141,53 @@ public class MicrodroidTestCase extends MicrodroidHostTestCaseBase {
|
||||||
return new JSONObject(Map.of("label", label, "path", path));
|
return new JSONObject(Map.of("label", label, "path", path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createPayloadMetadata(List<ActiveApexInfo> apexes, File payloadMetadata)
|
||||||
|
throws Exception {
|
||||||
|
// mk_payload's config
|
||||||
|
File configFile = new File(payloadMetadata.getParentFile(), "payload_config.json");
|
||||||
|
JSONObject config = new JSONObject();
|
||||||
|
config.put(
|
||||||
|
"apk",
|
||||||
|
new JSONObject(Map.of("name", "microdroid-apk", "path", "", "idsig_path", "")));
|
||||||
|
config.put("payload_config_path", "/mnt/apk/assets/vm_config.json");
|
||||||
|
config.put(
|
||||||
|
"apexes",
|
||||||
|
new JSONArray(
|
||||||
|
apexes.stream()
|
||||||
|
.map(apex -> new JSONObject(Map.of("name", apex.name, "path", "")))
|
||||||
|
.collect(toList())));
|
||||||
|
FileUtil.writeToFile(config.toString(), configFile);
|
||||||
|
|
||||||
|
File mkPayload = findTestFile("mk_payload");
|
||||||
|
RunUtil runUtil = new RunUtil();
|
||||||
|
// Set the parent dir on the PATH (e.g. <workdir>/bin)
|
||||||
|
String separator = System.getProperty("path.separator");
|
||||||
|
String path = mkPayload.getParentFile().getPath() + separator + System.getenv("PATH");
|
||||||
|
runUtil.setEnvVariable("PATH", path);
|
||||||
|
|
||||||
|
List<String> command = new ArrayList<String>();
|
||||||
|
command.add("mk_payload");
|
||||||
|
command.add("--metadata-only");
|
||||||
|
command.add(configFile.toString());
|
||||||
|
command.add(payloadMetadata.toString());
|
||||||
|
|
||||||
|
CommandResult result =
|
||||||
|
runUtil.runTimedCmd(
|
||||||
|
// mk_payload should run fast enough
|
||||||
|
5 * 1000, "/bin/bash", "-c", String.join(" ", command));
|
||||||
|
String out = result.getStdout();
|
||||||
|
String err = result.getStderr();
|
||||||
|
assertWithMessage(
|
||||||
|
"creating payload metadata failed:\n\tout: "
|
||||||
|
+ out
|
||||||
|
+ "\n\terr: "
|
||||||
|
+ err
|
||||||
|
+ "\n")
|
||||||
|
.about(command_results())
|
||||||
|
.that(result)
|
||||||
|
.isSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
private void resignVirtApex(File virtApexDir, File signingKey, Map<String, File> keyOverrides) {
|
private void resignVirtApex(File virtApexDir, File signingKey, Map<String, File> keyOverrides) {
|
||||||
File signVirtApex = findTestFile("sign_virt_apex");
|
File signVirtApex = findTestFile("sign_virt_apex");
|
||||||
|
|
||||||
|
@ -193,10 +242,12 @@ public class MicrodroidTestCase extends MicrodroidHostTestCaseBase {
|
||||||
static class ActiveApexInfo {
|
static class ActiveApexInfo {
|
||||||
public String name;
|
public String name;
|
||||||
public String path;
|
public String path;
|
||||||
|
public boolean provideSharedApexLibs;
|
||||||
|
|
||||||
ActiveApexInfo(String name, String path) {
|
ActiveApexInfo(String name, String path, boolean provideSharedApexLibs) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
|
this.provideSharedApexLibs = provideSharedApexLibs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,6 +266,10 @@ public class MicrodroidTestCase extends MicrodroidHostTestCaseBase {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<ActiveApexInfo> getSharedLibApexes() {
|
||||||
|
return mList.stream().filter(info -> info.provideSharedApexLibs).collect(toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ActiveApexInfoList getActiveApexInfoList() throws Exception {
|
private ActiveApexInfoList getActiveApexInfoList() throws Exception {
|
||||||
|
@ -229,10 +284,10 @@ public class MicrodroidTestCase extends MicrodroidHostTestCaseBase {
|
||||||
String uri, String localName, String qName, Attributes attributes) {
|
String uri, String localName, String qName, Attributes attributes) {
|
||||||
if (localName.equals("apex-info")
|
if (localName.equals("apex-info")
|
||||||
&& attributes.getValue("isActive").equals("true")) {
|
&& attributes.getValue("isActive").equals("true")) {
|
||||||
list.add(
|
String name = attributes.getValue("moduleName");
|
||||||
new ActiveApexInfo(
|
String path = attributes.getValue("modulePath");
|
||||||
attributes.getValue("moduleName"),
|
String sharedApex = attributes.getValue("provideSharedApexLibs");
|
||||||
attributes.getValue("modulePath")));
|
list.add(new ActiveApexInfo(name, path, "true".equals(sharedApex)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -277,14 +332,11 @@ public class MicrodroidTestCase extends MicrodroidHostTestCaseBase {
|
||||||
instanceImgPath,
|
instanceImgPath,
|
||||||
Integer.toString(10 * 1024 * 1024));
|
Integer.toString(10 * 1024 * 1024));
|
||||||
|
|
||||||
// payload-metadata is prepared on host with the two APEXes and APK
|
// payload-metadata is created on device
|
||||||
final String payloadMetadataPath = TEST_ROOT + "payload-metadata.img";
|
final String payloadMetadataPath = TEST_ROOT + "payload-metadata.img";
|
||||||
getDevice().pushFile(findTestFile("test-payload-metadata.img"), payloadMetadataPath);
|
|
||||||
|
|
||||||
// get paths to the two APEXes required for the VM.
|
// Load /apex/apex-info-list.xml to get paths to APEXes required for the VM.
|
||||||
ActiveApexInfoList list = getActiveApexInfoList();
|
ActiveApexInfoList list = getActiveApexInfoList();
|
||||||
final String statsdApexPath = list.get("com.android.os.statsd").path;
|
|
||||||
final String adbdApexPath = list.get("com.android.adbd").path;
|
|
||||||
|
|
||||||
// Since Java APP can't start a VM with a custom image, here, we start a VM using `vm run`
|
// Since Java APP can't start a VM with a custom image, here, we start a VM using `vm run`
|
||||||
// command with a VM Raw config which is equiv. to what virtualizationservice creates with
|
// command with a VM Raw config which is equiv. to what virtualizationservice creates with
|
||||||
|
@ -325,19 +377,26 @@ public class MicrodroidTestCase extends MicrodroidHostTestCaseBase {
|
||||||
|
|
||||||
// Add payload image disk with partitions:
|
// Add payload image disk with partitions:
|
||||||
// - payload-metadata
|
// - payload-metadata
|
||||||
// - apexes: com.android.os.statsd, com.android.adbd
|
// - apexes: com.android.os.statsd, com.android.adbd, [sharedlib apex](optional)
|
||||||
// - apk and idsig
|
// - apk and idsig
|
||||||
disks.put(
|
List<ActiveApexInfo> apexesForVm = new ArrayList<>();
|
||||||
new JSONObject()
|
apexesForVm.add(list.get("com.android.os.statsd"));
|
||||||
.put("writable", false)
|
apexesForVm.add(list.get("com.android.adbd"));
|
||||||
.put(
|
apexesForVm.addAll(list.getSharedLibApexes());
|
||||||
"partitions",
|
|
||||||
new JSONArray()
|
final JSONArray partitions = new JSONArray();
|
||||||
.put(newPartition("payload-metadata", payloadMetadataPath))
|
partitions.put(newPartition("payload-metadata", payloadMetadataPath));
|
||||||
.put(newPartition("com.android.os.statsd", statsdApexPath))
|
for (ActiveApexInfo apex : apexesForVm) {
|
||||||
.put(newPartition("com.android.adbd", adbdApexPath))
|
partitions.put(newPartition(apex.name, apex.path));
|
||||||
.put(newPartition("microdroid-apk", apkPath))
|
}
|
||||||
.put(newPartition("microdroid-apk-idsig", idSigPath))));
|
partitions
|
||||||
|
.put(newPartition("microdroid-apk", apkPath))
|
||||||
|
.put(newPartition("microdroid-apk-idsig", idSigPath));
|
||||||
|
disks.put(new JSONObject().put("writable", false).put("partitions", partitions));
|
||||||
|
|
||||||
|
final File localPayloadMetadata = new File(virtApexDir, "payload-metadata.img");
|
||||||
|
createPayloadMetadata(apexesForVm, localPayloadMetadata);
|
||||||
|
getDevice().pushFile(localPayloadMetadata, payloadMetadataPath);
|
||||||
|
|
||||||
config.put("protected", isProtected);
|
config.put("protected", isProtected);
|
||||||
|
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
{
|
|
||||||
"_comment": "This file is to create a payload-metadata partition for payload.img which is for MicrodroidTestApp to run with assets/vm_config.json",
|
|
||||||
"apexes": [
|
|
||||||
{
|
|
||||||
"name": "com.android.os.statsd",
|
|
||||||
"path": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.android.adbd",
|
|
||||||
"path": ""
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"apk": {
|
|
||||||
"name": "microdroid-apk",
|
|
||||||
"path": "",
|
|
||||||
"idsig_path": ""
|
|
||||||
},
|
|
||||||
"payload_config_path": "/mnt/apk/assets/vm_config.json"
|
|
||||||
}
|
|
Loading…
Reference in New Issue