Merge "Convert apex/boot_image_test.go to use test fixtures" am: 043427b276

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1626508

Change-Id: I6cf92425772991c86653eb274c356bacb46224c9
This commit is contained in:
Paul Duffin
2021-03-22 08:34:45 +00:00
committed by Automerger Merge Worker

View File

@@ -15,7 +15,6 @@
package apex package apex
import ( import (
"reflect"
"strings" "strings"
"testing" "testing"
@@ -28,7 +27,18 @@ import (
// modules from the ART apex. // modules from the ART apex.
func TestBootImages(t *testing.T) { func TestBootImages(t *testing.T) {
ctx := testApex(t, ` result := apexFixtureFactory.Extend(
// Configure some libraries in the art and framework boot images.
dexpreopt.FixtureSetArtBootJars("com.android.art:baz", "com.android.art:quuz"),
dexpreopt.FixtureSetBootJars("platform:foo", "platform:bar"),
filesForSdkLibrary.AddToFixture(),
// Some additional files needed for the art apex.
android.FixtureMergeMockFs(android.MockFS{
"com.android.art.avbpubkey": nil,
"com.android.art.pem": nil,
"system/sepolicy/apex/com.android.art-file_contexts": nil,
}),
).RunTestWithBp(t, `
java_sdk_library { java_sdk_library {
name: "foo", name: "foo",
srcs: ["b.java"], srcs: ["b.java"],
@@ -83,20 +93,10 @@ func TestBootImages(t *testing.T) {
image_name: "boot", image_name: "boot",
} }
`, `,
// Configure some libraries in the art and framework boot images.
withArtBootImageJars("com.android.art:baz", "com.android.art:quuz"),
withFrameworkBootImageJars("platform:foo", "platform:bar"),
withFiles(filesForSdkLibrary),
// Some additional files needed for the art apex.
withFiles(map[string][]byte{
"com.android.art.avbpubkey": nil,
"com.android.art.pem": nil,
"system/sepolicy/apex/com.android.art-file_contexts": nil,
}),
) )
// Make sure that the framework-boot-image is using the correct configuration. // Make sure that the framework-boot-image is using the correct configuration.
checkBootImage(t, ctx, "framework-boot-image", "platform:foo,platform:bar", ` checkBootImage(t, result, "framework-boot-image", "platform:foo,platform:bar", `
test_device/dex_bootjars/android/system/framework/arm/boot-foo.art test_device/dex_bootjars/android/system/framework/arm/boot-foo.art
test_device/dex_bootjars/android/system/framework/arm/boot-foo.oat test_device/dex_bootjars/android/system/framework/arm/boot-foo.oat
test_device/dex_bootjars/android/system/framework/arm/boot-foo.vdex test_device/dex_bootjars/android/system/framework/arm/boot-foo.vdex
@@ -112,7 +112,7 @@ test_device/dex_bootjars/android/system/framework/arm64/boot-bar.vdex
`) `)
// Make sure that the art-boot-image is using the correct configuration. // Make sure that the art-boot-image is using the correct configuration.
checkBootImage(t, ctx, "art-boot-image", "com.android.art:baz,com.android.art:quuz", ` checkBootImage(t, result, "art-boot-image", "com.android.art:baz,com.android.art:quuz", `
test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art
test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat
test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex
@@ -128,16 +128,14 @@ test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.vde
`) `)
} }
func checkBootImage(t *testing.T, ctx *android.TestContext, moduleName string, expectedConfiguredModules string, expectedBootImageFiles string) { func checkBootImage(t *testing.T, result *android.TestResult, moduleName string, expectedConfiguredModules string, expectedBootImageFiles string) {
t.Helper() t.Helper()
bootImage := ctx.ModuleForTests(moduleName, "android_common").Module().(*java.BootImageModule) bootImage := result.ModuleForTests(moduleName, "android_common").Module().(*java.BootImageModule)
bootImageInfo := ctx.ModuleProvider(bootImage, java.BootImageInfoProvider).(java.BootImageInfo) bootImageInfo := result.ModuleProvider(bootImage, java.BootImageInfoProvider).(java.BootImageInfo)
modules := bootImageInfo.Modules() modules := bootImageInfo.Modules()
if actual := modules.String(); actual != expectedConfiguredModules { android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String())
t.Errorf("invalid modules for %s: expected %q, actual %q", moduleName, expectedConfiguredModules, actual)
}
// Get a list of all the paths in the boot image sorted by arch type. // Get a list of all the paths in the boot image sorted by arch type.
allPaths := []string{} allPaths := []string{}
@@ -149,39 +147,15 @@ func checkBootImage(t *testing.T, ctx *android.TestContext, moduleName string, e
} }
} }
} }
if expected, actual := strings.TrimSpace(expectedBootImageFiles), strings.TrimSpace(strings.Join(allPaths, "\n")); !reflect.DeepEqual(expected, actual) {
t.Errorf("invalid paths for %s: expected \n%s, actual \n%s", moduleName, expected, actual)
}
}
func modifyDexpreoptConfig(configModifier func(dexpreoptConfig *dexpreopt.GlobalConfig)) func(fs map[string][]byte, config android.Config) { android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootImageFiles, strings.Join(allPaths, "\n"))
return func(fs map[string][]byte, config android.Config) {
// Initialize the dexpreopt GlobalConfig to an empty structure. This has no effect if it has
// already been set.
pathCtx := android.PathContextForTesting(config)
dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx)
dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig)
// Retrieve the existing configuration and modify it.
dexpreoptConfig = dexpreopt.GetGlobalConfig(pathCtx)
configModifier(dexpreoptConfig)
}
}
func withArtBootImageJars(bootJars ...string) func(fs map[string][]byte, config android.Config) {
return modifyDexpreoptConfig(func(dexpreoptConfig *dexpreopt.GlobalConfig) {
dexpreoptConfig.ArtApexJars = android.CreateTestConfiguredJarList(bootJars)
})
}
func withFrameworkBootImageJars(bootJars ...string) func(fs map[string][]byte, config android.Config) {
return modifyDexpreoptConfig(func(dexpreoptConfig *dexpreopt.GlobalConfig) {
dexpreoptConfig.BootJars = android.CreateTestConfiguredJarList(bootJars)
})
} }
func TestBootImageInApex(t *testing.T) { func TestBootImageInApex(t *testing.T) {
ctx := testApex(t, ` result := apexFixtureFactory.Extend(
// Configure some libraries in the framework boot image.
dexpreopt.FixtureSetBootJars("platform:foo", "platform:bar"),
).RunTestWithBp(t, `
apex { apex {
name: "myapex", name: "myapex",
key: "myapex.key", key: "myapex.key",
@@ -216,12 +190,9 @@ func TestBootImageInApex(t *testing.T) {
"myapex", "myapex",
], ],
} }
`, `)
// Configure some libraries in the framework boot image.
withFrameworkBootImageJars("platform:foo", "platform:bar"),
)
ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
"javalib/arm/boot-bar.art", "javalib/arm/boot-bar.art",
"javalib/arm/boot-bar.oat", "javalib/arm/boot-bar.oat",
"javalib/arm/boot-bar.vdex", "javalib/arm/boot-bar.vdex",