diff options
author | Per Larsen <perlarsen@google.com> | 2024-02-16 05:12:05 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2024-02-16 05:12:05 +0000 |
commit | d04c5db440c7a3047d76300fc30eee47e4e99bba (patch) | |
tree | 1aece90d561c2735b1a95f32d7f1f3bdd7862248 | |
parent | 10638b2c3dde79749a49bfcea03ab7713819243e (diff) | |
parent | 708f6b129b3c0ecda820325e80fd62e40408b37a (diff) | |
download | aosp-d04c5db440c7a3047d76300fc30eee47e4e99bba.tar.gz |
scripts: minor fixes am: 708f6b129b
Original change: https://android-review.googlesource.com/c/trusty/vendor/google/aosp/+/2942565
Change-Id: I4a8e4022a28f5204b7b2f36960b6d06f333df6f6
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rwxr-xr-x | scripts/build.py | 59 | ||||
-rwxr-xr-x | scripts/trusty_build_config.py | 8 |
2 files changed, 40 insertions, 27 deletions
diff --git a/scripts/build.py b/scripts/build.py index f0988e5..0c1063a 100755 --- a/scripts/build.py +++ b/scripts/build.py @@ -497,7 +497,7 @@ def get_build_deps(project_name, project, project_names, already_built): def create_test_map(args, build_config, projects): for project_name in projects: test_map = {} - test_map["ports"] = [] + test_map["ports"] = [] # TODO: should probably be called port_tests port_names = set() duplicates = set() project = build_config.get_project(project_name) @@ -505,59 +505,72 @@ def create_test_map(args, build_config, projects): if not project or not project.tests: return - tests_list = filter(lambda t: t.name.startswith("android-port-test:android-test:"),project.tests) - for test in tests_list: - port_name = re.sub("android-port-test:android-test:", "", test.name) + project_type_prefix = "android-port-test:android-test:" + for test in project.tests: + if not test.name.startswith(project_type_prefix): + continue + port_name = test.name.replace(project_type_prefix, "") if port_name in port_names: duplicates.add(port_name) continue port_names.add(port_name) - test_obj = { "port_name": port_name, - "needs": []} + test_obj = { "port_name": port_name, "needs": [] } + # TODO: this is duplicated in three places, extract into inner fn if hasattr(test, 'need') and hasattr(test.need, 'flags'): test_obj["needs"] = list(test.need.flags) if hasattr(test, 'port_type'): test_obj["type"] = str(test.port_type) + # BUG: this branch is never taken because composite tests don't + # start with `project_type_prefix` so the loop continues + # without ever processing composite tests. This means that + # tests in the sequence are not present in the output JSON. if isinstance(test, trusty_build_config.TrustyCompositeTest): test_obj["sequence"] = [] for subtest in test.sequence: - test_obj["sequence"].append(re.sub(project_type_prefix, "", subtest.name)) - if hasattr(subtest, 'need') and hasattr(subtest.need, 'flags'): + # TODO: verify that project_type_prefix is defined correctly + # TODO: shouldn't this be called test_type_prefix? + # (android, boot, host are the test types...) + subtest_name = subtest.name.replace(project_type_prefix, "") + test_obj["sequence"].append(subtest_name) + if hasattr(subtest, 'need') and hasattr(subtest.need, + 'flags'): test_obj["needs"] += list(subtest.need.flags) test_obj["needs"] = list(set(test_obj["needs"])) test_map["ports"].append(test_obj) - if len(duplicates) > 0: - print("ERROR: The following ports have been included multipe times") + if duplicates: + print("ERROR: The following port tests are included multiple times") for port in duplicates: print(port) sys.exit(-1) test_map["commands"] = [] - commands_list = filter(lambda t: t.name.startswith("android-test:"), project.tests) - for command in commands_list: - command_name = re.sub("android-test:", "", command.name) - command_obj = { "command_name": command_name, - "needs": []} - - if hasattr(command, 'need') and hasattr(command.need, 'flags'): - command_obj["needs"] = list(command.need.flags) - if hasattr(command, 'port_type'): - command_obj["type"] = str(command.port_type) - command_obj["command"] = command.command + for test in project.tests: + if not test.name.startswith("android-test:"): + continue + command_name = test.name.replace("android-test:", "") + command_obj = { "command_name": command_name, "needs": [] } + + if hasattr(test, 'need') and hasattr(test.need, 'flags'): + command_obj["needs"] = list(test.need.flags) + if hasattr(test, 'port_type'): + command_obj["type"] = str(test.port_type) + command_obj["command"] = test.command test_map["commands"].append(command_obj) - project_buildroot = os.path.join(args.build_root, "build-" + project_name) + project_buildroot = os.path.join(args.build_root, + "build-" + project_name) zip_path = os.path.join(project_buildroot, "trusty_test_package.zip") with ZipFile(zip_path, 'a', compression=ZIP_DEFLATED) as zipf: - zipf.writestr(project_name + "-test-map.json", json.dumps(test_map, indent=4)) + zipf.writestr(project_name + "-test-map.json", + json.dumps(test_map, indent=4)) def main(default_config=None, emulator=True): top = os.path.abspath(os.path.join(script_dir, "../../../../..")) diff --git a/scripts/trusty_build_config.py b/scripts/trusty_build_config.py index 0270dcf..a1a6ccd 100755 --- a/scripts/trusty_build_config.py +++ b/scripts/trusty_build_config.py @@ -114,8 +114,9 @@ class TrustyHostTest(TrustyTest): class TrustyAndroidTest(TrustyTest): """Stores a test name and command to run inside Android""" - def __init__(self, name, command, need = None, port_type = PortType.TEST, enabled=True, nameprefix="", runargs=(), - timeout=None): + def __init__(self, name, command, need=TrustyPortTestFlags(), + port_type=PortType.TEST, enabled=True, nameprefix="", + runargs=(), timeout=None): nameprefix = nameprefix + "android-test:" cmd = ["run", "--headless", "--shell-command", command] if timeout: @@ -125,13 +126,12 @@ class TrustyAndroidTest(TrustyTest): super().__init__(nameprefix + name, cmd, enabled, port_type) self.shell_command = command self.need = need - if not self.need: - self.need = TrustyPortTestFlags() def needs(self, **need): self.need.set(**need) return self + class TrustyPortTest(TrustyTest): """Stores a trusty port name for a test to run.""" |