From 34c32fabea769eb99f531cc7b3ebffc3dc6576eb Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 20 Jul 2021 15:58:05 -0700 Subject: [PATCH] Add TestArchProperties Add a test that verifies appropriate arch properties are squashed into each variant. Test: TestArchProperties Change-Id: I4a5044f3b2b3ca0a51dc457dec7157411ebad7e3 --- android/arch_test.go | 160 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) diff --git a/android/arch_test.go b/android/arch_test.go index 3aa4779fe..b513d15c2 100644 --- a/android/arch_test.go +++ b/android/arch_test.go @@ -473,3 +473,163 @@ func TestArchMutatorNativeBridge(t *testing.T) { }) } } + +type testArchPropertiesModule struct { + ModuleBase + properties struct { + A []string `android:"arch_variant"` + } +} + +func (testArchPropertiesModule) GenerateAndroidBuildActions(ctx ModuleContext) {} + +func TestArchProperties(t *testing.T) { + bp := ` + module { + name: "foo", + a: ["root"], + arch: { + arm: { + a: ["arm"], + armv7_a_neon: { a: ["armv7_a_neon"] }, + }, + arm64: { + a: ["arm64"], + armv8_a: { a: ["armv8_a"] }, + }, + x86: { a: ["x86"] }, + x86_64: { a: ["x86_64"] }, + }, + multilib: { + lib32: { a: ["lib32"] }, + lib64: { a: ["lib64"] }, + }, + target: { + bionic: { a: ["bionic"] }, + host: { a: ["host"] }, + android: { a: ["android"] }, + linux_bionic: { a: ["linux_bionic"] }, + linux: { a: ["linux"] }, + linux_glibc: { a: ["linux_glibc"] }, + windows: { a: ["windows"], enabled: true }, + not_windows: { a: ["not_windows"] }, + android32: { a: ["android32"] }, + android64: { a: ["android64"] }, + android_arm: { a: ["android_arm"] }, + android_arm64: { a: ["android_arm64"] }, + linux_x86: { a: ["linux_x86"] }, + linux_x86_64: { a: ["linux_x86_64"] }, + linux_glibc_x86: { a: ["linux_glibc_x86"] }, + linux_glibc_x86_64: { a: ["linux_glibc_x86_64"] }, + darwin_x86_64: { a: ["darwin_x86_64"] }, + windows_x86: { a: ["windows_x86"] }, + windows_x86_64: { a: ["windows_x86_64"] }, + }, + } + ` + + type result struct { + module string + variant string + property []string + } + + testCases := []struct { + name string + goOS string + preparer FixturePreparer + results []result + }{ + { + name: "default", + results: []result{ + { + module: "foo", + variant: "android_arm64_armv8-a", + property: []string{"root", "linux", "bionic", "android", "android64", "arm64", "armv8_a", "lib64", "android_arm64"}, + }, + { + module: "foo", + variant: "android_arm_armv7-a-neon", + property: []string{"root", "linux", "bionic", "android", "android64", "arm", "armv7_a_neon", "lib32", "android_arm"}, + }, + }, + }, + { + name: "linux", + goOS: "linux", + results: []result{ + { + module: "foo", + variant: "linux_glibc_x86_64", + property: []string{"root", "host", "linux", "linux_glibc", "not_windows", "x86_64", "lib64", "linux_x86_64", "linux_glibc_x86_64"}, + }, + { + module: "foo", + variant: "linux_glibc_x86", + property: []string{"root", "host", "linux", "linux_glibc", "not_windows", "x86", "lib32", "linux_x86", "linux_glibc_x86"}, + }, + }, + }, + { + name: "windows", + goOS: "linux", + preparer: FixtureModifyConfig(func(config Config) { + config.Targets[Windows] = []Target{ + {Windows, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", "", true}, + {Windows, Arch{ArchType: X86}, NativeBridgeDisabled, "", "", true}, + } + }), + results: []result{ + { + module: "foo", + variant: "windows_x86_64", + property: []string{"root", "host", "windows", "x86_64", "lib64", "windows_x86_64"}, + }, + { + module: "foo", + variant: "windows_x86", + property: []string{"root", "host", "windows", "x86", "lib32", "windows_x86"}, + }, + }, + }, + { + name: "darwin", + goOS: "darwin", + results: []result{ + { + module: "foo", + variant: "darwin_x86_64", + property: []string{"root", "host", "darwin", "not_windows", "x86_64", "lib64", "darwin_x86_64"}, + }, + }, + }, + } + + for _, tt := range testCases { + t.Run(tt.name, func(t *testing.T) { + if tt.goOS != "" && tt.goOS != runtime.GOOS { + t.Skipf("test requires runtime.GOOS==%s, got %s", tt.goOS, runtime.GOOS) + } + result := GroupFixturePreparers( + PrepareForTestWithArchMutator, + OptionalFixturePreparer(tt.preparer), + FixtureRegisterWithContext(func(ctx RegistrationContext) { + ctx.RegisterModuleType("module", func() Module { + module := &testArchPropertiesModule{} + module.AddProperties(&module.properties) + InitAndroidArchModule(module, HostAndDeviceDefault, MultilibBoth) + return module + }) + }), + ).RunTestWithBp(t, bp) + + for _, want := range tt.results { + t.Run(want.module+"_"+want.variant, func(t *testing.T) { + got := result.ModuleForTests(want.module, want.variant).Module().(*testArchPropertiesModule).properties.A + AssertArrayString(t, "arch mutator property", want.property, got) + }) + } + }) + } +}