Nikos Nikoleris has submitted this change. (
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]>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/19250
Reviewed-by: Giacomo Travaglini <[email protected]>
Reviewed-by: Jason Lowe-Power <[email protected]>
Maintainer: Jason Lowe-Power <[email protected]>
Tested-by: kokoro <[email protected]>
---
M tests/gem5/fixture.py
1 file changed, 52 insertions(+), 0 deletions(-)
Approvals:
Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved
Giacomo Travaglini: Looks good to me, approved
kokoro: Regressions pass
diff --git a/tests/gem5/fixture.py b/tests/gem5/fixture.py
index 00f43ef..b04a334 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,6 +72,45 @@
# Set path to none so it's not deleted
self.path = None
+class UniqueFixture(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.
+
+ :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(UniqueFixture, 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
+ super(UniqueFixture, self).__init__(self, **kwargs)
+ self._init(*args, **kwargs)
+ self._init_done = True
+
+ def setup(self, testitem):
+ with self.lock:
+ if hasattr(self, '_setup_done'):
+ return
+ self._setup_done = True
+ self._setup(testitem)
+
class SConsFixture(Fixture):
'''
--
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: 9
Gerrit-Owner: Nikos Nikoleris <[email protected]>
Gerrit-Assignee: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Ciro Santilli <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Nikos Nikoleris <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev