Skip to content

Commit ee99e72

Browse files
committed
pkgtest: print the contents of the output files when the comparison fails
1 parent 8985530 commit ee99e72

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

com.oracle.truffle.r.test.packages/pkgtest/__init__.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,24 @@ def _gnur_install_test(forwarded_args, pkgs, gnur_libinstall, gnur_install_tmp):
592592
log_step('END', 'install/test', 'GnuR')
593593

594594

595+
def get_contents(files):
596+
def robust_readlines(file):
597+
try:
598+
with open(file) as f:
599+
return f.readlines()
600+
except:
601+
return ["Could not read the contents of " + file]
602+
603+
# normalize to a list
604+
list = [files] if isinstance(files, str) else files
605+
# print contents of all the files
606+
'\n'.join([format_contents(x, robust_readlines(x)) for x in list])
607+
608+
609+
def format_contents(filename, contents):
610+
return '\n' + filename + "\n########\n{0}########".format('\n'.join(contents))
611+
612+
595613
def _set_test_status(fastr_test_info):
596614
def _failed_outputs(outputs):
597615
'''
@@ -619,13 +637,14 @@ def _failed_outputs(outputs):
619637
# What this likely means is that some native package is not
620638
# installed on the system so GNUR can't run the tests.
621639
# Ideally this never happens.
622-
logging.info("{0}: GnuR test had .fail outputs: {1}".format(pkg, str([s + '.fail' for s in gnur_failed_outputs])))
640+
failed_outputs = [s + '.fail' for s in gnur_failed_outputs]
641+
logging.info("{0}: GnuR test had .fail outputs: {1}\n{2}".format(pkg, str(failed_outputs), get_contents(failed_outputs)))
623642

624643
fastr_failed_outputs = _failed_outputs(fastr_outputs)
625644
if fastr_failed_outputs:
626645
# In addition to the similar comment for GNU R, this can happen
627646
# if, say, the JVM crashes (possible with native code packages)
628-
logging.info("{0}: FastR test had .fail outputs: {1}".format(pkg, str(fastr_failed_outputs)))
647+
logging.info("{0}: FastR test had .fail outputs: {1}\n{2}".format(pkg, str(fastr_failed_outputs), get_contents(fastr_failed_outputs)))
629648
fastr_test_status.set_status_code("FAILED")
630649

631650
# Now for each successful GNU R output we compare content (assuming FastR didn't fail)
@@ -665,6 +684,7 @@ def _failed_outputs(outputs):
665684

666685
# first, parse file and see if a known test framework has been used
667686
detected, ok, skipped, failed = handle_output_file(fastr_testfile_status.abspath, fastr_content)
687+
log_files = False
668688
if detected:
669689
# If a test framework is used, also parse the summary generated by GnuR to compare numbers.
670690
detected, gnur_ok, gnur_skipped, gnur_failed = handle_output_file(gnur_testfile_status.abspath,
@@ -676,9 +696,11 @@ def _failed_outputs(outputs):
676696

677697
if not fastr_invalid_numbers and total_fastr != total_gnur:
678698
logging.info(
679-
"Different number of tests executed. FastR = {} vs. GnuR = {}".format(total_fastr, total_gnur))
699+
"Different number of tests executed. FastR = {} vs. GnuR = {}\n".format(total_fastr, total_gnur))
700+
log_files = True
680701
elif fastr_invalid_numbers:
681702
logging.info("FastR reported invalid numbers of executed tests.")
703+
log_files = True
682704

683705
if fastr_invalid_numbers or total_fastr > total_gnur:
684706
# If FastR's numbers are invalid or GnuR ran fewer tests than FastR, we cannot trust the FastR numbers
@@ -705,17 +727,24 @@ def _failed_outputs(outputs):
705727
fastr_test_status.set_status_code("INDETERMINATE")
706728
# we don't know how many tests are in there, so consider the whole file to be one big skipped test
707729
fastr_testfile_status.set_report(0, 1, 0)
730+
log_files = True
708731
elif result != 0:
709732
fastr_test_status.set_status_code("FAILED")
710733
fastr_testfile_status.status = "FAILED"
711734
fastr_testfile_status.set_report(n_tests_passed, 0, n_tests_failed)
712735
logging.info("{0}: FastR output mismatch: {1}".format(pkg, gnur_test_output_relpath))
713736
logging.info(" output mismatch file: {0}".format(join(_pkg_testdir(RVM_FASTR, pkg), gnur_test_output_relpath)))
714737
logging.info(" output mismatch file: {0}".format(join(_pkg_testdir(RVM_GNUR, pkg), gnur_test_output_relpath)))
738+
log_files = True
715739
else:
716740
fastr_testfile_status.status = "OK"
717741
fastr_testfile_status.set_report(n_tests_passed, 0, n_tests_failed)
718742

743+
# print out the full output files if the test failed
744+
if log_files:
745+
logging.info(format_contents(gnur_testfile_status.abspath, gnur_content) + format_contents(
746+
fastr_testfile_status.abspath, fastr_content))
747+
719748
# we started out as UNKNOWN
720749
if not (fastr_test_status.status == "INDETERMINATE" or fastr_test_status.status == "FAILED"):
721750
fastr_test_status.set_status_code("OK")

com.oracle.truffle.r.test.packages/pkgtest/fuzzy_compare.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -45,10 +45,12 @@ def fuzzy_compare(gnur_content, fastr_content, gnur_filename, fastr_filename, cu
4545
fastr_start = _find_start(fastr_content)
4646
fastr_len = len(fastr_content)
4747
if not gnur_start or not gnur_end or not fastr_start:
48-
if not gnur_start or not gnur_end:
49-
logging.info("malformed GnuR output file {0}: ########\n{1}########".format(gnur_filename, gnur_content))
48+
if not gnur_start:
49+
logging.info("malformed start of the GnuR output")
50+
if not gnur_end:
51+
logging.info("malformed end of the GnuR output")
5052
if not fastr_start:
51-
logging.info("malformed FastR output file {0}: ########\n{1}########".format(fastr_filename, fastr_content))
53+
logging.info("malformed start of the FastR output")
5254
return -1, 0, 0
5355
gnur_i = gnur_start
5456
fastr_i = fastr_start
@@ -72,7 +74,7 @@ def fuzzy_compare(gnur_content, fastr_content, gnur_filename, fastr_filename, cu
7274
if gnur_line is None or fastr_line is None:
7375
# fail if FastR's output is shorter than GnuR's
7476
if gnur_line is not None and fastr_line is None:
75-
logging.debug("FastR's output is shorter than GnuR's")
77+
logging.info("FastR's output is shorter than GnuR's")
7678
overall_result = 1
7779
break
7880

@@ -131,9 +133,9 @@ def fuzzy_compare(gnur_content, fastr_content, gnur_filename, fastr_filename, cu
131133

132134
# report a mismatch or success
133135
if result == 1:
134-
logging.debug(gnur_filename + ':%d' % (gnur_cur_statement_start + 1) + ' vs. ' + fastr_filename + ':%d' % (
136+
logging.info(gnur_filename + ':%d' % (gnur_cur_statement_start + 1) + ' vs. ' + fastr_filename + ':%d' % (
135137
fastr_cur_statement_start + 1))
136-
logging.debug("%s\nvs.\n%s" % (gnur_line.strip(), fastr_line.strip()))
138+
logging.info("%s\nvs.\n%s" % (gnur_line.strip(), fastr_line.strip()))
137139

138140
# we need to synchronize the indices such that we can continue
139141
gnur_i = gnur_i + 1

0 commit comments

Comments
 (0)