Convert linkerconfig package to use test fixtures
Bug: 181070625 Test: m nothing Change-Id: Ic85e353ad8fa2aa324cd75d5bca8a1e31fd977a8
This commit is contained in:
parent
cf7f2e0a9e
commit
2a2fb66d6c
|
@ -27,7 +27,11 @@ var (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
pctx.HostBinToolVariable("conv_linker_config", "conv_linker_config")
|
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 {
|
type linkerConfigProperties struct {
|
||||||
|
|
|
@ -15,61 +15,25 @@
|
||||||
package linkerconfig
|
package linkerconfig
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"android/soong/android"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"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) {
|
func TestMain(m *testing.M) {
|
||||||
run := func() int {
|
os.Exit(m.Run())
|
||||||
setUp()
|
|
||||||
defer tearDown()
|
|
||||||
|
|
||||||
return m.Run()
|
|
||||||
}
|
|
||||||
|
|
||||||
os.Exit(run())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testContext(t *testing.T, bp string) *android.TestContext {
|
var prepareForLinkerConfigTest = android.GroupFixturePreparers(
|
||||||
t.Helper()
|
android.PrepareForTestWithAndroidBuildComponents,
|
||||||
|
android.FixtureRegisterWithContext(registerLinkerConfigBuildComponent),
|
||||||
fs := map[string][]byte{
|
android.FixtureAddFile("linker.config.json", nil),
|
||||||
"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
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBaseLinkerConfig(t *testing.T) {
|
func TestBaseLinkerConfig(t *testing.T) {
|
||||||
ctx := testContext(t, `
|
result := prepareForLinkerConfigTest.RunTestWithBp(t, `
|
||||||
linker_config {
|
linker_config {
|
||||||
name: "linker-config-base",
|
name: "linker-config-base",
|
||||||
src: "linker.config.json",
|
src: "linker.config.json",
|
||||||
|
@ -82,13 +46,13 @@ func TestBaseLinkerConfig(t *testing.T) {
|
||||||
"LOCAL_INSTALLED_MODULE_STEM": {"linker.config.pb"},
|
"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" {
|
if p.outputFilePath.Base() != "linker.config.pb" {
|
||||||
t.Errorf("expected linker.config.pb, got %q", p.outputFilePath.Base())
|
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 {
|
for k, expectedValue := range expected {
|
||||||
if value, ok := entries.EntryMap[k]; ok {
|
if value, ok := entries.EntryMap[k]; ok {
|
||||||
if !reflect.DeepEqual(value, expectedValue) {
|
if !reflect.DeepEqual(value, expectedValue) {
|
||||||
|
@ -105,7 +69,7 @@ func TestBaseLinkerConfig(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUninstallableLinkerConfig(t *testing.T) {
|
func TestUninstallableLinkerConfig(t *testing.T) {
|
||||||
ctx := testContext(t, `
|
result := prepareForLinkerConfigTest.RunTestWithBp(t, `
|
||||||
linker_config {
|
linker_config {
|
||||||
name: "linker-config-base",
|
name: "linker-config-base",
|
||||||
src: "linker.config.json",
|
src: "linker.config.json",
|
||||||
|
@ -115,8 +79,8 @@ func TestUninstallableLinkerConfig(t *testing.T) {
|
||||||
|
|
||||||
expected := []string{"true"}
|
expected := []string{"true"}
|
||||||
|
|
||||||
p := ctx.ModuleForTests("linker-config-base", "android_arm64_armv8-a").Module().(*linkerConfig)
|
p := result.ModuleForTests("linker-config-base", "android_arm64_armv8-a").Module().(*linkerConfig)
|
||||||
entries := android.AndroidMkEntriesForTest(t, ctx, p)[0]
|
entries := android.AndroidMkEntriesForTest(t, result.TestContext, p)[0]
|
||||||
if value, ok := entries.EntryMap["LOCAL_UNINSTALLABLE_MODULE"]; ok {
|
if value, ok := entries.EntryMap["LOCAL_UNINSTALLABLE_MODULE"]; ok {
|
||||||
if !reflect.DeepEqual(value, expected) {
|
if !reflect.DeepEqual(value, expected) {
|
||||||
t.Errorf("LOCAL_UNINSTALLABLE_MODULE is expected to be true but %s", value)
|
t.Errorf("LOCAL_UNINSTALLABLE_MODULE is expected to be true but %s", value)
|
||||||
|
|
Loading…
Reference in New Issue