diff options
author | 2021-03-24 13:41:56 +0000 | |
---|---|---|
committer | 2021-03-24 13:41:56 +0000 | |
commit | a1063c09f6f47b68d946ff61cef71692b19d48e5 (patch) | |
tree | a1be7c412465805e9f73851383158e22cf2f85e4 /dexpreopt/testing.go | |
parent | 70204f9fc914f53ab85cf277b50abc6748234691 (diff) | |
parent | 9fc9f53423d59adc9c7f249fcbb6d0f3a44952bd (diff) |
Merge changes I94f66e3e,I233a4fe1,Idbb37485
* changes:
Group all the preparations needed for testing dexpreopt
Separate methods used for fixture based and legacy tests
Use more inclusive language in dexpreopt/testing.go
Diffstat (limited to 'dexpreopt/testing.go')
-rw-r--r-- | dexpreopt/testing.go | 57 |
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. |