Loading linkerconfig/linkerconfig.go +5 −1 Original line number Diff line number Diff line Loading @@ -27,7 +27,11 @@ var ( func init() { pctx.HostBinToolVariable("conv_linker_config", "conv_linker_config") android.RegisterModuleType("linker_config", linkerConfigFactory) registerLinkerConfigBuildComponent(android.InitRegistrationContext) } func registerLinkerConfigBuildComponent(ctx android.RegistrationContext) { ctx.RegisterModuleType("linker_config", linkerConfigFactory) } type linkerConfigProperties struct { Loading linkerconfig/linkerconfig_test.go +23 −59 Original line number Diff line number Diff line Loading @@ -15,61 +15,25 @@ package linkerconfig import ( "android/soong/android" "io/ioutil" "os" "reflect" "testing" ) var buildDir string func setUp() { var err error buildDir, err = ioutil.TempDir("", "soong_etc_test") if err != nil { panic(err) } } func tearDown() { os.RemoveAll(buildDir) } "android/soong/android" ) func TestMain(m *testing.M) { run := func() int { setUp() defer tearDown() return m.Run() os.Exit(m.Run()) } os.Exit(run()) } func testContext(t *testing.T, bp string) *android.TestContext { t.Helper() fs := map[string][]byte{ "linker.config.json": nil, } config := android.TestArchConfig(buildDir, nil, bp, fs) ctx := android.NewTestArchContext(config) ctx.RegisterModuleType("linker_config", linkerConfigFactory) ctx.Register() _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) android.FailIfErrored(t, errs) _, errs = ctx.PrepareBuildActions(config) android.FailIfErrored(t, errs) return ctx } var prepareForLinkerConfigTest = android.GroupFixturePreparers( android.PrepareForTestWithAndroidBuildComponents, android.FixtureRegisterWithContext(registerLinkerConfigBuildComponent), android.FixtureAddFile("linker.config.json", nil), ) func TestBaseLinkerConfig(t *testing.T) { ctx := testContext(t, ` result := prepareForLinkerConfigTest.RunTestWithBp(t, ` linker_config { name: "linker-config-base", src: "linker.config.json", Loading @@ -82,13 +46,13 @@ func TestBaseLinkerConfig(t *testing.T) { "LOCAL_INSTALLED_MODULE_STEM": {"linker.config.pb"}, } p := ctx.ModuleForTests("linker-config-base", "android_arm64_armv8-a").Module().(*linkerConfig) p := result.ModuleForTests("linker-config-base", "android_arm64_armv8-a").Module().(*linkerConfig) if p.outputFilePath.Base() != "linker.config.pb" { t.Errorf("expected linker.config.pb, got %q", p.outputFilePath.Base()) } entries := android.AndroidMkEntriesForTest(t, ctx, p)[0] entries := android.AndroidMkEntriesForTest(t, result.TestContext, p)[0] for k, expectedValue := range expected { if value, ok := entries.EntryMap[k]; ok { if !reflect.DeepEqual(value, expectedValue) { Loading @@ -105,7 +69,7 @@ func TestBaseLinkerConfig(t *testing.T) { } func TestUninstallableLinkerConfig(t *testing.T) { ctx := testContext(t, ` result := prepareForLinkerConfigTest.RunTestWithBp(t, ` linker_config { name: "linker-config-base", src: "linker.config.json", Loading @@ -115,8 +79,8 @@ func TestUninstallableLinkerConfig(t *testing.T) { expected := []string{"true"} p := ctx.ModuleForTests("linker-config-base", "android_arm64_armv8-a").Module().(*linkerConfig) entries := android.AndroidMkEntriesForTest(t, ctx, p)[0] p := result.ModuleForTests("linker-config-base", "android_arm64_armv8-a").Module().(*linkerConfig) entries := android.AndroidMkEntriesForTest(t, result.TestContext, p)[0] if value, ok := entries.EntryMap["LOCAL_UNINSTALLABLE_MODULE"]; ok { if !reflect.DeepEqual(value, expected) { t.Errorf("LOCAL_UNINSTALLABLE_MODULE is expected to be true but %s", value) Loading Loading
linkerconfig/linkerconfig.go +5 −1 Original line number Diff line number Diff line Loading @@ -27,7 +27,11 @@ var ( func init() { pctx.HostBinToolVariable("conv_linker_config", "conv_linker_config") android.RegisterModuleType("linker_config", linkerConfigFactory) registerLinkerConfigBuildComponent(android.InitRegistrationContext) } func registerLinkerConfigBuildComponent(ctx android.RegistrationContext) { ctx.RegisterModuleType("linker_config", linkerConfigFactory) } type linkerConfigProperties struct { Loading
linkerconfig/linkerconfig_test.go +23 −59 Original line number Diff line number Diff line Loading @@ -15,61 +15,25 @@ package linkerconfig import ( "android/soong/android" "io/ioutil" "os" "reflect" "testing" ) var buildDir string func setUp() { var err error buildDir, err = ioutil.TempDir("", "soong_etc_test") if err != nil { panic(err) } } func tearDown() { os.RemoveAll(buildDir) } "android/soong/android" ) func TestMain(m *testing.M) { run := func() int { setUp() defer tearDown() return m.Run() os.Exit(m.Run()) } os.Exit(run()) } func testContext(t *testing.T, bp string) *android.TestContext { t.Helper() fs := map[string][]byte{ "linker.config.json": nil, } config := android.TestArchConfig(buildDir, nil, bp, fs) ctx := android.NewTestArchContext(config) ctx.RegisterModuleType("linker_config", linkerConfigFactory) ctx.Register() _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) android.FailIfErrored(t, errs) _, errs = ctx.PrepareBuildActions(config) android.FailIfErrored(t, errs) return ctx } var prepareForLinkerConfigTest = android.GroupFixturePreparers( android.PrepareForTestWithAndroidBuildComponents, android.FixtureRegisterWithContext(registerLinkerConfigBuildComponent), android.FixtureAddFile("linker.config.json", nil), ) func TestBaseLinkerConfig(t *testing.T) { ctx := testContext(t, ` result := prepareForLinkerConfigTest.RunTestWithBp(t, ` linker_config { name: "linker-config-base", src: "linker.config.json", Loading @@ -82,13 +46,13 @@ func TestBaseLinkerConfig(t *testing.T) { "LOCAL_INSTALLED_MODULE_STEM": {"linker.config.pb"}, } p := ctx.ModuleForTests("linker-config-base", "android_arm64_armv8-a").Module().(*linkerConfig) p := result.ModuleForTests("linker-config-base", "android_arm64_armv8-a").Module().(*linkerConfig) if p.outputFilePath.Base() != "linker.config.pb" { t.Errorf("expected linker.config.pb, got %q", p.outputFilePath.Base()) } entries := android.AndroidMkEntriesForTest(t, ctx, p)[0] entries := android.AndroidMkEntriesForTest(t, result.TestContext, p)[0] for k, expectedValue := range expected { if value, ok := entries.EntryMap[k]; ok { if !reflect.DeepEqual(value, expectedValue) { Loading @@ -105,7 +69,7 @@ func TestBaseLinkerConfig(t *testing.T) { } func TestUninstallableLinkerConfig(t *testing.T) { ctx := testContext(t, ` result := prepareForLinkerConfigTest.RunTestWithBp(t, ` linker_config { name: "linker-config-base", src: "linker.config.json", Loading @@ -115,8 +79,8 @@ func TestUninstallableLinkerConfig(t *testing.T) { expected := []string{"true"} p := ctx.ModuleForTests("linker-config-base", "android_arm64_armv8-a").Module().(*linkerConfig) entries := android.AndroidMkEntriesForTest(t, ctx, p)[0] p := result.ModuleForTests("linker-config-base", "android_arm64_armv8-a").Module().(*linkerConfig) entries := android.AndroidMkEntriesForTest(t, result.TestContext, p)[0] if value, ok := entries.EntryMap["LOCAL_UNINSTALLABLE_MODULE"]; ok { if !reflect.DeepEqual(value, expected) { t.Errorf("LOCAL_UNINSTALLABLE_MODULE is expected to be true but %s", value) Loading