Convert etc tests to use test fixtures
Bug: 181070625 Test: m nothing Change-Id: Ic248e233f57f966164284d7cab813398305482c9
This commit is contained in:
@@ -18,7 +18,6 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
@@ -60,25 +59,8 @@ var prebuiltEtcFixtureFactory = android.NewFixtureFactory(
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
// testPrebuiltEtc runs tests using the prebuiltEtcFixtureFactory
|
|
||||||
//
|
|
||||||
// Do not add any new usages of this, instead use the prebuiltEtcFixtureFactory directly as it
|
|
||||||
// makes it much easier to customize the test behavior.
|
|
||||||
//
|
|
||||||
// If it is necessary to customize the behavior of an existing test that uses this then please first
|
|
||||||
// convert the test to using prebuiltEtcFixtureFactory first and then in a following change add the
|
|
||||||
// appropriate fixture preparers. Keeping the conversion change separate makes it easy to verify
|
|
||||||
// that it did not change the test behavior unexpectedly.
|
|
||||||
//
|
|
||||||
// deprecated
|
|
||||||
func testPrebuiltEtc(t *testing.T, bp string) (*android.TestContext, android.Config) {
|
|
||||||
t.Helper()
|
|
||||||
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, bp)
|
|
||||||
return result.TestContext, result.Config
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPrebuiltEtcVariants(t *testing.T) {
|
func TestPrebuiltEtcVariants(t *testing.T) {
|
||||||
ctx, _ := testPrebuiltEtc(t, `
|
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, `
|
||||||
prebuilt_etc {
|
prebuilt_etc {
|
||||||
name: "foo.conf",
|
name: "foo.conf",
|
||||||
src: "foo.conf",
|
src: "foo.conf",
|
||||||
@@ -95,24 +77,24 @@ func TestPrebuiltEtcVariants(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
foo_variants := ctx.ModuleVariantsForTests("foo.conf")
|
foo_variants := result.ModuleVariantsForTests("foo.conf")
|
||||||
if len(foo_variants) != 1 {
|
if len(foo_variants) != 1 {
|
||||||
t.Errorf("expected 1, got %#v", foo_variants)
|
t.Errorf("expected 1, got %#v", foo_variants)
|
||||||
}
|
}
|
||||||
|
|
||||||
bar_variants := ctx.ModuleVariantsForTests("bar.conf")
|
bar_variants := result.ModuleVariantsForTests("bar.conf")
|
||||||
if len(bar_variants) != 2 {
|
if len(bar_variants) != 2 {
|
||||||
t.Errorf("expected 2, got %#v", bar_variants)
|
t.Errorf("expected 2, got %#v", bar_variants)
|
||||||
}
|
}
|
||||||
|
|
||||||
baz_variants := ctx.ModuleVariantsForTests("baz.conf")
|
baz_variants := result.ModuleVariantsForTests("baz.conf")
|
||||||
if len(baz_variants) != 1 {
|
if len(baz_variants) != 1 {
|
||||||
t.Errorf("expected 1, got %#v", bar_variants)
|
t.Errorf("expected 1, got %#v", bar_variants)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuiltEtcOutputPath(t *testing.T) {
|
func TestPrebuiltEtcOutputPath(t *testing.T) {
|
||||||
ctx, _ := testPrebuiltEtc(t, `
|
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, `
|
||||||
prebuilt_etc {
|
prebuilt_etc {
|
||||||
name: "foo.conf",
|
name: "foo.conf",
|
||||||
src: "foo.conf",
|
src: "foo.conf",
|
||||||
@@ -120,14 +102,12 @@ func TestPrebuiltEtcOutputPath(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
p := ctx.ModuleForTests("foo.conf", "android_arm64_armv8-a").Module().(*PrebuiltEtc)
|
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
||||||
if p.outputFilePath.Base() != "foo.installed.conf" {
|
result.AssertStringEquals("output file path", "foo.installed.conf", p.outputFilePath.Base())
|
||||||
t.Errorf("expected foo.installed.conf, got %q", p.outputFilePath.Base())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuiltEtcGlob(t *testing.T) {
|
func TestPrebuiltEtcGlob(t *testing.T) {
|
||||||
ctx, _ := testPrebuiltEtc(t, `
|
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, `
|
||||||
prebuilt_etc {
|
prebuilt_etc {
|
||||||
name: "my_foo",
|
name: "my_foo",
|
||||||
src: "foo.*",
|
src: "foo.*",
|
||||||
@@ -139,19 +119,15 @@ func TestPrebuiltEtcGlob(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
p := ctx.ModuleForTests("my_foo", "android_arm64_armv8-a").Module().(*PrebuiltEtc)
|
p := result.Module("my_foo", "android_arm64_armv8-a").(*PrebuiltEtc)
|
||||||
if p.outputFilePath.Base() != "my_foo" {
|
result.AssertStringEquals("my_foo output file path", "my_foo", p.outputFilePath.Base())
|
||||||
t.Errorf("expected my_foo, got %q", p.outputFilePath.Base())
|
|
||||||
}
|
|
||||||
|
|
||||||
p = ctx.ModuleForTests("my_bar", "android_arm64_armv8-a").Module().(*PrebuiltEtc)
|
p = result.Module("my_bar", "android_arm64_armv8-a").(*PrebuiltEtc)
|
||||||
if p.outputFilePath.Base() != "bar.conf" {
|
result.AssertStringEquals("my_bar output file path", "bar.conf", p.outputFilePath.Base())
|
||||||
t.Errorf("expected bar.conf, got %q", p.outputFilePath.Base())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuiltEtcAndroidMk(t *testing.T) {
|
func TestPrebuiltEtcAndroidMk(t *testing.T) {
|
||||||
ctx, _ := testPrebuiltEtc(t, `
|
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, `
|
||||||
prebuilt_etc {
|
prebuilt_etc {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
src: "foo.conf",
|
src: "foo.conf",
|
||||||
@@ -173,13 +149,11 @@ func TestPrebuiltEtcAndroidMk(t *testing.T) {
|
|||||||
"LOCAL_TARGET_REQUIRED_MODULES": {"targetModA"},
|
"LOCAL_TARGET_REQUIRED_MODULES": {"targetModA"},
|
||||||
}
|
}
|
||||||
|
|
||||||
mod := ctx.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*PrebuiltEtc)
|
mod := result.Module("foo", "android_arm64_armv8-a").(*PrebuiltEtc)
|
||||||
entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0]
|
entries := android.AndroidMkEntriesForTest(t, result.TestContext, mod)[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) {
|
result.AssertDeepEquals(k, expectedValue, value)
|
||||||
t.Errorf("Incorrect %s '%s', expected '%s'", k, value, expectedValue)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
t.Errorf("No %s defined, saw %q", k, entries.EntryMap)
|
t.Errorf("No %s defined, saw %q", k, entries.EntryMap)
|
||||||
}
|
}
|
||||||
@@ -187,7 +161,7 @@ func TestPrebuiltEtcAndroidMk(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuiltEtcRelativeInstallPathInstallDirPath(t *testing.T) {
|
func TestPrebuiltEtcRelativeInstallPathInstallDirPath(t *testing.T) {
|
||||||
ctx, _ := testPrebuiltEtc(t, `
|
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, `
|
||||||
prebuilt_etc {
|
prebuilt_etc {
|
||||||
name: "foo.conf",
|
name: "foo.conf",
|
||||||
src: "foo.conf",
|
src: "foo.conf",
|
||||||
@@ -195,11 +169,9 @@ func TestPrebuiltEtcRelativeInstallPathInstallDirPath(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
p := ctx.ModuleForTests("foo.conf", "android_arm64_armv8-a").Module().(*PrebuiltEtc)
|
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
||||||
expected := buildDir + "/target/product/test_device/system/etc/bar"
|
expected := buildDir + "/target/product/test_device/system/etc/bar"
|
||||||
if p.installDirPath.String() != expected {
|
result.AssertStringEquals("install dir", expected, p.installDirPath.String())
|
||||||
t.Errorf("expected %q, got %q", expected, p.installDirPath.String())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuiltEtcCannotSetRelativeInstallPathAndSubDir(t *testing.T) {
|
func TestPrebuiltEtcCannotSetRelativeInstallPathAndSubDir(t *testing.T) {
|
||||||
@@ -216,7 +188,7 @@ func TestPrebuiltEtcCannotSetRelativeInstallPathAndSubDir(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuiltEtcHost(t *testing.T) {
|
func TestPrebuiltEtcHost(t *testing.T) {
|
||||||
ctx, _ := testPrebuiltEtc(t, `
|
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, `
|
||||||
prebuilt_etc_host {
|
prebuilt_etc_host {
|
||||||
name: "foo.conf",
|
name: "foo.conf",
|
||||||
src: "foo.conf",
|
src: "foo.conf",
|
||||||
@@ -224,14 +196,14 @@ func TestPrebuiltEtcHost(t *testing.T) {
|
|||||||
`)
|
`)
|
||||||
|
|
||||||
buildOS := android.BuildOs.String()
|
buildOS := android.BuildOs.String()
|
||||||
p := ctx.ModuleForTests("foo.conf", buildOS+"_common").Module().(*PrebuiltEtc)
|
p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc)
|
||||||
if !p.Host() {
|
if !p.Host() {
|
||||||
t.Errorf("host bit is not set for a prebuilt_etc_host module.")
|
t.Errorf("host bit is not set for a prebuilt_etc_host module.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuiltUserShareInstallDirPath(t *testing.T) {
|
func TestPrebuiltUserShareInstallDirPath(t *testing.T) {
|
||||||
ctx, _ := testPrebuiltEtc(t, `
|
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, `
|
||||||
prebuilt_usr_share {
|
prebuilt_usr_share {
|
||||||
name: "foo.conf",
|
name: "foo.conf",
|
||||||
src: "foo.conf",
|
src: "foo.conf",
|
||||||
@@ -239,15 +211,13 @@ func TestPrebuiltUserShareInstallDirPath(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
p := ctx.ModuleForTests("foo.conf", "android_arm64_armv8-a").Module().(*PrebuiltEtc)
|
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
||||||
expected := buildDir + "/target/product/test_device/system/usr/share/bar"
|
expected := buildDir + "/target/product/test_device/system/usr/share/bar"
|
||||||
if p.installDirPath.String() != expected {
|
result.AssertStringEquals("install dir", expected, p.installDirPath.String())
|
||||||
t.Errorf("expected %q, got %q", expected, p.installDirPath.String())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) {
|
func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) {
|
||||||
ctx, config := testPrebuiltEtc(t, `
|
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, `
|
||||||
prebuilt_usr_share_host {
|
prebuilt_usr_share_host {
|
||||||
name: "foo.conf",
|
name: "foo.conf",
|
||||||
src: "foo.conf",
|
src: "foo.conf",
|
||||||
@@ -256,26 +226,22 @@ func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) {
|
|||||||
`)
|
`)
|
||||||
|
|
||||||
buildOS := android.BuildOs.String()
|
buildOS := android.BuildOs.String()
|
||||||
p := ctx.ModuleForTests("foo.conf", buildOS+"_common").Module().(*PrebuiltEtc)
|
p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc)
|
||||||
expected := filepath.Join(buildDir, "host", config.PrebuiltOS(), "usr", "share", "bar")
|
expected := filepath.Join(buildDir, "host", result.Config.PrebuiltOS(), "usr", "share", "bar")
|
||||||
if p.installDirPath.String() != expected {
|
result.AssertStringEquals("install dir", expected, p.installDirPath.String())
|
||||||
t.Errorf("expected %q, got %q", expected, p.installDirPath.String())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuiltFontInstallDirPath(t *testing.T) {
|
func TestPrebuiltFontInstallDirPath(t *testing.T) {
|
||||||
ctx, _ := testPrebuiltEtc(t, `
|
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, `
|
||||||
prebuilt_font {
|
prebuilt_font {
|
||||||
name: "foo.conf",
|
name: "foo.conf",
|
||||||
src: "foo.conf",
|
src: "foo.conf",
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
p := ctx.ModuleForTests("foo.conf", "android_arm64_armv8-a").Module().(*PrebuiltEtc)
|
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
||||||
expected := buildDir + "/target/product/test_device/system/fonts"
|
expected := buildDir + "/target/product/test_device/system/fonts"
|
||||||
if p.installDirPath.String() != expected {
|
result.AssertStringEquals("install dir", expected, p.installDirPath.String())
|
||||||
t.Errorf("expected %q, got %q", expected, p.installDirPath.String())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuiltFirmwareDirPath(t *testing.T) {
|
func TestPrebuiltFirmwareDirPath(t *testing.T) {
|
||||||
@@ -305,11 +271,9 @@ func TestPrebuiltFirmwareDirPath(t *testing.T) {
|
|||||||
}}
|
}}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.description, func(t *testing.T) {
|
t.Run(tt.description, func(t *testing.T) {
|
||||||
ctx, _ := testPrebuiltEtc(t, tt.config)
|
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, tt.config)
|
||||||
p := ctx.ModuleForTests("foo.conf", "android_arm64_armv8-a").Module().(*PrebuiltEtc)
|
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
||||||
if p.installDirPath.String() != tt.expectedPath {
|
result.AssertStringEquals("install dir", tt.expectedPath, p.installDirPath.String())
|
||||||
t.Errorf("expected %q, got %q", tt.expectedPath, p.installDirPath)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -341,11 +305,9 @@ func TestPrebuiltDSPDirPath(t *testing.T) {
|
|||||||
}}
|
}}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.description, func(t *testing.T) {
|
t.Run(tt.description, func(t *testing.T) {
|
||||||
ctx, _ := testPrebuiltEtc(t, tt.config)
|
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, tt.config)
|
||||||
p := ctx.ModuleForTests("foo.conf", "android_arm64_armv8-a").Module().(*PrebuiltEtc)
|
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
||||||
if p.installDirPath.String() != tt.expectedPath {
|
result.AssertStringEquals("install dir", tt.expectedPath, p.installDirPath.String())
|
||||||
t.Errorf("expected %q, got %q", tt.expectedPath, p.installDirPath)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user