From 7da471f3ab659f329b2ab95f4ae932a4857d59a1 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 16 Aug 2024 09:21:18 -0700 Subject: [PATCH] Add test for interactions between product variables and arch variant properties Add a test that verifies that arch variant product variable properties are correctly squashed into the top level properties. Bug: 322089980 Flag: EXEMPT test only Test: TestProductVariablesArch Change-Id: I62e9b4166761ce6ac0269e2fafc26d603e6b169e --- android/variable_test.go | 57 ++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/android/variable_test.go b/android/variable_test.go index 928bca609..73dc052d5 100644 --- a/android/variable_test.go +++ b/android/variable_test.go @@ -199,9 +199,7 @@ func TestProductVariables(t *testing.T) { ctx.RegisterModuleType("module3", testProductVariableModuleFactoryFactory(&struct { Foo []string }{})) - ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) { - ctx.BottomUp("variable", VariableMutator).Parallel() - }) + registerVariableBuildComponents(ctx) }), FixtureWithRootAndroidBp(bp), ).RunTest(t) @@ -210,14 +208,14 @@ func TestProductVariables(t *testing.T) { var testProductVariableDefaultsProperties = struct { Product_variables struct { Eng struct { - Foo []string + Foo []string `android:"arch_variant"` Bar []string - } - } + } `android:"arch_variant"` + } `android:"arch_variant"` }{} type productVariablesDefaultsTestProperties struct { - Foo []string + Foo []string `android:"arch_variant"` } type productVariablesDefaultsTestProperties2 struct { @@ -242,7 +240,7 @@ func productVariablesDefaultsTestModuleFactory() Module { module := &productVariablesDefaultsTestModule{} module.AddProperties(&module.properties) module.variableProperties = testProductVariableDefaultsProperties - InitAndroidModule(module) + InitAndroidArchModule(module, DeviceSupported, MultilibBoth) InitDefaultableModule(module) return module } @@ -324,3 +322,46 @@ func BenchmarkSliceToTypeArray(b *testing.B) { }) } } + +// Test a defaults module that supports more product variable properties than the target module. +func TestProductVariablesArch(t *testing.T) { + bp := ` + test { + name: "foo", + arch: { + arm: { + product_variables: { + eng: { + foo: ["arm"], + }, + }, + }, + arm64: { + product_variables: { + eng: { + foo: ["arm64"], + }, + }, + }, + }, + foo: ["module"], + } + ` + + result := GroupFixturePreparers( + FixtureModifyProductVariables(func(variables FixtureProductVariables) { + variables.Eng = boolPtr(true) + }), + PrepareForTestWithArchMutator, + PrepareForTestWithVariables, + FixtureRegisterWithContext(func(ctx RegistrationContext) { + ctx.RegisterModuleType("test", productVariablesDefaultsTestModuleFactory) + }), + FixtureWithRootAndroidBp(bp), + ).RunTest(t) + + foo := result.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*productVariablesDefaultsTestModule) + + want := []string{"module", "arm64"} + AssertDeepEquals(t, "foo", want, foo.properties.Foo) +}