Nikos Nikoleris has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/19251
Change subject: tests: Refactor the Gem5Fixture to derive from TargetFixture
......................................................................
tests: Refactor the Gem5Fixture to derive from TargetFixture
Change-Id: Ie868a7e18ef6c3271f3c8a658229657cd43997cb
---
M ext/testlib/fixture.py
M ext/testlib/main.py
M tests/gem5/fixture.py
3 files changed, 19 insertions(+), 96 deletions(-)
diff --git a/ext/testlib/fixture.py b/ext/testlib/fixture.py
index be89244..9331c78 100644
--- a/ext/testlib/fixture.py
+++ b/ext/testlib/fixture.py
@@ -75,17 +75,6 @@
def skip(self, testitem):
raise SkipException(self.name, testitem.metadata)
- def schedule_finalized(self, schedule):
- '''
- This method is called once the schedule of for tests is known.
- To enable tests to use the same fixture defintion for each
execution
- fixtures must return a copy of themselves in this method.
-
- :returns: a copy of this fixture which will be setup/torndown
- when the test item this object is tied to is about to execute.
- '''
- return self.copy()
-
def init(self, *args, **kwargs):
pass
@@ -95,9 +84,6 @@
def teardown(self, testitem):
pass
- def copy(self):
- return copy.deepcopy(self)
-
def skip_cleanup(self):
'''
If this method is called, then we should make sure that nothing is
diff --git a/ext/testlib/main.py b/ext/testlib/main.py
index ac79547..cbba000 100644
--- a/ext/testlib/main.py
+++ b/ext/testlib/main.py
@@ -254,20 +254,6 @@
log_handler.schedule_finalized(test_schedule)
- # Iterate through all fixtures notifying them of the test schedule.
- for suite in test_schedule:
- copied_fixtures = []
- for fixture in suite.fixtures:
-
copied_fixtures.append(fixture.schedule_finalized(test_schedule))
- suite.fixtures = copied_fixtures
-
- for test in suite:
- copied_fixtures = []
- for fixture in test.fixtures:
- copied_fixtures.append(fixture.schedule_finalized(
- test_schedule))
- test.fixtures = copied_fixtures
-
log.test_log.message(terminal.separator())
log.test_log.message('Running Tests from {} suites'
.format(len(test_schedule.suites)), bold=True)
diff --git a/tests/gem5/fixture.py b/tests/gem5/fixture.py
index 6964f03..43b1a79 100644
--- a/tests/gem5/fixture.py
+++ b/tests/gem5/fixture.py
@@ -120,21 +120,14 @@
:param directory: The directory which scons will -C (cd) into before
executing. If None is provided, will choose the config base_dir.
'''
- def __init__(self, directory=None, target_class=None, options=[]):
- self.directory = directory if directory else config.base_dir
- self.target_class = target_class if target_class else SConsTarget
- self.threads = config.threads
- self.targets = set()
- self.options = options
- super(SConsFixture, self).__init__()
- def setup(self, testitem):
+ def _setup(self, testitem):
if config.skip_build:
return
command = [
'scons', '-C', self.directory,
- '-j', str(self.threads),
+ '-j', str(config.threads),
'--ignore-style'
]
@@ -158,70 +151,28 @@
command.extend(self.options)
log_call(log.test_log, command)
+class Gem5Fixture(SConsFixture):
+ fixtures = {}
-class SConsTarget(Fixture):
- # The singleton scons fixture we'll use for all targets.
- default_scons_invocation = None
-
- def __init__(self, target, build_dir=None, invocation=None):
- '''
- Represents a target to be built by an 'invocation' of scons.
-
- :param target: The target known to scons.
-
- :param build_dir: The 'build' directory path which will be
prepended
- to the target name.
-
- :param invocation: Represents an invocation of scons which we will
- automatically attach this target to. If None provided, uses the
- main 'scons' invocation.
- '''
-
- if build_dir is None:
- build_dir = config.build_dir
- self.target = os.path.join(build_dir, target)
- super(SConsTarget, self).__init__(name=target)
-
- if invocation is None:
- if self.default_scons_invocation is None:
- SConsTarget.default_scons_invocation = SConsFixture()
- globalfixture(SConsTarget.default_scons_invocation)
-
- invocation = self.default_scons_invocation
- self.invocation = invocation
-
- def schedule_finalized(self, schedule):
- self.invocation.targets.add(self.target)
- return Fixture.schedule_finalized(self, schedule)
-
-class Gem5Fixture(SConsTarget):
- other_invocations = {} # stores scons invocations other than the
default
-
- def __init__(self, isa, variant, protocol=None):
+ def __new__(cls, isa, variant, protocol=None):
+ target_dir = joinpath(config.build_dir, isa.upper())
if protocol:
- # When specifying an non-default protocol, we have to make a
- # separate scons invocation with specific parameters. However,
if
- # more than one tests needs the same target, we need to make
sure
- # that we don't call scons too many times.
- target_dir = isa.upper()+'-'+protocol
- target = joinpath(target_dir, 'gem5.%s' % variant)
- if target_dir in self.other_invocations.keys():
- invocation = self.other_invocations[target_dir]
- else:
- options = ['PROTOCOL='+protocol, '--default='+isa.upper()]
- invocation = SConsFixture(options=options)
- globalfixture(invocation)
- Gem5Fixture.other_invocations[target_dir] = invocation
- else:
- target = joinpath(isa.upper(), 'gem5.%s' % variant)
- invocation = None # use default
- super(Gem5Fixture, self).__init__(target, invocation=invocation)
+ target_dir += '_' + protocol
+ target = joinpath(target_dir, 'gem5.%s' % variant)
+ obj = super(Gem5Fixture, cls).__new__(cls, target)
+ return obj
+ def _init(self, isa, variant, protocol=None):
self.name = constants.gem5_binary_fixture_name
- self.path = self.target
- self.isa = isa
- self.variant = variant
+ self.targets = [self.target]
+ self.path = self.target
+ self.directory = config.base_dir
+
+ self.options = []
+ if protocol:
+ self.options = [ '--default=' + isa.upper(),
+ 'PROTOCOL=' + protocol ]
class MakeFixture(Fixture):
def __init__(self, directory, *args, **kwargs):
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/19251
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: Ie868a7e18ef6c3271f3c8a658229657cd43997cb
Gerrit-Change-Number: 19251
Gerrit-PatchSet: 1
Gerrit-Owner: Nikos Nikoleris <nikos.nikole...@arm.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev