From 89648f98faf46f4c9ae2b084167a79f7da2df567 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Sat, 20 Mar 2021 00:36:55 +0000 Subject: [PATCH] Remove usages of FixtureFactory from misc packages These packages have already been migrated to use per test build directory so have no need for a FixtureFactory. Bug: 183235980 Test: m nothing Change-Id: I667d1d992caaf0f615de91f89efdae11c44986c2 --- bpf/bpf_test.go | 5 ++--- etc/prebuilt_etc_test.go | 27 +++++++++++++-------------- genrule/genrule_test.go | 23 ++++++++++++----------- python/python_test.go | 15 ++++++--------- sdk/cc_sdk_test.go | 3 ++- sdk/testing.go | 7 +++---- sh/sh_binary_test.go | 11 +++++------ sysprop/sysprop_test.go | 6 ++---- xml/xml_test.go | 6 ++---- 9 files changed, 47 insertions(+), 56 deletions(-) diff --git a/bpf/bpf_test.go b/bpf/bpf_test.go index 0bf15db75..51fbc15e1 100644 --- a/bpf/bpf_test.go +++ b/bpf/bpf_test.go @@ -26,8 +26,7 @@ func TestMain(m *testing.M) { os.Exit(m.Run()) } -var bpfFactory = android.NewFixtureFactory( - nil, +var prepareForBpfTest = android.GroupFixturePreparers( cc.PrepareForTestWithCcDefaultModules, android.FixtureMergeMockFs( map[string][]byte{ @@ -53,7 +52,7 @@ func TestBpfDataDependency(t *testing.T) { } ` - bpfFactory.RunTestWithBp(t, bp) + prepareForBpfTest.RunTestWithBp(t, bp) // We only verify the above BP configuration is processed successfully since the data property // value is not available for testing from this package. diff --git a/etc/prebuilt_etc_test.go b/etc/prebuilt_etc_test.go index f800c48f2..9c3db3bfb 100644 --- a/etc/prebuilt_etc_test.go +++ b/etc/prebuilt_etc_test.go @@ -26,8 +26,7 @@ func TestMain(m *testing.M) { os.Exit(m.Run()) } -var prebuiltEtcFixtureFactory = android.NewFixtureFactory( - nil, +var prepareForPrebuiltEtcTest = android.GroupFixturePreparers( android.PrepareForTestWithArchMutator, PrepareForTestWithPrebuiltEtc, android.FixtureMergeMockFs(android.MockFS{ @@ -38,7 +37,7 @@ var prebuiltEtcFixtureFactory = android.NewFixtureFactory( ) func TestPrebuiltEtcVariants(t *testing.T) { - result := prebuiltEtcFixtureFactory.RunTestWithBp(t, ` + result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` prebuilt_etc { name: "foo.conf", src: "foo.conf", @@ -72,7 +71,7 @@ func TestPrebuiltEtcVariants(t *testing.T) { } func TestPrebuiltEtcOutputPath(t *testing.T) { - result := prebuiltEtcFixtureFactory.RunTestWithBp(t, ` + result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` prebuilt_etc { name: "foo.conf", src: "foo.conf", @@ -85,7 +84,7 @@ func TestPrebuiltEtcOutputPath(t *testing.T) { } func TestPrebuiltEtcGlob(t *testing.T) { - result := prebuiltEtcFixtureFactory.RunTestWithBp(t, ` + result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` prebuilt_etc { name: "my_foo", src: "foo.*", @@ -105,7 +104,7 @@ func TestPrebuiltEtcGlob(t *testing.T) { } func TestPrebuiltEtcAndroidMk(t *testing.T) { - result := prebuiltEtcFixtureFactory.RunTestWithBp(t, ` + result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` prebuilt_etc { name: "foo", src: "foo.conf", @@ -139,7 +138,7 @@ func TestPrebuiltEtcAndroidMk(t *testing.T) { } func TestPrebuiltEtcRelativeInstallPathInstallDirPath(t *testing.T) { - result := prebuiltEtcFixtureFactory.RunTestWithBp(t, ` + result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` prebuilt_etc { name: "foo.conf", src: "foo.conf", @@ -153,7 +152,7 @@ func TestPrebuiltEtcRelativeInstallPathInstallDirPath(t *testing.T) { } func TestPrebuiltEtcCannotSetRelativeInstallPathAndSubDir(t *testing.T) { - prebuiltEtcFixtureFactory. + prepareForPrebuiltEtcTest. ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern("relative_install_path is set. Cannot set sub_dir")). RunTestWithBp(t, ` prebuilt_etc { @@ -166,7 +165,7 @@ func TestPrebuiltEtcCannotSetRelativeInstallPathAndSubDir(t *testing.T) { } func TestPrebuiltEtcHost(t *testing.T) { - result := prebuiltEtcFixtureFactory.RunTestWithBp(t, ` + result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` prebuilt_etc_host { name: "foo.conf", src: "foo.conf", @@ -181,7 +180,7 @@ func TestPrebuiltEtcHost(t *testing.T) { } func TestPrebuiltUserShareInstallDirPath(t *testing.T) { - result := prebuiltEtcFixtureFactory.RunTestWithBp(t, ` + result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` prebuilt_usr_share { name: "foo.conf", src: "foo.conf", @@ -195,7 +194,7 @@ func TestPrebuiltUserShareInstallDirPath(t *testing.T) { } func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) { - result := prebuiltEtcFixtureFactory.RunTestWithBp(t, ` + result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` prebuilt_usr_share_host { name: "foo.conf", src: "foo.conf", @@ -210,7 +209,7 @@ func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) { } func TestPrebuiltFontInstallDirPath(t *testing.T) { - result := prebuiltEtcFixtureFactory.RunTestWithBp(t, ` + result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` prebuilt_font { name: "foo.conf", src: "foo.conf", @@ -249,7 +248,7 @@ func TestPrebuiltFirmwareDirPath(t *testing.T) { }} for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - result := prebuiltEtcFixtureFactory.RunTestWithBp(t, tt.config) + result := prepareForPrebuiltEtcTest.RunTestWithBp(t, tt.config) p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPath) }) @@ -283,7 +282,7 @@ func TestPrebuiltDSPDirPath(t *testing.T) { }} for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - result := prebuiltEtcFixtureFactory.RunTestWithBp(t, tt.config) + result := prepareForPrebuiltEtcTest.RunTestWithBp(t, tt.config) p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPath) }) diff --git a/genrule/genrule_test.go b/genrule/genrule_test.go index 199a7df7b..bb17e8e05 100644 --- a/genrule/genrule_test.go +++ b/genrule/genrule_test.go @@ -28,8 +28,7 @@ func TestMain(m *testing.M) { os.Exit(m.Run()) } -var genruleFixtureFactory = android.NewFixtureFactory( - nil, +var prepareForGenRuleTest = android.GroupFixturePreparers( android.PrepareForTestWithArchMutator, android.PrepareForTestWithDefaults, @@ -447,7 +446,8 @@ func TestGenruleCmd(t *testing.T) { expectedErrors = append(expectedErrors, regexp.QuoteMeta(test.err)) } - result := genruleFixtureFactory.Extend( + result := android.GroupFixturePreparers( + prepareForGenRuleTest, android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { variables.Allow_missing_dependencies = proptools.BoolPtr(test.allowMissingDependencies) }), @@ -523,7 +523,7 @@ func TestGenruleHashInputs(t *testing.T) { }, } - result := genruleFixtureFactory.RunTestWithBp(t, testGenruleBp()+bp) + result := prepareForGenRuleTest.RunTestWithBp(t, testGenruleBp()+bp) for _, test := range testcases { t.Run(test.name, func(t *testing.T) { @@ -605,7 +605,7 @@ func TestGenSrcs(t *testing.T) { expectedErrors = append(expectedErrors, regexp.QuoteMeta(test.err)) } - result := genruleFixtureFactory. + result := prepareForGenRuleTest. ExtendWithErrorHandler(android.FixtureExpectsAllErrorsToMatchAPattern(expectedErrors)). RunTestWithBp(t, testGenruleBp()+bp) @@ -642,7 +642,7 @@ func TestGenruleDefaults(t *testing.T) { } ` - result := genruleFixtureFactory.RunTestWithBp(t, testGenruleBp()+bp) + result := prepareForGenRuleTest.RunTestWithBp(t, testGenruleBp()+bp) gen := result.Module("gen", "").(*Module) @@ -662,11 +662,12 @@ func TestGenruleWithBazel(t *testing.T) { } ` - result := genruleFixtureFactory.Extend(android.FixtureModifyConfig(func(config android.Config) { - config.BazelContext = android.MockBazelContext{ - AllFiles: map[string][]string{ - "//foo/bar:bar": []string{"bazelone.txt", "bazeltwo.txt"}}} - })).RunTestWithBp(t, testGenruleBp()+bp) + result := android.GroupFixturePreparers( + prepareForGenRuleTest, android.FixtureModifyConfig(func(config android.Config) { + config.BazelContext = android.MockBazelContext{ + AllFiles: map[string][]string{ + "//foo/bar:bar": []string{"bazelone.txt", "bazeltwo.txt"}}} + })).RunTestWithBp(t, testGenruleBp()+bp) gen := result.Module("foo", "").(*Module) diff --git a/python/python_test.go b/python/python_test.go index 6263c8a25..f57f504d7 100644 --- a/python/python_test.go +++ b/python/python_test.go @@ -335,13 +335,12 @@ func TestPythonModule(t *testing.T) { } t.Run(d.desc, func(t *testing.T) { - result := emptyFixtureFactory. - ExtendWithErrorHandler(android.FixtureExpectsAllErrorsToMatchAPattern(errorPatterns)). - RunTest(t, - android.PrepareForTestWithDefaults, - PrepareForTestWithPythonBuildComponents, - d.mockFiles.AddToFixture(), - ) + result := android.GroupFixturePreparers( + android.PrepareForTestWithDefaults, + PrepareForTestWithPythonBuildComponents, + d.mockFiles.AddToFixture(), + ).ExtendWithErrorHandler(android.FixtureExpectsAllErrorsToMatchAPattern(errorPatterns)). + RunTest(t) if len(result.Errs) > 0 { return @@ -376,8 +375,6 @@ func expectModule(t *testing.T, ctx *android.TestContext, name, variant, expecte android.AssertPathsRelativeToTopEquals(t, "depsSrcsZips", expectedDepsSrcsZips, base.depsSrcsZips) } -var emptyFixtureFactory = android.NewFixtureFactory(nil) - func TestMain(m *testing.M) { os.Exit(m.Run()) } diff --git a/sdk/cc_sdk_test.go b/sdk/cc_sdk_test.go index a2539c9a0..9626a047e 100644 --- a/sdk/cc_sdk_test.go +++ b/sdk/cc_sdk_test.go @@ -808,7 +808,8 @@ module_exports_snapshot { } func TestSnapshotWithSingleHostOsType(t *testing.T) { - result := sdkFixtureFactory.Extend( + result := android.GroupFixturePreparers( + prepareForSdkTest, ccTestFs.AddToFixture(), cc.PrepareForTestOnLinuxBionic, android.FixtureModifyConfig(func(config android.Config) { diff --git a/sdk/testing.go b/sdk/testing.go index 6df402cff..c319895f5 100644 --- a/sdk/testing.go +++ b/sdk/testing.go @@ -27,8 +27,7 @@ import ( "android/soong/java" ) -var sdkFixtureFactory = android.NewFixtureFactory( - nil, +var prepareForSdkTest = android.GroupFixturePreparers( apex.PrepareForTestWithApexBuildComponents, cc.PrepareForTestWithCcDefaultModules, genrule.PrepareForTestWithGenRuleBuildComponents, @@ -77,12 +76,12 @@ var PrepareForTestWithSdkBuildComponents = android.GroupFixturePreparers( func testSdkWithFs(t *testing.T, bp string, fs android.MockFS) *android.TestResult { t.Helper() - return sdkFixtureFactory.RunTest(t, fs.AddToFixture(), android.FixtureWithRootAndroidBp(bp)) + return prepareForSdkTest.RunTest(t, fs.AddToFixture(), android.FixtureWithRootAndroidBp(bp)) } func testSdkError(t *testing.T, pattern, bp string) { t.Helper() - sdkFixtureFactory. + prepareForSdkTest. ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)). RunTestWithBp(t, bp) } diff --git a/sh/sh_binary_test.go b/sh/sh_binary_test.go index 5887b56af..9e7e59462 100644 --- a/sh/sh_binary_test.go +++ b/sh/sh_binary_test.go @@ -13,8 +13,7 @@ func TestMain(m *testing.M) { os.Exit(m.Run()) } -var shFixtureFactory = android.NewFixtureFactory( - nil, +var prepareForShTest = android.GroupFixturePreparers( cc.PrepareForTestWithCcBuildComponents, PrepareForTestWithShBuildComponents, android.FixtureMergeMockFs(android.MockFS{ @@ -24,19 +23,19 @@ var shFixtureFactory = android.NewFixtureFactory( }), ) -// testShBinary runs tests using the shFixtureFactory +// testShBinary runs tests using the prepareForShTest // -// Do not add any new usages of this, instead use the shFixtureFactory directly as it makes it much +// Do not add any new usages of this, instead use the prepareForShTest directly as it makes it much // easier to customize the test behavior. // // If it is necessary to customize the behavior of an existing test that uses this then please first -// convert the test to using shFixtureFactory first and then in a following change add the +// convert the test to using prepareForShTest first and then in a following change add the // appropriate fixture preparers. Keeping the conversion change separate makes it easy to verify // that it did not change the test behavior unexpectedly. // // deprecated func testShBinary(t *testing.T, bp string) (*android.TestContext, android.Config) { - result := shFixtureFactory.RunTestWithBp(t, bp) + result := prepareForShTest.RunTestWithBp(t, bp) return result.TestContext, result.Config } diff --git a/sysprop/sysprop_test.go b/sysprop/sysprop_test.go index cb1e36230..e9d905186 100644 --- a/sysprop/sysprop_test.go +++ b/sysprop/sysprop_test.go @@ -30,8 +30,6 @@ func TestMain(m *testing.M) { os.Exit(m.Run()) } -var emptyFixtureFactory = android.NewFixtureFactory(nil) - func test(t *testing.T, bp string) *android.TestResult { t.Helper() @@ -124,7 +122,7 @@ func test(t *testing.T, bp string) *android.TestResult { "com/android2/OdmProperties.sysprop": nil, } - result := emptyFixtureFactory.RunTest(t, + result := android.GroupFixturePreparers( cc.PrepareForTestWithCcDefaultModules, java.PrepareForTestWithJavaDefaultModules, PrepareForTestWithSyspropBuildComponents, @@ -135,7 +133,7 @@ func test(t *testing.T, bp string) *android.TestResult { }), mockFS.AddToFixture(), android.FixtureWithRootAndroidBp(bp), - ) + ).RunTest(t) return result } diff --git a/xml/xml_test.go b/xml/xml_test.go index 83ae51c4a..a59a29318 100644 --- a/xml/xml_test.go +++ b/xml/xml_test.go @@ -26,8 +26,6 @@ func TestMain(m *testing.M) { os.Exit(m.Run()) } -var emptyFixtureFactory = android.NewFixtureFactory(nil) - func testXml(t *testing.T, bp string) *android.TestResult { fs := android.MockFS{ "foo.xml": nil, @@ -37,13 +35,13 @@ func testXml(t *testing.T, bp string) *android.TestResult { "baz.xml": nil, } - return emptyFixtureFactory.RunTest(t, + return android.GroupFixturePreparers( android.PrepareForTestWithArchMutator, etc.PrepareForTestWithPrebuiltEtc, PreparerForTestWithXmlBuildComponents, fs.AddToFixture(), android.FixtureWithRootAndroidBp(bp), - ) + ).RunTest(t) } // Minimal test