summaryrefslogtreecommitdiff
path: root/java/testing.go
diff options
context:
space:
mode:
Diffstat (limited to 'java/testing.go')
-rw-r--r--java/testing.go72
1 files changed, 46 insertions, 26 deletions
diff --git a/java/testing.go b/java/testing.go
index 82a2103fd..295b8d0a7 100644
--- a/java/testing.go
+++ b/java/testing.go
@@ -43,7 +43,7 @@ var PrepareForTestWithJavaBuildComponents = android.GroupFixturePreparers(
// Make sure that mutators and module types, e.g. prebuilt mutators available.
android.PrepareForTestWithAndroidBuildComponents,
// Make java build components available to the test.
- android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
+ android.FixtureRegisterWithContext(registerRequiredBuildComponentsForTest),
android.FixtureRegisterWithContext(registerJavaPluginBuildComponents),
)
@@ -52,7 +52,16 @@ var PrepareForTestWithJavaDefaultModules = android.GroupFixturePreparers(
// Make sure that all the module types used in the defaults are registered.
PrepareForTestWithJavaBuildComponents,
// The java default module definitions.
- android.FixtureAddTextFile(defaultJavaDir+"/Android.bp", GatherRequiredDepsForTest()),
+ android.FixtureAddTextFile(defaultJavaDir+"/Android.bp", gatherRequiredDepsForTest()),
+ // Add dexpreopt compat libs (android.test.base, etc.) and a fake dex2oatd module.
+ dexpreopt.PrepareForTestWithDexpreoptCompatLibs,
+ dexpreopt.PrepareForTestWithFakeDex2oatd,
+)
+
+// Provides everything needed by dexpreopt.
+var PrepareForTestWithDexpreopt = android.GroupFixturePreparers(
+ PrepareForTestWithJavaDefaultModules,
+ dexpreopt.PrepareForTestByEnablingDexpreopt,
)
var PrepareForTestWithOverlayBuildComponents = android.FixtureRegisterWithContext(registerOverlayBuildComponents)
@@ -178,7 +187,22 @@ func prebuiltApisFilesForLibs(apiLevels []string, sdkLibs []string) map[string][
//
// In particular this must register all the components that are used in the `Android.bp` snippet
// returned by GatherRequiredDepsForTest()
+//
+// deprecated: Use test fixtures instead, e.g. PrepareForTestWithJavaBuildComponents
func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
+ registerRequiredBuildComponentsForTest(ctx)
+
+ // Make sure that any tool related module types needed by dexpreopt have been registered.
+ dexpreopt.RegisterToolModulesForTest(ctx)
+}
+
+// registerRequiredBuildComponentsForTest registers the build components used by
+// PrepareForTestWithJavaDefaultModules.
+//
+// As functionality is moved out of here into separate FixturePreparer instances they should also
+// be moved into GatherRequiredDepsForTest for use by tests that have not yet switched to use test
+// fixtures.
+func registerRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
RegisterAARBuildComponents(ctx)
RegisterAppBuildComponents(ctx)
RegisterAppImportBuildComponents(ctx)
@@ -193,15 +217,32 @@ func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
RegisterSdkLibraryBuildComponents(ctx)
RegisterStubsBuildComponents(ctx)
RegisterSystemModulesBuildComponents(ctx)
-
- // Make sure that any tool related module types needed by dexpreopt have been registered.
- dexpreopt.RegisterToolModulesForTest(ctx)
}
// Gather the module definitions needed by tests that depend upon code from this package.
//
// Returns an `Android.bp` snippet that defines the modules that are needed by this package.
+//
+// deprecated: Use test fixtures instead, e.g. PrepareForTestWithJavaDefaultModules
func GatherRequiredDepsForTest() string {
+ bp := gatherRequiredDepsForTest()
+
+ // For class loader context and <uses-library> tests.
+ bp += dexpreopt.CompatLibDefinitionsForTest()
+
+ // Make sure that any tools needed for dexpreopting are defined.
+ bp += dexpreopt.BpToolModulesForTest()
+
+ return bp
+}
+
+// gatherRequiredDepsForTest gathers the module definitions used by
+// PrepareForTestWithJavaDefaultModules.
+//
+// As functionality is moved out of here into separate FixturePreparer instances they should also
+// be moved into GatherRequiredDepsForTest for use by tests that have not yet switched to use test
+// fixtures.
+func gatherRequiredDepsForTest() string {
var bp string
extraModules := []string{
@@ -233,24 +274,6 @@ func GatherRequiredDepsForTest() string {
`, extra)
}
- // For class loader context and <uses-library> tests.
- dexpreoptModules := []string{"android.test.runner"}
- dexpreoptModules = append(dexpreoptModules, dexpreopt.CompatUsesLibs...)
- dexpreoptModules = append(dexpreoptModules, dexpreopt.OptionalCompatUsesLibs...)
-
- for _, extra := range dexpreoptModules {
- bp += fmt.Sprintf(`
- java_library {
- name: "%s",
- srcs: ["a.java"],
- sdk_version: "none",
- system_modules: "stable-core-platform-api-stubs-system-modules",
- compile_dex: true,
- installable: true,
- }
- `, extra)
- }
-
bp += `
java_library {
name: "framework",
@@ -287,9 +310,6 @@ func GatherRequiredDepsForTest() string {
`, extra)
}
- // Make sure that any tools needed for dexpreopting are defined.
- bp += dexpreopt.BpToolModulesForTest()
-
// Make sure that the dex_bootjars singleton module is instantiated for the tests.
bp += `
dex_bootjars {