summaryrefslogtreecommitdiff
path: root/dexpreopt/testing.go
diff options
context:
space:
mode:
Diffstat (limited to 'dexpreopt/testing.go')
-rw-r--r--dexpreopt/testing.go57
1 files changed, 48 insertions, 9 deletions
diff --git a/dexpreopt/testing.go b/dexpreopt/testing.go
index 8e90295b1..48014824b 100644
--- a/dexpreopt/testing.go
+++ b/dexpreopt/testing.go
@@ -15,39 +15,78 @@
package dexpreopt
import (
+ "fmt"
+
"android/soong/android"
)
-type dummyToolBinary struct {
+type fakeToolBinary struct {
android.ModuleBase
}
-func (m *dummyToolBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {}
+func (m *fakeToolBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {}
-func (m *dummyToolBinary) HostToolPath() android.OptionalPath {
+func (m *fakeToolBinary) HostToolPath() android.OptionalPath {
return android.OptionalPathForPath(android.PathForTesting("dex2oat"))
}
-func dummyToolBinaryFactory() android.Module {
- module := &dummyToolBinary{}
+func fakeToolBinaryFactory() android.Module {
+ module := &fakeToolBinary{}
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst)
return module
}
func RegisterToolModulesForTest(ctx android.RegistrationContext) {
- ctx.RegisterModuleType("dummy_tool_binary", dummyToolBinaryFactory)
+ ctx.RegisterModuleType("fake_tool_binary", fakeToolBinaryFactory)
}
func BpToolModulesForTest() string {
return `
- dummy_tool_binary {
+ fake_tool_binary {
name: "dex2oatd",
}
`
}
-// Prepares a test fixture by enabling dexpreopt.
-var PrepareForTestWithDexpreopt = FixtureModifyGlobalConfig(func(*GlobalConfig) {})
+func CompatLibDefinitionsForTest() string {
+ bp := ""
+
+ // For class loader context and <uses-library> tests.
+ dexpreoptModules := []string{"android.test.runner"}
+ dexpreoptModules = append(dexpreoptModules, CompatUsesLibs...)
+ dexpreoptModules = append(dexpreoptModules, 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)
+ }
+
+ return bp
+}
+
+var PrepareForTestWithDexpreoptCompatLibs = android.GroupFixturePreparers(
+ android.FixtureAddFile("defaults/dexpreopt/compat/a.java", nil),
+ android.FixtureAddTextFile("defaults/dexpreopt/compat/Android.bp", CompatLibDefinitionsForTest()),
+)
+
+var PrepareForTestWithFakeDex2oatd = android.GroupFixturePreparers(
+ android.FixtureRegisterWithContext(RegisterToolModulesForTest),
+ android.FixtureAddTextFile("defaults/dexpreopt/Android.bp", BpToolModulesForTest()),
+)
+
+// Prepares a test fixture by enabling dexpreopt, registering the fake_tool_binary module type and
+// using that to define the `dex2oatd` module.
+var PrepareForTestByEnablingDexpreopt = android.GroupFixturePreparers(
+ FixtureModifyGlobalConfig(func(*GlobalConfig) {}),
+)
// FixtureModifyGlobalConfig enables dexpreopt (unless modified by the mutator) and modifies the
// configuration.