From 0337613afcf9803eaa977d787c6d5c03f743db4d Mon Sep 17 00:00:00 2001 From: "Bobby R. Bruce" Date: Mon, 4 Sep 2023 23:34:39 -0700 Subject: [PATCH] ext,tests: Add `--build-targets` option to `./main.py list` This allows for build target information (i.e., the gem5 binary to be built for the tests) to be returned. Change-Id: I6638b54cbb1822555f58e74938d36043c11108ba --- ext/testlib/configuration.py | 13 +++++++++---- ext/testlib/fixture.py | 14 ++++++++++++++ ext/testlib/main.py | 13 +++++++++---- ext/testlib/query.py | 14 +++++++++++++- tests/gem5/fixture.py | 12 ++++++++++++ 5 files changed, 57 insertions(+), 9 deletions(-) diff --git a/ext/testlib/configuration.py b/ext/testlib/configuration.py index 918a3f92b3..07f636b03b 100644 --- a/ext/testlib/configuration.py +++ b/ext/testlib/configuration.py @@ -744,6 +744,12 @@ class ListParser(ArgParser): default=False, help="List all tags.", ).add_to(parser) + Argument( + "--build-targets", + action="store_true", + default=False, + help="List all the gem5 build targets.", + ).add_to(parser) Argument( "-q", dest="quiet", @@ -752,12 +758,11 @@ class ListParser(ArgParser): help="Quiet output (machine readable).", ).add_to(parser) Argument( - '--uid', - action='store', + "--uid", + action="store", default=None, - help='UID of a specific test item to list.' + help="UID of a specific test item to list.", ).add_to(parser) - common_args.directories.add_to(parser) common_args.bin_path.add_to(parser) diff --git a/ext/testlib/fixture.py b/ext/testlib/fixture.py index 0138f018bb..aa735cc1c5 100644 --- a/ext/testlib/fixture.py +++ b/ext/testlib/fixture.py @@ -29,6 +29,8 @@ import testlib.helper as helper from testlib.configuration import constants +from typing import Optional + class SkipException(Exception): def __init__(self, fixture, testitem): @@ -80,6 +82,18 @@ class Fixture(object): def teardown(self, testitem): pass + def get_get_build_info(self) -> Optional[dict]: + # If this is a gem5 build it will return the target gem5 build path + # and any additional build information. E.g.: + # + # /path/to/gem5/build/NULL/gem5.opt--default=NULL PROTOCOL=MI_example + # + # In this example this may be passed to scons to build gem5 in + # accordance to the test's build requirements. + # + # If this fixtures is not a build of gem5, None is returned. + return None + def __str__(self): return f"{self.name} fixture" diff --git a/ext/testlib/main.py b/ext/testlib/main.py index e9dd892947..f8d04cec56 100644 --- a/ext/testlib/main.py +++ b/ext/testlib/main.py @@ -245,10 +245,12 @@ def do_list(): if configuration.config.uid: uid_ = uid.UID.from_uid(configuration.config.uid) if isinstance(uid_, uid.TestUID): - log.test_log.error('Unable to list a standalone test.\n' - 'Gem5 expects test suites to be the smallest unit ' - ' of test.\n\n' - 'Pass a SuiteUID instead.') + log.test_log.error( + "Unable to list a standalone test.\n" + "Gem5 expects test suites to be the smallest unit " + " of test.\n\n" + "Pass a SuiteUID instead." + ) return test_schedule = loader_mod.Loader().load_schedule_for_suites(uid_) if get_config_tags(): @@ -273,10 +275,13 @@ def do_list(): qrunner.list_tags() elif configuration.config.fixtures: qrunner.list_fixtures() + elif configuration.config.build_targets: + qrunner.list_build_targets() else: qrunner.list_suites() qrunner.list_tests() qrunner.list_tags() + qrunner.list_build_targets() return 0 diff --git a/ext/testlib/query.py b/ext/testlib/query.py index 74541002cd..be1c5a6792 100644 --- a/ext/testlib/query.py +++ b/ext/testlib/query.py @@ -57,11 +57,23 @@ class QueryRunner(object): def list_fixtures(self): log.test_log.message(terminal.separator()) - log.test_log.message('Listing all Test Fixtures.', bold=True) + log.test_log.message("Listing all Test Fixtures.", bold=True) log.test_log.message(terminal.separator()) for fixture in self.schedule.all_fixtures(): log.test_log.message(fixture, machine_readable=True) + def list_build_targets(self): + log.test_log.message(terminal.separator()) + log.test_log.message("Listing all gem5 Build Targets.", bold=True) + log.test_log.message(terminal.separator()) + builds = [] + for fixture in self.schedule.all_fixtures(): + build = fixture.get_get_build_info() + if build and build not in builds: + builds.append(build) + for build in builds: + log.test_log.message(build, machine_readable=True) + def list_suites(self): log.test_log.message(terminal.separator()) log.test_log.message("Listing all Test Suites.", bold=True) diff --git a/tests/gem5/fixture.py b/tests/gem5/fixture.py index d3312c9a63..0f53539b40 100644 --- a/tests/gem5/fixture.py +++ b/tests/gem5/fixture.py @@ -53,6 +53,8 @@ from testlib.helper import log_call, cacheresult, joinpath, absdirpath import testlib.log as log from testlib.state import Result +from typing import Optional, List + class VariableFixture(Fixture): def __init__(self, value=None, name=None): @@ -147,6 +149,10 @@ class SConsFixture(UniqueFixture): obj = super(SConsFixture, cls).__new__(cls, target) return obj + def _setup(self, testitem): + if config.skip_build: + return + def _setup(self, testitem): if config.skip_build: return @@ -204,6 +210,12 @@ class Gem5Fixture(SConsFixture): self.options = ["--default=" + isa.upper(), "PROTOCOL=" + protocol] self.set_global() + def get_get_build_info(self) -> Optional[str]: + build_target = self.target + if self.options: + build_target += " ".join(self.options) + return build_target + class MakeFixture(Fixture): def __init__(self, directory, *args, **kwargs):