From d4f5d932a1f966797a0ea671af088d88019d5417 Mon Sep 17 00:00:00 2001 From: Dennis Shen Date: Tue, 31 Jan 2023 20:27:21 +0000 Subject: [PATCH] Add soong unit test for trimmed apex build BUG: b/259381334 TEST: m nothing Change-Id: I49e5d31a6f5c4f9a72a6a4b3b2ab7114b996adbc --- android/testing.go | 5 ++++ apex/apex_test.go | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/android/testing.go b/android/testing.go index e4202ae6b..fc39a9c7a 100644 --- a/android/testing.go +++ b/android/testing.go @@ -1125,6 +1125,11 @@ func SetKatiEnabledForTests(config Config) { config.katiEnabled = true } +func SetTrimmedApexEnabledForTests(config Config) { + config.productVariables.TrimmedApex = new(bool) + *config.productVariables.TrimmedApex = true +} + func AndroidMkEntriesForTest(t *testing.T, ctx *TestContext, mod blueprint.Module) []AndroidMkEntries { t.Helper() var p AndroidMkEntriesProvider diff --git a/apex/apex_test.go b/apex/apex_test.go index ea068eeba..31e848e42 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -9862,3 +9862,70 @@ func TestApexBuildsAgainstApiSurfaceStubLibraries(t *testing.T) { libcCoreVariant := result.ModuleForTests("libc.apiimport", "android_arm64_armv8-a_shared").Module() android.AssertBoolEquals(t, "core variant should link against source libc", true, hasDep(libfooCoreVariant, libcCoreVariant)) } + +func TestTrimmedApex(t *testing.T) { + bp := ` + apex { + name: "myapex", + key: "myapex.key", + native_shared_libs: ["libfoo","libbaz"], + min_sdk_version: "29", + trim_against: "mydcla", + } + apex { + name: "mydcla", + key: "myapex.key", + native_shared_libs: ["libfoo","libbar"], + min_sdk_version: "29", + file_contexts: ":myapex-file_contexts", + dynamic_common_lib_apex: true, + } + apex_key { + name: "myapex.key", + } + cc_library { + name: "libfoo", + shared_libs: ["libc"], + apex_available: ["myapex","mydcla"], + min_sdk_version: "29", + } + cc_library { + name: "libbar", + shared_libs: ["libc"], + apex_available: ["myapex","mydcla"], + min_sdk_version: "29", + } + cc_library { + name: "libbaz", + shared_libs: ["libc"], + apex_available: ["myapex","mydcla"], + min_sdk_version: "29", + } + cc_api_library { + name: "libc", + src: "libc.so", + min_sdk_version: "29", + recovery_available: true, + } + api_imports { + name: "api_imports", + shared_libs: [ + "libc", + ], + header_libs: [], + } + ` + ctx := testApex(t, bp) + module := ctx.ModuleForTests("myapex", "android_common_myapex_image") + apexRule := module.MaybeRule("apexRule") + if apexRule.Rule == nil { + t.Errorf("Expecting regular apex rule but a non regular apex rule found") + } + + ctx = testApex(t, bp, android.FixtureModifyConfig(android.SetTrimmedApexEnabledForTests)) + trimmedApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("TrimmedApexRule") + libs_to_trim := trimmedApexRule.Args["libs_to_trim"] + android.AssertStringDoesContain(t, "missing lib to trim", libs_to_trim, "libfoo") + android.AssertStringDoesContain(t, "missing lib to trim", libs_to_trim, "libbar") + android.AssertStringDoesNotContain(t, "unexpected libs in the libs to trim", libs_to_trim, "libbaz") +}