Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 65eb794a authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Reland "Add TestArchProperties""

parents f8c46663 4e87990c
Loading
Loading
Loading
Loading
+161 −0
Original line number Diff line number Diff line
@@ -473,3 +473,164 @@ 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 },
				darwin: { a:  ["darwin"] },
				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)
				})
			}
		})
	}
}