diff options
Diffstat (limited to 'android/testing.go')
| -rw-r--r-- | android/testing.go | 113 |
1 files changed, 59 insertions, 54 deletions
diff --git a/android/testing.go b/android/testing.go index 2a9c6584e..e39a1a749 100644 --- a/android/testing.go +++ b/android/testing.go @@ -183,15 +183,14 @@ func NewTestArchContext(config Config) *TestContext { type TestContext struct { *Context preArch, preDeps, postDeps, finalDeps []RegisterMutatorFunc - bp2buildPreArch, bp2buildMutators []RegisterMutatorFunc NameResolver *NameResolver - // The list of pre-singletons and singletons registered for the test. - preSingletons, singletons sortableComponents + // The list of singletons registered for the test. + singletons sortableComponents - // The order in which the pre-singletons, mutators and singletons will be run in this test + // The order in which the mutators and singletons will be run in this test // context; for debugging. - preSingletonOrder, mutatorOrder, singletonOrder []string + mutatorOrder, singletonOrder []string } func (ctx *TestContext) PreArchMutators(f RegisterMutatorFunc) { @@ -203,7 +202,7 @@ func (ctx *TestContext) HardCodedPreArchMutators(f RegisterMutatorFunc) { ctx.PreArchMutators(f) } -func (ctx *TestContext) ModuleProvider(m blueprint.Module, p blueprint.ProviderKey) interface{} { +func (ctx *TestContext) moduleProvider(m blueprint.Module, p blueprint.AnyProviderKey) (any, bool) { return ctx.Context.ModuleProvider(m, p) } @@ -219,14 +218,14 @@ func (ctx *TestContext) FinalDepsMutators(f RegisterMutatorFunc) { ctx.finalDeps = append(ctx.finalDeps, f) } -func (ctx *TestContext) RegisterBp2BuildConfig(config Bp2BuildConversionAllowlist) { - ctx.config.Bp2buildPackageConfig = config +func (ctx *TestContext) OtherModuleProviderAdaptor() OtherModuleProviderContext { + return NewOtherModuleProviderAdaptor(func(module blueprint.Module, provider blueprint.AnyProviderKey) (any, bool) { + return ctx.moduleProvider(module, provider) + }) } -// PreArchBp2BuildMutators adds mutators to be register for converting Android Blueprint modules -// into Bazel BUILD targets that should run prior to deps and conversion. -func (ctx *TestContext) PreArchBp2BuildMutators(f RegisterMutatorFunc) { - ctx.bp2buildPreArch = append(ctx.bp2buildPreArch, f) +func (ctx *TestContext) OtherModulePropertyErrorf(module Module, property string, fmt_ string, args ...interface{}) { + panic(fmt.Sprintf(fmt_, args...)) } // registeredComponentOrder defines the order in which a sortableComponent type is registered at @@ -397,9 +396,6 @@ type registrationSorter struct { // Used to ensure that this is only created once. once sync.Once - // The order of pre-singletons - preSingletonOrder registeredComponentOrder - // The order of mutators mutatorOrder registeredComponentOrder @@ -412,9 +408,6 @@ type registrationSorter struct { // Only the first call has any effect. func (s *registrationSorter) populate() { s.once.Do(func() { - // Create an ordering from the globally registered pre-singletons. - s.preSingletonOrder = registeredComponentOrderFromExistingOrder("pre-singleton", preSingletons) - // Created an ordering from the globally registered mutators. globallyRegisteredMutators := collateGloballyRegisteredMutators() s.mutatorOrder = registeredComponentOrderFromExistingOrder("mutator", globallyRegisteredMutators) @@ -441,11 +434,6 @@ func globallyRegisteredComponentsOrder() *registrationSorter { func (ctx *TestContext) Register() { globalOrder := globallyRegisteredComponentsOrder() - // Ensure that the pre-singletons used in the test are in the same order as they are used at - // runtime. - globalOrder.preSingletonOrder.enforceOrdering(ctx.preSingletons) - ctx.preSingletons.registerAll(ctx.Context) - mutators := collateRegisteredMutators(ctx.preArch, ctx.preDeps, ctx.postDeps, ctx.finalDeps) // Ensure that the mutators used in the test are in the same order as they are used at runtime. globalOrder.mutatorOrder.enforceOrdering(mutators) @@ -456,23 +444,10 @@ func (ctx *TestContext) Register() { ctx.singletons.registerAll(ctx.Context) // Save the sorted components order away to make them easy to access while debugging. - ctx.preSingletonOrder = componentsToNames(preSingletons) ctx.mutatorOrder = componentsToNames(mutators) ctx.singletonOrder = componentsToNames(singletons) } -// RegisterForBazelConversion prepares a test context for bp2build conversion. -func (ctx *TestContext) RegisterForBazelConversion() { - ctx.config.BuildMode = Bp2build - RegisterMutatorsForBazelConversion(ctx.Context, ctx.bp2buildPreArch) -} - -// RegisterForApiBazelConversion prepares a test context for API bp2build conversion. -func (ctx *TestContext) RegisterForApiBazelConversion() { - ctx.config.BuildMode = ApiBp2build - RegisterMutatorsForApiBazelConversion(ctx.Context, ctx.bp2buildPreArch) -} - func (ctx *TestContext) ParseFileList(rootDir string, filePaths []string) (deps []string, errs []error) { // This function adapts the old style ParseFileList calls that are spread throughout the tests // to the new style that takes a config. @@ -495,12 +470,18 @@ func (ctx *TestContext) RegisterSingletonModuleType(name string, factory Singlet ctx.RegisterModuleType(name, m) } +func (ctx *TestContext) RegisterParallelSingletonModuleType(name string, factory SingletonModuleFactory) { + s, m := SingletonModuleFactoryAdaptor(name, factory) + ctx.RegisterParallelSingletonType(name, s) + ctx.RegisterModuleType(name, m) +} + func (ctx *TestContext) RegisterSingletonType(name string, factory SingletonFactory) { - ctx.singletons = append(ctx.singletons, newSingleton(name, factory)) + ctx.singletons = append(ctx.singletons, newSingleton(name, factory, false)) } -func (ctx *TestContext) RegisterPreSingletonType(name string, factory SingletonFactory) { - ctx.preSingletons = append(ctx.preSingletons, newPreSingleton(name, factory)) +func (ctx *TestContext) RegisterParallelSingletonType(name string, factory SingletonFactory) { + ctx.singletons = append(ctx.singletons, newSingleton(name, factory, true)) } // ModuleVariantForTests selects a specific variant of the module with the given @@ -748,7 +729,6 @@ type TestingBuildParams struct { // - Depfile // - Rspfile // - RspfileContent -// - SymlinkOutputs // - CommandDeps // - CommandOrderOnly // @@ -770,8 +750,6 @@ func (p TestingBuildParams) RelativeToTop() TestingBuildParams { bparams.Depfile = normalizeWritablePathRelativeToTop(bparams.Depfile) bparams.Output = normalizeWritablePathRelativeToTop(bparams.Output) bparams.Outputs = bparams.Outputs.RelativeToTop() - bparams.SymlinkOutput = normalizeWritablePathRelativeToTop(bparams.SymlinkOutput) - bparams.SymlinkOutputs = bparams.SymlinkOutputs.RelativeToTop() bparams.ImplicitOutput = normalizeWritablePathRelativeToTop(bparams.ImplicitOutput) bparams.ImplicitOutputs = bparams.ImplicitOutputs.RelativeToTop() bparams.Input = normalizePathRelativeToTop(bparams.Input) @@ -789,7 +767,6 @@ func (p TestingBuildParams) RelativeToTop() TestingBuildParams { rparams.Depfile = normalizeStringRelativeToTop(p.config, rparams.Depfile) rparams.Rspfile = normalizeStringRelativeToTop(p.config, rparams.Rspfile) rparams.RspfileContent = normalizeStringRelativeToTop(p.config, rparams.RspfileContent) - rparams.SymlinkOutputs = normalizeStringArrayRelativeToTop(p.config, rparams.SymlinkOutputs) rparams.CommandDeps = normalizeStringArrayRelativeToTop(p.config, rparams.CommandDeps) rparams.CommandOrderOnly = normalizeStringArrayRelativeToTop(p.config, rparams.CommandOrderOnly) @@ -1041,20 +1018,21 @@ func (m TestingModule) VariablesForTestsRelativeToTop() map[string]string { return normalizeStringMapRelativeToTop(m.config, m.module.VariablesForTests()) } -// OutputFiles calls OutputFileProducer.OutputFiles on the encapsulated module, exits the test -// immediately if there is an error and otherwise returns the result of calling Paths.RelativeToTop +// OutputFiles checks if module base outputFiles property has any output +// files can be used to return. +// Exits the test immediately if there is an error and +// otherwise returns the result of calling Paths.RelativeToTop // on the returned Paths. func (m TestingModule) OutputFiles(t *testing.T, tag string) Paths { - producer, ok := m.module.(OutputFileProducer) - if !ok { - t.Fatalf("%q must implement OutputFileProducer\n", m.module.Name()) - } - paths, err := producer.OutputFiles(tag) - if err != nil { - t.Fatal(err) + outputFiles := m.Module().base().outputFiles + if tag == "" && outputFiles.DefaultOutputFiles != nil { + return outputFiles.DefaultOutputFiles.RelativeToTop() + } else if taggedOutputFiles, hasTag := outputFiles.TaggedOutputFiles[tag]; hasTag { + return taggedOutputFiles.RelativeToTop() } - return paths.RelativeToTop() + t.Fatal(fmt.Errorf("No test output file has been set for tag %q", tag)) + return nil } // TestingSingleton is wrapper around an android.Singleton that provides methods to find information about individual @@ -1148,7 +1126,8 @@ func AndroidMkEntriesForTest(t *testing.T, ctx *TestContext, mod blueprint.Modul } entriesList := p.AndroidMkEntries() - for i, _ := range entriesList { + aconfigUpdateAndroidMkEntries(ctx, mod.(Module), &entriesList) + for i := range entriesList { entriesList[i].fillInEntries(ctx, mod) } return entriesList @@ -1163,6 +1142,7 @@ func AndroidMkDataForTest(t *testing.T, ctx *TestContext, mod blueprint.Module) } data := p.AndroidMk() data.fillInData(ctx, mod) + aconfigUpdateAndroidMkData(ctx, mod.(Module), &data) return data } @@ -1305,3 +1285,28 @@ func StringRelativeToTop(config Config, command string) string { func StringsRelativeToTop(config Config, command []string) []string { return normalizeStringArrayRelativeToTop(config, command) } + +func EnsureListContainsSuffix(t *testing.T, result []string, expected string) { + t.Helper() + if !SuffixInList(result, expected) { + t.Errorf("%q is not found in %v", expected, result) + } +} + +type panickingConfigAndErrorContext struct { + ctx *TestContext +} + +func (ctx *panickingConfigAndErrorContext) OtherModulePropertyErrorf(module Module, property, fmt string, args ...interface{}) { + panic(ctx.ctx.PropertyErrorf(module, property, fmt, args...).Error()) +} + +func (ctx *panickingConfigAndErrorContext) Config() Config { + return ctx.ctx.Config() +} + +func PanickingConfigAndErrorContext(ctx *TestContext) ConfigAndErrorContext { + return &panickingConfigAndErrorContext{ + ctx: ctx, + } +} |