Merge "Allow android tests to specify a mainline package name" am: bc6dc9f546
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2419560 Change-Id: Ic45dc2d792cab6b40841825c6240c7fe0327d9cb Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
d595fdc9a8
4 changed files with 67 additions and 1 deletions
10
java/app.go
10
java/app.go
|
@ -984,8 +984,11 @@ type appTestProperties struct {
|
||||||
// The name of the android_app module that the tests will run against.
|
// The name of the android_app module that the tests will run against.
|
||||||
Instrumentation_for *string
|
Instrumentation_for *string
|
||||||
|
|
||||||
// if specified, the instrumentation target package name in the manifest is overwritten by it.
|
// If specified, the instrumentation target package name in the manifest is overwritten by it.
|
||||||
Instrumentation_target_package *string
|
Instrumentation_target_package *string
|
||||||
|
|
||||||
|
// If specified, the mainline module package name in the test config is overwritten by it.
|
||||||
|
Mainline_package_name *string
|
||||||
}
|
}
|
||||||
|
|
||||||
type AndroidTest struct {
|
type AndroidTest struct {
|
||||||
|
@ -1063,6 +1066,11 @@ func (a *AndroidTest) FixTestConfig(ctx android.ModuleContext, testConfig androi
|
||||||
FlagWithArg("--package-name ", *a.overridableAppProperties.Package_name)
|
FlagWithArg("--package-name ", *a.overridableAppProperties.Package_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if a.appTestProperties.Mainline_package_name != nil {
|
||||||
|
fixNeeded = true
|
||||||
|
command.FlagWithArg("--mainline-package-name ", *a.appTestProperties.Mainline_package_name)
|
||||||
|
}
|
||||||
|
|
||||||
if fixNeeded {
|
if fixNeeded {
|
||||||
rule.Build("fix_test_config", "fix test config")
|
rule.Build("fix_test_config", "fix test config")
|
||||||
return fixedConfig
|
return fixedConfig
|
||||||
|
|
|
@ -2330,12 +2330,14 @@ func TestAndroidTest_FixTestConfig(t *testing.T) {
|
||||||
srcs: ["b.java"],
|
srcs: ["b.java"],
|
||||||
package_name: "com.android.bar.test",
|
package_name: "com.android.bar.test",
|
||||||
instrumentation_for: "foo",
|
instrumentation_for: "foo",
|
||||||
|
mainline_package_name: "com.android.bar",
|
||||||
}
|
}
|
||||||
|
|
||||||
override_android_test {
|
override_android_test {
|
||||||
name: "baz_test",
|
name: "baz_test",
|
||||||
base: "foo_test",
|
base: "foo_test",
|
||||||
package_name: "com.android.baz.test",
|
package_name: "com.android.baz.test",
|
||||||
|
mainline_package_name: "com.android.baz",
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
@ -2354,6 +2356,7 @@ func TestAndroidTest_FixTestConfig(t *testing.T) {
|
||||||
expectedFlags: []string{
|
expectedFlags: []string{
|
||||||
"--manifest out/soong/.intermediates/bar_test/android_common/manifest_fixer/AndroidManifest.xml",
|
"--manifest out/soong/.intermediates/bar_test/android_common/manifest_fixer/AndroidManifest.xml",
|
||||||
"--package-name com.android.bar.test",
|
"--package-name com.android.bar.test",
|
||||||
|
"--mainline-package-name com.android.bar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -2363,6 +2366,8 @@ func TestAndroidTest_FixTestConfig(t *testing.T) {
|
||||||
"--manifest out/soong/.intermediates/foo_test/android_common_baz_test/manifest_fixer/AndroidManifest.xml",
|
"--manifest out/soong/.intermediates/foo_test/android_common_baz_test/manifest_fixer/AndroidManifest.xml",
|
||||||
"--package-name com.android.baz.test",
|
"--package-name com.android.baz.test",
|
||||||
"--test-file-name baz_test.apk",
|
"--test-file-name baz_test.apk",
|
||||||
|
"out/soong/.intermediates/foo_test/android_common_baz_test/test_config_fixer/AndroidTest.xml",
|
||||||
|
"--mainline-package-name com.android.baz",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,8 @@ from manifest import write_xml
|
||||||
KNOWN_PREPARERS = ['com.android.tradefed.targetprep.TestAppInstallSetup',
|
KNOWN_PREPARERS = ['com.android.tradefed.targetprep.TestAppInstallSetup',
|
||||||
'com.android.tradefed.targetprep.suite.SuiteApkInstaller']
|
'com.android.tradefed.targetprep.suite.SuiteApkInstaller']
|
||||||
|
|
||||||
|
MAINLINE_CONTROLLER = 'com.android.tradefed.testtype.suite.module.MainlineTestModuleController'
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
"""Parse commandline arguments."""
|
"""Parse commandline arguments."""
|
||||||
|
|
||||||
|
@ -41,6 +43,8 @@ def parse_args():
|
||||||
help=('overwrite package fields in the test config'))
|
help=('overwrite package fields in the test config'))
|
||||||
parser.add_argument('--test-file-name', default='', dest='test_file_name',
|
parser.add_argument('--test-file-name', default='', dest='test_file_name',
|
||||||
help=('overwrite test file name in the test config'))
|
help=('overwrite test file name in the test config'))
|
||||||
|
parser.add_argument('--mainline-package-name', default='', dest='mainline_package_name',
|
||||||
|
help=('overwrite mainline module package name in the test config'))
|
||||||
parser.add_argument('input', help='input test config file')
|
parser.add_argument('input', help='input test config file')
|
||||||
parser.add_argument('output', help='output test config file')
|
parser.add_argument('output', help='output test config file')
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
@ -72,6 +76,16 @@ def overwrite_test_file_name(test_config_doc, test_file_name):
|
||||||
if option.getAttribute('name') == "test-file-name":
|
if option.getAttribute('name') == "test-file-name":
|
||||||
option.setAttribute('value', test_file_name)
|
option.setAttribute('value', test_file_name)
|
||||||
|
|
||||||
|
def overwrite_mainline_module_package_name(test_config_doc, mainline_package_name):
|
||||||
|
|
||||||
|
test_config = parse_test_config(test_config_doc)
|
||||||
|
|
||||||
|
for obj in get_children_with_tag(test_config, 'object'):
|
||||||
|
if obj.getAttribute('class') == MAINLINE_CONTROLLER:
|
||||||
|
for option in get_children_with_tag(obj, 'option'):
|
||||||
|
if option.getAttribute('name') == "mainline-module-package-name":
|
||||||
|
option.setAttribute('value', mainline_package_name)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Program entry point."""
|
"""Program entry point."""
|
||||||
try:
|
try:
|
||||||
|
@ -88,6 +102,9 @@ def main():
|
||||||
if args.test_file_name:
|
if args.test_file_name:
|
||||||
overwrite_test_file_name(doc, args.test_file_name)
|
overwrite_test_file_name(doc, args.test_file_name)
|
||||||
|
|
||||||
|
if args.mainline_package_name:
|
||||||
|
overwrite_mainline_module_package_name(doc, args.mainline_package_name)
|
||||||
|
|
||||||
with open(args.output, 'w') as f:
|
with open(args.output, 'w') as f:
|
||||||
write_xml(f, doc)
|
write_xml(f, doc)
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,8 @@ from xml.dom import minidom
|
||||||
|
|
||||||
import test_config_fixer
|
import test_config_fixer
|
||||||
|
|
||||||
|
from manifest import write_xml
|
||||||
|
|
||||||
sys.dont_write_bytecode = True
|
sys.dont_write_bytecode = True
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,5 +119,39 @@ class OverwriteTestFileNameTest(unittest.TestCase):
|
||||||
self.assertEqual(expected, output.getvalue())
|
self.assertEqual(expected, output.getvalue())
|
||||||
|
|
||||||
|
|
||||||
|
class OverwriteMainlineModulePackageNameTest(unittest.TestCase):
|
||||||
|
""" Unit tests for overwrite_mainline_module_package_name function """
|
||||||
|
|
||||||
|
test_config = (
|
||||||
|
'<?xml version="1.0" encoding="utf-8"?>\n'
|
||||||
|
'<configuration description="Runs some tests.">\n'
|
||||||
|
' <target_preparer class="com.android.tradefed.targetprep.TestAppInstallSetup">\n'
|
||||||
|
' <option name="test-file-name" value="foo.apk"/>\n'
|
||||||
|
' </target_preparer>\n'
|
||||||
|
' <test class="com.android.tradefed.testtype.AndroidJUnitTest">\n'
|
||||||
|
' <option name="package" value="com.android.foo"/>\n'
|
||||||
|
' <option name="runtime-hint" value="20s"/>\n'
|
||||||
|
' </test>\n'
|
||||||
|
' <object type="module_controller" class="com.android.tradefed.testtype.suite.module.MainlineTestModuleController">\n'
|
||||||
|
' <option name="enable" value="true"/>\n'
|
||||||
|
' <option name="mainline-module-package-name" value="%s"/>\n'
|
||||||
|
' </object>\n'
|
||||||
|
'</configuration>\n')
|
||||||
|
|
||||||
|
def test_testappinstallsetup(self):
|
||||||
|
doc = minidom.parseString(self.test_config % ("com.android.old.package.name"))
|
||||||
|
|
||||||
|
test_config_fixer.overwrite_mainline_module_package_name(doc, "com.android.new.package.name")
|
||||||
|
output = io.StringIO()
|
||||||
|
test_config_fixer.write_xml(output, doc)
|
||||||
|
|
||||||
|
# Only the mainline module package name should be updated. Format the xml
|
||||||
|
# with minidom first to avoid mismatches due to trivial reformatting.
|
||||||
|
expected = io.StringIO()
|
||||||
|
write_xml(expected, minidom.parseString(self.test_config % ("com.android.new.package.name")))
|
||||||
|
self.maxDiff = None
|
||||||
|
self.assertEqual(expected.getvalue(), output.getvalue())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main(verbosity=2)
|
unittest.main(verbosity=2)
|
||||||
|
|
Loading…
Reference in a new issue