diff options
author | 2021-09-09 08:09:41 +0000 | |
---|---|---|
committer | 2021-09-15 09:01:07 +0000 | |
commit | ca9bc98e0cfe9a519cfdd13450a68f1ed7ad5b02 (patch) | |
tree | ddf50ea990f4c9a1e00db3adde1b5dca22276be1 /java/dexpreopt_test.go | |
parent | 709f02707d4c130f0b633de9d7134f9f34dbf569 (diff) |
Preopt APEX system server jars.
The path to the artifacts will in the form of
/system/framework/oat/<arch>/<encoded-jar-path>@classes.{odex,vdex,art},
where <encoded-jar-path> is the path to the jar file with "/" replaced
by "@". For example,
/system/framework/oat/x86_64/apex@com.android.art@javalib@service-art.jar@classes.odex
There will be a follow-up CL to update ART runtime to recognize
artifacts in that path.
Test: m com.android.art
Bug: 194150908
Change-Id: Ic89fd63c4b1cd565684cead83fc91dae3bc97a4c
Diffstat (limited to 'java/dexpreopt_test.go')
-rw-r--r-- | java/dexpreopt_test.go | 227 |
1 files changed, 222 insertions, 5 deletions
diff --git a/java/dexpreopt_test.go b/java/dexpreopt_test.go index 8dc7b798a..1c1070add 100644 --- a/java/dexpreopt_test.go +++ b/java/dexpreopt_test.go @@ -17,6 +17,7 @@ package java import ( "fmt" "runtime" + "strings" "testing" "android/soong/android" @@ -24,11 +25,17 @@ import ( "android/soong/dexpreopt" ) +func init() { + RegisterFakeRuntimeApexMutator() +} + func TestDexpreoptEnabled(t *testing.T) { tests := []struct { - name string - bp string - enabled bool + name string + bp string + moduleName string + apexVariant bool + enabled bool }{ { name: "app", @@ -148,13 +155,81 @@ func TestDexpreoptEnabled(t *testing.T) { }`, enabled: true, }, + { + name: "apex variant", + bp: ` + java_library { + name: "foo", + installable: true, + srcs: ["a.java"], + apex_available: ["com.android.apex1"], + }`, + apexVariant: true, + enabled: false, + }, + { + name: "apex variant of apex system server jar", + bp: ` + java_library { + name: "service-foo", + installable: true, + srcs: ["a.java"], + apex_available: ["com.android.apex1"], + }`, + moduleName: "service-foo", + apexVariant: true, + enabled: true, + }, + { + name: "apex variant of prebuilt apex system server jar", + bp: ` + java_library { + name: "prebuilt_service-foo", + installable: true, + srcs: ["a.java"], + apex_available: ["com.android.apex1"], + }`, + moduleName: "prebuilt_service-foo", + apexVariant: true, + enabled: true, + }, + { + name: "platform variant of apex system server jar", + bp: ` + java_library { + name: "service-foo", + installable: true, + srcs: ["a.java"], + apex_available: ["com.android.apex1"], + }`, + moduleName: "service-foo", + apexVariant: false, + enabled: false, + }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - ctx, _ := testJava(t, test.bp) + preparers := android.GroupFixturePreparers( + PrepareForTestWithJavaDefaultModules, + PrepareForTestWithFakeApexMutator, + dexpreopt.FixtureSetApexSystemServerJars("com.android.apex1:service-foo"), + ) + + result := preparers.RunTestWithBp(t, test.bp) + ctx := result.TestContext + + moduleName := "foo" + if test.moduleName != "" { + moduleName = test.moduleName + } + + variant := "android_common" + if test.apexVariant { + variant += "_apex1000" + } - dexpreopt := ctx.ModuleForTests("foo", "android_common").MaybeRule("dexpreopt") + dexpreopt := ctx.ModuleForTests(moduleName, variant).MaybeRule("dexpreopt") enabled := dexpreopt.Rule != nil if enabled != test.enabled { @@ -220,3 +295,145 @@ func TestDex2oatToolDeps(t *testing.T) { testDex2oatToolDep(true, true, true, prebuiltDex2oatPath) testDex2oatToolDep(false, true, false, prebuiltDex2oatPath) } + +func TestDexpreoptBuiltInstalledForApex(t *testing.T) { + preparers := android.GroupFixturePreparers( + PrepareForTestWithJavaDefaultModules, + PrepareForTestWithFakeApexMutator, + dexpreopt.FixtureSetApexSystemServerJars("com.android.apex1:service-foo"), + ) + + // An APEX system server jar. + result := preparers.RunTestWithBp(t, ` + java_library { + name: "service-foo", + installable: true, + srcs: ["a.java"], + apex_available: ["com.android.apex1"], + }`) + ctx := result.TestContext + module := ctx.ModuleForTests("service-foo", "android_common_apex1000") + library := module.Module().(*Library) + + installs := library.dexpreopter.DexpreoptBuiltInstalledForApex() + + android.AssertIntEquals(t, "install count", 2, len(installs)) + + android.AssertStringEquals(t, "installs[0] FullModuleName", + "service-foo-dexpreopt-arm64-apex@com.android.apex1@javalib@service-foo.jar@classes.odex", + installs[0].FullModuleName()) + + android.AssertStringEquals(t, "installs[0] SubModuleName", + "-dexpreopt-arm64-apex@com.android.apex1@javalib@service-foo.jar@classes.odex", + installs[0].SubModuleName()) + + android.AssertStringEquals(t, "installs[1] FullModuleName", + "service-foo-dexpreopt-arm64-apex@com.android.apex1@javalib@service-foo.jar@classes.vdex", + installs[1].FullModuleName()) + + android.AssertStringEquals(t, "installs[1] SubModuleName", + "-dexpreopt-arm64-apex@com.android.apex1@javalib@service-foo.jar@classes.vdex", + installs[1].SubModuleName()) + + // Not an APEX system server jar. + result = preparers.RunTestWithBp(t, ` + java_library { + name: "foo", + installable: true, + srcs: ["a.java"], + }`) + ctx = result.TestContext + module = ctx.ModuleForTests("foo", "android_common") + library = module.Module().(*Library) + + installs = library.dexpreopter.DexpreoptBuiltInstalledForApex() + + android.AssertIntEquals(t, "install count", 0, len(installs)) +} + +func filterDexpreoptEntriesList(entriesList []android.AndroidMkEntries) []android.AndroidMkEntries { + var results []android.AndroidMkEntries + for _, entries := range entriesList { + if strings.Contains(entries.EntryMap["LOCAL_MODULE"][0], "-dexpreopt-") { + results = append(results, entries) + } + } + return results +} + +func verifyEntries(t *testing.T, message string, expectedModule string, + expectedPrebuiltModuleFile string, expectedModulePath string, expectedInstalledModuleStem string, + entries android.AndroidMkEntries) { + android.AssertStringEquals(t, message+" LOCAL_MODULE", expectedModule, + entries.EntryMap["LOCAL_MODULE"][0]) + + android.AssertStringEquals(t, message+" LOCAL_MODULE_CLASS", "ETC", + entries.EntryMap["LOCAL_MODULE_CLASS"][0]) + + android.AssertStringDoesContain(t, message+" LOCAL_PREBUILT_MODULE_FILE", + entries.EntryMap["LOCAL_PREBUILT_MODULE_FILE"][0], expectedPrebuiltModuleFile) + + android.AssertStringDoesContain(t, message+" LOCAL_MODULE_PATH", + entries.EntryMap["LOCAL_MODULE_PATH"][0], expectedModulePath) + + android.AssertStringEquals(t, message+" LOCAL_INSTALLED_MODULE_STEM", + expectedInstalledModuleStem, entries.EntryMap["LOCAL_INSTALLED_MODULE_STEM"][0]) + + android.AssertStringEquals(t, message+" LOCAL_NOT_AVAILABLE_FOR_PLATFORM", + "false", entries.EntryMap["LOCAL_NOT_AVAILABLE_FOR_PLATFORM"][0]) +} + +func TestAndroidMkEntriesForApex(t *testing.T) { + preparers := android.GroupFixturePreparers( + PrepareForTestWithJavaDefaultModules, + PrepareForTestWithFakeApexMutator, + dexpreopt.FixtureSetApexSystemServerJars("com.android.apex1:service-foo"), + ) + + // An APEX system server jar. + result := preparers.RunTestWithBp(t, ` + java_library { + name: "service-foo", + installable: true, + srcs: ["a.java"], + apex_available: ["com.android.apex1"], + }`) + ctx := result.TestContext + module := ctx.ModuleForTests("service-foo", "android_common_apex1000") + + entriesList := android.AndroidMkEntriesForTest(t, ctx, module.Module()) + entriesList = filterDexpreoptEntriesList(entriesList) + + android.AssertIntEquals(t, "entries count", 2, len(entriesList)) + + verifyEntries(t, + "entriesList[0]", + "service-foo-dexpreopt-arm64-apex@com.android.apex1@javalib@service-foo.jar@classes.odex", + "/dexpreopt/oat/arm64/javalib.odex", + "/system/framework/oat/arm64", + "apex@com.android.apex1@javalib@service-foo.jar@classes.odex", + entriesList[0]) + + verifyEntries(t, + "entriesList[1]", + "service-foo-dexpreopt-arm64-apex@com.android.apex1@javalib@service-foo.jar@classes.vdex", + "/dexpreopt/oat/arm64/javalib.vdex", + "/system/framework/oat/arm64", + "apex@com.android.apex1@javalib@service-foo.jar@classes.vdex", + entriesList[1]) + + // Not an APEX system server jar. + result = preparers.RunTestWithBp(t, ` + java_library { + name: "foo", + installable: true, + srcs: ["a.java"], + }`) + ctx = result.TestContext + module = ctx.ModuleForTests("foo", "android_common") + + entriesList = android.AndroidMkEntriesForTest(t, ctx, module.Module()) + entriesList = filterDexpreoptEntriesList(entriesList) + + android.AssertIntEquals(t, "entries count", 0, len(entriesList)) +} |