Convert linkerconfig package to use test fixtures
Bug: 181070625 Test: m nothing Change-Id: Ic85e353ad8fa2aa324cd75d5bca8a1e31fd977a8
This commit is contained in:
parent
cf7f2e0a9e
commit
2a2fb66d6c
2 changed files with 28 additions and 60 deletions
|
@ -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 {
|
||||
|
|
|
@ -15,65 +15,29 @@
|
|||
package linkerconfig
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
run := func() int {
|
||||
setUp()
|
||||
defer tearDown()
|
||||
|
||||
return m.Run()
|
||||
}
|
||||
|
||||
os.Exit(run())
|
||||
os.Exit(m.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, `
|
||||
linker_config {
|
||||
name: "linker-config-base",
|
||||
src: "linker.config.json",
|
||||
}
|
||||
result := prepareForLinkerConfigTest.RunTestWithBp(t, `
|
||||
linker_config {
|
||||
name: "linker-config-base",
|
||||
src: "linker.config.json",
|
||||
}
|
||||
`)
|
||||
|
||||
expected := map[string][]string{
|
||||
|
@ -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) {
|
||||
|
@ -105,18 +69,18 @@ func TestBaseLinkerConfig(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUninstallableLinkerConfig(t *testing.T) {
|
||||
ctx := testContext(t, `
|
||||
linker_config {
|
||||
name: "linker-config-base",
|
||||
src: "linker.config.json",
|
||||
installable: false,
|
||||
}
|
||||
result := prepareForLinkerConfigTest.RunTestWithBp(t, `
|
||||
linker_config {
|
||||
name: "linker-config-base",
|
||||
src: "linker.config.json",
|
||||
installable: false,
|
||||
}
|
||||
`)
|
||||
|
||||
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…
Reference in a new issue