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
This commit is contained in:
commit
a1063c09f6
|
@ -15,39 +15,78 @@
|
||||||
package dexpreopt
|
package dexpreopt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
)
|
)
|
||||||
|
|
||||||
type dummyToolBinary struct {
|
type fakeToolBinary struct {
|
||||||
android.ModuleBase
|
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"))
|
return android.OptionalPathForPath(android.PathForTesting("dex2oat"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func dummyToolBinaryFactory() android.Module {
|
func fakeToolBinaryFactory() android.Module {
|
||||||
module := &dummyToolBinary{}
|
module := &fakeToolBinary{}
|
||||||
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst)
|
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst)
|
||||||
return module
|
return module
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterToolModulesForTest(ctx android.RegistrationContext) {
|
func RegisterToolModulesForTest(ctx android.RegistrationContext) {
|
||||||
ctx.RegisterModuleType("dummy_tool_binary", dummyToolBinaryFactory)
|
ctx.RegisterModuleType("fake_tool_binary", fakeToolBinaryFactory)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BpToolModulesForTest() string {
|
func BpToolModulesForTest() string {
|
||||||
return `
|
return `
|
||||||
dummy_tool_binary {
|
fake_tool_binary {
|
||||||
name: "dex2oatd",
|
name: "dex2oatd",
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepares a test fixture by enabling dexpreopt.
|
func CompatLibDefinitionsForTest() string {
|
||||||
var PrepareForTestWithDexpreopt = FixtureModifyGlobalConfig(func(*GlobalConfig) {})
|
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
|
// FixtureModifyGlobalConfig enables dexpreopt (unless modified by the mutator) and modifies the
|
||||||
// configuration.
|
// configuration.
|
||||||
|
|
|
@ -53,7 +53,7 @@ var prepareForJavaTest = android.GroupFixturePreparers(
|
||||||
android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
|
android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
|
||||||
ctx.RegisterPreSingletonType("sdk_versions", sdkPreSingletonFactory)
|
ctx.RegisterPreSingletonType("sdk_versions", sdkPreSingletonFactory)
|
||||||
}),
|
}),
|
||||||
dexpreopt.PrepareForTestWithDexpreopt,
|
PrepareForTestWithDexpreopt,
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
@ -68,7 +68,7 @@ func TestMain(m *testing.M) {
|
||||||
func testJavaError(t *testing.T, pattern string, bp string) (*android.TestContext, android.Config) {
|
func testJavaError(t *testing.T, pattern string, bp string) (*android.TestContext, android.Config) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
result := android.GroupFixturePreparers(
|
result := android.GroupFixturePreparers(
|
||||||
prepareForJavaTest, dexpreopt.PrepareForTestWithDexpreopt).
|
prepareForJavaTest, dexpreopt.PrepareForTestByEnablingDexpreopt).
|
||||||
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)).
|
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)).
|
||||||
RunTestWithBp(t, bp)
|
RunTestWithBp(t, bp)
|
||||||
return result.TestContext, result.Config
|
return result.TestContext, result.Config
|
||||||
|
|
|
@ -43,7 +43,7 @@ var PrepareForTestWithJavaBuildComponents = android.GroupFixturePreparers(
|
||||||
// Make sure that mutators and module types, e.g. prebuilt mutators available.
|
// Make sure that mutators and module types, e.g. prebuilt mutators available.
|
||||||
android.PrepareForTestWithAndroidBuildComponents,
|
android.PrepareForTestWithAndroidBuildComponents,
|
||||||
// Make java build components available to the test.
|
// Make java build components available to the test.
|
||||||
android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
|
android.FixtureRegisterWithContext(registerRequiredBuildComponentsForTest),
|
||||||
android.FixtureRegisterWithContext(registerJavaPluginBuildComponents),
|
android.FixtureRegisterWithContext(registerJavaPluginBuildComponents),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -52,7 +52,16 @@ var PrepareForTestWithJavaDefaultModules = android.GroupFixturePreparers(
|
||||||
// Make sure that all the module types used in the defaults are registered.
|
// Make sure that all the module types used in the defaults are registered.
|
||||||
PrepareForTestWithJavaBuildComponents,
|
PrepareForTestWithJavaBuildComponents,
|
||||||
// The java default module definitions.
|
// 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)
|
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
|
// In particular this must register all the components that are used in the `Android.bp` snippet
|
||||||
// returned by GatherRequiredDepsForTest()
|
// returned by GatherRequiredDepsForTest()
|
||||||
|
//
|
||||||
|
// deprecated: Use test fixtures instead, e.g. PrepareForTestWithJavaBuildComponents
|
||||||
func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
|
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)
|
RegisterAARBuildComponents(ctx)
|
||||||
RegisterAppBuildComponents(ctx)
|
RegisterAppBuildComponents(ctx)
|
||||||
RegisterAppImportBuildComponents(ctx)
|
RegisterAppImportBuildComponents(ctx)
|
||||||
|
@ -193,15 +217,32 @@ func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
|
||||||
RegisterSdkLibraryBuildComponents(ctx)
|
RegisterSdkLibraryBuildComponents(ctx)
|
||||||
RegisterStubsBuildComponents(ctx)
|
RegisterStubsBuildComponents(ctx)
|
||||||
RegisterSystemModulesBuildComponents(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.
|
// 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.
|
// 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 {
|
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
|
var bp string
|
||||||
|
|
||||||
extraModules := []string{
|
extraModules := []string{
|
||||||
|
@ -233,24 +274,6 @@ func GatherRequiredDepsForTest() string {
|
||||||
`, extra)
|
`, 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 += `
|
bp += `
|
||||||
java_library {
|
java_library {
|
||||||
name: "framework",
|
name: "framework",
|
||||||
|
@ -287,9 +310,6 @@ func GatherRequiredDepsForTest() string {
|
||||||
`, extra)
|
`, 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.
|
// Make sure that the dex_bootjars singleton module is instantiated for the tests.
|
||||||
bp += `
|
bp += `
|
||||||
dex_bootjars {
|
dex_bootjars {
|
||||||
|
|
Loading…
Reference in New Issue