Add integration testing infrastructure
Fix mutator registration for tests to allow different tests in the same package to register different mutators. Allow tests to track the resulting ModuleBuildParams objects to use in assertions, and provide helpers for getting them. For example: config := android.TestConfig(buildDir) ctx := android.NewTestContext() ctx.RegisterModuleType(...) ctx.MockFileSystem(...) ctx.ParseBlueprintsFile("Android.bp") ctx.PrepareBuildActions(config) ctx.Register() // Get the Inputs value passed to the javac rule for the foo module inputs := ctx.ModuleForTests("foo".Rule("javac").Inputs Test: java_test.go Change-Id: I10c82967f5f3586d2c176f169906b571ed82fc73
This commit is contained in:
@@ -15,8 +15,6 @@
|
||||
package android
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
)
|
||||
|
||||
@@ -27,9 +25,6 @@ import (
|
||||
// Deps
|
||||
// PostDeps
|
||||
|
||||
var registerMutatorsOnce sync.Once
|
||||
var registeredMutators []*mutator
|
||||
|
||||
func registerMutatorsToContext(ctx *blueprint.Context, mutators []*mutator) {
|
||||
for _, t := range mutators {
|
||||
var handle blueprint.MutatorHandle
|
||||
@@ -44,56 +39,24 @@ func registerMutatorsToContext(ctx *blueprint.Context, mutators []*mutator) {
|
||||
}
|
||||
}
|
||||
|
||||
func registerMutators(ctx *blueprint.Context) {
|
||||
|
||||
registerMutatorsOnce.Do(func() {
|
||||
ctx := ®isterMutatorsContext{}
|
||||
|
||||
register := func(funcs []RegisterMutatorFunc) {
|
||||
for _, f := range funcs {
|
||||
f(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
ctx.TopDown("load_hooks", loadHookMutator).Parallel()
|
||||
ctx.BottomUp("prebuilts", prebuiltMutator).Parallel()
|
||||
ctx.BottomUp("defaults_deps", defaultsDepsMutator).Parallel()
|
||||
ctx.TopDown("defaults", defaultsMutator).Parallel()
|
||||
|
||||
register(preArch)
|
||||
|
||||
ctx.BottomUp("arch", archMutator).Parallel()
|
||||
ctx.TopDown("arch_hooks", archHookMutator).Parallel()
|
||||
|
||||
register(preDeps)
|
||||
|
||||
ctx.BottomUp("deps", depsMutator).Parallel()
|
||||
|
||||
ctx.TopDown("prebuilt_select", PrebuiltSelectModuleMutator).Parallel()
|
||||
ctx.BottomUp("prebuilt_replace", PrebuiltReplaceMutator).Parallel()
|
||||
|
||||
register(postDeps)
|
||||
|
||||
registeredMutators = ctx.mutators
|
||||
})
|
||||
|
||||
registerMutatorsToContext(ctx, registeredMutators)
|
||||
}
|
||||
|
||||
func RegisterTestMutators(ctx *blueprint.Context) {
|
||||
mutators := ®isterMutatorsContext{}
|
||||
func registerMutators(ctx *blueprint.Context, preArch, preDeps, postDeps []RegisterMutatorFunc) {
|
||||
mctx := ®isterMutatorsContext{}
|
||||
|
||||
register := func(funcs []RegisterMutatorFunc) {
|
||||
for _, f := range funcs {
|
||||
f(mutators)
|
||||
f(mctx)
|
||||
}
|
||||
}
|
||||
|
||||
register(testPreDeps)
|
||||
mutators.BottomUp("deps", depsMutator).Parallel()
|
||||
register(testPostDeps)
|
||||
register(preArch)
|
||||
|
||||
registerMutatorsToContext(ctx, mutators.mutators)
|
||||
register(preDeps)
|
||||
|
||||
mctx.BottomUp("deps", depsMutator).Parallel()
|
||||
|
||||
register(postDeps)
|
||||
|
||||
registerMutatorsToContext(ctx, mctx.mutators)
|
||||
}
|
||||
|
||||
type registerMutatorsContext struct {
|
||||
@@ -107,7 +70,24 @@ type RegisterMutatorsContext interface {
|
||||
|
||||
type RegisterMutatorFunc func(RegisterMutatorsContext)
|
||||
|
||||
var preArch, preDeps, postDeps, testPreDeps, testPostDeps []RegisterMutatorFunc
|
||||
var preArch = []RegisterMutatorFunc{
|
||||
func(ctx RegisterMutatorsContext) {
|
||||
ctx.TopDown("load_hooks", loadHookMutator).Parallel()
|
||||
},
|
||||
registerPrebuiltsPreArchMutators,
|
||||
registerDefaultsPreArchMutators,
|
||||
}
|
||||
|
||||
var preDeps = []RegisterMutatorFunc{
|
||||
func(ctx RegisterMutatorsContext) {
|
||||
ctx.BottomUp("arch", archMutator).Parallel()
|
||||
ctx.TopDown("arch_hooks", archHookMutator).Parallel()
|
||||
},
|
||||
}
|
||||
|
||||
var postDeps = []RegisterMutatorFunc{
|
||||
registerPrebuiltsPostDepsMutators,
|
||||
}
|
||||
|
||||
func PreArchMutators(f RegisterMutatorFunc) {
|
||||
preArch = append(preArch, f)
|
||||
@@ -121,14 +101,6 @@ func PostDepsMutators(f RegisterMutatorFunc) {
|
||||
postDeps = append(postDeps, f)
|
||||
}
|
||||
|
||||
func TestPreDepsMutators(f RegisterMutatorFunc) {
|
||||
testPreDeps = append(testPreDeps, f)
|
||||
}
|
||||
|
||||
func TeststPostDepsMutators(f RegisterMutatorFunc) {
|
||||
testPostDeps = append(testPostDeps, f)
|
||||
}
|
||||
|
||||
type AndroidTopDownMutator func(TopDownMutatorContext)
|
||||
|
||||
type TopDownMutatorContext interface {
|
||||
|
Reference in New Issue
Block a user