From 738a6d5bc41505d157b924a69057673ef9cac568 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 16 Mar 2021 19:10:48 +0000 Subject: [PATCH] Convert android/arch_test.go to test fixtures Bug: 182885307 Test: m nothing Change-Id: I4c9c133a1560731869fa5e8fdd81ecc4f54f4821 --- android/arch_test.go | 67 ++++++++++++++++++++++++-------------------- android/config.go | 17 ----------- 2 files changed, 36 insertions(+), 48 deletions(-) diff --git a/android/arch_test.go b/android/arch_test.go index 4cef4c8e6..09cb52370 100644 --- a/android/arch_test.go +++ b/android/arch_test.go @@ -273,6 +273,13 @@ func archTestModuleFactory() Module { return m } +var prepareForArchTest = GroupFixturePreparers( + PrepareForTestWithArchMutator, + FixtureRegisterWithContext(func(ctx RegistrationContext) { + ctx.RegisterModuleType("module", archTestModuleFactory) + }), +) + func TestArchMutator(t *testing.T) { var buildOSVariants []string var buildOS32Variants []string @@ -309,7 +316,7 @@ func TestArchMutator(t *testing.T) { testCases := []struct { name string - config func(Config) + preparer FixturePreparer fooVariants []string barVariants []string bazVariants []string @@ -317,7 +324,7 @@ func TestArchMutator(t *testing.T) { }{ { name: "normal", - config: nil, + preparer: nil, fooVariants: []string{"android_arm64_armv8-a", "android_arm_armv7-a-neon"}, barVariants: append(buildOSVariants, "android_arm64_armv8-a", "android_arm_armv7-a-neon"), bazVariants: nil, @@ -325,11 +332,11 @@ func TestArchMutator(t *testing.T) { }, { name: "host-only", - config: func(config Config) { + preparer: FixtureModifyConfig(func(config Config) { config.BuildOSTarget = Target{} config.BuildOSCommonTarget = Target{} config.Targets[Android] = nil - }, + }), fooVariants: nil, barVariants: buildOSVariants, bazVariants: nil, @@ -351,19 +358,13 @@ func TestArchMutator(t *testing.T) { for _, tt := range testCases { t.Run(tt.name, func(t *testing.T) { - config := TestArchConfig(buildDir, nil, bp, nil) - - ctx := NewTestArchContext(config) - ctx.RegisterModuleType("module", archTestModuleFactory) - ctx.Register() - if tt.config != nil { - tt.config(config) - } - - _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) - FailIfErrored(t, errs) - _, errs = ctx.PrepareBuildActions(config) - FailIfErrored(t, errs) + result := emptyTestFixtureFactory.RunTest(t, + prepareForArchTest, + // Test specific preparer + OptionalFixturePreparer(tt.preparer), + FixtureWithRootAndroidBp(bp), + ) + ctx := result.TestContext if g, w := enabledVariants(ctx, "foo"), tt.fooVariants; !reflect.DeepEqual(w, g) { t.Errorf("want foo variants:\n%q\ngot:\n%q\n", w, g) @@ -412,14 +413,14 @@ func TestArchMutatorNativeBridge(t *testing.T) { testCases := []struct { name string - config func(Config) + preparer FixturePreparer fooVariants []string barVariants []string bazVariants []string }{ { name: "normal", - config: nil, + preparer: nil, fooVariants: []string{"android_x86_64_silvermont", "android_x86_silvermont"}, barVariants: []string{"android_x86_64_silvermont", "android_native_bridge_arm64_armv8-a", "android_x86_silvermont", "android_native_bridge_arm_armv7-a-neon"}, bazVariants: []string{"android_native_bridge_arm64_armv8-a", "android_native_bridge_arm_armv7-a-neon"}, @@ -440,19 +441,23 @@ func TestArchMutatorNativeBridge(t *testing.T) { for _, tt := range testCases { t.Run(tt.name, func(t *testing.T) { - config := TestArchConfigNativeBridge(buildDir, nil, bp, nil) + result := emptyTestFixtureFactory.RunTest(t, + prepareForArchTest, + // Test specific preparer + OptionalFixturePreparer(tt.preparer), + // Prepare for native bridge test + FixtureModifyConfig(func(config Config) { + config.Targets[Android] = []Target{ + {Android, Arch{ArchType: X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", "", false}, + {Android, Arch{ArchType: X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridgeDisabled, "", "", false}, + {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridgeEnabled, "x86_64", "arm64", false}, + {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridgeEnabled, "x86", "arm", false}, + } + }), + FixtureWithRootAndroidBp(bp), + ) - ctx := NewTestArchContext(config) - ctx.RegisterModuleType("module", archTestModuleFactory) - ctx.Register() - if tt.config != nil { - tt.config(config) - } - - _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) - FailIfErrored(t, errs) - _, errs = ctx.PrepareBuildActions(config) - FailIfErrored(t, errs) + ctx := result.TestContext if g, w := enabledVariants(ctx, "foo"), tt.fooVariants; !reflect.DeepEqual(w, g) { t.Errorf("want foo variants:\n%q\ngot:\n%q\n", w, g) diff --git a/android/config.go b/android/config.go index f4685a196..d7c82a099 100644 --- a/android/config.go +++ b/android/config.go @@ -278,23 +278,6 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string return Config{config} } -// TestArchConfigNativeBridge returns a Config object suitable for using -// for tests that need to run the arch mutator for native bridge supported -// archs. -func TestArchConfigNativeBridge(buildDir string, env map[string]string, bp string, fs map[string][]byte) Config { - testConfig := TestArchConfig(buildDir, env, bp, fs) - config := testConfig.config - - config.Targets[Android] = []Target{ - {Android, Arch{ArchType: X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", "", false}, - {Android, Arch{ArchType: X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridgeDisabled, "", "", false}, - {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridgeEnabled, "x86_64", "arm64", false}, - {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridgeEnabled, "x86", "arm", false}, - } - - return testConfig -} - func fuchsiaTargets() map[OsType][]Target { return map[OsType][]Target{ Fuchsia: {