Nikos Nikoleris has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/19250
Change subject: tests: Add base class for fixtures that generate a target
file
......................................................................
tests: Add base class for fixtures that generate a target file
The new TargetFixture can be used as a base class for fixtures that
generate/download a file. These fixtures are guarrantied to be unique
and their setup function is only executed once.
Change-Id: I6a8737b06c4e74f3e29736ec363f61251d85da8c
Signed-off-by: Nikos Nikoleris <[email protected]>
---
M tests/gem5/fixture.py
1 file changed, 52 insertions(+), 1 deletion(-)
diff --git a/tests/gem5/fixture.py b/tests/gem5/fixture.py
index 00f43ef..6964f03 100644
--- a/tests/gem5/fixture.py
+++ b/tests/gem5/fixture.py
@@ -1,3 +1,15 @@
+# Copyright (c) 2019 ARM Limited
+# All rights reserved
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder. You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
# Copyright (c) 2017 Mark D. Hill and David A. Wood
# All rights reserved.
#
@@ -29,6 +41,7 @@
import os
import tempfile
import shutil
+import threading
from testlib.fixture import Fixture, globalfixture
from testlib.config import config, constants
@@ -59,8 +72,46 @@
# Set path to none so it's not deleted
self.path = None
+class TargetFixture(Fixture):
+ '''
+ Base class for fixtures that generate a target in the
+ filesystem. If the same fixture is used by more than one
+ test/suite, rather than creating a copy of the fixture, it returns
+ the same object and makes sure that setup is only executed
+ once. Devired classses should override the _init and _setup
+ functions.
-class SConsFixture(Fixture):
+ :param target: The absolute path of the target in the filesystem.
+
+ '''
+ fixtures = {}
+
+ def __new__(cls, target):
+ if target in cls.fixtures:
+ obj = cls.fixtures[target]
+ else:
+ obj = super(Fixture, cls).__new__(cls)
+ obj.lock = threading.Lock()
+ obj.target = target
+ cls.fixtures[target] = obj
+ return obj
+
+ def __init__(self, *args, **kwargs):
+ with self.lock:
+ if hasattr(self, '_init_done'):
+ return
+ self._init_done = True
+ self._init(*args, **kwargs)
+
+ def setup(self, testitem):
+ with self.lock:
+ if hasattr(self, '_setup_done'):
+ return
+ self._setup_done = True
+ self._setup(testitem)
+
+
+class SConsFixture(TargetFixture):
'''
Fixture will wait until all SCons targets are collected and tests are
about to be ran, then will invocate a single instance of SCons for all
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/19250
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: I6a8737b06c4e74f3e29736ec363f61251d85da8c
Gerrit-Change-Number: 19250
Gerrit-PatchSet: 1
Gerrit-Owner: Nikos Nikoleris <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev