diff --git a/bpf/bpf.go b/bpf/bpf.go index 8142f10a5..fa1a84d04 100644 --- a/bpf/bpf.go +++ b/bpf/bpf.go @@ -26,7 +26,7 @@ import ( ) func init() { - android.RegisterModuleType("bpf", BpfFactory) + registerBpfBuildComponents(android.InitRegistrationContext) pctx.Import("android/soong/cc/config") } @@ -43,6 +43,12 @@ var ( "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. type BpfModule interface { android.Module diff --git a/bpf/bpf_test.go b/bpf/bpf_test.go index be9e36ea5..eb0d8c8f7 100644 --- a/bpf/bpf_test.go +++ b/bpf/bpf_test.go @@ -46,24 +46,20 @@ func TestMain(m *testing.M) { } os.Exit(run()) + } -func testConfig(buildDir string, env map[string]string, bp string) android.Config { - mockFS := map[string][]byte{ - "bpf.c": nil, - "BpfTest.cpp": nil, - } - - return cc.TestConfig(buildDir, android.Android, env, bp, mockFS) -} - -func testContext(config android.Config) *android.TestContext { - ctx := cc.CreateTestContext(config) - ctx.RegisterModuleType("bpf", BpfFactory) - ctx.Register() - - return ctx -} +var bpfFactory = android.NewFixtureFactory( + &buildDir, + cc.PrepareForTestWithCcDefaultModules, + android.FixtureMergeMockFs( + map[string][]byte{ + "bpf.c": nil, + "BpfTest.cpp": nil, + }, + ), + PrepareForTestWithBpf, +) func TestBpfDataDependency(t *testing.T) { bp := ` @@ -80,16 +76,7 @@ func TestBpfDataDependency(t *testing.T) { } ` - config := testConfig(buildDir, nil, bp) - ctx := testContext(config) - - _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) - if errs == nil { - _, errs = ctx.PrepareBuildActions(config) - } - if errs != nil { - t.Fatal(errs) - } + bpfFactory.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.