Merge changes Iccba8caf,I1eb49f25,Id77575f8,I5679cb51,I7f9f3eb6, ...
* changes: Convert android/ninja_deps_test.go to test fixtures Add NinjaDeps to TestResult Convert android/singleton_module_test.go to test fixtures Convert android/neverallow_test.go to test fixtures Convert android/singleton_module_test.go to test fixtures Convert android/variable_test.go to test fixtures Convert android/soong_config_modules_test.go to test fixtures Convert android/mutator_test.go to test fixtures Convert android/deptag_test.go to test fixtures
This commit is contained in:
commit
387f4ce1ee
|
@ -80,21 +80,20 @@ func TestInstallDependencyTag(t *testing.T) {
|
|||
}
|
||||
`
|
||||
|
||||
config := TestArchConfig(buildDir, nil, bp, nil)
|
||||
ctx := NewTestArchContext(config)
|
||||
result := emptyTestFixtureFactory.RunTest(t,
|
||||
PrepareForTestWithArchMutator,
|
||||
FixtureWithRootAndroidBp(bp),
|
||||
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
||||
ctx.RegisterModuleType("test_module", testInstallDependencyTagModuleFactory)
|
||||
}),
|
||||
)
|
||||
|
||||
ctx.RegisterModuleType("test_module", testInstallDependencyTagModuleFactory)
|
||||
config := result.Config
|
||||
|
||||
ctx.Register()
|
||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
||||
FailIfErrored(t, errs)
|
||||
_, errs = ctx.PrepareBuildActions(config)
|
||||
FailIfErrored(t, errs)
|
||||
|
||||
hostFoo := ctx.ModuleForTests("foo", config.BuildOSCommonTarget.String()).Description("install")
|
||||
hostInstallDep := ctx.ModuleForTests("install_dep", config.BuildOSCommonTarget.String()).Description("install")
|
||||
hostTransitive := ctx.ModuleForTests("transitive", config.BuildOSCommonTarget.String()).Description("install")
|
||||
hostDep := ctx.ModuleForTests("dep", config.BuildOSCommonTarget.String()).Description("install")
|
||||
hostFoo := result.ModuleForTests("foo", config.BuildOSCommonTarget.String()).Description("install")
|
||||
hostInstallDep := result.ModuleForTests("install_dep", config.BuildOSCommonTarget.String()).Description("install")
|
||||
hostTransitive := result.ModuleForTests("transitive", config.BuildOSCommonTarget.String()).Description("install")
|
||||
hostDep := result.ModuleForTests("dep", config.BuildOSCommonTarget.String()).Description("install")
|
||||
|
||||
if g, w := hostFoo.Implicits.Strings(), hostInstallDep.Output.String(); !InList(w, g) {
|
||||
t.Errorf("expected host dependency %q, got %q", w, g)
|
||||
|
@ -112,10 +111,10 @@ func TestInstallDependencyTag(t *testing.T) {
|
|||
t.Errorf("expected no host dependency %q, got %q", w, g)
|
||||
}
|
||||
|
||||
deviceFoo := ctx.ModuleForTests("foo", "android_common").Description("install")
|
||||
deviceInstallDep := ctx.ModuleForTests("install_dep", "android_common").Description("install")
|
||||
deviceTransitive := ctx.ModuleForTests("transitive", "android_common").Description("install")
|
||||
deviceDep := ctx.ModuleForTests("dep", "android_common").Description("install")
|
||||
deviceFoo := result.ModuleForTests("foo", "android_common").Description("install")
|
||||
deviceInstallDep := result.ModuleForTests("install_dep", "android_common").Description("install")
|
||||
deviceTransitive := result.ModuleForTests("transitive", "android_common").Description("install")
|
||||
deviceDep := result.ModuleForTests("dep", "android_common").Description("install")
|
||||
|
||||
if g, w := deviceFoo.OrderOnly.Strings(), deviceInstallDep.Output.String(); !InList(w, g) {
|
||||
t.Errorf("expected device dependency %q, got %q", w, g)
|
||||
|
|
|
@ -582,6 +582,10 @@ type TestResult struct {
|
|||
|
||||
// The errors that were reported during the test.
|
||||
Errs []error
|
||||
|
||||
// The ninja deps is a list of the ninja files dependencies that were added by the modules and
|
||||
// singletons via the *.AddNinjaFileDeps() methods.
|
||||
NinjaDeps []string
|
||||
}
|
||||
|
||||
var _ FixtureFactory = (*fixtureFactory)(nil)
|
||||
|
@ -722,9 +726,14 @@ func (f *fixture) RunTest() *TestResult {
|
|||
}
|
||||
|
||||
ctx.Register()
|
||||
_, errs := ctx.ParseBlueprintsFiles("ignored")
|
||||
var ninjaDeps []string
|
||||
extraNinjaDeps, errs := ctx.ParseBlueprintsFiles("ignored")
|
||||
if len(errs) == 0 {
|
||||
_, errs = ctx.PrepareBuildActions(f.config)
|
||||
ninjaDeps = append(ninjaDeps, extraNinjaDeps...)
|
||||
extraNinjaDeps, errs = ctx.PrepareBuildActions(f.config)
|
||||
if len(errs) == 0 {
|
||||
ninjaDeps = append(ninjaDeps, extraNinjaDeps...)
|
||||
}
|
||||
}
|
||||
|
||||
result := &TestResult{
|
||||
|
@ -732,6 +741,7 @@ func (f *fixture) RunTest() *TestResult {
|
|||
fixture: f,
|
||||
Config: f.config,
|
||||
Errs: errs,
|
||||
NinjaDeps: ninjaDeps,
|
||||
}
|
||||
|
||||
f.errorHandler.CheckErrors(f.t, result)
|
||||
|
|
|
@ -16,12 +16,10 @@ package android
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
"github.com/google/blueprint/proptools"
|
||||
)
|
||||
|
||||
type mutatorTestModule struct {
|
||||
|
@ -67,28 +65,20 @@ func TestMutatorAddMissingDependencies(t *testing.T) {
|
|||
}
|
||||
`
|
||||
|
||||
config := TestConfig(buildDir, nil, bp, nil)
|
||||
config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
|
||||
result := emptyTestFixtureFactory.RunTest(t,
|
||||
PrepareForTestWithAllowMissingDependencies,
|
||||
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
||||
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
|
||||
ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
|
||||
ctx.TopDown("add_missing_dependencies", addMissingDependenciesMutator)
|
||||
})
|
||||
}),
|
||||
FixtureWithRootAndroidBp(bp),
|
||||
)
|
||||
|
||||
ctx := NewTestContext(config)
|
||||
ctx.SetAllowMissingDependencies(true)
|
||||
foo := result.ModuleForTests("foo", "").Module().(*mutatorTestModule)
|
||||
|
||||
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
|
||||
ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
|
||||
ctx.TopDown("add_missing_dependencies", addMissingDependenciesMutator)
|
||||
})
|
||||
|
||||
ctx.Register()
|
||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
||||
FailIfErrored(t, errs)
|
||||
_, errs = ctx.PrepareBuildActions(config)
|
||||
FailIfErrored(t, errs)
|
||||
|
||||
foo := ctx.ModuleForTests("foo", "").Module().(*mutatorTestModule)
|
||||
|
||||
if g, w := foo.missingDeps, []string{"added_missing_dep", "regular_missing_dep"}; !reflect.DeepEqual(g, w) {
|
||||
t.Errorf("want foo missing deps %q, got %q", w, g)
|
||||
}
|
||||
AssertDeepEquals(t, "foo missing deps", []string{"added_missing_dep", "regular_missing_dep"}, foo.missingDeps)
|
||||
}
|
||||
|
||||
func TestModuleString(t *testing.T) {
|
||||
|
@ -98,52 +88,47 @@ func TestModuleString(t *testing.T) {
|
|||
}
|
||||
`
|
||||
|
||||
config := TestConfig(buildDir, nil, bp, nil)
|
||||
|
||||
ctx := NewTestContext(config)
|
||||
|
||||
var moduleStrings []string
|
||||
|
||||
ctx.PreArchMutators(func(ctx RegisterMutatorsContext) {
|
||||
ctx.BottomUp("pre_arch", func(ctx BottomUpMutatorContext) {
|
||||
moduleStrings = append(moduleStrings, ctx.Module().String())
|
||||
ctx.CreateVariations("a", "b")
|
||||
})
|
||||
ctx.TopDown("rename_top_down", func(ctx TopDownMutatorContext) {
|
||||
moduleStrings = append(moduleStrings, ctx.Module().String())
|
||||
ctx.Rename(ctx.Module().base().Name() + "_renamed1")
|
||||
})
|
||||
})
|
||||
emptyTestFixtureFactory.RunTest(t,
|
||||
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
||||
|
||||
ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
|
||||
ctx.BottomUp("pre_deps", func(ctx BottomUpMutatorContext) {
|
||||
moduleStrings = append(moduleStrings, ctx.Module().String())
|
||||
ctx.CreateVariations("c", "d")
|
||||
})
|
||||
})
|
||||
ctx.PreArchMutators(func(ctx RegisterMutatorsContext) {
|
||||
ctx.BottomUp("pre_arch", func(ctx BottomUpMutatorContext) {
|
||||
moduleStrings = append(moduleStrings, ctx.Module().String())
|
||||
ctx.CreateVariations("a", "b")
|
||||
})
|
||||
ctx.TopDown("rename_top_down", func(ctx TopDownMutatorContext) {
|
||||
moduleStrings = append(moduleStrings, ctx.Module().String())
|
||||
ctx.Rename(ctx.Module().base().Name() + "_renamed1")
|
||||
})
|
||||
})
|
||||
|
||||
ctx.PostDepsMutators(func(ctx RegisterMutatorsContext) {
|
||||
ctx.BottomUp("post_deps", func(ctx BottomUpMutatorContext) {
|
||||
moduleStrings = append(moduleStrings, ctx.Module().String())
|
||||
ctx.CreateLocalVariations("e", "f")
|
||||
})
|
||||
ctx.BottomUp("rename_bottom_up", func(ctx BottomUpMutatorContext) {
|
||||
moduleStrings = append(moduleStrings, ctx.Module().String())
|
||||
ctx.Rename(ctx.Module().base().Name() + "_renamed2")
|
||||
})
|
||||
ctx.BottomUp("final", func(ctx BottomUpMutatorContext) {
|
||||
moduleStrings = append(moduleStrings, ctx.Module().String())
|
||||
})
|
||||
})
|
||||
ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
|
||||
ctx.BottomUp("pre_deps", func(ctx BottomUpMutatorContext) {
|
||||
moduleStrings = append(moduleStrings, ctx.Module().String())
|
||||
ctx.CreateVariations("c", "d")
|
||||
})
|
||||
})
|
||||
|
||||
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
|
||||
ctx.PostDepsMutators(func(ctx RegisterMutatorsContext) {
|
||||
ctx.BottomUp("post_deps", func(ctx BottomUpMutatorContext) {
|
||||
moduleStrings = append(moduleStrings, ctx.Module().String())
|
||||
ctx.CreateLocalVariations("e", "f")
|
||||
})
|
||||
ctx.BottomUp("rename_bottom_up", func(ctx BottomUpMutatorContext) {
|
||||
moduleStrings = append(moduleStrings, ctx.Module().String())
|
||||
ctx.Rename(ctx.Module().base().Name() + "_renamed2")
|
||||
})
|
||||
ctx.BottomUp("final", func(ctx BottomUpMutatorContext) {
|
||||
moduleStrings = append(moduleStrings, ctx.Module().String())
|
||||
})
|
||||
})
|
||||
|
||||
ctx.Register()
|
||||
|
||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
||||
FailIfErrored(t, errs)
|
||||
_, errs = ctx.PrepareBuildActions(config)
|
||||
FailIfErrored(t, errs)
|
||||
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
|
||||
}),
|
||||
FixtureWithRootAndroidBp(bp),
|
||||
)
|
||||
|
||||
want := []string{
|
||||
// Initial name.
|
||||
|
@ -184,9 +169,7 @@ func TestModuleString(t *testing.T) {
|
|||
"foo_renamed2{pre_arch:b,pre_deps:d,post_deps:f}",
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(moduleStrings, want) {
|
||||
t.Errorf("want module String() values:\n%q\ngot:\n%q", want, moduleStrings)
|
||||
}
|
||||
AssertDeepEquals(t, "module String() values", want, moduleStrings)
|
||||
}
|
||||
|
||||
func TestFinalDepsPhase(t *testing.T) {
|
||||
|
@ -202,52 +185,46 @@ func TestFinalDepsPhase(t *testing.T) {
|
|||
}
|
||||
`
|
||||
|
||||
config := TestConfig(buildDir, nil, bp, nil)
|
||||
|
||||
ctx := NewTestContext(config)
|
||||
|
||||
finalGot := map[string]int{}
|
||||
|
||||
dep1Tag := struct {
|
||||
blueprint.BaseDependencyTag
|
||||
}{}
|
||||
dep2Tag := struct {
|
||||
blueprint.BaseDependencyTag
|
||||
}{}
|
||||
emptyTestFixtureFactory.RunTest(t,
|
||||
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
||||
dep1Tag := struct {
|
||||
blueprint.BaseDependencyTag
|
||||
}{}
|
||||
dep2Tag := struct {
|
||||
blueprint.BaseDependencyTag
|
||||
}{}
|
||||
|
||||
ctx.PostDepsMutators(func(ctx RegisterMutatorsContext) {
|
||||
ctx.BottomUp("far_deps_1", func(ctx BottomUpMutatorContext) {
|
||||
if !strings.HasPrefix(ctx.ModuleName(), "common_dep") {
|
||||
ctx.AddFarVariationDependencies([]blueprint.Variation{}, dep1Tag, "common_dep_1")
|
||||
}
|
||||
})
|
||||
ctx.BottomUp("variant", func(ctx BottomUpMutatorContext) {
|
||||
ctx.CreateLocalVariations("a", "b")
|
||||
})
|
||||
})
|
||||
|
||||
ctx.FinalDepsMutators(func(ctx RegisterMutatorsContext) {
|
||||
ctx.BottomUp("far_deps_2", func(ctx BottomUpMutatorContext) {
|
||||
if !strings.HasPrefix(ctx.ModuleName(), "common_dep") {
|
||||
ctx.AddFarVariationDependencies([]blueprint.Variation{}, dep2Tag, "common_dep_2")
|
||||
}
|
||||
})
|
||||
ctx.BottomUp("final", func(ctx BottomUpMutatorContext) {
|
||||
finalGot[ctx.Module().String()] += 1
|
||||
ctx.VisitDirectDeps(func(mod Module) {
|
||||
finalGot[fmt.Sprintf("%s -> %s", ctx.Module().String(), mod)] += 1
|
||||
ctx.PostDepsMutators(func(ctx RegisterMutatorsContext) {
|
||||
ctx.BottomUp("far_deps_1", func(ctx BottomUpMutatorContext) {
|
||||
if !strings.HasPrefix(ctx.ModuleName(), "common_dep") {
|
||||
ctx.AddFarVariationDependencies([]blueprint.Variation{}, dep1Tag, "common_dep_1")
|
||||
}
|
||||
})
|
||||
ctx.BottomUp("variant", func(ctx BottomUpMutatorContext) {
|
||||
ctx.CreateLocalVariations("a", "b")
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
|
||||
ctx.FinalDepsMutators(func(ctx RegisterMutatorsContext) {
|
||||
ctx.BottomUp("far_deps_2", func(ctx BottomUpMutatorContext) {
|
||||
if !strings.HasPrefix(ctx.ModuleName(), "common_dep") {
|
||||
ctx.AddFarVariationDependencies([]blueprint.Variation{}, dep2Tag, "common_dep_2")
|
||||
}
|
||||
})
|
||||
ctx.BottomUp("final", func(ctx BottomUpMutatorContext) {
|
||||
finalGot[ctx.Module().String()] += 1
|
||||
ctx.VisitDirectDeps(func(mod Module) {
|
||||
finalGot[fmt.Sprintf("%s -> %s", ctx.Module().String(), mod)] += 1
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
ctx.Register()
|
||||
|
||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
||||
FailIfErrored(t, errs)
|
||||
_, errs = ctx.PrepareBuildActions(config)
|
||||
FailIfErrored(t, errs)
|
||||
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
|
||||
}),
|
||||
FixtureWithRootAndroidBp(bp),
|
||||
)
|
||||
|
||||
finalWant := map[string]int{
|
||||
"common_dep_1{variant:a}": 1,
|
||||
|
@ -262,37 +239,31 @@ func TestFinalDepsPhase(t *testing.T) {
|
|||
"foo{variant:b} -> common_dep_2{variant:a}": 1,
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(finalWant, finalGot) {
|
||||
t.Errorf("want:\n%q\ngot:\n%q", finalWant, finalGot)
|
||||
}
|
||||
AssertDeepEquals(t, "final", finalWant, finalGot)
|
||||
}
|
||||
|
||||
func TestNoCreateVariationsInFinalDeps(t *testing.T) {
|
||||
config := TestConfig(buildDir, nil, `test {name: "foo"}`, nil)
|
||||
ctx := NewTestContext(config)
|
||||
|
||||
checkErr := func() {
|
||||
if err := recover(); err == nil || !strings.Contains(fmt.Sprintf("%s", err), "not allowed in FinalDepsMutators") {
|
||||
panic("Expected FinalDepsMutators consistency check to fail")
|
||||
}
|
||||
}
|
||||
|
||||
ctx.FinalDepsMutators(func(ctx RegisterMutatorsContext) {
|
||||
ctx.BottomUp("vars", func(ctx BottomUpMutatorContext) {
|
||||
defer checkErr()
|
||||
ctx.CreateVariations("a", "b")
|
||||
})
|
||||
ctx.BottomUp("local_vars", func(ctx BottomUpMutatorContext) {
|
||||
defer checkErr()
|
||||
ctx.CreateLocalVariations("a", "b")
|
||||
})
|
||||
})
|
||||
emptyTestFixtureFactory.RunTest(t,
|
||||
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
||||
ctx.FinalDepsMutators(func(ctx RegisterMutatorsContext) {
|
||||
ctx.BottomUp("vars", func(ctx BottomUpMutatorContext) {
|
||||
defer checkErr()
|
||||
ctx.CreateVariations("a", "b")
|
||||
})
|
||||
ctx.BottomUp("local_vars", func(ctx BottomUpMutatorContext) {
|
||||
defer checkErr()
|
||||
ctx.CreateLocalVariations("a", "b")
|
||||
})
|
||||
})
|
||||
|
||||
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
|
||||
ctx.Register()
|
||||
|
||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
||||
FailIfErrored(t, errs)
|
||||
_, errs = ctx.PrepareBuildActions(config)
|
||||
FailIfErrored(t, errs)
|
||||
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
|
||||
}),
|
||||
FixtureWithRootAndroidBp(`test {name: "foo"}`),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ var neverallowTests = []struct {
|
|||
rules []Rule
|
||||
|
||||
// Additional contents to add to the virtual filesystem used by the tests.
|
||||
fs map[string][]byte
|
||||
fs MockFS
|
||||
|
||||
// The expected error patterns. If empty then no errors are expected, otherwise each error
|
||||
// reported must be matched by at least one of these patterns. A pattern matches if the error
|
||||
|
@ -285,41 +285,36 @@ var neverallowTests = []struct {
|
|||
},
|
||||
}
|
||||
|
||||
var prepareForNeverAllowTest = GroupFixturePreparers(
|
||||
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
||||
ctx.RegisterModuleType("cc_library", newMockCcLibraryModule)
|
||||
ctx.RegisterModuleType("java_library", newMockJavaLibraryModule)
|
||||
ctx.RegisterModuleType("java_library_host", newMockJavaLibraryModule)
|
||||
ctx.RegisterModuleType("java_device_for_host", newMockJavaLibraryModule)
|
||||
ctx.RegisterModuleType("makefile_goal", newMockMakefileGoalModule)
|
||||
ctx.PostDepsMutators(RegisterNeverallowMutator)
|
||||
}),
|
||||
)
|
||||
|
||||
func TestNeverallow(t *testing.T) {
|
||||
for _, test := range neverallowTests {
|
||||
// Create a test per config to allow for test specific config, e.g. test rules.
|
||||
config := TestConfig(buildDir, nil, "", test.fs)
|
||||
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
// If the test has its own rules then use them instead of the default ones.
|
||||
if test.rules != nil {
|
||||
SetTestNeverallowRules(config, test.rules)
|
||||
}
|
||||
_, errs := testNeverallow(config)
|
||||
CheckErrorsAgainstExpectations(t, errs, test.expectedErrors)
|
||||
emptyTestFixtureFactory.
|
||||
ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)).
|
||||
RunTest(t,
|
||||
prepareForNeverAllowTest,
|
||||
FixtureModifyConfig(func(config Config) {
|
||||
// If the test has its own rules then use them instead of the default ones.
|
||||
if test.rules != nil {
|
||||
SetTestNeverallowRules(config, test.rules)
|
||||
}
|
||||
}),
|
||||
test.fs.AddToFixture(),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testNeverallow(config Config) (*TestContext, []error) {
|
||||
ctx := NewTestContext(config)
|
||||
ctx.RegisterModuleType("cc_library", newMockCcLibraryModule)
|
||||
ctx.RegisterModuleType("java_library", newMockJavaLibraryModule)
|
||||
ctx.RegisterModuleType("java_library_host", newMockJavaLibraryModule)
|
||||
ctx.RegisterModuleType("java_device_for_host", newMockJavaLibraryModule)
|
||||
ctx.RegisterModuleType("makefile_goal", newMockMakefileGoalModule)
|
||||
ctx.PostDepsMutators(RegisterNeverallowMutator)
|
||||
ctx.Register()
|
||||
|
||||
_, errs := ctx.ParseBlueprintsFiles("Android.bp")
|
||||
if len(errs) > 0 {
|
||||
return ctx, errs
|
||||
}
|
||||
|
||||
_, errs = ctx.PrepareBuildActions(config)
|
||||
return ctx, errs
|
||||
}
|
||||
|
||||
type mockCcLibraryProperties struct {
|
||||
Include_dirs []string
|
||||
Vendor_available *bool
|
||||
|
|
|
@ -53,23 +53,20 @@ func (testNinjaDepsSingleton) GenerateBuildActions(ctx SingletonContext) {
|
|||
}
|
||||
|
||||
func TestNinjaDeps(t *testing.T) {
|
||||
fs := map[string][]byte{
|
||||
fs := MockFS{
|
||||
"test_ninja_deps/exists": nil,
|
||||
}
|
||||
config := TestConfig(buildDir, nil, "", fs)
|
||||
|
||||
ctx := NewTestContext(config)
|
||||
ctx.RegisterSingletonType("test_ninja_deps_singleton", testNinjaDepsSingletonFactory)
|
||||
ctx.RegisterSingletonType("ninja_deps_singleton", ninjaDepsSingletonFactory)
|
||||
ctx.Register()
|
||||
|
||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
||||
FailIfErrored(t, errs)
|
||||
ninjaDeps, errs := ctx.PrepareBuildActions(config)
|
||||
FailIfErrored(t, errs)
|
||||
result := emptyTestFixtureFactory.RunTest(t,
|
||||
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
||||
ctx.RegisterSingletonType("test_ninja_deps_singleton", testNinjaDepsSingletonFactory)
|
||||
ctx.RegisterSingletonType("ninja_deps_singleton", ninjaDepsSingletonFactory)
|
||||
}),
|
||||
fs.AddToFixture(),
|
||||
)
|
||||
|
||||
// Verify that the ninja file has a dependency on the test_ninja_deps directory.
|
||||
if g, w := ninjaDeps, "test_ninja_deps"; !InList(w, g) {
|
||||
if g, w := result.NinjaDeps, "test_ninja_deps"; !InList(w, g) {
|
||||
t.Errorf("expected %q in %q", w, g)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
|
||||
var packageTests = []struct {
|
||||
name string
|
||||
fs map[string][]byte
|
||||
fs MockFS
|
||||
expectedErrors []string
|
||||
}{
|
||||
// Package default_visibility handling is tested in visibility_test.go
|
||||
|
@ -61,43 +61,13 @@ var packageTests = []struct {
|
|||
func TestPackage(t *testing.T) {
|
||||
for _, test := range packageTests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
_, errs := testPackage(test.fs)
|
||||
|
||||
expectedErrors := test.expectedErrors
|
||||
if expectedErrors == nil {
|
||||
FailIfErrored(t, errs)
|
||||
} else {
|
||||
for _, expectedError := range expectedErrors {
|
||||
FailIfNoMatchingErrors(t, expectedError, errs)
|
||||
}
|
||||
if len(errs) > len(expectedErrors) {
|
||||
t.Errorf("additional errors found, expected %d, found %d", len(expectedErrors), len(errs))
|
||||
for i, expectedError := range expectedErrors {
|
||||
t.Errorf("expectedErrors[%d] = %s", i, expectedError)
|
||||
}
|
||||
for i, err := range errs {
|
||||
t.Errorf("errs[%d] = %s", i, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
emptyTestFixtureFactory.
|
||||
ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)).
|
||||
RunTest(t,
|
||||
PrepareForTestWithArchMutator,
|
||||
PrepareForTestWithPackageModule,
|
||||
test.fs.AddToFixture(),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testPackage(fs map[string][]byte) (*TestContext, []error) {
|
||||
|
||||
// Create a new config per test as visibility information is stored in the config.
|
||||
config := TestArchConfig(buildDir, nil, "", fs)
|
||||
|
||||
ctx := NewTestArchContext(config)
|
||||
RegisterPackageBuildComponents(ctx)
|
||||
ctx.Register()
|
||||
|
||||
_, errs := ctx.ParseBlueprintsFiles(".")
|
||||
if len(errs) > 0 {
|
||||
return ctx, errs
|
||||
}
|
||||
|
||||
_, errs = ctx.PrepareBuildActions(config)
|
||||
return ctx, errs
|
||||
}
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
package android
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -43,23 +41,14 @@ func testSingletonModuleFactory() SingletonModule {
|
|||
return tsm
|
||||
}
|
||||
|
||||
func runSingletonModuleTest(bp string) (*TestContext, []error) {
|
||||
config := TestConfig(buildDir, nil, bp, nil)
|
||||
var prepareForSingletonModuleTest = GroupFixturePreparers(
|
||||
// Enable Kati output to test SingletonModules with MakeVars.
|
||||
config.katiEnabled = true
|
||||
ctx := NewTestContext(config)
|
||||
ctx.RegisterSingletonModuleType("test_singleton_module", testSingletonModuleFactory)
|
||||
ctx.RegisterSingletonType("makevars", makeVarsSingletonFunc)
|
||||
ctx.Register()
|
||||
|
||||
_, errs := ctx.ParseBlueprintsFiles("Android.bp")
|
||||
if len(errs) > 0 {
|
||||
return ctx, errs
|
||||
}
|
||||
|
||||
_, errs = ctx.PrepareBuildActions(config)
|
||||
return ctx, errs
|
||||
}
|
||||
PrepareForTestWithAndroidMk,
|
||||
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
||||
ctx.RegisterSingletonModuleType("test_singleton_module", testSingletonModuleFactory)
|
||||
ctx.RegisterSingletonType("makevars", makeVarsSingletonFunc)
|
||||
}),
|
||||
)
|
||||
|
||||
func TestSingletonModule(t *testing.T) {
|
||||
bp := `
|
||||
|
@ -67,16 +56,15 @@ func TestSingletonModule(t *testing.T) {
|
|||
name: "test_singleton_module",
|
||||
}
|
||||
`
|
||||
ctx, errs := runSingletonModuleTest(bp)
|
||||
if len(errs) > 0 {
|
||||
t.Fatal(errs)
|
||||
}
|
||||
result := emptyTestFixtureFactory.
|
||||
RunTest(t,
|
||||
prepareForSingletonModuleTest,
|
||||
FixtureWithRootAndroidBp(bp),
|
||||
)
|
||||
|
||||
ops := ctx.ModuleForTests("test_singleton_module", "").Module().(*testSingletonModule).ops
|
||||
ops := result.ModuleForTests("test_singleton_module", "").Module().(*testSingletonModule).ops
|
||||
wantOps := []string{"GenerateAndroidBuildActions", "GenerateSingletonBuildActions", "MakeVars"}
|
||||
if !reflect.DeepEqual(ops, wantOps) {
|
||||
t.Errorf("Expected operations %q, got %q", wantOps, ops)
|
||||
}
|
||||
AssertDeepEquals(t, "operations", wantOps, ops)
|
||||
}
|
||||
|
||||
func TestDuplicateSingletonModule(t *testing.T) {
|
||||
|
@ -89,23 +77,22 @@ func TestDuplicateSingletonModule(t *testing.T) {
|
|||
name: "test_singleton_module2",
|
||||
}
|
||||
`
|
||||
_, errs := runSingletonModuleTest(bp)
|
||||
if len(errs) == 0 {
|
||||
t.Fatal("expected duplicate SingletonModule error")
|
||||
}
|
||||
if len(errs) != 1 || !strings.Contains(errs[0].Error(), `Duplicate SingletonModule "test_singleton_module", previously used in`) {
|
||||
t.Fatalf("expected duplicate SingletonModule error, got %q", errs)
|
||||
}
|
||||
|
||||
emptyTestFixtureFactory.
|
||||
ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern([]string{
|
||||
`\QDuplicate SingletonModule "test_singleton_module", previously used in\E`,
|
||||
})).RunTest(t,
|
||||
prepareForSingletonModuleTest,
|
||||
FixtureWithRootAndroidBp(bp),
|
||||
)
|
||||
}
|
||||
|
||||
func TestUnusedSingletonModule(t *testing.T) {
|
||||
bp := ``
|
||||
ctx, errs := runSingletonModuleTest(bp)
|
||||
if len(errs) > 0 {
|
||||
t.Fatal(errs)
|
||||
}
|
||||
result := emptyTestFixtureFactory.RunTest(t,
|
||||
prepareForSingletonModuleTest,
|
||||
)
|
||||
|
||||
singleton := ctx.SingletonForTests("test_singleton_module").Singleton()
|
||||
singleton := result.SingletonForTests("test_singleton_module").Singleton()
|
||||
sm := singleton.(*singletonModuleSingletonAdaptor).sm
|
||||
ops := sm.(*testSingletonModule).ops
|
||||
if ops != nil {
|
||||
|
@ -126,24 +113,17 @@ func TestVariantSingletonModule(t *testing.T) {
|
|||
}
|
||||
`
|
||||
|
||||
config := TestConfig(buildDir, nil, bp, nil)
|
||||
ctx := NewTestContext(config)
|
||||
ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
|
||||
ctx.BottomUp("test_singleton_module_mutator", testVariantSingletonModuleMutator)
|
||||
})
|
||||
ctx.RegisterSingletonModuleType("test_singleton_module", testSingletonModuleFactory)
|
||||
ctx.Register()
|
||||
|
||||
_, errs := ctx.ParseBlueprintsFiles("Android.bp")
|
||||
|
||||
if len(errs) == 0 {
|
||||
_, errs = ctx.PrepareBuildActions(config)
|
||||
}
|
||||
|
||||
if len(errs) == 0 {
|
||||
t.Fatal("expected duplicate SingletonModule error")
|
||||
}
|
||||
if len(errs) != 1 || !strings.Contains(errs[0].Error(), `GenerateAndroidBuildActions already called for variant`) {
|
||||
t.Fatalf("expected duplicate SingletonModule error, got %q", errs)
|
||||
}
|
||||
emptyTestFixtureFactory.
|
||||
ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern([]string{
|
||||
`\QGenerateAndroidBuildActions already called for variant\E`,
|
||||
})).
|
||||
RunTest(t,
|
||||
prepareForSingletonModuleTest,
|
||||
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
||||
ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
|
||||
ctx.BottomUp("test_singleton_module_mutator", testVariantSingletonModuleMutator)
|
||||
})
|
||||
}),
|
||||
FixtureWithRootAndroidBp(bp),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
package android
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -181,17 +180,23 @@ func TestSoongConfigModule(t *testing.T) {
|
|||
}
|
||||
`
|
||||
|
||||
run := func(t *testing.T, bp string, fs map[string][]byte) {
|
||||
fixtureForVendorVars := func(vars map[string]map[string]string) FixturePreparer {
|
||||
return FixtureModifyProductVariables(func(variables FixtureProductVariables) {
|
||||
variables.VendorVars = vars
|
||||
})
|
||||
}
|
||||
|
||||
run := func(t *testing.T, bp string, fs MockFS) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
config Config
|
||||
preparer FixturePreparer
|
||||
fooExpectedFlags []string
|
||||
fooDefaultsExpectedFlags []string
|
||||
}{
|
||||
{
|
||||
name: "withValues",
|
||||
config: testConfigWithVendorVars(buildDir, bp, fs, map[string]map[string]string{
|
||||
"acme": map[string]string{
|
||||
preparer: fixtureForVendorVars(map[string]map[string]string{
|
||||
"acme": {
|
||||
"board": "soc_a",
|
||||
"size": "42",
|
||||
"feature1": "true",
|
||||
|
@ -221,8 +226,8 @@ func TestSoongConfigModule(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "empty_prop_for_string_var",
|
||||
config: testConfigWithVendorVars(buildDir, bp, fs, map[string]map[string]string{
|
||||
"acme": map[string]string{"board": "soc_c"}}),
|
||||
preparer: fixtureForVendorVars(map[string]map[string]string{
|
||||
"acme": {"board": "soc_c"}}),
|
||||
fooExpectedFlags: []string{
|
||||
"DEFAULT",
|
||||
"-DGENERIC",
|
||||
|
@ -237,8 +242,8 @@ func TestSoongConfigModule(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "unused_string_var",
|
||||
config: testConfigWithVendorVars(buildDir, bp, fs, map[string]map[string]string{
|
||||
"acme": map[string]string{"board": "soc_d"}}),
|
||||
preparer: fixtureForVendorVars(map[string]map[string]string{
|
||||
"acme": {"board": "soc_d"}}),
|
||||
fooExpectedFlags: []string{
|
||||
"DEFAULT",
|
||||
"-DGENERIC",
|
||||
|
@ -254,8 +259,8 @@ func TestSoongConfigModule(t *testing.T) {
|
|||
},
|
||||
|
||||
{
|
||||
name: "conditions_default",
|
||||
config: testConfigWithVendorVars(buildDir, bp, fs, map[string]map[string]string{}),
|
||||
name: "conditions_default",
|
||||
preparer: fixtureForVendorVars(map[string]map[string]string{}),
|
||||
fooExpectedFlags: []string{
|
||||
"DEFAULT",
|
||||
"-DGENERIC",
|
||||
|
@ -272,32 +277,29 @@ func TestSoongConfigModule(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
ctx := NewTestContext(tc.config)
|
||||
ctx.RegisterModuleType("soong_config_module_type_import", soongConfigModuleTypeImportFactory)
|
||||
ctx.RegisterModuleType("soong_config_module_type", soongConfigModuleTypeFactory)
|
||||
ctx.RegisterModuleType("soong_config_string_variable", soongConfigStringVariableDummyFactory)
|
||||
ctx.RegisterModuleType("soong_config_bool_variable", soongConfigBoolVariableDummyFactory)
|
||||
ctx.RegisterModuleType("test_defaults", soongConfigTestDefaultsModuleFactory)
|
||||
ctx.RegisterModuleType("test", soongConfigTestModuleFactory)
|
||||
ctx.PreArchMutators(RegisterDefaultsPreArchMutators)
|
||||
ctx.Register()
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
result := emptyTestFixtureFactory.RunTest(t,
|
||||
tc.preparer,
|
||||
PrepareForTestWithDefaults,
|
||||
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
||||
ctx.RegisterModuleType("soong_config_module_type_import", soongConfigModuleTypeImportFactory)
|
||||
ctx.RegisterModuleType("soong_config_module_type", soongConfigModuleTypeFactory)
|
||||
ctx.RegisterModuleType("soong_config_string_variable", soongConfigStringVariableDummyFactory)
|
||||
ctx.RegisterModuleType("soong_config_bool_variable", soongConfigBoolVariableDummyFactory)
|
||||
ctx.RegisterModuleType("test_defaults", soongConfigTestDefaultsModuleFactory)
|
||||
ctx.RegisterModuleType("test", soongConfigTestModuleFactory)
|
||||
}),
|
||||
fs.AddToFixture(),
|
||||
FixtureWithRootAndroidBp(bp),
|
||||
)
|
||||
|
||||
_, errs := ctx.ParseBlueprintsFiles("Android.bp")
|
||||
FailIfErrored(t, errs)
|
||||
_, errs = ctx.PrepareBuildActions(tc.config)
|
||||
FailIfErrored(t, errs)
|
||||
foo := result.ModuleForTests("foo", "").Module().(*soongConfigTestModule)
|
||||
AssertDeepEquals(t, "foo cflags", tc.fooExpectedFlags, foo.props.Cflags)
|
||||
|
||||
foo := ctx.ModuleForTests("foo", "").Module().(*soongConfigTestModule)
|
||||
if g, w := foo.props.Cflags, tc.fooExpectedFlags; !reflect.DeepEqual(g, w) {
|
||||
t.Errorf("%s: wanted foo cflags %q, got %q", tc.name, w, g)
|
||||
}
|
||||
|
||||
fooDefaults := ctx.ModuleForTests("foo_with_defaults", "").Module().(*soongConfigTestModule)
|
||||
if g, w := fooDefaults.props.Cflags, tc.fooDefaultsExpectedFlags; !reflect.DeepEqual(g, w) {
|
||||
t.Errorf("%s: wanted foo_with_defaults cflags %q, got %q", tc.name, w, g)
|
||||
}
|
||||
fooDefaults := result.ModuleForTests("foo_with_defaults", "").Module().(*soongConfigTestModule)
|
||||
AssertDeepEquals(t, "foo_with_defaults cflags", tc.fooDefaultsExpectedFlags, fooDefaults.props.Cflags)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
t.Run("single file", func(t *testing.T) {
|
||||
|
|
|
@ -181,32 +181,30 @@ func TestProductVariables(t *testing.T) {
|
|||
name: "baz",
|
||||
}
|
||||
`
|
||||
config := TestConfig(buildDir, nil, bp, nil)
|
||||
config.TestProductVariables.Eng = proptools.BoolPtr(true)
|
||||
|
||||
ctx := NewTestContext(config)
|
||||
// A module type that has a srcs property but not a cflags property.
|
||||
ctx.RegisterModuleType("module1", testProductVariableModuleFactoryFactory(&struct {
|
||||
Srcs []string
|
||||
}{}))
|
||||
// A module type that has a cflags property but not a srcs property.
|
||||
ctx.RegisterModuleType("module2", testProductVariableModuleFactoryFactory(&struct {
|
||||
Cflags []string
|
||||
}{}))
|
||||
// A module type that does not have any properties that match product_variables.
|
||||
ctx.RegisterModuleType("module3", testProductVariableModuleFactoryFactory(&struct {
|
||||
Foo []string
|
||||
}{}))
|
||||
ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
|
||||
ctx.BottomUp("variable", VariableMutator).Parallel()
|
||||
})
|
||||
|
||||
ctx.Register()
|
||||
|
||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
||||
FailIfErrored(t, errs)
|
||||
_, errs = ctx.PrepareBuildActions(config)
|
||||
FailIfErrored(t, errs)
|
||||
emptyTestFixtureFactory.RunTest(t,
|
||||
FixtureModifyProductVariables(func(variables FixtureProductVariables) {
|
||||
variables.Eng = proptools.BoolPtr(true)
|
||||
}),
|
||||
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
||||
// A module type that has a srcs property but not a cflags property.
|
||||
ctx.RegisterModuleType("module1", testProductVariableModuleFactoryFactory(&struct {
|
||||
Srcs []string
|
||||
}{}))
|
||||
// A module type that has a cflags property but not a srcs property.
|
||||
ctx.RegisterModuleType("module2", testProductVariableModuleFactoryFactory(&struct {
|
||||
Cflags []string
|
||||
}{}))
|
||||
// A module type that does not have any properties that match product_variables.
|
||||
ctx.RegisterModuleType("module3", testProductVariableModuleFactoryFactory(&struct {
|
||||
Foo []string
|
||||
}{}))
|
||||
ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
|
||||
ctx.BottomUp("variable", VariableMutator).Parallel()
|
||||
})
|
||||
}),
|
||||
FixtureWithRootAndroidBp(bp),
|
||||
)
|
||||
}
|
||||
|
||||
var testProductVariableDefaultsProperties = struct {
|
||||
|
@ -290,32 +288,23 @@ func TestProductVariablesDefaults(t *testing.T) {
|
|||
}
|
||||
`
|
||||
|
||||
config := TestConfig(buildDir, nil, bp, nil)
|
||||
config.TestProductVariables.Eng = boolPtr(true)
|
||||
result := emptyTestFixtureFactory.RunTest(t,
|
||||
FixtureModifyProductVariables(func(variables FixtureProductVariables) {
|
||||
variables.Eng = boolPtr(true)
|
||||
}),
|
||||
PrepareForTestWithDefaults,
|
||||
PrepareForTestWithVariables,
|
||||
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
||||
ctx.RegisterModuleType("test", productVariablesDefaultsTestModuleFactory)
|
||||
ctx.RegisterModuleType("defaults", productVariablesDefaultsTestDefaultsFactory)
|
||||
}),
|
||||
FixtureWithRootAndroidBp(bp),
|
||||
)
|
||||
|
||||
ctx := NewTestContext(config)
|
||||
|
||||
ctx.RegisterModuleType("test", productVariablesDefaultsTestModuleFactory)
|
||||
ctx.RegisterModuleType("defaults", productVariablesDefaultsTestDefaultsFactory)
|
||||
|
||||
ctx.PreArchMutators(RegisterDefaultsPreArchMutators)
|
||||
ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
|
||||
ctx.BottomUp("variable", VariableMutator).Parallel()
|
||||
})
|
||||
|
||||
ctx.Register()
|
||||
|
||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
||||
FailIfErrored(t, errs)
|
||||
_, errs = ctx.PrepareBuildActions(config)
|
||||
FailIfErrored(t, errs)
|
||||
|
||||
foo := ctx.ModuleForTests("foo", "").Module().(*productVariablesDefaultsTestModule)
|
||||
foo := result.ModuleForTests("foo", "").Module().(*productVariablesDefaultsTestModule)
|
||||
|
||||
want := []string{"defaults", "module", "product_variable_defaults", "product_variable_module"}
|
||||
if g, w := foo.properties.Foo, want; !reflect.DeepEqual(g, w) {
|
||||
t.Errorf("expected foo %q, got %q", w, g)
|
||||
}
|
||||
AssertDeepEquals(t, "foo", want, foo.properties.Foo)
|
||||
}
|
||||
|
||||
func BenchmarkSliceToTypeArray(b *testing.B) {
|
||||
|
|
Loading…
Reference in New Issue