summaryrefslogtreecommitdiff
path: root/android/config_test.go
diff options
context:
space:
mode:
author Justin Yun <justinyun@google.com> 2025-03-18 02:55:44 -0700
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2025-03-18 02:55:44 -0700
commit6fc7cbe2597a93d152404e1706d1bd10bf33075d (patch)
treede7d9e4e4abbd3a8d953dcb108940abfb7612cb9 /android/config_test.go
parentd0bde424e3119c0ad0ff8879786d2cc1febe1dfa (diff)
parentd648ee443516cc45f349c9a8322550cf375f7eec (diff)
Generic configuration for generic system modules. am: be6f81d61e am: d648ee4435
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/3425639 Change-Id: Ibd30d3911934db8857cf84de75200207a2a7331c Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'android/config_test.go')
-rw-r--r--android/config_test.go69
1 files changed, 69 insertions, 0 deletions
diff --git a/android/config_test.go b/android/config_test.go
index d1b26c12a..81b7c3eb5 100644
--- a/android/config_test.go
+++ b/android/config_test.go
@@ -281,3 +281,72 @@ func TestPartialCompile(t *testing.T) {
})
}
}
+
+type configTestProperties struct {
+ Use_generic_config *bool
+}
+
+type configTestModule struct {
+ ModuleBase
+ properties configTestProperties
+}
+
+func (d *configTestModule) GenerateAndroidBuildActions(ctx ModuleContext) {
+ deviceName := ctx.Config().DeviceName()
+ if ctx.ModuleName() == "foo" {
+ if ctx.Module().UseGenericConfig() {
+ ctx.PropertyErrorf("use_generic_config", "must not be set for this test")
+ }
+ } else if ctx.ModuleName() == "bar" {
+ if !ctx.Module().UseGenericConfig() {
+ ctx.ModuleErrorf("\"use_generic_config: true\" must be set for this test")
+ }
+ }
+
+ if ctx.Module().UseGenericConfig() {
+ if deviceName != "generic" {
+ ctx.ModuleErrorf("Device name for this module must be \"generic\" but %q\n", deviceName)
+ }
+ } else {
+ if deviceName == "generic" {
+ ctx.ModuleErrorf("Device name for this module must not be \"generic\"\n")
+ }
+ }
+}
+
+func configTestModuleFactory() Module {
+ module := &configTestModule{}
+ module.AddProperties(&module.properties)
+ InitAndroidModule(module)
+ return module
+}
+
+var prepareForConfigTest = GroupFixturePreparers(
+ FixtureRegisterWithContext(func(ctx RegistrationContext) {
+ ctx.RegisterModuleType("test", configTestModuleFactory)
+ }),
+)
+
+func TestGenericConfig(t *testing.T) {
+ bp := `
+ test {
+ name: "foo",
+ }
+
+ test {
+ name: "bar",
+ use_generic_config: true,
+ }
+ `
+
+ result := GroupFixturePreparers(
+ prepareForConfigTest,
+ FixtureWithRootAndroidBp(bp),
+ ).RunTest(t)
+
+ foo := result.Module("foo", "").(*configTestModule)
+ bar := result.Module("bar", "").(*configTestModule)
+
+ AssertBoolEquals(t, "Do not use generic config", false, foo.UseGenericConfig())
+ AssertBoolEquals(t, "Use generic config", true, bar.UseGenericConfig())
+}