Support test fixtures in etc package
Restructures the etc package test setup code to create FixturePreparer instances for setting up a test fixture. Bug: 181070625 Test: m nothing Change-Id: I6f269c9cb3f4ab2756beddd13a719f9b222f7156
This commit is contained in:
parent
8bd286590b
commit
1172fed8eb
|
@ -54,6 +54,8 @@ func RegisterPrebuiltEtcBuildComponents(ctx android.RegistrationContext) {
|
|||
ctx.RegisterModuleType("prebuilt_dsp", PrebuiltDSPFactory)
|
||||
}
|
||||
|
||||
var PrepareForTestWithPrebuiltEtc = android.FixtureRegisterWithContext(RegisterPrebuiltEtcBuildComponents)
|
||||
|
||||
type prebuiltEtcProperties struct {
|
||||
// Source file of this prebuilt. Can reference a genrule type module with the ":module" syntax.
|
||||
Src *string `android:"path,arch_variant"`
|
||||
|
|
|
@ -49,58 +49,34 @@ func TestMain(m *testing.M) {
|
|||
os.Exit(run())
|
||||
}
|
||||
|
||||
func testPrebuiltEtcContext(t *testing.T, bp string) (*android.TestContext, android.Config) {
|
||||
fs := map[string][]byte{
|
||||
var prebuiltEtcFixtureFactory = android.NewFixtureFactory(
|
||||
&buildDir,
|
||||
android.PrepareForTestWithArchMutator,
|
||||
PrepareForTestWithPrebuiltEtc,
|
||||
android.FixtureMergeMockFs(android.MockFS{
|
||||
"foo.conf": nil,
|
||||
"bar.conf": nil,
|
||||
"baz.conf": nil,
|
||||
}
|
||||
|
||||
config := android.TestArchConfig(buildDir, nil, bp, fs)
|
||||
|
||||
ctx := android.NewTestArchContext(config)
|
||||
ctx.RegisterModuleType("prebuilt_etc", PrebuiltEtcFactory)
|
||||
ctx.RegisterModuleType("prebuilt_etc_host", PrebuiltEtcHostFactory)
|
||||
ctx.RegisterModuleType("prebuilt_usr_share", PrebuiltUserShareFactory)
|
||||
ctx.RegisterModuleType("prebuilt_usr_share_host", PrebuiltUserShareHostFactory)
|
||||
ctx.RegisterModuleType("prebuilt_font", PrebuiltFontFactory)
|
||||
ctx.RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory)
|
||||
ctx.RegisterModuleType("prebuilt_dsp", PrebuiltDSPFactory)
|
||||
ctx.Register()
|
||||
|
||||
return ctx, config
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
||||
// testPrebuiltEtc runs tests using the prebuiltEtcFixtureFactory
|
||||
//
|
||||
// Do not add any new usages of this, instead use the prebuiltEtcFixtureFactory 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 prebuiltEtcFixtureFactory 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 testPrebuiltEtc(t *testing.T, bp string) (*android.TestContext, android.Config) {
|
||||
t.Helper()
|
||||
|
||||
ctx, config := testPrebuiltEtcContext(t, bp)
|
||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
||||
android.FailIfErrored(t, errs)
|
||||
_, errs = ctx.PrepareBuildActions(config)
|
||||
android.FailIfErrored(t, errs)
|
||||
|
||||
return ctx, config
|
||||
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, bp)
|
||||
return result.TestContext, result.Config
|
||||
}
|
||||
|
||||
func testPrebuiltEtcError(t *testing.T, pattern, bp string) {
|
||||
t.Helper()
|
||||
|
||||
ctx, config := testPrebuiltEtcContext(t, bp)
|
||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
||||
if len(errs) > 0 {
|
||||
android.FailIfNoMatchingErrors(t, pattern, errs)
|
||||
return
|
||||
}
|
||||
|
||||
_, errs = ctx.PrepareBuildActions(config)
|
||||
if len(errs) > 0 {
|
||||
android.FailIfNoMatchingErrors(t, pattern, errs)
|
||||
return
|
||||
}
|
||||
|
||||
t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
|
||||
}
|
||||
func TestPrebuiltEtcVariants(t *testing.T) {
|
||||
ctx, _ := testPrebuiltEtc(t, `
|
||||
prebuilt_etc {
|
||||
|
@ -227,7 +203,9 @@ func TestPrebuiltEtcRelativeInstallPathInstallDirPath(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPrebuiltEtcCannotSetRelativeInstallPathAndSubDir(t *testing.T) {
|
||||
testPrebuiltEtcError(t, "relative_install_path is set. Cannot set sub_dir", `
|
||||
prebuiltEtcFixtureFactory.
|
||||
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern("relative_install_path is set. Cannot set sub_dir")).
|
||||
RunTestWithBp(t, `
|
||||
prebuilt_etc {
|
||||
name: "foo.conf",
|
||||
src: "foo.conf",
|
||||
|
|
Loading…
Reference in New Issue