Support test fixtures in sh package
Restructures the sh package test setup code to create FixturePreparer instances for setting up a test fixture and converts some tests to use it. The goal with this change is not to switch all the sh tests over to directly using the new model but instead to ensure that the majority of the sh tests run with the new model, to allow existing tests to easily switch to the new model when needed and to allow dependent packages to be switched to the new model. Bug: 181070625 Test: m nothing Change-Id: Ib2c6ac2842d6fafde5663d3ee63c3f934913a00e
This commit is contained in:
parent
12c7eb8cb1
commit
56fb8ee920
2 changed files with 43 additions and 21 deletions
|
@ -40,14 +40,32 @@ var pctx = android.NewPackageContext("android/soong/sh")
|
||||||
func init() {
|
func init() {
|
||||||
pctx.Import("android/soong/android")
|
pctx.Import("android/soong/android")
|
||||||
|
|
||||||
android.RegisterModuleType("sh_binary", ShBinaryFactory)
|
registerShBuildComponents(android.InitRegistrationContext)
|
||||||
android.RegisterModuleType("sh_binary_host", ShBinaryHostFactory)
|
|
||||||
android.RegisterModuleType("sh_test", ShTestFactory)
|
|
||||||
android.RegisterModuleType("sh_test_host", ShTestHostFactory)
|
|
||||||
|
|
||||||
android.RegisterBp2BuildMutator("sh_binary", ShBinaryBp2Build)
|
android.RegisterBp2BuildMutator("sh_binary", ShBinaryBp2Build)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func registerShBuildComponents(ctx android.RegistrationContext) {
|
||||||
|
ctx.RegisterModuleType("sh_binary", ShBinaryFactory)
|
||||||
|
ctx.RegisterModuleType("sh_binary_host", ShBinaryHostFactory)
|
||||||
|
ctx.RegisterModuleType("sh_test", ShTestFactory)
|
||||||
|
ctx.RegisterModuleType("sh_test_host", ShTestHostFactory)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test fixture preparer that will register most sh build components.
|
||||||
|
//
|
||||||
|
// Singletons and mutators should only be added here if they are needed for a majority of sh
|
||||||
|
// module types, otherwise they should be added under a separate preparer to allow them to be
|
||||||
|
// selected only when needed to reduce test execution time.
|
||||||
|
//
|
||||||
|
// Module types do not have much of an overhead unless they are used so this should include as many
|
||||||
|
// module types as possible. The exceptions are those module types that require mutators and/or
|
||||||
|
// singletons in order to function in which case they should be kept together in a separate
|
||||||
|
// preparer.
|
||||||
|
var PrepareForTestWithShBuildComponents = android.GroupFixturePreparers(
|
||||||
|
android.FixtureRegisterWithContext(registerShBuildComponents),
|
||||||
|
)
|
||||||
|
|
||||||
type shBinaryProperties struct {
|
type shBinaryProperties struct {
|
||||||
// Source file of this prebuilt.
|
// Source file of this prebuilt.
|
||||||
Src *string `android:"path,arch_variant"`
|
Src *string `android:"path,arch_variant"`
|
||||||
|
|
|
@ -37,28 +37,32 @@ func TestMain(m *testing.M) {
|
||||||
os.Exit(run())
|
os.Exit(run())
|
||||||
}
|
}
|
||||||
|
|
||||||
func testShBinary(t *testing.T, bp string) (*android.TestContext, android.Config) {
|
var shFixtureFactory = android.NewFixtureFactory(
|
||||||
fs := map[string][]byte{
|
&buildDir,
|
||||||
|
cc.PrepareForTestWithCcBuildComponents,
|
||||||
|
PrepareForTestWithShBuildComponents,
|
||||||
|
android.FixtureMergeMockFs(android.MockFS{
|
||||||
"test.sh": nil,
|
"test.sh": nil,
|
||||||
"testdata/data1": nil,
|
"testdata/data1": nil,
|
||||||
"testdata/sub/data2": nil,
|
"testdata/sub/data2": nil,
|
||||||
}
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
config := android.TestArchConfig(buildDir, nil, bp, fs)
|
// testShBinary runs tests using the shFixtureFactory
|
||||||
|
//
|
||||||
|
// Do not add any new usages of this, instead use the shFixtureFactory 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
|
||||||
|
// 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)
|
||||||
|
|
||||||
ctx := android.NewTestArchContext(config)
|
return result.TestContext, result.Config
|
||||||
ctx.RegisterModuleType("sh_test", ShTestFactory)
|
|
||||||
ctx.RegisterModuleType("sh_test_host", ShTestHostFactory)
|
|
||||||
|
|
||||||
cc.RegisterRequiredBuildComponentsForTest(ctx)
|
|
||||||
|
|
||||||
ctx.Register()
|
|
||||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
|
||||||
android.FailIfErrored(t, errs)
|
|
||||||
_, errs = ctx.PrepareBuildActions(config)
|
|
||||||
android.FailIfErrored(t, errs)
|
|
||||||
|
|
||||||
return ctx, config
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestShTestSubDir(t *testing.T) {
|
func TestShTestSubDir(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue