summaryrefslogtreecommitdiff
path: root/scripts/test_config_fixer.py
diff options
context:
space:
mode:
author Ronald Braunstein <rbraunstein@google.com> 2024-02-02 12:37:20 -0800
committer Ronald Braunstein <rbraunstein@google.com> 2024-03-06 00:38:56 +0000
commitfce431652d87cb9727cb187b101b1e89b831b254 (patch)
treed93d5ded81b3e16bb2ee2cc05246952baad95111 /scripts/test_config_fixer.py
parentaf9fc549ca6ba53b80813bd16aac4924e716dbe7 (diff)
Test_Module_Config soong implementation
New soong module type `TestModuleConfig` This module type allows to write: test_module_config { name: "DerivedFrameworks1", base: "FrameworksServicesTests", include_filters: ["com.android.server.accessibility.FingerprintGestureDispatcherTest"], } This goal is to put the test options (include_fitler in this case) in Android.bp rather than TEST_MAPPING to be able to name a set of options and to allow the CI to more precise about which part of a TestModule might be failing. In general, it is recommended to split up tests rather than use this approach, but that isn't always feasible. More details on project here:  https://docs.google.com/document/d/1MpA4BS6mTr-1D-K9MVmzdHkSufAvIkkM4gPEUglNodk/edit?tab=t.0 Migration plan here: https://docs.google.com/document/d/1x3w-BvKO3E-GbY8YOSBuzJC6-pkLkuhfjSyZ1hJQBYM/edit?tab=t.0 Some details of final output: * All the [data] files from Derived are the same as base. * The apk names is changed to be the Module name * The test options are added to .config file * test-file-name in the .config file (for base.apk) is changed to be new apk. * module-info.json is hand inspected between base and derived. * I added a .manifest file so future tools know what base is, if they need it. We are working a mechanism to use a CAS so the zip of the testcases won't explode. (however the trident disk image will get bigger) % tree -ls out/target/product/shiba/testcases/DerivedFrameworks1 out/target/product/shiba/testcases/FrameworksServicesTests [ 4096] out/target/product/shiba/testcases/DerivedFrameworks1 ├── [ 4096] arm64 │   └── [ 72346281] DerivedFrameworks1.apk ├── [ 20887] BstatsTestApp.apk ├── [ 4096] data │   └── [ 851] broken_shortcut.xml ├── [ 3157] DerivedFrameworks1.config ├── [ 12695] JobTestApp.apk ├── [ 8599] MediaButtonReceiverHolderTestHelperApp.apk ├── [ 16791] SimpleServiceTestApp1.apk ├── [ 16791] SimpleServiceTestApp2.apk ├── [ 16791] SimpleServiceTestApp3.apk ├── [ 1017540] SuspendTestApp.apk └── [ 36] test_module_config.manifest [ 4096] out/target/product/shiba/testcases/FrameworksServicesTests ├── [ 4096] arm64 │   └── [ 72346281] FrameworksServicesTests.apk ├── [ 20887] BstatsTestApp.apk ├── [ 4096] data │   └── [ 851] broken_shortcut.xml ├── [ 2866] FrameworksServicesTests.config ├── [ 12695] JobTestApp.apk ├── [ 8599] MediaButtonReceiverHolderTestHelperApp.apk ├── [ 16791] SimpleServiceTestApp1.apk ├── [ 16791] SimpleServiceTestApp2.apk ├── [ 16791] SimpleServiceTestApp3.apk └── [ 1017540] SuspendTestApp.apk Fixes: 314148134 Test: atest DerivedFrameworks1 DerivedFrameworks2 Test: m blueprint_tests Change-Id: Ib73a3404557e0bd583b065f0cf2fd55fba9ccdbe
Diffstat (limited to 'scripts/test_config_fixer.py')
-rw-r--r--scripts/test_config_fixer.py55
1 files changed, 54 insertions, 1 deletions
diff --git a/scripts/test_config_fixer.py b/scripts/test_config_fixer.py
index 07e01a14a..2876bcb63 100644
--- a/scripts/test_config_fixer.py
+++ b/scripts/test_config_fixer.py
@@ -19,6 +19,7 @@
from __future__ import print_function
import argparse
+import json
import sys
from xml.dom import minidom
@@ -31,6 +32,8 @@ from manifest import write_xml
KNOWN_PREPARERS = ['com.android.tradefed.targetprep.TestAppInstallSetup',
'com.android.tradefed.targetprep.suite.SuiteApkInstaller']
+KNOWN_TEST_RUNNERS = ['com.android.tradefed.testtype.AndroidJUnitTest']
+
MAINLINE_CONTROLLER = 'com.android.tradefed.testtype.suite.module.MainlineTestModuleController'
def parse_args():
@@ -43,8 +46,12 @@ def parse_args():
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('--orig-test-file-name', default='', dest='orig_test_file_name',
+ help=('Use with test-file-name to only override a single apk'))
parser.add_argument('--mainline-package-name', default='', dest='mainline_package_name',
help=('overwrite mainline module package name in the test config'))
+ parser.add_argument('--test-runner-options', default='', dest='test_runner_options',
+ help=('Add test runner options 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()
@@ -76,6 +83,18 @@ def overwrite_test_file_name(test_config_doc, test_file_name):
if option.getAttribute('name') == "test-file-name":
option.setAttribute('value', test_file_name)
+def overwrite_single_test_file_name(test_config_doc, orig_test_file_name, new_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') in KNOWN_PREPARERS:
+ options = get_children_with_tag(test, 'option')
+ for option in options:
+ if option.getAttribute('name') == "test-file-name" and option.getAttribute('value') == orig_test_file_name:
+ option.setAttribute('value', new_test_file_name)
+
def overwrite_mainline_module_package_name(test_config_doc, mainline_package_name):
test_config = parse_test_config(test_config_doc)
@@ -86,6 +105,31 @@ def overwrite_mainline_module_package_name(test_config_doc, mainline_package_nam
if option.getAttribute('name') == "mainline-module-package-name":
option.setAttribute('value', mainline_package_name)
+def add_test_runner_options_toplevel(test_config_doc, test_runner_options):
+
+ test_config = parse_test_config(test_config_doc)
+
+ test_config.appendChild(test_config_doc.createComment("Options from Android.bp"))
+ test_config.appendChild(test_config_doc.createTextNode("\n"))
+ for new_option in json.loads(test_runner_options):
+ option = test_config_doc.createElement("option")
+ # name and value are mandatory,
+ name = new_option.get('Name')
+ if not name:
+ raise RuntimeError('"name" must set in test_runner_option"')
+ value = new_option.get('Value')
+ if not value:
+ raise RuntimeError('"value" must set in test_runner_option"')
+ option.setAttribute('name', name) # 'include-filter')
+ option.setAttribute('value', value) # 'android.test.example.devcodelab.DevCodelabTest#testHelloFail')
+ key = new_option.get('Key')
+ if key:
+ option.setAttribute('key', key) # 'include-filter')
+ # add tab and newline for readability
+ test_config.appendChild(test_config_doc.createTextNode(" "))
+ test_config.appendChild(option)
+ test_config.appendChild(test_config_doc.createTextNode("\n"))
+
def main():
"""Program entry point."""
try:
@@ -100,11 +144,20 @@ def main():
overwrite_package_name(doc, manifest_doc, args.package_name)
if args.test_file_name:
- overwrite_test_file_name(doc, args.test_file_name)
+ if args.orig_test_file_name:
+ overwrite_single_test_file_name(doc, args.orig_test_file_name, args.test_file_name)
+ else:
+ # You probably never want to override the test_file_name if there
+ # are several in the xml, but this is currently only used on generated
+ # AndroidTest.xml where there is only a single test-file-name (no data)
+ overwrite_test_file_name(doc, args.test_file_name)
if args.mainline_package_name:
overwrite_mainline_module_package_name(doc, args.mainline_package_name)
+ if args.test_runner_options:
+ add_test_runner_options_toplevel(doc, args.test_runner_options)
+
with open(args.output, 'w') as f:
write_xml(f, doc)