From cf1cc9bc72673cebccd225c05dcbb10e4f605852 Mon Sep 17 00:00:00 2001 From: Eirini Koutsaniti Date: Wed, 25 Jan 2023 10:22:02 +0100 Subject: [PATCH 1/3] Add stdout+stderr in fail report of sanity errors --- reframe/frontend/statistics.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/reframe/frontend/statistics.py b/reframe/frontend/statistics.py index 03e0d14cba..2ac7b813cc 100644 --- a/reframe/frontend/statistics.py +++ b/reframe/frontend/statistics.py @@ -3,7 +3,9 @@ # # SPDX-License-Identifier: BSD-3-Clause +import contextlib import inspect +import os import shutil import traceback @@ -229,6 +231,20 @@ def json(self, force=False): return self._run_data def print_failure_report(self, printer, rerun_info=True): + def first_n_lines_of_file(filename, prefix, num_lines=10): + lines = [ + f'--- {filename} (first {num_lines} lines) ---' + ] + with contextlib.suppress(OSError): + with open(os.path.join(prefix, filename)) as fp: + for i, line in enumerate(fp): + if i < num_lines: + # Remove trailing '\n' + lines.append(line[:-1]) + + lines += [f'--- {filename} ---'] + return lines + line_width = shutil.get_terminal_size()[0] printer.info(line_width * '=') printer.info('SUMMARY OF FAILURES') @@ -264,7 +280,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']}") + mssg = r['fail_reason'] + if mssg.startswith('sanity error'): + lines = [mssg] + lines += first_n_lines_of_file(r['job_stdout'], prefix = r['stagedir']) + lines += first_n_lines_of_file(r['job_stderr'], prefix = r['stagedir']) + mssg = '\n'.join(lines) + + printer.info(f" * Reason: {mssg}") tb = ''.join(traceback.format_exception(*r['fail_info'].values())) if r['fail_severe']: From 760da95e046c3f7848265c0126a0e9e686c61ddd Mon Sep 17 00:00:00 2001 From: Eirini Koutsaniti Date: Thu, 26 Jan 2023 11:10:21 +0100 Subject: [PATCH 2/3] Address PR comments --- reframe/frontend/statistics.py | 35 ++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/reframe/frontend/statistics.py b/reframe/frontend/statistics.py index 2ac7b813cc..f9c334f74a 100644 --- a/reframe/frontend/statistics.py +++ b/reframe/frontend/statistics.py @@ -231,18 +231,25 @@ def json(self, force=False): return self._run_data def print_failure_report(self, printer, rerun_info=True): - def first_n_lines_of_file(filename, prefix, num_lines=10): - lines = [ - f'--- {filename} (first {num_lines} lines) ---' - ] - with contextlib.suppress(OSError): + 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[:-1]) + lines.append(line.rstrip()) + + lines += [f'--- {filename} ---'] + except OSError as e: + lines = [f'--- {filename} ({e}) ---'] - lines += [f'--- {filename} ---'] return lines line_width = shutil.get_terminal_size()[0] @@ -280,14 +287,14 @@ def first_n_lines_of_file(filename, prefix, num_lines=10): f" -p {r['environment']} --system " f"{r['system']} -r'") - mssg = r['fail_reason'] - if mssg.startswith('sanity error'): - lines = [mssg] - lines += first_n_lines_of_file(r['job_stdout'], prefix = r['stagedir']) - lines += first_n_lines_of_file(r['job_stderr'], prefix = r['stagedir']) - mssg = '\n'.join(lines) + 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: {mssg}") + printer.info(f" * Reason: {msg}") tb = ''.join(traceback.format_exception(*r['fail_info'].values())) if r['fail_severe']: From 1ea48de3dbf9736b2311396d95dc41d948ef9296 Mon Sep 17 00:00:00 2001 From: Eirini Koutsaniti Date: Thu, 26 Jan 2023 11:15:31 +0100 Subject: [PATCH 3/3] Remove unused import --- reframe/frontend/statistics.py | 1 - 1 file changed, 1 deletion(-) diff --git a/reframe/frontend/statistics.py b/reframe/frontend/statistics.py index f9c334f74a..3640dc4b30 100644 --- a/reframe/frontend/statistics.py +++ b/reframe/frontend/statistics.py @@ -3,7 +3,6 @@ # # SPDX-License-Identifier: BSD-3-Clause -import contextlib import inspect import os import shutil