summaryrefslogtreecommitdiff
path: root/testsuite/driver/testlib.py
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/driver/testlib.py')
-rw-r--r--testsuite/driver/testlib.py59
1 files changed, 57 insertions, 2 deletions
diff --git a/testsuite/driver/testlib.py b/testsuite/driver/testlib.py
index 3fefb5274d..95274f30e5 100644
--- a/testsuite/driver/testlib.py
+++ b/testsuite/driver/testlib.py
@@ -1131,9 +1131,9 @@ def do_compile(name, way, should_fail, top_mod, extra_mods, extra_hc_opts, **kwa
# no problems found, this test passed
return passed()
-def compile_cmp_asm( name, way, extra_hc_opts ):
+def compile_cmp_asm( name, way, ext, extra_hc_opts ):
print('Compile only, extra args = ', extra_hc_opts)
- result = simple_build(name + '.cmm', way, '-keep-s-files -O ' + extra_hc_opts, 0, '', 0, 0)
+ result = simple_build(name + '.' + ext, way, '-keep-s-files -O ' + extra_hc_opts, 0, '', 0, 0)
if badResult(result):
return result
@@ -1153,6 +1153,24 @@ def compile_cmp_asm( name, way, extra_hc_opts ):
# no problems found, this test passed
return passed()
+def compile_grep_asm( name, way, ext, is_substring, extra_hc_opts ):
+ print('Compile only, extra args = ', extra_hc_opts)
+ result = simple_build(name + '.' + ext, way, '-keep-s-files -O ' + extra_hc_opts, 0, '', 0, 0)
+
+ if badResult(result):
+ return result
+
+ expected_pat_file = find_expected_file(name, 'asm')
+ actual_asm_file = add_suffix(name, 's')
+
+ if not grep_output(join_normalisers(normalise_errmsg),
+ expected_pat_file, actual_asm_file,
+ is_substring):
+ return failBecause('asm mismatch')
+
+ # no problems found, this test passed
+ return passed()
+
# -----------------------------------------------------------------------------
# Compile-and-run tests
@@ -1735,6 +1753,43 @@ def compare_outputs(way, kind, normaliser, expected_file, actual_file, diff_file
else:
return False
+# Checks that each line from pattern_file is present in actual_file as
+# a substring or regex pattern depending on is_substring.
+def grep_output(normaliser, pattern_file, actual_file, is_substring=True):
+ expected_path = in_srcdir(pattern_file)
+ actual_path = in_testdir(actual_file)
+
+ expected_patterns = read_no_crs(expected_path).strip().split('\n')
+ actual_raw = read_no_crs(actual_path)
+ actual_str = normaliser(actual_raw)
+
+ success = True
+ failed_patterns = []
+
+ def regex_match(pat, actual):
+ return re.search(pat, actual) is not None
+
+ def substring_match(pat, actual):
+ return pat in actual
+
+ def is_match(pat, actual):
+ if is_substring:
+ return substring_match(pat, actual)
+ else:
+ return regex_match(pat, actual)
+
+ for pat in expected_patterns:
+ if not is_match(pat, actual_str):
+ success = False
+ failed_patterns.append(pat)
+
+ if not success:
+ print('Actual output does not contain the following patterns:')
+ for pat in failed_patterns:
+ print(pat)
+
+ return success
+
# Note [Output comparison]
#
# We do two types of output comparison: