From 4495f84f684cb6dad137ce4f3c9926ac79768f74 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Tue, 25 Apr 2023 16:39:59 +0900 Subject: [PATCH] Add allowed-deps tests These tests capture - track updatable apexes - do not track apex-only modules - track transitive deps - track external deps (with mark) Bug: 274041915 Test: m nothing Change-Id: I629015f5aa4a1a7627d0ba6d92fd42bb99c96287 --- apex/apex_singleton.go | 6 ++- apex/apex_test.go | 87 ++++++++++++++++++++++++++++++++++++++++++ apex/testing.go | 1 + 3 files changed, 93 insertions(+), 1 deletion(-) diff --git a/apex/apex_singleton.go b/apex/apex_singleton.go index 158194937..ebc35cf5c 100644 --- a/apex/apex_singleton.go +++ b/apex/apex_singleton.go @@ -23,7 +23,11 @@ import ( ) func init() { - android.RegisterSingletonType("apex_depsinfo_singleton", apexDepsInfoSingletonFactory) + registerApexDepsInfoComponents(android.InitRegistrationContext) +} + +func registerApexDepsInfoComponents(ctx android.RegistrationContext) { + ctx.RegisterSingletonType("apex_depsinfo_singleton", apexDepsInfoSingletonFactory) } type apexDepsInfoSingleton struct { diff --git a/apex/apex_test.go b/apex/apex_test.go index d08d2466e..31b7ef7ff 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -1980,6 +1980,93 @@ func TestApexMinSdkVersion_InVendorApex(t *testing.T) { android.AssertStringDoesContain(t, "cflags", cflags, "-target aarch64-linux-android29") } +func TestTrackAllowedDeps(t *testing.T) { + ctx := testApex(t, ` + apex { + name: "myapex", + key: "myapex.key", + updatable: true, + native_shared_libs: [ + "mylib", + "yourlib", + ], + min_sdk_version: "29", + } + + apex { + name: "myapex2", + key: "myapex.key", + updatable: false, + native_shared_libs: ["yourlib"], + } + + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + + cc_library { + name: "mylib", + srcs: ["mylib.cpp"], + shared_libs: ["libbar"], + min_sdk_version: "29", + apex_available: ["myapex"], + } + + cc_library { + name: "libbar", + stubs: { versions: ["29", "30"] }, + } + + cc_library { + name: "yourlib", + srcs: ["mylib.cpp"], + min_sdk_version: "29", + apex_available: ["myapex", "myapex2", "//apex_available:platform"], + } + `, withFiles(android.MockFS{ + "packages/modules/common/build/allowed_deps.txt": nil, + })) + + depsinfo := ctx.SingletonForTests("apex_depsinfo_singleton") + inputs := depsinfo.Rule("generateApexDepsInfoFilesRule").BuildParams.Inputs.Strings() + android.AssertStringListContains(t, "updatable myapex should generate depsinfo file", inputs, + "out/soong/.intermediates/myapex/android_common_myapex_image/depsinfo/flatlist.txt") + android.AssertStringListDoesNotContain(t, "non-updatable myapex2 should not generate depsinfo file", inputs, + "out/soong/.intermediates/myapex2/android_common_myapex2_image/depsinfo/flatlist.txt") + + myapex := ctx.ModuleForTests("myapex", "android_common_myapex_image") + flatlist := strings.Split(myapex.Output("depsinfo/flatlist.txt").BuildParams.Args["content"], "\\n") + android.AssertStringListContains(t, "deps with stubs should be tracked in depsinfo as external dep", + flatlist, "libbar(minSdkVersion:(no version)) (external)") + android.AssertStringListDoesNotContain(t, "do not track if not available for platform", + flatlist, "mylib:(minSdkVersion:29)") + android.AssertStringListContains(t, "track platform-available lib", + flatlist, "yourlib(minSdkVersion:29)") +} + +func TestTrackAllowedDeps_SkipWithoutAllowedDepsTxt(t *testing.T) { + ctx := testApex(t, ` + apex { + name: "myapex", + key: "myapex.key", + updatable: true, + min_sdk_version: "29", + } + + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + `) + depsinfo := ctx.SingletonForTests("apex_depsinfo_singleton") + if nil != depsinfo.MaybeRule("generateApexDepsInfoFilesRule").Output { + t.Error("apex_depsinfo_singleton shouldn't run when allowed_deps.txt doesn't exist") + } +} + func TestPlatformUsesLatestStubsFromApexes(t *testing.T) { ctx := testApex(t, ` apex { diff --git a/apex/testing.go b/apex/testing.go index 69bd73e5d..3b200f05b 100644 --- a/apex/testing.go +++ b/apex/testing.go @@ -19,6 +19,7 @@ import "android/soong/android" var PrepareForTestWithApexBuildComponents = android.GroupFixturePreparers( android.FixtureRegisterWithContext(registerApexBuildComponents), android.FixtureRegisterWithContext(registerApexKeyBuildComponents), + android.FixtureRegisterWithContext(registerApexDepsInfoComponents), // Additional files needed in tests that disallow non-existent source files. // This includes files that are needed by all, or at least most, instances of an apex module type. android.MockFS{