xref: /aosp_15_r20/build/soong/aconfig/aconfig_value_set_test.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
1// Copyright 2018 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package aconfig
16
17import (
18	"testing"
19
20	"android/soong/android"
21
22	"github.com/google/blueprint"
23)
24
25func TestAconfigValueSet(t *testing.T) {
26	bp := `
27				aconfig_values {
28					name: "one",
29					srcs: [ "blah.aconfig_values" ],
30					package: "foo.package"
31				}
32
33				aconfig_value_set {
34					name: "module_name",
35          values: [ "one" ],
36				}
37			`
38	result := runTest(t, android.FixtureExpectsNoErrors, bp)
39
40	module := result.ModuleForTests("module_name", "").Module().(*ValueSetModule)
41
42	// Check that the provider has the right contents
43	depData, _ := android.OtherModuleProvider(result, module, valueSetProviderKey)
44	android.AssertStringEquals(t, "AvailablePackages", "blah.aconfig_values", depData.AvailablePackages["foo.package"][0].String())
45}
46
47func TestAconfigValueSetBpGlob(t *testing.T) {
48	result := android.GroupFixturePreparers(
49		PrepareForTestWithAconfigBuildComponents,
50		android.FixtureMergeMockFs(
51			map[string][]byte{
52				// .../some_release/android.foo/
53				"some_release/android.foo/Android.bp": []byte(`
54				aconfig_values {
55					name: "aconfig-values-platform_build_release-some_release-android.foo-all",
56					package: "android.foo",
57					srcs: [
58						"*.textproto",
59					],
60				}
61				`),
62				"some_release/android.foo/flag.textproto": nil,
63
64				// .../some_release/android.bar/
65				"some_release/android.bar/Android.bp": []byte(`
66				aconfig_values {
67					name: "aconfig-values-platform_build_release-some_release-android.bar-all",
68					package: "android.bar",
69					srcs: [
70						"*.textproto",
71					],
72				}
73				`),
74				"some_release/android.bar/flag.textproto": nil,
75
76				// .../some_release/
77				"some_release/Android.bp": []byte(`
78				aconfig_value_set {
79					name: "aconfig_value_set-platform_build_release-some_release",
80					srcs: [
81						"*/Android.bp",
82					],
83				}
84				`),
85			},
86		),
87	).RunTest(t)
88
89	checkModuleHasDependency := func(name, variant, dep string) bool {
90		t.Helper()
91		module := result.ModuleForTests(name, variant).Module()
92		depFound := false
93		result.VisitDirectDeps(module, func(m blueprint.Module) {
94			if m.Name() == dep {
95				depFound = true
96			}
97		})
98		return depFound
99	}
100	android.AssertBoolEquals(t,
101		"aconfig_value_set expected to depend on aconfig_value via srcs",
102		true,
103		checkModuleHasDependency(
104			"aconfig_value_set-platform_build_release-some_release",
105			"",
106			"aconfig-values-platform_build_release-some_release-android.foo-all",
107		),
108	)
109	android.AssertBoolEquals(t,
110		"aconfig_value_set expected to depend on aconfig_value via srcs",
111		true,
112		checkModuleHasDependency(
113			"aconfig_value_set-platform_build_release-some_release",
114			"",
115			"aconfig-values-platform_build_release-some_release-android.bar-all",
116		),
117	)
118}
119
120func TestAconfigValueSetBpGlobError(t *testing.T) {
121	android.GroupFixturePreparers(
122		PrepareForTestWithAconfigBuildComponents,
123		android.FixtureMergeMockFs(
124			map[string][]byte{
125				// .../some_release/android.bar/
126				"some_release/android.bar/Android.bp": []byte(`
127				aconfig_values {
128					name: "aconfig-values-platform_build_release-some_release-android_bar-all",
129					package: "android.bar",
130					srcs: [
131						"*.textproto",
132					],
133				}
134				`),
135				"some_release/android.bar/flag.textproto": nil,
136
137				// .../some_release/
138				"some_release/Android.bp": []byte(`
139				aconfig_value_set {
140					name: "aconfig_value_set-platform_build_release-some_release",
141					srcs: [
142						"*/Android.bp",
143					],
144				}
145				`),
146			},
147		),
148	).ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(
149		`module "aconfig_value_set-platform_build_release-some_release": module ` +
150			`"aconfig-values-platform_build_release-some_release-android.bar-all" not found. ` +
151			`Rename the aconfig_values module defined in "some_release/android.bar/Android.bp" ` +
152			`to "aconfig-values-platform_build_release-some_release-android.bar-all"`),
153	).RunTest(t)
154}
155