Convert kernel package to use test fixtures
Bug: 181070625 Test: m nothing Change-Id: Ibd3cc62feec1b911d74451d53cea81607d3bec36
This commit is contained in:
parent
cf7f2e0a9e
commit
e5ac250ab4
2 changed files with 17 additions and 80 deletions
|
@ -27,8 +27,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
android.RegisterModuleType("prebuilt_kernel_modules", prebuiltKernelModulesFactory)
|
|
||||||
pctx.Import("android/soong/cc/config")
|
pctx.Import("android/soong/cc/config")
|
||||||
|
registerKernelBuildComponents(android.InitRegistrationContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func registerKernelBuildComponents(ctx android.RegistrationContext) {
|
||||||
|
ctx.RegisterModuleType("prebuilt_kernel_modules", prebuiltKernelModulesFactory)
|
||||||
}
|
}
|
||||||
|
|
||||||
type prebuiltKernelModules struct {
|
type prebuiltKernelModules struct {
|
||||||
|
|
|
@ -15,73 +15,29 @@
|
||||||
package kernel
|
package kernel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
"android/soong/cc"
|
"android/soong/cc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testKernelModules(t *testing.T, bp string, fs map[string][]byte) (*android.TestContext, android.Config) {
|
|
||||||
bp = bp + `
|
|
||||||
cc_binary_host {
|
|
||||||
name: "depmod",
|
|
||||||
srcs: ["depmod.cpp"],
|
|
||||||
stl: "none",
|
|
||||||
static_executable: true,
|
|
||||||
system_shared_libs: [],
|
|
||||||
}
|
|
||||||
`
|
|
||||||
bp = bp + cc.GatherRequiredDepsForTest(android.Android)
|
|
||||||
|
|
||||||
fs["depmod.cpp"] = nil
|
|
||||||
cc.GatherRequiredFilesForTest(fs)
|
|
||||||
|
|
||||||
config := android.TestArchConfig(buildDir, nil, bp, fs)
|
|
||||||
|
|
||||||
ctx := android.NewTestArchContext(config)
|
|
||||||
ctx.RegisterModuleType("prebuilt_kernel_modules", prebuiltKernelModulesFactory)
|
|
||||||
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
|
|
||||||
cc.RegisterRequiredBuildComponentsForTest(ctx)
|
|
||||||
|
|
||||||
ctx.Register()
|
|
||||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
|
||||||
android.FailIfErrored(t, errs)
|
|
||||||
_, errs = ctx.PrepareBuildActions(config)
|
|
||||||
android.FailIfErrored(t, errs)
|
|
||||||
|
|
||||||
return ctx, config
|
|
||||||
}
|
|
||||||
|
|
||||||
func ensureListContains(t *testing.T, result []string, expected string) {
|
|
||||||
t.Helper()
|
|
||||||
if !android.InList(expected, result) {
|
|
||||||
t.Errorf("%q is not found in %v", expected, result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ensureContains(t *testing.T, result string, expected string) {
|
|
||||||
t.Helper()
|
|
||||||
if !strings.Contains(result, expected) {
|
|
||||||
t.Errorf("%q is not found in %q", expected, result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestKernelModulesFilelist(t *testing.T) {
|
func TestKernelModulesFilelist(t *testing.T) {
|
||||||
ctx, _ := testKernelModules(t, `
|
ctx := android.GroupFixturePreparers(
|
||||||
|
cc.PrepareForTestWithCcDefaultModules,
|
||||||
|
android.FixtureRegisterWithContext(registerKernelBuildComponents),
|
||||||
|
android.MockFS{
|
||||||
|
"depmod.cpp": nil,
|
||||||
|
"mod1.ko": nil,
|
||||||
|
"mod2.ko": nil,
|
||||||
|
}.AddToFixture(),
|
||||||
|
).RunTestWithBp(t, `
|
||||||
prebuilt_kernel_modules {
|
prebuilt_kernel_modules {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
srcs: ["*.ko"],
|
srcs: ["*.ko"],
|
||||||
kernel_version: "5.10",
|
kernel_version: "5.10",
|
||||||
}
|
}
|
||||||
`,
|
`)
|
||||||
map[string][]byte{
|
|
||||||
"mod1.ko": nil,
|
|
||||||
"mod2.ko": nil,
|
|
||||||
})
|
|
||||||
|
|
||||||
expected := []string{
|
expected := []string{
|
||||||
"lib/modules/5.10/mod1.ko",
|
"lib/modules/5.10/mod1.ko",
|
||||||
|
@ -98,32 +54,9 @@ func TestKernelModulesFilelist(t *testing.T) {
|
||||||
}
|
}
|
||||||
actual = android.SortedUniqueStrings(actual)
|
actual = android.SortedUniqueStrings(actual)
|
||||||
expected = android.SortedUniqueStrings(expected)
|
expected = android.SortedUniqueStrings(expected)
|
||||||
if !reflect.DeepEqual(actual, expected) {
|
android.AssertDeepEquals(t, "foo packaging specs", expected, actual)
|
||||||
t.Errorf("\ngot: %v\nexpected: %v\n", actual, expected)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var buildDir string
|
|
||||||
|
|
||||||
func setUp() {
|
|
||||||
var err error
|
|
||||||
buildDir, err = ioutil.TempDir("", "soong_kernel_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())
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue