Giacomo Travaglini has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/44445 )
Change subject: tests: Define a MatchFileRegex verifier
......................................................................
tests: Define a MatchFileRegex verifier
Using it as a base class for MatchRegex.
While the latter is using a regex to scan the stdout and stderr files,
MatchFileRegex is more generically allowing you to specify which file to
scan at __init__ time.
Signed-off-by: Giacomo Travaglini <giacomo.travagl...@arm.com>
Change-Id: I2a64dab9c88a632b0a6b400ba02aafe473b3e62d
---
M tests/gem5/verifier.py
1 file changed, 43 insertions(+), 18 deletions(-)
diff --git a/tests/gem5/verifier.py b/tests/gem5/verifier.py
index 60d44f3..b539a67 100644
--- a/tests/gem5/verifier.py
+++ b/tests/gem5/verifier.py
@@ -1,3 +1,15 @@
+# Copyright (c) 2021 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.
#
@@ -161,34 +173,47 @@
re.compile(r'''^\s*"(cwd|input|codefile)":'''),
)
-class MatchRegex(Verifier):
- def __init__(self, regex, match_stderr=True, match_stdout=True):
- super(MatchRegex, self).__init__()
+class MatchFileRegex(Verifier):
+ """
+ Looking for a match between a regex pattern and the content of a list
+ of files. Verifier will pass as long as the pattern is found in at
least
+ one of the files.
+ """
+ def __init__(self, regex, filenames):
+ super(MatchFileRegex, self).__init__()
self.regex = _iterable_regex(regex)
- self.match_stderr = match_stderr
- self.match_stdout = match_stdout
+ self.filenames = filenames
+
+ def parse_file(self, fname):
+ with open(fname, 'r') as file_:
+ for line in file_:
+ for regex in self.regex:
+ if re.match(regex, line):
+ return True
def test(self, params):
fixtures = params.fixtures
# Get the file from the tempdir of the test.
tempdir = fixtures[constants.tempdir_fixture_name].path
- def parse_file(fname):
- with open(fname, 'r') as file_:
- for line in file_:
- for regex in self.regex:
- if re.match(regex, line):
- return True
- if self.match_stdout:
- if parse_file(joinpath(tempdir,
- constants.gem5_simulation_stdout)):
+ for fname in self.filenames:
+ if self.parse_file(joinpath(tempdir, fname)):
return # Success
- if self.match_stderr:
- if parse_file(joinpath(tempdir,
- constants.gem5_simulation_stderr)):
- return # Success
+
test_util.fail('Could not match regex.')
+class MatchRegex(MatchFileRegex):
+ """
+ Looking for a match between a regex pattern and stdout/stderr.
+ """
+ def __init__(self, regex, match_stderr=True, match_stdout=True):
+ filenames = list()
+ if match_stdout:
+ filenames.append(constants.gem5_simulation_stdout)
+ if match_stderr:
+ filenames.append(constants.gem5_simulation_stderr)
+ super(MatchRegex, self).__init__(regex, filenames)
+
_re_type = type(re.compile(''))
def _iterable_regex(regex):
if isinstance(regex, _re_type) or isinstance(regex, str):
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/44445
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I2a64dab9c88a632b0a6b400ba02aafe473b3e62d
Gerrit-Change-Number: 44445
Gerrit-PatchSet: 1
Gerrit-Owner: Giacomo Travaglini <giacomo.travagl...@arm.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s