xref: /aosp_15_r20/build/soong/android/variable_test.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
1*333d2b36SAndroid Build Coastguard Worker// Copyright 2015 Google Inc. All rights reserved.
2*333d2b36SAndroid Build Coastguard Worker//
3*333d2b36SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License");
4*333d2b36SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License.
5*333d2b36SAndroid Build Coastguard Worker// You may obtain a copy of the License at
6*333d2b36SAndroid Build Coastguard Worker//
7*333d2b36SAndroid Build Coastguard Worker//     http://www.apache.org/licenses/LICENSE-2.0
8*333d2b36SAndroid Build Coastguard Worker//
9*333d2b36SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software
10*333d2b36SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS,
11*333d2b36SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*333d2b36SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and
13*333d2b36SAndroid Build Coastguard Worker// limitations under the License.
14*333d2b36SAndroid Build Coastguard Worker
15*333d2b36SAndroid Build Coastguard Workerpackage android
16*333d2b36SAndroid Build Coastguard Worker
17*333d2b36SAndroid Build Coastguard Workerimport (
18*333d2b36SAndroid Build Coastguard Worker	"reflect"
19*333d2b36SAndroid Build Coastguard Worker	"strconv"
20*333d2b36SAndroid Build Coastguard Worker	"testing"
21*333d2b36SAndroid Build Coastguard Worker
22*333d2b36SAndroid Build Coastguard Worker	"github.com/google/blueprint/proptools"
23*333d2b36SAndroid Build Coastguard Worker)
24*333d2b36SAndroid Build Coastguard Worker
25*333d2b36SAndroid Build Coastguard Workertype printfIntoPropertyTestCase struct {
26*333d2b36SAndroid Build Coastguard Worker	in  string
27*333d2b36SAndroid Build Coastguard Worker	val interface{}
28*333d2b36SAndroid Build Coastguard Worker	out string
29*333d2b36SAndroid Build Coastguard Worker	err bool
30*333d2b36SAndroid Build Coastguard Worker}
31*333d2b36SAndroid Build Coastguard Worker
32*333d2b36SAndroid Build Coastguard Workervar printfIntoPropertyTestCases = []printfIntoPropertyTestCase{
33*333d2b36SAndroid Build Coastguard Worker	{
34*333d2b36SAndroid Build Coastguard Worker		in:  "%d",
35*333d2b36SAndroid Build Coastguard Worker		val: 0,
36*333d2b36SAndroid Build Coastguard Worker		out: "0",
37*333d2b36SAndroid Build Coastguard Worker	},
38*333d2b36SAndroid Build Coastguard Worker	{
39*333d2b36SAndroid Build Coastguard Worker		in:  "%d",
40*333d2b36SAndroid Build Coastguard Worker		val: 1,
41*333d2b36SAndroid Build Coastguard Worker		out: "1",
42*333d2b36SAndroid Build Coastguard Worker	},
43*333d2b36SAndroid Build Coastguard Worker	{
44*333d2b36SAndroid Build Coastguard Worker		in:  "%d",
45*333d2b36SAndroid Build Coastguard Worker		val: 2,
46*333d2b36SAndroid Build Coastguard Worker		out: "2",
47*333d2b36SAndroid Build Coastguard Worker	},
48*333d2b36SAndroid Build Coastguard Worker	{
49*333d2b36SAndroid Build Coastguard Worker		in:  "%d",
50*333d2b36SAndroid Build Coastguard Worker		val: false,
51*333d2b36SAndroid Build Coastguard Worker		out: "0",
52*333d2b36SAndroid Build Coastguard Worker	},
53*333d2b36SAndroid Build Coastguard Worker	{
54*333d2b36SAndroid Build Coastguard Worker		in:  "%d",
55*333d2b36SAndroid Build Coastguard Worker		val: true,
56*333d2b36SAndroid Build Coastguard Worker		out: "1",
57*333d2b36SAndroid Build Coastguard Worker	},
58*333d2b36SAndroid Build Coastguard Worker	{
59*333d2b36SAndroid Build Coastguard Worker		in:  "%d",
60*333d2b36SAndroid Build Coastguard Worker		val: -1,
61*333d2b36SAndroid Build Coastguard Worker		out: "-1",
62*333d2b36SAndroid Build Coastguard Worker	},
63*333d2b36SAndroid Build Coastguard Worker
64*333d2b36SAndroid Build Coastguard Worker	{
65*333d2b36SAndroid Build Coastguard Worker		in:  "-DA=%d",
66*333d2b36SAndroid Build Coastguard Worker		val: 1,
67*333d2b36SAndroid Build Coastguard Worker		out: "-DA=1",
68*333d2b36SAndroid Build Coastguard Worker	},
69*333d2b36SAndroid Build Coastguard Worker	{
70*333d2b36SAndroid Build Coastguard Worker		in:  "-DA=%du",
71*333d2b36SAndroid Build Coastguard Worker		val: 1,
72*333d2b36SAndroid Build Coastguard Worker		out: "-DA=1u",
73*333d2b36SAndroid Build Coastguard Worker	},
74*333d2b36SAndroid Build Coastguard Worker	{
75*333d2b36SAndroid Build Coastguard Worker		in:  "-DA=%s",
76*333d2b36SAndroid Build Coastguard Worker		val: "abc",
77*333d2b36SAndroid Build Coastguard Worker		out: "-DA=abc",
78*333d2b36SAndroid Build Coastguard Worker	},
79*333d2b36SAndroid Build Coastguard Worker	{
80*333d2b36SAndroid Build Coastguard Worker		in:  `-DA="%s"`,
81*333d2b36SAndroid Build Coastguard Worker		val: "abc",
82*333d2b36SAndroid Build Coastguard Worker		out: `-DA="abc"`,
83*333d2b36SAndroid Build Coastguard Worker	},
84*333d2b36SAndroid Build Coastguard Worker
85*333d2b36SAndroid Build Coastguard Worker	{
86*333d2b36SAndroid Build Coastguard Worker		in:  "%%",
87*333d2b36SAndroid Build Coastguard Worker		err: true,
88*333d2b36SAndroid Build Coastguard Worker	},
89*333d2b36SAndroid Build Coastguard Worker	{
90*333d2b36SAndroid Build Coastguard Worker		in:  "%d%s",
91*333d2b36SAndroid Build Coastguard Worker		err: true,
92*333d2b36SAndroid Build Coastguard Worker	},
93*333d2b36SAndroid Build Coastguard Worker	{
94*333d2b36SAndroid Build Coastguard Worker		in:  "%d,%s",
95*333d2b36SAndroid Build Coastguard Worker		err: true,
96*333d2b36SAndroid Build Coastguard Worker	},
97*333d2b36SAndroid Build Coastguard Worker	{
98*333d2b36SAndroid Build Coastguard Worker		in:  "%d",
99*333d2b36SAndroid Build Coastguard Worker		val: "",
100*333d2b36SAndroid Build Coastguard Worker		err: true,
101*333d2b36SAndroid Build Coastguard Worker	},
102*333d2b36SAndroid Build Coastguard Worker	{
103*333d2b36SAndroid Build Coastguard Worker		in:  "%d",
104*333d2b36SAndroid Build Coastguard Worker		val: 1.5,
105*333d2b36SAndroid Build Coastguard Worker		err: true,
106*333d2b36SAndroid Build Coastguard Worker	},
107*333d2b36SAndroid Build Coastguard Worker	{
108*333d2b36SAndroid Build Coastguard Worker		in:  "%f",
109*333d2b36SAndroid Build Coastguard Worker		val: 1.5,
110*333d2b36SAndroid Build Coastguard Worker		err: true,
111*333d2b36SAndroid Build Coastguard Worker	},
112*333d2b36SAndroid Build Coastguard Worker}
113*333d2b36SAndroid Build Coastguard Worker
114*333d2b36SAndroid Build Coastguard Workerfunc TestPrintfIntoProperty(t *testing.T) {
115*333d2b36SAndroid Build Coastguard Worker	for _, testCase := range printfIntoPropertyTestCases {
116*333d2b36SAndroid Build Coastguard Worker		s := testCase.in
117*333d2b36SAndroid Build Coastguard Worker		v := reflect.ValueOf(&s).Elem()
118*333d2b36SAndroid Build Coastguard Worker		err := printfIntoProperty(v, testCase.val)
119*333d2b36SAndroid Build Coastguard Worker		if err != nil && !testCase.err {
120*333d2b36SAndroid Build Coastguard Worker			t.Errorf("unexpected error %s", err)
121*333d2b36SAndroid Build Coastguard Worker		} else if err == nil && testCase.err {
122*333d2b36SAndroid Build Coastguard Worker			t.Errorf("expected error")
123*333d2b36SAndroid Build Coastguard Worker		} else if err == nil && v.String() != testCase.out {
124*333d2b36SAndroid Build Coastguard Worker			t.Errorf("expected %q got %q", testCase.out, v.String())
125*333d2b36SAndroid Build Coastguard Worker		}
126*333d2b36SAndroid Build Coastguard Worker	}
127*333d2b36SAndroid Build Coastguard Worker}
128*333d2b36SAndroid Build Coastguard Worker
129*333d2b36SAndroid Build Coastguard Workertype testProductVariableModule struct {
130*333d2b36SAndroid Build Coastguard Worker	ModuleBase
131*333d2b36SAndroid Build Coastguard Worker}
132*333d2b36SAndroid Build Coastguard Worker
133*333d2b36SAndroid Build Coastguard Workerfunc (m *testProductVariableModule) GenerateAndroidBuildActions(ctx ModuleContext) {
134*333d2b36SAndroid Build Coastguard Worker}
135*333d2b36SAndroid Build Coastguard Worker
136*333d2b36SAndroid Build Coastguard Workervar testProductVariableProperties = struct {
137*333d2b36SAndroid Build Coastguard Worker	Product_variables struct {
138*333d2b36SAndroid Build Coastguard Worker		Eng struct {
139*333d2b36SAndroid Build Coastguard Worker			Srcs   []string
140*333d2b36SAndroid Build Coastguard Worker			Cflags []string
141*333d2b36SAndroid Build Coastguard Worker		}
142*333d2b36SAndroid Build Coastguard Worker	}
143*333d2b36SAndroid Build Coastguard Worker}{}
144*333d2b36SAndroid Build Coastguard Worker
145*333d2b36SAndroid Build Coastguard Workerfunc testProductVariableModuleFactoryFactory(props interface{}) func() Module {
146*333d2b36SAndroid Build Coastguard Worker	return func() Module {
147*333d2b36SAndroid Build Coastguard Worker		m := &testProductVariableModule{}
148*333d2b36SAndroid Build Coastguard Worker		clonedProps := proptools.CloneProperties(reflect.ValueOf(props)).Interface()
149*333d2b36SAndroid Build Coastguard Worker		m.AddProperties(clonedProps)
150*333d2b36SAndroid Build Coastguard Worker
151*333d2b36SAndroid Build Coastguard Worker		// Set a default soongConfigVariableProperties, this will be used as the input to the property struct filter
152*333d2b36SAndroid Build Coastguard Worker		// for this test module.
153*333d2b36SAndroid Build Coastguard Worker		m.variableProperties = testProductVariableProperties
154*333d2b36SAndroid Build Coastguard Worker		InitAndroidModule(m)
155*333d2b36SAndroid Build Coastguard Worker		return m
156*333d2b36SAndroid Build Coastguard Worker	}
157*333d2b36SAndroid Build Coastguard Worker}
158*333d2b36SAndroid Build Coastguard Worker
159*333d2b36SAndroid Build Coastguard Workerfunc TestProductVariables(t *testing.T) {
160*333d2b36SAndroid Build Coastguard Worker	// Test that a module can use one product variable even if it doesn't have all the properties
161*333d2b36SAndroid Build Coastguard Worker	// supported by that product variable.
162*333d2b36SAndroid Build Coastguard Worker	bp := `
163*333d2b36SAndroid Build Coastguard Worker		module1 {
164*333d2b36SAndroid Build Coastguard Worker			name: "foo",
165*333d2b36SAndroid Build Coastguard Worker			product_variables: {
166*333d2b36SAndroid Build Coastguard Worker				eng: {
167*333d2b36SAndroid Build Coastguard Worker					srcs: ["foo.c"],
168*333d2b36SAndroid Build Coastguard Worker				},
169*333d2b36SAndroid Build Coastguard Worker			},
170*333d2b36SAndroid Build Coastguard Worker		}
171*333d2b36SAndroid Build Coastguard Worker		module2 {
172*333d2b36SAndroid Build Coastguard Worker			name: "bar",
173*333d2b36SAndroid Build Coastguard Worker			product_variables: {
174*333d2b36SAndroid Build Coastguard Worker				eng: {
175*333d2b36SAndroid Build Coastguard Worker					cflags: ["-DBAR"],
176*333d2b36SAndroid Build Coastguard Worker				},
177*333d2b36SAndroid Build Coastguard Worker			},
178*333d2b36SAndroid Build Coastguard Worker		}
179*333d2b36SAndroid Build Coastguard Worker
180*333d2b36SAndroid Build Coastguard Worker		module3 {
181*333d2b36SAndroid Build Coastguard Worker			name: "baz",
182*333d2b36SAndroid Build Coastguard Worker		}
183*333d2b36SAndroid Build Coastguard Worker	`
184*333d2b36SAndroid Build Coastguard Worker
185*333d2b36SAndroid Build Coastguard Worker	GroupFixturePreparers(
186*333d2b36SAndroid Build Coastguard Worker		FixtureModifyProductVariables(func(variables FixtureProductVariables) {
187*333d2b36SAndroid Build Coastguard Worker			variables.Eng = proptools.BoolPtr(true)
188*333d2b36SAndroid Build Coastguard Worker		}),
189*333d2b36SAndroid Build Coastguard Worker		FixtureRegisterWithContext(func(ctx RegistrationContext) {
190*333d2b36SAndroid Build Coastguard Worker			// A module type that has a srcs property but not a cflags property.
191*333d2b36SAndroid Build Coastguard Worker			ctx.RegisterModuleType("module1", testProductVariableModuleFactoryFactory(&struct {
192*333d2b36SAndroid Build Coastguard Worker				Srcs []string
193*333d2b36SAndroid Build Coastguard Worker			}{}))
194*333d2b36SAndroid Build Coastguard Worker			// A module type that has a cflags property but not a srcs property.
195*333d2b36SAndroid Build Coastguard Worker			ctx.RegisterModuleType("module2", testProductVariableModuleFactoryFactory(&struct {
196*333d2b36SAndroid Build Coastguard Worker				Cflags []string
197*333d2b36SAndroid Build Coastguard Worker			}{}))
198*333d2b36SAndroid Build Coastguard Worker			// A module type that does not have any properties that match product_variables.
199*333d2b36SAndroid Build Coastguard Worker			ctx.RegisterModuleType("module3", testProductVariableModuleFactoryFactory(&struct {
200*333d2b36SAndroid Build Coastguard Worker				Foo []string
201*333d2b36SAndroid Build Coastguard Worker			}{}))
202*333d2b36SAndroid Build Coastguard Worker			registerVariableBuildComponents(ctx)
203*333d2b36SAndroid Build Coastguard Worker		}),
204*333d2b36SAndroid Build Coastguard Worker		FixtureWithRootAndroidBp(bp),
205*333d2b36SAndroid Build Coastguard Worker	).RunTest(t)
206*333d2b36SAndroid Build Coastguard Worker}
207*333d2b36SAndroid Build Coastguard Worker
208*333d2b36SAndroid Build Coastguard Workervar testProductVariableDefaultsProperties = struct {
209*333d2b36SAndroid Build Coastguard Worker	Product_variables struct {
210*333d2b36SAndroid Build Coastguard Worker		Eng struct {
211*333d2b36SAndroid Build Coastguard Worker			Foo []string `android:"arch_variant"`
212*333d2b36SAndroid Build Coastguard Worker			Bar []string
213*333d2b36SAndroid Build Coastguard Worker		} `android:"arch_variant"`
214*333d2b36SAndroid Build Coastguard Worker	} `android:"arch_variant"`
215*333d2b36SAndroid Build Coastguard Worker}{}
216*333d2b36SAndroid Build Coastguard Worker
217*333d2b36SAndroid Build Coastguard Workertype productVariablesDefaultsTestProperties struct {
218*333d2b36SAndroid Build Coastguard Worker	Foo []string `android:"arch_variant"`
219*333d2b36SAndroid Build Coastguard Worker}
220*333d2b36SAndroid Build Coastguard Worker
221*333d2b36SAndroid Build Coastguard Workertype productVariablesDefaultsTestProperties2 struct {
222*333d2b36SAndroid Build Coastguard Worker	Foo []string
223*333d2b36SAndroid Build Coastguard Worker	Bar []string
224*333d2b36SAndroid Build Coastguard Worker}
225*333d2b36SAndroid Build Coastguard Worker
226*333d2b36SAndroid Build Coastguard Workertype productVariablesDefaultsTestModule struct {
227*333d2b36SAndroid Build Coastguard Worker	ModuleBase
228*333d2b36SAndroid Build Coastguard Worker	DefaultableModuleBase
229*333d2b36SAndroid Build Coastguard Worker	properties productVariablesDefaultsTestProperties
230*333d2b36SAndroid Build Coastguard Worker}
231*333d2b36SAndroid Build Coastguard Worker
232*333d2b36SAndroid Build Coastguard Workerfunc (d *productVariablesDefaultsTestModule) GenerateAndroidBuildActions(ctx ModuleContext) {
233*333d2b36SAndroid Build Coastguard Worker	ctx.Build(pctx, BuildParams{
234*333d2b36SAndroid Build Coastguard Worker		Rule:   Touch,
235*333d2b36SAndroid Build Coastguard Worker		Output: PathForModuleOut(ctx, "out"),
236*333d2b36SAndroid Build Coastguard Worker	})
237*333d2b36SAndroid Build Coastguard Worker}
238*333d2b36SAndroid Build Coastguard Worker
239*333d2b36SAndroid Build Coastguard Workerfunc productVariablesDefaultsTestModuleFactory() Module {
240*333d2b36SAndroid Build Coastguard Worker	module := &productVariablesDefaultsTestModule{}
241*333d2b36SAndroid Build Coastguard Worker	module.AddProperties(&module.properties)
242*333d2b36SAndroid Build Coastguard Worker	module.variableProperties = testProductVariableDefaultsProperties
243*333d2b36SAndroid Build Coastguard Worker	InitAndroidArchModule(module, DeviceSupported, MultilibBoth)
244*333d2b36SAndroid Build Coastguard Worker	InitDefaultableModule(module)
245*333d2b36SAndroid Build Coastguard Worker	return module
246*333d2b36SAndroid Build Coastguard Worker}
247*333d2b36SAndroid Build Coastguard Worker
248*333d2b36SAndroid Build Coastguard Workertype productVariablesDefaultsTestDefaults struct {
249*333d2b36SAndroid Build Coastguard Worker	ModuleBase
250*333d2b36SAndroid Build Coastguard Worker	DefaultsModuleBase
251*333d2b36SAndroid Build Coastguard Worker}
252*333d2b36SAndroid Build Coastguard Worker
253*333d2b36SAndroid Build Coastguard Workerfunc productVariablesDefaultsTestDefaultsFactory() Module {
254*333d2b36SAndroid Build Coastguard Worker	defaults := &productVariablesDefaultsTestDefaults{}
255*333d2b36SAndroid Build Coastguard Worker	defaults.AddProperties(&productVariablesDefaultsTestProperties{})
256*333d2b36SAndroid Build Coastguard Worker	defaults.AddProperties(&productVariablesDefaultsTestProperties2{})
257*333d2b36SAndroid Build Coastguard Worker	defaults.variableProperties = testProductVariableDefaultsProperties
258*333d2b36SAndroid Build Coastguard Worker	InitDefaultsModule(defaults)
259*333d2b36SAndroid Build Coastguard Worker	return defaults
260*333d2b36SAndroid Build Coastguard Worker}
261*333d2b36SAndroid Build Coastguard Worker
262*333d2b36SAndroid Build Coastguard Worker// Test a defaults module that supports more product variable properties than the target module.
263*333d2b36SAndroid Build Coastguard Workerfunc TestProductVariablesDefaults(t *testing.T) {
264*333d2b36SAndroid Build Coastguard Worker	bp := `
265*333d2b36SAndroid Build Coastguard Worker		defaults {
266*333d2b36SAndroid Build Coastguard Worker			name: "defaults",
267*333d2b36SAndroid Build Coastguard Worker			product_variables: {
268*333d2b36SAndroid Build Coastguard Worker				eng: {
269*333d2b36SAndroid Build Coastguard Worker					foo: ["product_variable_defaults"],
270*333d2b36SAndroid Build Coastguard Worker					bar: ["product_variable_defaults"],
271*333d2b36SAndroid Build Coastguard Worker				},
272*333d2b36SAndroid Build Coastguard Worker			},
273*333d2b36SAndroid Build Coastguard Worker			foo: ["defaults"],
274*333d2b36SAndroid Build Coastguard Worker			bar: ["defaults"],
275*333d2b36SAndroid Build Coastguard Worker		}
276*333d2b36SAndroid Build Coastguard Worker
277*333d2b36SAndroid Build Coastguard Worker		test {
278*333d2b36SAndroid Build Coastguard Worker			name: "foo",
279*333d2b36SAndroid Build Coastguard Worker			defaults: ["defaults"],
280*333d2b36SAndroid Build Coastguard Worker			foo: ["module"],
281*333d2b36SAndroid Build Coastguard Worker			product_variables: {
282*333d2b36SAndroid Build Coastguard Worker				eng: {
283*333d2b36SAndroid Build Coastguard Worker					foo: ["product_variable_module"],
284*333d2b36SAndroid Build Coastguard Worker				},
285*333d2b36SAndroid Build Coastguard Worker			},
286*333d2b36SAndroid Build Coastguard Worker		}
287*333d2b36SAndroid Build Coastguard Worker	`
288*333d2b36SAndroid Build Coastguard Worker
289*333d2b36SAndroid Build Coastguard Worker	result := GroupFixturePreparers(
290*333d2b36SAndroid Build Coastguard Worker		FixtureModifyProductVariables(func(variables FixtureProductVariables) {
291*333d2b36SAndroid Build Coastguard Worker			variables.Eng = boolPtr(true)
292*333d2b36SAndroid Build Coastguard Worker		}),
293*333d2b36SAndroid Build Coastguard Worker		PrepareForTestWithDefaults,
294*333d2b36SAndroid Build Coastguard Worker		PrepareForTestWithVariables,
295*333d2b36SAndroid Build Coastguard Worker		FixtureRegisterWithContext(func(ctx RegistrationContext) {
296*333d2b36SAndroid Build Coastguard Worker			ctx.RegisterModuleType("test", productVariablesDefaultsTestModuleFactory)
297*333d2b36SAndroid Build Coastguard Worker			ctx.RegisterModuleType("defaults", productVariablesDefaultsTestDefaultsFactory)
298*333d2b36SAndroid Build Coastguard Worker		}),
299*333d2b36SAndroid Build Coastguard Worker		FixtureWithRootAndroidBp(bp),
300*333d2b36SAndroid Build Coastguard Worker	).RunTest(t)
301*333d2b36SAndroid Build Coastguard Worker
302*333d2b36SAndroid Build Coastguard Worker	foo := result.ModuleForTests("foo", "").Module().(*productVariablesDefaultsTestModule)
303*333d2b36SAndroid Build Coastguard Worker
304*333d2b36SAndroid Build Coastguard Worker	want := []string{"defaults", "module", "product_variable_defaults", "product_variable_module"}
305*333d2b36SAndroid Build Coastguard Worker	AssertDeepEquals(t, "foo", want, foo.properties.Foo)
306*333d2b36SAndroid Build Coastguard Worker}
307*333d2b36SAndroid Build Coastguard Worker
308*333d2b36SAndroid Build Coastguard Workerfunc BenchmarkSliceToTypeArray(b *testing.B) {
309*333d2b36SAndroid Build Coastguard Worker	for _, n := range []int{1, 2, 4, 8, 100} {
310*333d2b36SAndroid Build Coastguard Worker		var propStructs []interface{}
311*333d2b36SAndroid Build Coastguard Worker		for i := 0; i < n; i++ {
312*333d2b36SAndroid Build Coastguard Worker			propStructs = append(propStructs, &struct {
313*333d2b36SAndroid Build Coastguard Worker				A *string
314*333d2b36SAndroid Build Coastguard Worker				B string
315*333d2b36SAndroid Build Coastguard Worker			}{})
316*333d2b36SAndroid Build Coastguard Worker
317*333d2b36SAndroid Build Coastguard Worker		}
318*333d2b36SAndroid Build Coastguard Worker		b.Run(strconv.Itoa(n), func(b *testing.B) {
319*333d2b36SAndroid Build Coastguard Worker			for i := 0; i < b.N; i++ {
320*333d2b36SAndroid Build Coastguard Worker				_ = sliceToTypeArray(propStructs)
321*333d2b36SAndroid Build Coastguard Worker			}
322*333d2b36SAndroid Build Coastguard Worker		})
323*333d2b36SAndroid Build Coastguard Worker	}
324*333d2b36SAndroid Build Coastguard Worker}
325*333d2b36SAndroid Build Coastguard Worker
326*333d2b36SAndroid Build Coastguard Worker// Test a defaults module that supports more product variable properties than the target module.
327*333d2b36SAndroid Build Coastguard Workerfunc TestProductVariablesArch(t *testing.T) {
328*333d2b36SAndroid Build Coastguard Worker	bp := `
329*333d2b36SAndroid Build Coastguard Worker		test {
330*333d2b36SAndroid Build Coastguard Worker			name: "foo",
331*333d2b36SAndroid Build Coastguard Worker			arch: {
332*333d2b36SAndroid Build Coastguard Worker				arm: {
333*333d2b36SAndroid Build Coastguard Worker					product_variables: {
334*333d2b36SAndroid Build Coastguard Worker						eng: {
335*333d2b36SAndroid Build Coastguard Worker							foo: ["arm"],
336*333d2b36SAndroid Build Coastguard Worker						},
337*333d2b36SAndroid Build Coastguard Worker					},
338*333d2b36SAndroid Build Coastguard Worker				},
339*333d2b36SAndroid Build Coastguard Worker				arm64: {
340*333d2b36SAndroid Build Coastguard Worker					product_variables: {
341*333d2b36SAndroid Build Coastguard Worker						eng: {
342*333d2b36SAndroid Build Coastguard Worker							foo: ["arm64"],
343*333d2b36SAndroid Build Coastguard Worker						},
344*333d2b36SAndroid Build Coastguard Worker					},
345*333d2b36SAndroid Build Coastguard Worker				},
346*333d2b36SAndroid Build Coastguard Worker			},
347*333d2b36SAndroid Build Coastguard Worker			foo: ["module"],
348*333d2b36SAndroid Build Coastguard Worker		}
349*333d2b36SAndroid Build Coastguard Worker	`
350*333d2b36SAndroid Build Coastguard Worker
351*333d2b36SAndroid Build Coastguard Worker	result := GroupFixturePreparers(
352*333d2b36SAndroid Build Coastguard Worker		FixtureModifyProductVariables(func(variables FixtureProductVariables) {
353*333d2b36SAndroid Build Coastguard Worker			variables.Eng = boolPtr(true)
354*333d2b36SAndroid Build Coastguard Worker		}),
355*333d2b36SAndroid Build Coastguard Worker		PrepareForTestWithArchMutator,
356*333d2b36SAndroid Build Coastguard Worker		PrepareForTestWithVariables,
357*333d2b36SAndroid Build Coastguard Worker		FixtureRegisterWithContext(func(ctx RegistrationContext) {
358*333d2b36SAndroid Build Coastguard Worker			ctx.RegisterModuleType("test", productVariablesDefaultsTestModuleFactory)
359*333d2b36SAndroid Build Coastguard Worker		}),
360*333d2b36SAndroid Build Coastguard Worker		FixtureWithRootAndroidBp(bp),
361*333d2b36SAndroid Build Coastguard Worker	).RunTest(t)
362*333d2b36SAndroid Build Coastguard Worker
363*333d2b36SAndroid Build Coastguard Worker	foo := result.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*productVariablesDefaultsTestModule)
364*333d2b36SAndroid Build Coastguard Worker
365*333d2b36SAndroid Build Coastguard Worker	want := []string{"module", "arm64"}
366*333d2b36SAndroid Build Coastguard Worker	AssertDeepEquals(t, "foo", want, foo.properties.Foo)
367*333d2b36SAndroid Build Coastguard Worker}
368