Skip to content

Commit

Permalink
Merge pull request #2762 from ekouts/feat/sanity_failures
Browse files Browse the repository at this point in the history
[feat] Print the first lines of stderr and stdout in case of sanity failures
  • Loading branch information
vkarak committed Jan 26, 2023
2 parents 12827d9 + 1ea48de commit 0fbffce
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion reframe/frontend/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# SPDX-License-Identifier: BSD-3-Clause

import inspect
import os
import shutil
import traceback

Expand Down Expand Up @@ -229,6 +230,27 @@ def json(self, force=False):
return self._run_data

def print_failure_report(self, printer, rerun_info=True):
def _head_n(filename, prefix, num_lines=10):
# filename and prefix are `None` before setup
if filename is None or prefix is None:
return []

try:
with open(os.path.join(prefix, filename)) as fp:
lines = [
f'--- {filename} (first {num_lines} lines) ---'
]
for i, line in enumerate(fp):
if i < num_lines:
# Remove trailing '\n'
lines.append(line.rstrip())

lines += [f'--- {filename} ---']
except OSError as e:
lines = [f'--- {filename} ({e}) ---']

return lines

line_width = shutil.get_terminal_size()[0]
printer.info(line_width * '=')
printer.info('SUMMARY OF FAILURES')
Expand Down Expand Up @@ -264,7 +286,14 @@ def print_failure_report(self, printer, rerun_info=True):
f" -p {r['environment']} --system "
f"{r['system']} -r'")

printer.info(f" * Reason: {r['fail_reason']}")
msg = r['fail_reason']
if isinstance(r['fail_info']['exc_value'], errors.SanityError):
lines = [msg]
lines += _head_n(r['job_stdout'], prefix = r['stagedir'])
lines += _head_n(r['job_stderr'], prefix = r['stagedir'])
msg = '\n'.join(lines)

printer.info(f" * Reason: {msg}")

tb = ''.join(traceback.format_exception(*r['fail_info'].values()))
if r['fail_severe']:
Expand Down

0 comments on commit 0fbffce

Please sign in to comment.