Gabe Black has submitted this change and it was merged. (
https://gem5-review.googlesource.com/10701 )
Change subject: tests: Make "UnitTest"s more like GTest so they can be in
other dirs.
......................................................................
tests: Make "UnitTest"s more like GTest so they can be in other dirs.
The original implementation of UnitTest forced all the output binaries
to live in the unittest directory, effectively forcing a flat
namespace, and seperating the tests from the things they were supposed
to be testing.
This changes makes them work more like the newer GTest tests in that
they can be based out of whatever directory makes sense, although
they're currently all still in unittest for the time being.
This change also gets rid of automatically tagging the sources
associated with a test with the tests name. The first reason for that
was that this also forced a flat namespace, since the tests names
didn't have any reference to the test's path. Second, this way of
pulling in additional files wasn't necessary any more, now that the
UnitTest sources could be source filters like they can be for GTests.
Change-Id: I3d96ed766ac5170842dbd6daee39f2873bcd6c75
Reviewed-on: https://gem5-review.googlesource.com/10701
Reviewed-by: Andreas Sandberg <[email protected]>
Maintainer: Gabe Black <[email protected]>
---
M src/SConscript
M src/unittest/SConscript
2 files changed, 15 insertions(+), 13 deletions(-)
Approvals:
Andreas Sandberg: Looks good to me, approved
Gabe Black: Looks good to me, approved
diff --git a/src/SConscript b/src/SConscript
index 339059d..b76e075 100755
--- a/src/SConscript
+++ b/src/SConscript
@@ -315,31 +315,31 @@
'''Create a UnitTest'''
all = []
- def __init__(self, target, *sources, **kwargs):
- '''Specify the target name and any sources. Sources that are
- not SourceFiles are evalued with Source(). All files are
- tagged with the name of the UnitTest target.'''
+ def __init__(self, target, *srcs_and_filts, **kwargs):
+ '''Specify the target name and any sources. Sources that are
+ not SourceFiles are evalued with Source().'''
+
+ isFilter = lambda arg: isinstance(arg, SourceFilter)
+ self.filters = filter(isFilter, srcs_and_filts)
+ sources = filter(lambda a: not isFilter(a), srcs_and_filts)
srcs = SourceList()
for src in sources:
if not isinstance(src, SourceFile):
- src = Source(src, tags=str(target))
+ src = Source(src, tags=[])
srcs.append(src)
self.sources = srcs
self.target = target
self.main = kwargs.get('main', False)
self.all.append(self)
+ self.dir = Dir('.')
class GTest(UnitTest):
'''Create a unit test based on the google test framework.'''
all = []
def __init__(self, *args, **kwargs):
- isFilter = lambda arg: isinstance(arg, SourceFilter)
- self.filters = filter(isFilter, args)
- args = filter(lambda a: not isFilter(a), args)
super(GTest, self).__init__(*args, **kwargs)
- self.dir = Dir('.')
self.skip_lib = kwargs.pop('skip_lib', False)
# Children should have access
@@ -1081,12 +1081,14 @@
main_objs = [ s.static(new_env) for s in Source.all.with_tag('main') ]
for test in UnitTest.all:
- test_sources = Source.all.with_tag(str(test.target))
+ test_sources = list(test.sources)
+ for f in test.filters:
+ test_sources += Source.all.apply_filter(f)
test_objs = [ s.static(new_env) for s in test_sources ]
if test.main:
test_objs += main_objs
- path = 'unittest/%s.%s' % (test.target, label)
- new_env.Program(path, test_objs + static_objs)
+ new_env.Program(test.dir.File('%s.%s' % (test.target, label)),
+ test_objs + static_objs)
gtest_env = new_env.Clone()
gtest_env.Append(LIBS=gtest_env['GTEST_LIBS'])
diff --git a/src/unittest/SConscript b/src/unittest/SConscript
index 394f151..752db1f 100644
--- a/src/unittest/SConscript
+++ b/src/unittest/SConscript
@@ -41,7 +41,7 @@
UnitTest('strnumtest', 'strnumtest.cc')
stattest_py = PySource('m5', 'stattestmain.py', tags='stattest')
-UnitTest('stattest', 'stattest.cc', stattest_py, main=True)
+UnitTest('stattest', 'stattest.cc', with_tag('stattest'), main=True)
UnitTest('symtest', 'symtest.cc')
UnitTest('tokentest', 'tokentest.cc')
--
To view, visit https://gem5-review.googlesource.com/10701
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: I3d96ed766ac5170842dbd6daee39f2873bcd6c75
Gerrit-Change-Number: 10701
Gerrit-PatchSet: 4
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev