Make apex/boot_image_test.go more realistic

Previously it was unrealistic because the "boot" image cannot be added
to an apex (because it references modules from multiple different
apexes). Only the "art" image can be added to an apex. So, this change
switches to use the "art" image which requires the apex name is changed
to "com.android.art".

This change also adds an equivalent test for prebuilt_boot_image as
well as a check of the module dependencies for the mybootimage module.

Bug: 177892522
Test: m nothing
Change-Id: I20089b02c80bedc072dbb950dce09bc4e8397f3a
diff --git a/apex/boot_image_test.go b/apex/boot_image_test.go
index 91b45fc..debeee8 100644
--- a/apex/boot_image_test.go
+++ b/apex/boot_image_test.go
@@ -160,24 +160,29 @@
 	android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootImageFiles, strings.Join(allPaths, "\n"))
 }
 
-func TestBootImageInApex(t *testing.T) {
+func TestBootImageInArtApex(t *testing.T) {
 	result := android.GroupFixturePreparers(
 		prepareForTestWithBootImage,
-		prepareForTestWithMyapex,
-		// Configure some libraries in the framework boot image.
-		dexpreopt.FixtureSetBootJars("platform:foo", "platform:bar"),
+		prepareForTestWithArtApex,
+
+		// Configure some libraries in the art boot image.
+		dexpreopt.FixtureSetArtBootJars("com.android.art:foo", "com.android.art:bar"),
 	).RunTestWithBp(t, `
 		apex {
-			name: "myapex",
-			key: "myapex.key",
+			name: "com.android.art",
+			key: "com.android.art.key",
 			boot_images: [
 				"mybootimage",
 			],
+			java_libs: [
+				"foo",
+				"bar",
+			],
 			updatable: false,
 		}
 
 		apex_key {
-			name: "myapex.key",
+			name: "com.android.art.key",
 			public_key: "testkey.avbpubkey",
 			private_key: "testkey.pem",
 		}
@@ -186,52 +191,123 @@
 			name: "foo",
 			srcs: ["b.java"],
 			installable: true,
+			apex_available: [
+				"com.android.art",
+			],
 		}
 
 		java_library {
 			name: "bar",
 			srcs: ["b.java"],
 			installable: true,
+			apex_available: [
+				"com.android.art",
+			],
 		}
 
 		boot_image {
 			name: "mybootimage",
-			image_name: "boot",
+			image_name: "art",
 			apex_available: [
-				"myapex",
+				"com.android.art",
 			],
 		}
 
 		// Make sure that a preferred prebuilt doesn't affect the apex.
 		prebuilt_boot_image {
 			name: "mybootimage",
-			image_name: "boot",
+			image_name: "art",
 			prefer: true,
 			apex_available: [
-				"myapex",
+				"com.android.art",
 			],
 		}
 	`)
 
-	ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
+	ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
+		"javalib/arm/boot.art",
+		"javalib/arm/boot.oat",
+		"javalib/arm/boot.vdex",
 		"javalib/arm/boot-bar.art",
 		"javalib/arm/boot-bar.oat",
 		"javalib/arm/boot-bar.vdex",
-		"javalib/arm/boot-foo.art",
-		"javalib/arm/boot-foo.oat",
-		"javalib/arm/boot-foo.vdex",
+		"javalib/arm64/boot.art",
+		"javalib/arm64/boot.oat",
+		"javalib/arm64/boot.vdex",
 		"javalib/arm64/boot-bar.art",
 		"javalib/arm64/boot-bar.oat",
 		"javalib/arm64/boot-bar.vdex",
-		"javalib/arm64/boot-foo.art",
-		"javalib/arm64/boot-foo.oat",
-		"javalib/arm64/boot-foo.vdex",
+		"javalib/bar.jar",
+		"javalib/foo.jar",
 	})
 
-	java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
-		`myapex.key`,
+	java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
+		`bar`,
+		`com.android.art.key`,
+		`foo`,
 		`mybootimage`,
 	})
 }
 
+func TestBootImageInPrebuiltArtApex(t *testing.T) {
+	result := android.GroupFixturePreparers(
+		prepareForTestWithBootImage,
+		prepareForTestWithArtApex,
+
+		android.FixtureMergeMockFs(android.MockFS{
+			"com.android.art-arm64.apex": nil,
+			"com.android.art-arm.apex":   nil,
+		}),
+
+		// Configure some libraries in the art boot image.
+		dexpreopt.FixtureSetArtBootJars("com.android.art:foo", "com.android.art:bar"),
+	).RunTestWithBp(t, `
+		prebuilt_apex {
+			name: "com.android.art",
+			arch: {
+				arm64: {
+					src: "com.android.art-arm64.apex",
+				},
+				arm: {
+					src: "com.android.art-arm.apex",
+				},
+			},
+			exported_java_libs: ["foo", "bar"],
+		}
+
+		java_import {
+			name: "foo",
+			jars: ["foo.jar"],
+			apex_available: [
+				"com.android.art",
+			],
+		}
+
+		java_import {
+			name: "bar",
+			jars: ["bar.jar"],
+			apex_available: [
+				"com.android.art",
+			],
+		}
+
+		prebuilt_boot_image {
+			name: "mybootimage",
+			image_name: "art",
+			apex_available: [
+				"com.android.art",
+			],
+		}
+	`)
+
+	java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common", []string{
+		`prebuilt_bar`,
+		`prebuilt_foo`,
+	})
+
+	java.CheckModuleDependencies(t, result.TestContext, "mybootimage", "android_common", []string{
+		`dex2oatd`,
+	})
+}
+
 // TODO(b/177892522) - add test for host apex.