tests: Add protocol as an option to SconsFixture
authorJason Lowe-Power <jason@lowepower.com>
Fri, 5 Apr 2019 02:02:16 +0000 (19:02 -0700)
committerJason Lowe-Power <jason@lowepower.com>
Fri, 12 Apr 2019 15:31:55 +0000 (15:31 +0000)
Change-Id: I16e9a6169e7ad50601e460e221d6a05db1208783
Signed-off-by: Jason Lowe-Power <jason@lowepower.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/17872
Reviewed-by: Anthony Gutierrez <anthony.gutierrez@amd.com>
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
tests/gem5/fixture.py
tests/gem5/suite.py

index 97aab46f50070eb6d6a90ab6f6edc4878314f183..00f43ef6af79af77f199b22482da74ae16326c8e 100644 (file)
@@ -69,11 +69,12 @@ class SConsFixture(Fixture):
     :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):
+    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):
@@ -101,9 +102,9 @@ class SConsFixture(Fixture):
                     "You may want to run with only a single ISA"
                     "(--isa=), use --skip-build, or use 'rerun'.")
 
-
-
         command.extend(self.targets)
+        if self.options:
+            command.extend(self.options)
         log_call(log.test_log, command)
 
 
@@ -143,9 +144,27 @@ class SConsTarget(Fixture):
         return Fixture.schedule_finalized(self, schedule)
 
 class Gem5Fixture(SConsTarget):
-    def __init__(self, isa, variant):
-        target = joinpath(isa.upper(), 'gem5.%s' % variant)
-        super(Gem5Fixture, self).__init__(target)
+    other_invocations = {} # stores scons invocations other than the default
+
+    def __init__(self, isa, variant, protocol=None):
+        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)
 
         self.name = constants.gem5_binary_fixture_name
         self.path = self.target
index 47cf421e16b83df92b8b3a3cb5873f5baccfb420..2db1668cd0dff52c61e62b11f88057b3dc46eb3b 100644 (file)
@@ -45,7 +45,8 @@ def gem5_verify_config(name,
                        fixtures=[],
                        valid_isas=constants.supported_isas,
                        valid_variants=constants.supported_variants,
-                       length=constants.supported_lengths[0]):
+                       length=constants.supported_lengths[0],
+                       protocol=None):
     '''
     Helper class to generate common gem5 tests using verifiers.
 
@@ -86,6 +87,8 @@ def gem5_verify_config(name,
                     given_name=name,
                     isa=isa,
                     opt=opt)
+            if protocol:
+                _name += '-'+protocol
 
             # Create the running of gem5 subtest.
             # NOTE: We specifically create this test before our verifiers so
@@ -107,7 +110,7 @@ def gem5_verify_config(name,
             # Create the gem5 target for the specific architecture and
             # variant.
             _fixtures = copy.copy(fixtures)
-            _fixtures.append(Gem5Fixture(isa, opt))
+            _fixtures.append(Gem5Fixture(isa, opt, protocol))
             _fixtures.append(tempdir)
             _fixtures.append(gem5_returncode)