Support test fixtures in bpf package

Restructures the bpf package test setup code to create FixturePreparer
instances for setting up a test fixture and converts the test to use
it.

Bug: 181070625
Test: m nothing
Change-Id: I7c76ed6dc292ca92d76ef95c4167f7ca2d68e1af
This commit is contained in:
Paul Duffin
2021-02-24 18:51:54 +00:00
parent 02a3d65402
commit 12c7eb8cb1
2 changed files with 20 additions and 27 deletions

View File

@@ -26,7 +26,7 @@ import (
) )
func init() { func init() {
android.RegisterModuleType("bpf", BpfFactory) registerBpfBuildComponents(android.InitRegistrationContext)
pctx.Import("android/soong/cc/config") pctx.Import("android/soong/cc/config")
} }
@@ -43,6 +43,12 @@ var (
"ccCmd", "cFlags") "ccCmd", "cFlags")
) )
func registerBpfBuildComponents(ctx android.RegistrationContext) {
ctx.RegisterModuleType("bpf", BpfFactory)
}
var PrepareForTestWithBpf = android.FixtureRegisterWithContext(registerBpfBuildComponents)
// BpfModule interface is used by the apex package to gather information from a bpf module. // BpfModule interface is used by the apex package to gather information from a bpf module.
type BpfModule interface { type BpfModule interface {
android.Module android.Module

View File

@@ -46,24 +46,20 @@ func TestMain(m *testing.M) {
} }
os.Exit(run()) os.Exit(run())
} }
func testConfig(buildDir string, env map[string]string, bp string) android.Config { var bpfFactory = android.NewFixtureFactory(
mockFS := map[string][]byte{ &buildDir,
"bpf.c": nil, cc.PrepareForTestWithCcDefaultModules,
"BpfTest.cpp": nil, android.FixtureMergeMockFs(
} map[string][]byte{
"bpf.c": nil,
return cc.TestConfig(buildDir, android.Android, env, bp, mockFS) "BpfTest.cpp": nil,
} },
),
func testContext(config android.Config) *android.TestContext { PrepareForTestWithBpf,
ctx := cc.CreateTestContext(config) )
ctx.RegisterModuleType("bpf", BpfFactory)
ctx.Register()
return ctx
}
func TestBpfDataDependency(t *testing.T) { func TestBpfDataDependency(t *testing.T) {
bp := ` bp := `
@@ -80,16 +76,7 @@ func TestBpfDataDependency(t *testing.T) {
} }
` `
config := testConfig(buildDir, nil, bp) bpfFactory.RunTestWithBp(t, bp)
ctx := testContext(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
if errs == nil {
_, errs = ctx.PrepareBuildActions(config)
}
if errs != nil {
t.Fatal(errs)
}
// We only verify the above BP configuration is processed successfully since the data property // We only verify the above BP configuration is processed successfully since the data property
// value is not available for testing from this package. // value is not available for testing from this package.