Implement android_test_import
Test: app_test.go, prebuilt CTS tests Fixes: 132371143 Change-Id: Ife12ba691dfa597dde90faf0957224a6f444e139
This commit is contained in:
@@ -122,6 +122,15 @@ func testSuiteComponent(w io.Writer, test_suites []string) {
|
||||
}
|
||||
}
|
||||
|
||||
func testSuiteComponentEntries(entries *android.AndroidMkEntries, test_suites []string) {
|
||||
entries.SetString("LOCAL_MODULE_TAGS", "tests")
|
||||
if len(test_suites) > 0 {
|
||||
entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", test_suites...)
|
||||
} else {
|
||||
entries.SetString("LOCAL_COMPATIBILITY_SUITE", "null-suite")
|
||||
}
|
||||
}
|
||||
|
||||
func (j *Test) AndroidMk() android.AndroidMkData {
|
||||
data := j.Library.AndroidMk()
|
||||
data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
|
||||
@@ -632,6 +641,15 @@ func (a *AndroidAppImport) AndroidMkEntries() android.AndroidMkEntries {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *AndroidTestImport) AndroidMkEntries() android.AndroidMkEntries {
|
||||
entries := a.AndroidAppImport.AndroidMkEntries()
|
||||
entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
|
||||
testSuiteComponentEntries(entries, a.testProperties.Test_suites)
|
||||
androidMkEntriesWriteTestData(a.data, entries)
|
||||
})
|
||||
return entries
|
||||
}
|
||||
|
||||
func androidMkWriteTestData(data android.Paths, ret *android.AndroidMkData) {
|
||||
var testFiles []string
|
||||
for _, d := range data {
|
||||
@@ -643,3 +661,11 @@ func androidMkWriteTestData(data android.Paths, ret *android.AndroidMkData) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func androidMkEntriesWriteTestData(data android.Paths, entries *android.AndroidMkEntries) {
|
||||
var testFiles []string
|
||||
for _, d := range data {
|
||||
testFiles = append(testFiles, d.String()+":"+d.Rel())
|
||||
}
|
||||
entries.AddStrings("LOCAL_COMPATIBILITY_SUPPORT_FILES", testFiles...)
|
||||
}
|
||||
|
38
java/app.go
38
java/app.go
@@ -39,6 +39,7 @@ func init() {
|
||||
android.RegisterModuleType("android_app_certificate", AndroidAppCertificateFactory)
|
||||
android.RegisterModuleType("override_android_app", OverrideAndroidAppModuleFactory)
|
||||
android.RegisterModuleType("android_app_import", AndroidAppImportFactory)
|
||||
android.RegisterModuleType("android_test_import", AndroidTestImportFactory)
|
||||
|
||||
initAndroidAppImportVariantGroupTypes()
|
||||
}
|
||||
@@ -866,6 +867,10 @@ func (a *AndroidAppImport) uncompressDex(
|
||||
}
|
||||
|
||||
func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
a.generateAndroidBuildActions(ctx)
|
||||
}
|
||||
|
||||
func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
numCertPropsSet := 0
|
||||
if String(a.properties.Certificate) != "" {
|
||||
numCertPropsSet++
|
||||
@@ -1024,6 +1029,39 @@ func AndroidAppImportFactory() android.Module {
|
||||
return module
|
||||
}
|
||||
|
||||
type AndroidTestImport struct {
|
||||
AndroidAppImport
|
||||
|
||||
testProperties testProperties
|
||||
|
||||
data android.Paths
|
||||
}
|
||||
|
||||
func (a *AndroidTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
a.generateAndroidBuildActions(ctx)
|
||||
|
||||
a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data)
|
||||
}
|
||||
|
||||
// android_test_import imports a prebuilt test apk with additional processing specified in the
|
||||
// module. DPI or arch variant configurations can be made as with android_app_import.
|
||||
func AndroidTestImportFactory() android.Module {
|
||||
module := &AndroidTestImport{}
|
||||
module.AddProperties(&module.properties)
|
||||
module.AddProperties(&module.dexpreoptProperties)
|
||||
module.AddProperties(&module.usesLibrary.usesLibraryProperties)
|
||||
module.AddProperties(&module.testProperties)
|
||||
module.populateAllVariantStructs()
|
||||
android.AddLoadHook(module, func(ctx android.LoadHookContext) {
|
||||
module.processVariants(ctx)
|
||||
})
|
||||
|
||||
InitJavaModule(module, android.DeviceSupported)
|
||||
android.InitSingleSourcePrebuiltModule(module, &module.properties, "Apk")
|
||||
|
||||
return module
|
||||
}
|
||||
|
||||
type UsesLibraryProperties struct {
|
||||
// A list of shared library modules that will be listed in uses-library tags in the AndroidManifest.xml file.
|
||||
Uses_libs []string
|
||||
|
@@ -1381,6 +1381,34 @@ func TestAndroidAppImport_ArchVariants(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAndroidTestImport(t *testing.T) {
|
||||
ctx, config := testJava(t, `
|
||||
android_test_import {
|
||||
name: "foo",
|
||||
apk: "prebuilts/apk/app.apk",
|
||||
presigned: true,
|
||||
data: [
|
||||
"testdata/data",
|
||||
],
|
||||
}
|
||||
`)
|
||||
|
||||
test := ctx.ModuleForTests("foo", "android_common").Module().(*AndroidTestImport)
|
||||
|
||||
// Check android mks.
|
||||
entries := android.AndroidMkEntriesForTest(t, config, "", test)
|
||||
expected := []string{"tests"}
|
||||
actual := entries.EntryMap["LOCAL_MODULE_TAGS"]
|
||||
if !reflect.DeepEqual(expected, actual) {
|
||||
t.Errorf("Unexpected module tags - expected: %q, actual: %q", expected, actual)
|
||||
}
|
||||
expected = []string{"testdata/data:testdata/data"}
|
||||
actual = entries.EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"]
|
||||
if !reflect.DeepEqual(expected, actual) {
|
||||
t.Errorf("Unexpected test data - expected: %q, actual: %q", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStl(t *testing.T) {
|
||||
ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
|
||||
cc_library {
|
||||
|
@@ -66,6 +66,7 @@ func testContext(bp string, fs map[string][]byte) *android.TestContext {
|
||||
ctx.RegisterModuleType("android_library", android.ModuleFactoryAdaptor(AndroidLibraryFactory))
|
||||
ctx.RegisterModuleType("android_test", android.ModuleFactoryAdaptor(AndroidTestFactory))
|
||||
ctx.RegisterModuleType("android_test_helper_app", android.ModuleFactoryAdaptor(AndroidTestHelperAppFactory))
|
||||
ctx.RegisterModuleType("android_test_import", android.ModuleFactoryAdaptor(AndroidTestImportFactory))
|
||||
ctx.RegisterModuleType("java_binary", android.ModuleFactoryAdaptor(BinaryFactory))
|
||||
ctx.RegisterModuleType("java_binary_host", android.ModuleFactoryAdaptor(BinaryHostFactory))
|
||||
ctx.RegisterModuleType("java_device_for_host", android.ModuleFactoryAdaptor(DeviceForHostFactory))
|
||||
@@ -200,6 +201,8 @@ func testContext(bp string, fs map[string][]byte) *android.TestContext {
|
||||
|
||||
"cert/new_cert.x509.pem": nil,
|
||||
"cert/new_cert.pk8": nil,
|
||||
|
||||
"testdata/data": nil,
|
||||
}
|
||||
|
||||
for k, v := range fs {
|
||||
|
Reference in New Issue
Block a user