Skip to content
Snippets Groups Projects
Commit 4cfec0e6 authored by Giovanni La Mura's avatar Giovanni La Mura
Browse files

Enable mismatch-only logging and report summary

parent 36c854d4
No related branches found
No related tags found
No related merge requests found
#!/bin/python #!/bin/python
## @package pycompare ## @file pycompare
# Script to perform output consistency tests # Script to perform output consistency tests
# #
# Comparing the numeric output can be rendered hard by the amount of information # Comparing the numeric output can be rendered hard by the amount of information
...@@ -41,6 +41,7 @@ def main(): ...@@ -41,6 +41,7 @@ def main():
print("ERROR COUNT: %d"%errors) print("ERROR COUNT: %d"%errors)
print("WARNING COUNT: %d"%warnings) print("WARNING COUNT: %d"%warnings)
print("NOISE COUNT: %d"%noisy) print("NOISE COUNT: %d"%noisy)
if (config['log_html']): reformat_log(config, errors, warnings, noisy)
if (errors > 0): if (errors > 0):
print("FAILURE: {0:s} is not consistent with {1:s}".format( print("FAILURE: {0:s} is not consistent with {1:s}".format(
config['c_file_name'], config['fortran_file_name'] config['c_file_name'], config['fortran_file_name']
...@@ -114,9 +115,10 @@ def compare_lines(f_line, c_line, config, line_num=0, num_len=1, log_file=None): ...@@ -114,9 +115,10 @@ def compare_lines(f_line, c_line, config, line_num=0, num_len=1, log_file=None):
f_line = f_line.replace("D-","E-").replace("D+","E+") f_line = f_line.replace("D-","E-").replace("D+","E+")
if (f_line == c_line): if (f_line == c_line):
if log_file is not None: if log_file is not None:
num_format = " <div><pre><code>{0:0%dd}"%num_len if (config['full_log']):
log_line = (num_format + ": {1:s}</code></pre></div>\n").format(line_num, c_line[:-1]) num_format = " <div><pre><code>{0:0%dd}"%num_len
log_file.write(log_line) log_line = (num_format + ": {1:s}</code></pre></div>\n").format(line_num, c_line[:-1])
log_file.write(log_line)
else: else:
iter_f_values = number_reg.finditer(f_line) iter_f_values = number_reg.finditer(f_line)
iter_c_values = number_reg.finditer(c_line) iter_c_values = number_reg.finditer(c_line)
...@@ -165,7 +167,7 @@ def compare_lines(f_line, c_line, config, line_num=0, num_len=1, log_file=None): ...@@ -165,7 +167,7 @@ def compare_lines(f_line, c_line, config, line_num=0, num_len=1, log_file=None):
elif (severities[-1] == 2): warnings += 1 elif (severities[-1] == 2): warnings += 1
elif (severities[-1] == 3): errors += 1 elif (severities[-1] == 3): errors += 1
if log_file is not None: if log_file is not None:
if (len(severities) > 1): if (len(severities) > 0):
if (severities[-1] == 0): if (severities[-1] == 0):
log_line = ( log_line = (
log_line + c_groups[-1] + c_line[c_ends[-1]:len(c_line) - 2] log_line + c_groups[-1] + c_line[c_ends[-1]:len(c_line) - 2]
...@@ -189,6 +191,8 @@ def compare_lines(f_line, c_line, config, line_num=0, num_len=1, log_file=None): ...@@ -189,6 +191,8 @@ def compare_lines(f_line, c_line, config, line_num=0, num_len=1, log_file=None):
#END INDENT #END INDENT
else: else:
if (log_file is not None): if (log_file is not None):
num_format = " <div><pre><code>{0:0%dd}"%num_len
log_line = (num_format + ": ").format(line_num)
log_line = ( log_line = (
log_line + "</code><span style=\"font-weight: bold; color: rgb(255,0,0)\"><code>" log_line + "</code><span style=\"font-weight: bold; color: rgb(255,0,0)\"><code>"
+ c_line + "</code></span><code>" + c_line + "</code></span><code>"
...@@ -246,6 +250,7 @@ def parse_arguments(): ...@@ -246,6 +250,7 @@ def parse_arguments():
config = { config = {
'fortran_file_name': '', 'fortran_file_name': '',
'c_file_name': '', 'c_file_name': '',
'full_log': False,
'log_html': False, 'log_html': False,
'html_output': 'pycompare.html', 'html_output': 'pycompare.html',
'warning_threshold': 0.005, 'warning_threshold': 0.005,
...@@ -258,10 +263,12 @@ def parse_arguments(): ...@@ -258,10 +263,12 @@ def parse_arguments():
config['fortran_file_name'] = split_arg[1] config['fortran_file_name'] = split_arg[1]
elif (arg.startswith("--cfile")): elif (arg.startswith("--cfile")):
config['c_file_name'] = split_arg[1] config['c_file_name'] = split_arg[1]
elif (arg.startswith("--full")):
config['full_log'] = True
elif (arg.startswith("--html")): elif (arg.startswith("--html")):
config['log_html'] = True config['log_html'] = True
elif (arg.startswith("--logname")): if (len(split_arg) == 2):
config['html_output'] = split_arg[1] config['html_output'] = split_arg[1]
elif (arg.startswith("--warn")): elif (arg.startswith("--warn")):
config['warning_threshold'] = float(split_arg[1]) config['warning_threshold'] = float(split_arg[1])
elif (arg.startswith("--help")): elif (arg.startswith("--help")):
...@@ -282,14 +289,30 @@ def print_help(): ...@@ -282,14 +289,30 @@ def print_help():
print("Usage: \"./pycompare.py OPTIONS\" ") print("Usage: \"./pycompare.py OPTIONS\" ")
print(" ") print(" ")
print("Valid options are: ") print("Valid options are: ")
print("--ffile=FORTRAN_OUTPUT File containing the output of the FORTRAN code (mandatory).") print("--ffile=FORTRAN_OUTPUT File containing the output of the FORTRAN code (mandatory).")
print("--cfile=C++_OUTPUT File containing the output of the C++ code (mandatory).") print("--cfile=C++_OUTPUT File containing the output of the C++ code (mandatory).")
print("--help Print this help and exit.") print("--full Print all lines to log file (default prints only mismatches).")
print("--html Enable logging to HTML file.") print("--help Print this help and exit.")
print("--logname Name of the HTML log file (default is \"pycompare.html\").") print("--html[=OPT_OUTPUT_NAME] Enable logging to HTML file (default logs to \"pycompare.html\").")
print("--quick Stop on first mismatch (default is to perform a full check).") print("--quick Stop on first mismatch (default is to perform a full check).")
print("--warn Set a fractional threshold for numeric warning (default=0.005).") print("--warn Set a fractional threshold for numeric warning (default=0.005).")
print(" ") print(" ")
def reformat_log(config, errors, warnings, noisy):
log_file = open(config['html_output'], 'r')
log_lines = log_file.readlines()
log_file.close()
log_file = open(config['html_output'], 'w')
for i in range(7): log_file.write(log_lines[i] + "\n")
str_errors = "error" if errors == 1 else "errors"
str_warnings = "warning" if warnings == 1 else "warnings"
str_noisy = "noisy value" if noisy == 1 else "noisy values"
summary = " <div>Comparison yielded %d %s"%(errors, str_errors)
summary = summary + ", %d %s"%(warnings, str_warnings)
summary = summary + " and %d %s.</div>\n"%(noisy, str_noisy)
log_file.write(summary)
for i in range(7, len(log_lines)): log_file.write(log_lines[i] + "\n")
log_file.close()
# ### PROGRAM EXECUTION ### # ### PROGRAM EXECUTION ###
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment