Pass Config to NewTestContext instead of ctx.Register

Prepare for using Config when adding singletons by passing
Config to NewTestContext and NewContext instead of to ctx.Register.
This will enable a followup change to store SingletonMakeVarsProviders
registered on the Context in the Config, which is necessary to run
multiple tests in parallel without data races.

Test: all soong tests
Change-Id: Id229629a4e42ff4487d317241673837726c075fc
This commit is contained in:
Colin Cross
2020-10-29 17:09:13 -07:00
parent 45e0c95f85
commit ae8600b507
45 changed files with 209 additions and 208 deletions

View File

@@ -23,6 +23,7 @@ import (
func init() {
android.RegisterPreSingletonType("overlay", OverlaySingletonFactory)
}
var androidResourceIgnoreFilenames = []string{

View File

@@ -59,7 +59,7 @@ func testAppConfig(env map[string]string, bp string, fs map[string][]byte) andro
func testApp(t *testing.T, bp string) *android.TestContext {
config := testAppConfig(nil, bp, nil)
ctx := testContext()
ctx := testContext(config)
run(t, ctx, config)
@@ -220,7 +220,7 @@ func TestAndroidAppSet_Variants(t *testing.T) {
config.TestProductVariables.AAPTPrebuiltDPI = test.aaptPrebuiltDPI
config.TestProductVariables.Platform_sdk_version = &test.sdkVersion
config.Targets[android.Android] = test.targets
ctx := testContext()
ctx := testContext(config)
run(t, ctx, config)
module := ctx.ModuleForTests("foo", "android_common")
const packedSplitApks = "foo.zip"
@@ -657,7 +657,7 @@ func TestResourceDirs(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
config := testConfig(nil, fmt.Sprintf(bp, testCase.prop), fs)
ctx := testContext()
ctx := testContext(config)
run(t, ctx, config)
module := ctx.ModuleForTests("foo", "android_common")
@@ -973,7 +973,7 @@ func TestAndroidResources(t *testing.T) {
config.TestProductVariables.EnforceRROExcludedOverlays = testCase.enforceRROExcludedOverlays
}
ctx := testContext()
ctx := testContext(config)
run(t, ctx, config)
resourceListToFiles := func(module android.TestingModule, list []string) (files []string) {
@@ -1039,7 +1039,7 @@ func TestAndroidResources(t *testing.T) {
}
func checkSdkVersion(t *testing.T, config android.Config, expectedSdkVersion string) {
ctx := testContext()
ctx := testContext(config)
run(t, ctx, config)
@@ -1633,7 +1633,7 @@ func TestCertificates(t *testing.T) {
if test.certificateOverride != "" {
config.TestProductVariables.CertificateOverrides = []string{test.certificateOverride}
}
ctx := testContext()
ctx := testContext(config)
run(t, ctx, config)
foo := ctx.ModuleForTests("foo", "android_common")
@@ -1698,7 +1698,7 @@ func TestRequestV4SigningFlag(t *testing.T) {
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
config := testAppConfig(nil, test.bp, nil)
ctx := testContext()
ctx := testContext(config)
run(t, ctx, config)
foo := ctx.ModuleForTests("foo", "android_common")
@@ -1758,7 +1758,7 @@ func TestPackageNameOverride(t *testing.T) {
if test.packageNameOverride != "" {
config.TestProductVariables.PackageNameOverrides = []string{test.packageNameOverride}
}
ctx := testContext()
ctx := testContext(config)
run(t, ctx, config)
foo := ctx.ModuleForTests("foo", "android_common")
@@ -1793,7 +1793,7 @@ func TestInstrumentationTargetOverridden(t *testing.T) {
`
config := testAppConfig(nil, bp, nil)
config.TestProductVariables.ManifestPackageNameOverrides = []string{"foo:org.dandroid.bp"}
ctx := testContext()
ctx := testContext(config)
run(t, ctx, config)
@@ -2416,7 +2416,7 @@ func TestAndroidAppImport_DpiVariants(t *testing.T) {
config := testAppConfig(nil, bp, nil)
config.TestProductVariables.AAPTPreferredConfig = test.aaptPreferredConfig
config.TestProductVariables.AAPTPrebuiltDPI = test.aaptPrebuiltDPI
ctx := testContext()
ctx := testContext(config)
run(t, ctx, config)
@@ -2777,7 +2777,7 @@ func TestUsesLibraries(t *testing.T) {
config := testAppConfig(nil, bp, nil)
config.TestProductVariables.MissingUsesLibraries = []string{"baz"}
ctx := testContext()
ctx := testContext(config)
run(t, ctx, config)
@@ -3129,7 +3129,7 @@ func TestUncompressDex(t *testing.T) {
config.TestProductVariables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
}
ctx := testContext()
ctx := testContext(config)
run(t, ctx, config)
@@ -3209,7 +3209,7 @@ func TestRuntimeResourceOverlay(t *testing.T) {
}
`
config := testAppConfig(nil, bp, fs)
ctx := testContext()
ctx := testContext(config)
run(t, ctx, config)
m := ctx.ModuleForTests("foo", "android_common")
@@ -3506,7 +3506,7 @@ func TestEnforceRRO_propagatesToDependencies(t *testing.T) {
config.TestProductVariables.EnforceRROExemptedTargets = testCase.enforceRROExemptTargets
}
ctx := testContext()
ctx := testContext(config)
run(t, ctx, config)
modules := []string{"foo", "bar"}

View File

@@ -51,7 +51,7 @@ func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOu
dexpreoptConfig.BootJars = android.CreateTestConfiguredJarList([]string{"platform:foo", "platform:bar", "platform:baz"})
dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig)
ctx := testContext()
ctx := testContext(config)
RegisterDexpreoptBootJarsComponents(ctx)
run(t, ctx, config)

View File

@@ -29,8 +29,8 @@ func testConfigWithBootJars(bp string, bootJars []string) android.Config {
return config
}
func testContextWithHiddenAPI() *android.TestContext {
ctx := testContext()
func testContextWithHiddenAPI(config android.Config) *android.TestContext {
ctx := testContext(config)
ctx.RegisterSingletonType("hiddenapi", hiddenAPISingletonFactory)
return ctx
}
@@ -38,7 +38,7 @@ func testContextWithHiddenAPI() *android.TestContext {
func testHiddenAPIWithConfig(t *testing.T, config android.Config) *android.TestContext {
t.Helper()
ctx := testContextWithHiddenAPI()
ctx := testContextWithHiddenAPI(config)
run(t, ctx, config)
return ctx

View File

@@ -70,9 +70,9 @@ func testConfig(env map[string]string, bp string, fs map[string][]byte) android.
return config
}
func testContext() *android.TestContext {
func testContext(config android.Config) *android.TestContext {
ctx := android.NewTestArchContext()
ctx := android.NewTestArchContext(config)
RegisterJavaBuildComponents(ctx)
RegisterAppBuildComponents(ctx)
RegisterAARBuildComponents(ctx)
@@ -115,7 +115,7 @@ func run(t *testing.T, ctx *android.TestContext, config android.Config) {
pathCtx := android.PathContextForTesting(config)
dexpreopt.SetTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx))
ctx.Register(config)
ctx.Register()
_, errs := ctx.ParseBlueprintsFiles("Android.bp")
android.FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
@@ -129,12 +129,12 @@ func testJavaError(t *testing.T, pattern string, bp string) (*android.TestContex
func testJavaErrorWithConfig(t *testing.T, pattern string, config android.Config) (*android.TestContext, android.Config) {
t.Helper()
ctx := testContext()
ctx := testContext(config)
pathCtx := android.PathContextForTesting(config)
dexpreopt.SetTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx))
ctx.Register(config)
ctx.Register()
_, errs := ctx.ParseBlueprintsFiles("Android.bp")
if len(errs) > 0 {
android.FailIfNoMatchingErrors(t, pattern, errs)
@@ -163,7 +163,7 @@ func testJava(t *testing.T, bp string) (*android.TestContext, android.Config) {
func testJavaWithConfig(t *testing.T, config android.Config) (*android.TestContext, android.Config) {
t.Helper()
ctx := testContext()
ctx := testContext(config)
run(t, ctx, config)
return ctx, config
@@ -1440,7 +1440,7 @@ func TestJavaLibrary(t *testing.T) {
}
`),
})
ctx := testContext()
ctx := testContext(config)
run(t, ctx, config)
}
@@ -1458,7 +1458,7 @@ func TestJavaImport(t *testing.T) {
}
`),
})
ctx := testContext()
ctx := testContext(config)
run(t, ctx, config)
}

View File

@@ -356,7 +356,7 @@ func TestClasspath(t *testing.T) {
config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
config.TestProductVariables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
}
ctx := testContext()
ctx := testContext(config)
run(t, ctx, config)
checkClasspath(t, ctx, true /* isJava8 */)
@@ -377,7 +377,7 @@ func TestClasspath(t *testing.T) {
config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
config.TestProductVariables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
}
ctx := testContext()
ctx := testContext(config)
run(t, ctx, config)
checkClasspath(t, ctx, false /* isJava8 */)
@@ -401,7 +401,7 @@ func TestClasspath(t *testing.T) {
config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
config.TestProductVariables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
}
ctx := testContext()
ctx := testContext(config)
run(t, ctx, config)
checkClasspath(t, ctx, true /* isJava8 */)
@@ -417,7 +417,7 @@ func TestClasspath(t *testing.T) {
config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
config.TestProductVariables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
}
ctx := testContext()
ctx := testContext(config)
run(t, ctx, config)
checkClasspath(t, ctx, false /* isJava8 */)