diff options
author | Jaewoong Jung <jungjw@google.com> | 2020-01-14 10:27:18 -0800 |
---|---|---|
committer | Jaewoong Jung <jungjw@google.com> | 2020-01-17 06:08:12 -0800 |
commit | 3998234d8cf6575ec2f862346c0f1c27c94c28e2 (patch) | |
tree | 34ff9cabfc8d0438bd5dbbfe923315c91c518dc7 /scripts | |
parent | 1be2d48005d45e4061d21dec17a4e6714a600232 (diff) | |
download | build_soong-3998234d8cf6575ec2f862346c0f1c27c94c28e2.tar.gz build_soong-3998234d8cf6575ec2f862346c0f1c27c94c28e2.tar.bz2 build_soong-3998234d8cf6575ec2f862346c0f1c27c94c28e2.zip |
Overwrite test-file-name in test config.
If the install apk name is different than the module name, use
test_config_fixer to update the test-file-name value in the config.
Test: app_test.go
Fixes: 147375216
Change-Id: I2141eeebbb3552995400b45634712306673fd812
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/test_config_fixer.py | 18 | ||||
-rw-r--r-- | scripts/test_config_fixer_test.py | 27 |
2 files changed, 44 insertions, 1 deletions
diff --git a/scripts/test_config_fixer.py b/scripts/test_config_fixer.py index 7bb4b52a..32d5b175 100644 --- a/scripts/test_config_fixer.py +++ b/scripts/test_config_fixer.py @@ -37,6 +37,8 @@ def parse_args(): help=('AndroidManifest.xml that contains the original package name')) parser.add_argument('--package-name', default='', dest='package_name', help=('overwrite package fields in the test config')) + parser.add_argument('--test-file-name', default='', dest='test_file_name', + help=('overwrite test file name in the test config')) parser.add_argument('input', help='input test config file') parser.add_argument('output', help='output test config file') return parser.parse_args() @@ -46,7 +48,6 @@ def overwrite_package_name(test_config_doc, manifest_doc, package_name): manifest = parse_manifest(manifest_doc) original_package = manifest.getAttribute('package') - print('package: ' + original_package) test_config = parse_test_config(test_config_doc) tests = get_children_with_tag(test_config, 'test') @@ -57,6 +58,18 @@ def overwrite_package_name(test_config_doc, manifest_doc, package_name): if option.getAttribute('name') == "package" and option.getAttribute('value') == original_package: option.setAttribute('value', package_name) +def overwrite_test_file_name(test_config_doc, test_file_name): + + test_config = parse_test_config(test_config_doc) + tests = get_children_with_tag(test_config, 'target_preparer') + + for test in tests: + if test.getAttribute('class') == "com.android.tradefed.targetprep.TestAppInstallSetup": + options = get_children_with_tag(test, 'option') + for option in options: + if option.getAttribute('name') == "test-file-name": + option.setAttribute('value', test_file_name) + def main(): """Program entry point.""" try: @@ -70,6 +83,9 @@ def main(): manifest_doc = minidom.parse(args.manifest) overwrite_package_name(doc, manifest_doc, args.package_name) + if args.test_file_name: + overwrite_test_file_name(doc, args.test_file_name) + with open(args.output, 'wb') as f: write_xml(f, doc) diff --git a/scripts/test_config_fixer_test.py b/scripts/test_config_fixer_test.py index b90582ed..1272c6b3 100644 --- a/scripts/test_config_fixer_test.py +++ b/scripts/test_config_fixer_test.py @@ -67,5 +67,32 @@ class OverwritePackageNameTest(unittest.TestCase): self.assertEqual(expected, output.getvalue()) +class OverwriteTestFileNameTest(unittest.TestCase): + """ Unit tests for overwrite_test_file_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="%s"/>\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' + '</configuration>\n') + + def test_all(self): + doc = minidom.parseString(self.test_config % ("foo.apk")) + + test_config_fixer.overwrite_test_file_name(doc, "bar.apk") + output = StringIO.StringIO() + test_config_fixer.write_xml(output, doc) + + # Only the matching package name in a test node should be updated. + expected = self.test_config % ("bar.apk") + self.assertEqual(expected, output.getvalue()) + + if __name__ == '__main__': unittest.main(verbosity=2) |