From f1e6a048d0de49618b379ccb148d6d6b29eb18a0 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Mon, 9 Jan 2023 15:43:29 +0000 Subject: [PATCH] Test using soong_config_module_type with singleton module type Singleton module types have some special behavior that can cause problems when trying to extend them with soong_config_module_type so this adds some tests of how they work together. Currently, the tests show that they do not work together, a follow up change will correct that. Bug: 264876909 Test: m nothing Change-Id: I250ee4e18b3c04d1c91808f55722da74b813a570 --- android/soong_config_modules_test.go | 98 +++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 9 deletions(-) diff --git a/android/soong_config_modules_test.go b/android/soong_config_modules_test.go index 32b3a1977..9ee01e92f 100644 --- a/android/soong_config_modules_test.go +++ b/android/soong_config_modules_test.go @@ -15,12 +15,10 @@ package android import ( + "fmt" "testing" ) -type soongConfigTestDefaultsModuleProperties struct { -} - type soongConfigTestDefaultsModule struct { ModuleBase DefaultsModuleBase @@ -413,10 +411,92 @@ func TestDuplicateStringValueInSoongConfigStringVariable(t *testing.T) { })).RunTest(t) } -func testConfigWithVendorVars(buildDir, bp string, fs map[string][]byte, vendorVars map[string]map[string]string) Config { - config := TestConfig(buildDir, nil, bp, fs) - - config.TestProductVariables.VendorVars = vendorVars - - return config +type soongConfigTestSingletonModule struct { + SingletonModuleBase + props soongConfigTestSingletonModuleProperties +} + +type soongConfigTestSingletonModuleProperties struct { + Fragments []struct { + Apex string + Module string + } +} + +func soongConfigTestSingletonModuleFactory() SingletonModule { + m := &soongConfigTestSingletonModule{} + m.AddProperties(&m.props) + InitAndroidModule(m) + return m +} + +func (t *soongConfigTestSingletonModule) GenerateAndroidBuildActions(ModuleContext) {} + +func (t *soongConfigTestSingletonModule) GenerateSingletonBuildActions(SingletonContext) {} + +var prepareForSoongConfigTestSingletonModule = FixtureRegisterWithContext(func(ctx RegistrationContext) { + ctx.RegisterSingletonModuleType("test_singleton", soongConfigTestSingletonModuleFactory) +}) + +func TestSoongConfigModuleSingletonModule(t *testing.T) { + bp := ` + soong_config_module_type { + name: "acme_test_singleton", + module_type: "test_singleton", + config_namespace: "acme", + bool_variables: ["coyote"], + properties: ["fragments"], + } + + acme_test_singleton { + name: "wiley", + fragments: [ + { + apex: "com.android.acme", + module: "road-runner", + }, + ], + soong_config_variables: { + coyote: { + fragments: [ + { + apex: "com.android.acme", + module: "wiley", + }, + ], + }, + }, + } + ` + + for _, test := range []struct { + coyote bool + expectedFragments string + }{ + { + coyote: false, + expectedFragments: "[{Apex:com.android.acme Module:road-runner}]", + }, + { + coyote: true, + expectedFragments: "[{Apex:com.android.acme Module:road-runner} {Apex:com.android.acme Module:wiley}]", + }, + } { + t.Run(fmt.Sprintf("coyote:%t", test.coyote), func(t *testing.T) { + GroupFixturePreparers( + PrepareForTestWithSoongConfigModuleBuildComponents, + prepareForSoongConfigTestSingletonModule, + FixtureWithRootAndroidBp(bp), + FixtureModifyProductVariables(func(variables FixtureProductVariables) { + variables.VendorVars = map[string]map[string]string{ + "acme": { + "coyote": fmt.Sprintf("%t", test.coyote), + }, + } + }), + ).ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern([]string{ + `\QDuplicate SingletonModule "test_singleton", previously used in\E`, + })).RunTest(t) + }) + } }