summaryrefslogtreecommitdiff
path: root/java/testing.go
diff options
context:
space:
mode:
author Paul Duffin <paulduffin@google.com> 2021-03-23 15:41:11 +0000
committer Paul Duffin <paulduffin@google.com> 2021-03-24 08:30:27 +0000
commit9fc9f53423d59adc9c7f249fcbb6d0f3a44952bd (patch)
treebf00bc7993b6db3364c08b191a0c445a3b5bedd8 /java/testing.go
parent3c84eaaa984805936e71d678ffd67032beefb2c8 (diff)
Group all the preparations needed for testing dexpreopt
Make it easier to test dexpreopt functionality by grouping all the fixture preparations together. Bug: 177892522 Test: m nothing Change-Id: I94f66e3ec82efc4fd791f4fdab678d298565e452
Diffstat (limited to 'java/testing.go')
-rw-r--r--java/testing.go46
1 files changed, 21 insertions, 25 deletions
diff --git a/java/testing.go b/java/testing.go
index d5be5b8db..295b8d0a7 100644
--- a/java/testing.go
+++ b/java/testing.go
@@ -53,6 +53,15 @@ var PrepareForTestWithJavaDefaultModules = android.GroupFixturePreparers(
PrepareForTestWithJavaBuildComponents,
// The java default module definitions.
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)
@@ -182,6 +191,9 @@ func prebuiltApisFilesForLibs(apiLevels []string, sdkLibs []string) map[string][
// 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
@@ -205,9 +217,6 @@ 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.
@@ -216,7 +225,15 @@ func registerRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
//
// deprecated: Use test fixtures instead, e.g. PrepareForTestWithJavaDefaultModules
func GatherRequiredDepsForTest() string {
- return gatherRequiredDepsForTest()
+ 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
@@ -257,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",
@@ -311,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 {