From 0abe7a35c371564dbab3d733ba0622de7d0a6fbf Mon Sep 17 00:00:00 2001 From: David Ogden <12831266+dav-og@users.noreply.github.com> Date: Wed, 2 Dec 2026 13:46:32 +0000 Subject: [PATCH 1/4] Summarise the checks against limits at the start of the test reports. The regression, verification and comparison reports gain a section with one row per case: its status, the number of checks, and the check closest to its limit with the measured value, the limit and the share of the limit used. Cases that are not PASS come first, and every check outside a limit or a warning threshold is listed below the table. The figures and the per-case sections are unchanged. The numbers are read from the status files that the comparisons already write (tests/utilities/comparison_verdict.py); nothing new is computed. Until now a WARN in a passing run, and how close a passing case was to its limit, could only be found by opening the figure of each case. tests/unit/python/test_report_summary.py covers the share calculation, the ordering, the listing of checks outside a limit and names that contain a pipe. --- .../utilities/generate_comparison_report.py | 7 + .../utilities/generate_regression_report.py | 7 +- tests/unit/CMakeLists.txt | 4 + tests/unit/python/test_report_summary.py | 87 ++++++++++++ tests/utilities/report_generator.py | 133 ++++++++++++++++++ .../utilities/generate_verification_report.py | 5 + 6 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 tests/unit/python/test_report_summary.py diff --git a/tests/comparison/utilities/generate_comparison_report.py b/tests/comparison/utilities/generate_comparison_report.py index 243f081..2cf82c8 100644 --- a/tests/comparison/utilities/generate_comparison_report.py +++ b/tests/comparison/utilities/generate_comparison_report.py @@ -22,6 +22,7 @@ from report_generator import ( display_name, embed_plot_image, + generate_checks_summary, generate_pdf as shared_generate_pdf, generate_report_header, results_tests_search_bases, @@ -121,6 +122,7 @@ def find_comparison_tests(build_dir, config=None): "metrics": status_data.get("metrics", {}) if status_data else {}, "note": status_data.get("note") if status_data else None, "comparisons": status_data.get("comparisons") if status_data else None, + "checks": status_data.get("checks", []) if status_data else [], "plots": plots, "test_dir": test_dir, } @@ -220,6 +222,11 @@ def generate_report(build_dir, output_dir, html_styling=False, config=None): content.append(f"- **Outcome:** {outcome_line}") content.append("") + # Measured values against their limits, from the status files of the cases. + content.extend(generate_checks_summary([ + {"test_name": f"{model}/{name}", "status": data["status"], "checks": data["checks"], "note": data["note"]} + for model in sorted(tests) for name, data in sorted(tests[model].items())])) + if tests: for model in sorted(tests.keys()): content.append("\\clearpage") diff --git a/tests/regression/utilities/generate_regression_report.py b/tests/regression/utilities/generate_regression_report.py index 97f96ad..cdeabc0 100644 --- a/tests/regression/utilities/generate_regression_report.py +++ b/tests/regression/utilities/generate_regression_report.py @@ -22,6 +22,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent / "utilities")) from report_generator import ( find_status_files, + generate_checks_summary, find_plot_files as shared_find_plot_files, generate_report_header, embed_plot_image, @@ -436,7 +437,11 @@ def generate_markdown_report( if html_styling: content.append('') content.append("") - + + # Measured values against their limits, from the status files of the cases. + content.extend(generate_checks_summary( + list(_read_status_files(build_dir, config=config).values()))) + # Add page break before detailed test results section content.append("\\clearpage") content.append("") diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 82a4904..69859d0 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -417,6 +417,10 @@ if(Python3_FOUND) COMMAND ${Python3_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/python/test_sampled_history.py") set_tests_properties(test_sampled_history PROPERTIES LABELS "unit;chrono-free") seastack_python_interpreter_dll_path(test_sampled_history) + # Summary of checks against limits in the test reports (standard library only). + add_test(NAME test_report_summary + COMMAND ${Python3_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/python/test_report_summary.py") + set_tests_properties(test_report_summary PROPERTIES LABELS "unit;chrono-free") add_test( NAME test_demo_features_python COMMAND ${Python3_EXECUTABLE} diff --git a/tests/unit/python/test_report_summary.py b/tests/unit/python/test_report_summary.py new file mode 100644 index 0000000..43a3c0b --- /dev/null +++ b/tests/unit/python/test_report_summary.py @@ -0,0 +1,87 @@ +"""Summary of checks against limits in the test reports (tests/utilities/report_generator.py).""" + +from pathlib import Path +import sys +import unittest + +sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "utilities")) +from report_generator import check_limit_share, generate_checks_summary + + +def _case(name, status, checks, note=None): + payload = {"test_name": name, "status": status, "checks": checks} + if note: + payload["note"] = note + return payload + + +class CheckLimitShareTest(unittest.TestCase): + def test_share_is_value_over_upper_limit(self): + self.assertAlmostEqual(check_limit_share({"value": 0.5, "max": 2.0}), 0.25) + self.assertEqual(check_limit_share({"value": 0.0, "max": 2.0}), 0.0) + # A value above its limit uses more than all of it. + self.assertAlmostEqual(check_limit_share({"value": 3.0, "max": 2.0}), 1.5) + + def test_no_share_without_a_usable_upper_limit(self): + for check in ({"value": 0.99, "min": 0.9}, # lower limit only + {"value": 0.3, "warn_max": 0.1}, # warning threshold only + {"name": "files exist"}, # yes/no check + {"value": "nan", "max": 1.0}, # not a number + {"value": float("nan"), "max": 1.0}, + {"value": -0.1, "max": 1.0}, # signed quantity + {"value": 0.1, "max": 0.0}, + {"value": True, "max": 1.0}): + with self.subTest(check=check): + self.assertIsNone(check_limit_share(check)) + + +class ChecksSummaryTest(unittest.TestCase): + def test_no_cases_gives_no_section(self): + self.assertEqual(generate_checks_summary([]), []) + + def test_each_case_shows_the_check_closest_to_its_limit(self): + lines = generate_checks_summary([_case("decay", "PASS", [ + {"name": "rms", "value": 1.0e-4, "max": 1.0e-2, "status": "PASS"}, + {"name": "max_abs", "value": 5.0e-3, "max": 1.0e-2, "status": "PASS"}, + ])]) + row = next(line for line in lines if line.startswith("| decay ")) + self.assertEqual(row, "| decay | PASS | 2 | max_abs | 0.005 | max 0.01 | 50.0% |") + self.assertIn("All 2 checks in 1 cases are within their limits and warning thresholds.", lines) + + def test_cases_that_are_not_pass_come_first_and_their_checks_are_listed(self): + lines = generate_checks_summary([ + _case("b_pass", "PASS", [{"name": "rms", "value": 0.0, "max": 1.0, "status": "PASS"}]), + _case("a_info", "INFO", []), + _case("c_warn", "WARN", [ + {"name": "l2", "value": 0.2, "max": 1.0, "status": "PASS"}, + {"name": "linf", "value": 0.6, "max": 1.0, "warn_max": 0.5, "status": "WARN"}]), + _case("d_fail", "FAIL", [{"name": "rms", "value": 2.0, "max": 1.0, "status": "FAIL"}], + note="rms: outside its limit"), + ]) + rows = [line.split("|")[1].strip() for line in lines if line.startswith("| ") and "Case" not in line] + # First table in status order, then the two checks outside a limit or + # threshold, in the same case order. + self.assertEqual(rows, ["d_fail", "c_warn", "a_info", "b_pass", "d_fail", "c_warn"]) + self.assertIn("| c_warn | WARN | 2 | linf | 0.6 | max 1 | 60.0% |", lines) + self.assertIn("| c_warn | linf | 0.6 | max 1 | max 0.5 | WARN |", lines) + self.assertIn("| d_fail | rms | 2 | max 1 | - | FAIL |", lines) + self.assertIn("| a_info | INFO | 0 | - | - | - | - |", lines) + self.assertIn("- **d_fail** (FAIL): rms: outside its limit", lines) + self.assertFalse(any(line.startswith("All ") for line in lines)) + + def test_small_shares_and_zero_are_distinguished(self): + lines = generate_checks_summary([ + _case("exact", "PASS", [{"name": "rms", "value": 0.0, "max": 1.0, "status": "PASS"}]), + _case("tiny", "PASS", [{"name": "rms", "value": 1.0e-6, "max": 1.0, "status": "PASS"}]), + ]) + self.assertIn("| exact | PASS | 1 | rms | 0 | max 1 | 0% |", lines) + self.assertIn("| tiny | PASS | 1 | rms | 1e-06 | max 1 | <0.1% |", lines) + + def test_a_pipe_in_a_name_does_not_break_the_table(self): + lines = generate_checks_summary([_case("case", "PASS", [ + {"name": "|phase difference| (deg)", "value": 0.5, "max": 1.0, "status": "PASS"}])]) + self.assertIn("| case | PASS | 1 | \\|phase difference\\| (deg) | 0.5 | max 1 | 50.0% |", lines) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/utilities/report_generator.py b/tests/utilities/report_generator.py index ab8c7bb..75cdf6f 100644 --- a/tests/utilities/report_generator.py +++ b/tests/utilities/report_generator.py @@ -550,6 +550,139 @@ def generate_pdf( return None +_STATUS_RANK = {"FAIL": 0, "NO DATA": 1, "UNKNOWN": 1, "WARN": 2, "INFO": 3, "PASS": 4} + + +def _is_number(value) -> bool: + return isinstance(value, (int, float)) and not isinstance(value, bool) + + +def _format_number(value) -> str: + """A value or limit as it is shown in the summary tables.""" + if not _is_number(value): + return "-" if value is None else str(value) + return "0" if value == 0 else f"{value:.3g}" + + +def _table_text(text) -> str: + """Text that is safe inside a Markdown pipe-table cell.""" + return str(text).replace("|", "\\|").replace("\n", " ") + + +def check_limit_share(check) -> Optional[float]: + """Share of its upper limit that a check's value uses, or None. + + Defined as value / max for a check with a positive upper limit ("max") and + a non-negative value, which covers the error measures (RMS, maximum, norms) + of the comparisons. A check with only a lower limit, or without a number, + has no share. + """ + value, limit = check.get("value"), check.get("max") + if not _is_number(value) or not _is_number(limit): + return None + if value != value or limit != limit or value < 0 or limit <= 0: # NaN, sign + return None + return value / limit + + +def _format_share(share: Optional[float]) -> str: + if share is None: + return "-" + if share == 0: + return "0%" + return "<0.1%" if share < 0.001 else f"{100.0 * share:.1f}%" + + +def _format_limit(check) -> str: + parts = [] + if "max" in check: + parts.append(f"max {_format_number(check['max'])}") + if "min" in check: + parts.append(f"min {_format_number(check['min'])}") + return ", ".join(parts) if parts else "-" + + +def _closest_check(checks): + """The check that matters most in a case: worst status first, then the largest share of its limit.""" + def key(check): + share = check_limit_share(check) + return (_STATUS_RANK.get(check.get("status", "UNKNOWN"), 1), -(share if share is not None else -1.0)) + return min(checks, key=key) if checks else None + + +def generate_checks_summary(payloads, heading="Checks against limits"): + """Summarise the numeric checks of a suite from its status files. + + The first table has one row per case: its status, the number of checks, + and the check that is closest to its limit with its value, limit and the + share of the limit used. Cases that are not PASS come first. The second + table lists every check that is outside a limit or a warning threshold. + + Args: + payloads: status-file contents, each a dict with "test_name", "status" + and "checks" (as written by tests/utilities/comparison_verdict.py). + heading: section heading. + + Returns: + List of markdown lines; empty when there are no payloads. + """ + cases = [p for p in payloads if isinstance(p, dict)] + if not cases: + return [] + cases.sort(key=lambda p: (_STATUS_RANK.get(p.get("status", "UNKNOWN"), 1), str(p.get("test_name", "")))) + + content = [f"## {heading}", ""] + content.append( + "Each case is judged by one or more checks of a measured value against a limit. " + "The table shows, for each case, the check that is closest to its limit.") + content.append("") + # The number of dashes sets the relative column widths in the PDF. + content.append("| Case | Status | Checks | Closest to its limit | Value | Limit | Share of limit |") + content.append("|--------------------------|------|-----|--------------------------|--------|----------|-------|") + + flagged = [] + n_checks = 0 + for payload in cases: + name = _table_text(payload.get("test_name", "(unnamed)")) + status = payload.get("status", "UNKNOWN") + checks = [c for c in payload.get("checks") or [] if isinstance(c, dict)] + n_checks += len(checks) + closest = _closest_check(checks) + if closest is None: + content.append(f"| {name} | {status} | 0 | - | - | - | - |") + else: + content.append( + f"| {name} | {status} | {len(checks)} | {_table_text(closest.get('name', '-'))} | " + f"{_format_number(closest.get('value'))} | {_format_limit(closest)} | " + f"{_format_share(check_limit_share(closest))} |") + flagged += [(name, c) for c in checks if c.get("status") != "PASS"] + content.append("") + + if flagged: + content.append("Checks outside a limit or a warning threshold:") + content.append("") + content.append("| Case | Check | Value | Limit | Warning threshold | Status |") + content.append("|----------------------|--------------------------|--------|----------|----------|------|") + for name, check in flagged: + warn = ", ".join(f"{key[5:]} {_format_number(check[key])}" for key in ("warn_max", "warn_min") if key in check) + content.append( + f"| {name} | {_table_text(check.get('name', '-'))} | {_format_number(check.get('value'))} | " + f"{_format_limit(check)} | {warn or '-'} | {check.get('status', 'UNKNOWN')} |") + content.append("") + else: + content.append( + f"All {n_checks} checks in {len(cases)} cases are within their limits and warning thresholds.") + content.append("") + + notes = [(p.get("test_name", "(unnamed)"), p.get("status", "UNKNOWN"), p.get("note")) + for p in cases if p.get("status") != "PASS" and p.get("note")] + for name, status, note in notes: + content.append(f"- **{_table_text(name)}** ({status}): {note}") + if notes: + content.append("") + return content + + def aggregate_status(status_data): """Compute overall status from a list of status records. diff --git a/tests/verification/utilities/generate_verification_report.py b/tests/verification/utilities/generate_verification_report.py index 12128e7..2e4fb64 100644 --- a/tests/verification/utilities/generate_verification_report.py +++ b/tests/verification/utilities/generate_verification_report.py @@ -21,6 +21,7 @@ from report_generator import ( display_name, find_status_files, + generate_checks_summary, find_plot_files as shared_find_plot_files, generate_report_header, embed_plot_image, @@ -215,6 +216,10 @@ def generate_report(build_dir, output_dir, config=None, html_styling=False): content.append(f"- **Outcome:** {outcome_line}") content.append("") + # Measured values against their limits, from the status files of the cases. + content.extend(generate_checks_summary( + [dict(payload, test_name=name) for name, payload in ver_status.items()])) + ver_plot_groups = {g: ps for g, ps in plots.items() if g in reported} if ver_plot_groups: From 2b4ee6f3d007df960a76d8e0c6b1f200db6f24c8 Mon Sep 17 00:00:00 2001 From: David Ogden <12831266+dav-og@users.noreply.github.com> Date: Wed, 2 Dec 2026 13:46:32 +0000 Subject: [PATCH 2/4] Publish the report summary and a PDF of the regression report from every CI run. The Linux Chrono job now installs pandoc and LaTeX on every run, so the regression report is written as PDF for each pull request; the verification and comparison PDFs still come with the full suites. A new artifact, pdf-reports, holds the PDFs alone with their figures resampled to 150 dpi by Ghostscript (lossless) for reading on screen; if the resampling fails the full-resolution PDF is uploaded and a warning is logged. scripts/ci/report_section.py copies the checks-against-limits section of each report to the page of the workflow run, for every platform. tests/README.md describes the summary section and where the PDFs are. --- .github/workflows/ci.yml | 95 +++++++++++++++++++++++++++++------- scripts/ci/report_section.py | 62 +++++++++++++++++++++++ tests/README.md | 5 +- 3 files changed, 142 insertions(+), 20 deletions(-) create mode 100644 scripts/ci/report_section.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 61374f5..948df84 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -317,10 +317,18 @@ jobs: - name: Run the unit tests run: ./scripts/unix/ctest_suite.sh unit -j "${CTEST_JOBS}" --junit test-results/unit.xml + # With pandoc on PATH, ctest_suite.sh also writes each report as a PDF. + # Ghostscript makes the screen-resolution copies uploaded as pdf-reports. + - name: Install pandoc, LaTeX and Ghostscript + if: ${{ !cancelled() && steps.build.conclusion == 'success' && matrix.pdf }} + run: | + sudo apt-get install --yes --no-install-recommends \ + pandoc texlive-xetex texlive-latex-recommended texlive-fonts-recommended lmodern ghostscript + - name: Run the regression tests if: ${{ !cancelled() && steps.build.conclusion == 'success' }} run: > - ./scripts/unix/ctest_suite.sh regression -j "${CTEST_JOBS}" --no-pdf + ./scripts/unix/ctest_suite.sh regression -j "${CTEST_JOBS}" ${PDF_OPTION} --junit test-results/regression.xml - name: Run the external-module tests @@ -331,13 +339,6 @@ jobs: --output-junit test-results/external.xml # ---- Full suites (see FULL_SUITES above) ---- - # With pandoc on PATH, ctest_suite.sh also writes each report as a PDF. - - name: Install pandoc and LaTeX - if: ${{ !cancelled() && steps.build.conclusion == 'success' && env.FULL_SUITES == 'true' && matrix.pdf }} - run: | - sudo apt-get install --yes --no-install-recommends \ - pandoc texlive-xetex texlive-latex-recommended texlive-fonts-recommended lmodern - - name: Run the verification tests if: ${{ !cancelled() && steps.build.conclusion == 'success' && env.FULL_SUITES == 'true' }} run: > @@ -370,21 +371,39 @@ jobs: continue-on-error: true run: ./scripts/unix/ctest_suite.sh benchmark --junit test-results/benchmark.xml - # The report generators keep going when the PDF conversion fails. - - name: Check that the PDF reports were written - if: ${{ !cancelled() && steps.build.conclusion == 'success' && env.FULL_SUITES == 'true' && matrix.pdf }} + # The report generators keep going when the PDF conversion fails, so the + # PDFs are checked here. Each is also copied to pdf-reports/ with its + # figures resampled to 150 dpi (lossless), for reading on screen; the + # full-resolution PDF stays in the reports artifact. + - name: Check and collect the PDF reports + if: ${{ !cancelled() && steps.build.conclusion == 'success' && matrix.pdf }} run: | + reports="regression/report/regression_test_report.pdf" + if [[ "${FULL_SUITES}" == "true" ]]; then + reports="${reports} verification/report/verification_report.pdf comparison/report/comparison_test_report.pdf" + fi + mkdir -p pdf-reports status=0 - for report in \ - regression/report/regression_test_report.pdf \ - verification/report/verification_report.pdf \ - comparison/report/comparison_test_report.pdf; do - if [[ -s "build/bin/Release/results/tests/${report}" ]]; then - echo "[OK] ${report}" - else + for report in ${reports}; do + source_pdf="build/bin/Release/results/tests/${report}" + if [[ ! -s "${source_pdf}" ]]; then echo "::error::PDF report missing or empty: ${report}" status=1 + continue + fi + screen_pdf="pdf-reports/$(basename "${report}")" + if ! gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite \ + -dDownsampleColorImages=true -dColorImageDownsampleType=/Bicubic \ + -dColorImageResolution=150 -dColorImageDownsampleThreshold=1.0 \ + -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode \ + -dDownsampleGrayImages=true -dGrayImageDownsampleType=/Bicubic \ + -dGrayImageResolution=150 -dGrayImageDownsampleThreshold=1.0 \ + -dAutoFilterGrayImages=false -dGrayImageFilter=/FlateEncode \ + -sOutputFile="${screen_pdf}" "${source_pdf}" || [[ ! -s "${screen_pdf}" ]]; then + echo "::warning::could not resample ${report}; uploading the full-resolution PDF" + cp "${source_pdf}" "${screen_pdf}" fi + echo "[OK] ${report}: $(du -h "${source_pdf}" | cut -f1) -> $(du -h "${screen_pdf}" | cut -f1)" done exit "${status}" @@ -403,6 +422,21 @@ jobs: done exit "${status}" + # The summary of measured values against their limits, from each report, + # on the page of the workflow run. + - name: Show the checks against limits on the run page + if: ${{ !cancelled() && steps.build.conclusion == 'success' }} + run: | + reports="regression/report/regression_test_report.md" + if [[ "${FULL_SUITES}" == "true" ]]; then + reports="${reports} verification/report/verification_report.md comparison/report/comparison_test_report.md" + fi + for report in ${reports}; do + python3 scripts/ci/report_section.py "build/bin/Release/results/tests/${report}" \ + --title "${report%%/*} checks against limits (${{ matrix.name }})" \ + --summary "${GITHUB_STEP_SUMMARY}" || true + done + - name: Record disk use if: ${{ !cancelled() }} run: | @@ -433,6 +467,16 @@ jobs: if-no-files-found: warn retention-days: 30 + # The PDFs alone, at screen resolution: the download for reading the reports. + - name: Upload the PDF reports + if: ${{ !cancelled() && steps.build.conclusion == 'success' && matrix.pdf }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: pdf-reports + path: pdf-reports/ + if-no-files-found: warn + retention-days: 30 + # The Windows jobs use the PowerShell entry points under scripts/windows. # Eigen and HDF5 come from the vcpkg checkout on the runner image. chrono-free-windows: @@ -794,6 +838,21 @@ jobs: } exit $status + # The summary of measured values against their limits, from each report, + # on the page of the workflow run. + - name: Show the checks against limits on the run page + if: ${{ !cancelled() && steps.build.conclusion == 'success' }} + run: | + $reports = @('regression/report/regression_test_report.md') + if ($env:FULL_SUITES -eq 'true') { + $reports += 'verification/report/verification_report.md', 'comparison/report/comparison_test_report.md' + } + foreach ($report in $reports) { + $suite = ($report -split '/')[0] + python scripts/ci/report_section.py "build/bin/Release/results/tests/$report" --title "$suite checks against limits (Windows)" --summary $env:GITHUB_STEP_SUMMARY + } + exit 0 + - name: Upload test results if: ${{ !cancelled() }} uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 diff --git a/scripts/ci/report_section.py b/scripts/ci/report_section.py new file mode 100644 index 0000000..355353b --- /dev/null +++ b/scripts/ci/report_section.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 +"""Copy one section of a Markdown test report to another file. + +Usage: + python3 scripts/ci/report_section.py --summary FILE + [--heading "Checks against limits"] [--title TEXT] + +The continuous integration jobs use this to show the summary of checks against +limits (written by the report generators under tests/) on the page of a +workflow run: FILE is then the file named by GITHUB_STEP_SUMMARY. + +The section starts at the level-2 heading with the given text and ends before +the next level-2 heading or page break. --title replaces the heading text in +the copy, for example to name the suite and platform. + +Exit code 0 = section copied, 1 = report or section not found, 2 = usage error. +Standard library only. +""" +from __future__ import annotations + +import argparse +import sys +from pathlib import Path + + +def extract_section(lines: list[str], heading: str) -> list[str]: + """Lines of the section under '## ', without the heading line.""" + start = next((i for i, line in enumerate(lines) if line.strip() == f"## {heading}"), None) + if start is None: + return [] + section = [] + for line in lines[start + 1:]: + if line.startswith("## ") or line.strip() == "\\clearpage": + break + section.append(line) + return section + + +def main() -> int: + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument("report", type=Path, help="Markdown report written by a report generator") + parser.add_argument("--summary", type=Path, required=True, help="file to append the section to") + parser.add_argument("--heading", default="Checks against limits", help="heading text of the section") + parser.add_argument("--title", help="heading text to use in the copy (default: --heading)") + args = parser.parse_args() + + if not args.report.is_file(): + print(f"[FAIL] report not found: {args.report}", file=sys.stderr) + return 1 + section = extract_section(args.report.read_text(encoding="utf-8").splitlines(), args.heading) + if not section: + print(f"[FAIL] no section '## {args.heading}' in {args.report}", file=sys.stderr) + return 1 + with args.summary.open("a", encoding="utf-8") as handle: + handle.write(f"### {args.title or args.heading}\n") + handle.write("\n".join(section).rstrip() + "\n\n") + print(f"[OK] copied '## {args.heading}' from {args.report} ({len(section)} lines)") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/tests/README.md b/tests/README.md index 6f9ea1e..d147655 100644 --- a/tests/README.md +++ b/tests/README.md @@ -71,7 +71,8 @@ The Chrono job also runs the **full suites** (verification, comparison, long reg - **Threads:** two tests run at a time, each with `OMP_NUM_THREADS=2`. - **Skipped tests fail the run.** CTest exits with 0 when a test returns its skip code, for example when a Python package is missing; `scripts/ci/check_ctest_junit.py` reads the JUnit report of each suite and fails unless every test ran and passed. The suite scripts write that report with `--junit FILE` (Unix) or `-Junit FILE` (Windows). - **Benchmarks do not fail the run.** Timings on shared runners are for information only. -- **Results:** each job uploads its JUnit reports and logs, and the Chrono job its Markdown reports with figures. The full suites on Linux also write the reports as PDF. +- **Results:** each job uploads its JUnit reports and logs, and the Chrono job its Markdown reports with figures. The page of a workflow run shows each report's table of checks against limits for every platform. +- **PDF reports:** the Linux Chrono job writes the regression report as PDF on every run, and the verification and comparison reports with the full suites. The artifact `pdf-reports` holds the PDFs alone with their figures resampled to 150 dpi, for reading on screen; the full-resolution PDFs are in `chrono-linux-reports`. - **Not covered:** the VSG GUI build and the release packages. ## Test-only environment variables @@ -89,7 +90,7 @@ verification and comparison generators. ## Reports (summary) -Regression, verification, and comparison can produce **Markdown** reports under `build/bin//results/tests/...` (e.g. `.../regression/report/regression_test_report.md`). **PDF** needs Pandoc and a LaTeX engine (MiKTeX, MacTeX, TeX Live); Windows runners add PDF when `pandoc` is on `PATH` unless you pass `-NoPdf`. Markdown is still written if PDF conversion fails. +Regression, verification, and comparison can produce **Markdown** reports under `build/bin//results/tests/...` (e.g. `.../regression/report/regression_test_report.md`). Each report starts with a table of **checks against limits**: one row per case with its status and the check that is closest to its limit (measured value, limit and share of the limit used), followed by every check that is outside a limit or a warning threshold. The numbers come from the status files that the comparisons write. **PDF** needs Pandoc and a LaTeX engine (MiKTeX, MacTeX, TeX Live); Windows runners add PDF when `pandoc` is on `PATH` unless you pass `-NoPdf`. Markdown is still written if PDF conversion fails. The CTest report tests `verification_report_generation` and `comparison_report_generation` fail when no status file is found, when a status file cannot be read, when a status is FAIL or not recognised, or when a PASS or WARN has no positive comparison count. Both also fail when a case registered in the build has no result, when a result belongs to no registered case, or (verification) when a test name has more than one status file. The registered cases are written at configure time to `tests/verification/expected_groups.txt` and `tests/comparison/expected_cases.txt` in the build directory; `rm3_mooring` is registered only with `SEASTACK_ENABLE_MOORING=ON`. The report's summary outcome uses the same checks. From 36e9f70cb3fa2cde02e11cc47cc274d0ce4266d9 Mon Sep 17 00:00:00 2001 From: David Ogden <12831266+dav-og@users.noreply.github.com> Date: Wed, 2 Dec 2026 15:08:14 +0000 Subject: [PATCH 3/4] Make the PDF reports of all three platforms in one CI artifact. The Chrono jobs on Linux, macOS and Windows now hand over their Markdown reports and figures, and a new job, PDF test reports, converts them all to PDF on one Linux runner with pandoc and LaTeX (scripts/ci/render_reports.py, using the PDF settings of tests/utilities/report_generator.py and the platform in the subtitle). It uploads one artifact, test-reports, with linux/, macos/ and windows/ folders and the figures resampled to 150 dpi, then deletes the intermediate report-sources-* artifacts. This replaces the per-platform chrono-*-reports artifacts and the Linux-only pdf-reports artifact, and LaTeX is no longer installed in the Linux test job. The regression reports are in every run; verification and comparison with the full suites. A report that cannot be converted, or a required one that is missing for a platform that produced reports, fails the job, and All checks requires it. --- .github/workflows/ci.yml | 180 +++++++++++++++++++++-------------- scripts/ci/render_reports.py | 84 ++++++++++++++++ tests/README.md | 4 +- 3 files changed, 195 insertions(+), 73 deletions(-) create mode 100644 scripts/ci/render_reports.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 948df84..d08b847 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -176,14 +176,11 @@ jobs: - name: Linux id: linux os: ubuntu-24.04 - pdf: true - name: macOS id: macos os: macos-15 - pdf: false - env: - # PDF reports are written on Linux only; the other platforms write Markdown. - PDF_OPTION: ${{ !matrix.pdf && '--no-pdf' || '' }} + # The reports are written as Markdown here; the test-reports job converts + # those of every platform to PDF. steps: - name: Check out the source uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -317,18 +314,10 @@ jobs: - name: Run the unit tests run: ./scripts/unix/ctest_suite.sh unit -j "${CTEST_JOBS}" --junit test-results/unit.xml - # With pandoc on PATH, ctest_suite.sh also writes each report as a PDF. - # Ghostscript makes the screen-resolution copies uploaded as pdf-reports. - - name: Install pandoc, LaTeX and Ghostscript - if: ${{ !cancelled() && steps.build.conclusion == 'success' && matrix.pdf }} - run: | - sudo apt-get install --yes --no-install-recommends \ - pandoc texlive-xetex texlive-latex-recommended texlive-fonts-recommended lmodern ghostscript - - name: Run the regression tests if: ${{ !cancelled() && steps.build.conclusion == 'success' }} run: > - ./scripts/unix/ctest_suite.sh regression -j "${CTEST_JOBS}" ${PDF_OPTION} + ./scripts/unix/ctest_suite.sh regression -j "${CTEST_JOBS}" --no-pdf --junit test-results/regression.xml - name: Run the external-module tests @@ -342,20 +331,20 @@ jobs: - name: Run the verification tests if: ${{ !cancelled() && steps.build.conclusion == 'success' && env.FULL_SUITES == 'true' }} run: > - ./scripts/unix/ctest_suite.sh verification -j "${CTEST_JOBS}" ${PDF_OPTION} + ./scripts/unix/ctest_suite.sh verification -j "${CTEST_JOBS}" --no-pdf --junit test-results/verification.xml - name: Run the comparison tests if: ${{ !cancelled() && steps.build.conclusion == 'success' && env.FULL_SUITES == 'true' }} run: > - ./scripts/unix/ctest_suite.sh comparison -j "${CTEST_JOBS}" ${PDF_OPTION} + ./scripts/unix/ctest_suite.sh comparison -j "${CTEST_JOBS}" --no-pdf --junit test-results/comparison.xml # Runs last of the CTest suites, so the regression report describes the long run. - name: Run the long regression tests if: ${{ !cancelled() && steps.build.conclusion == 'success' && env.FULL_SUITES == 'true' }} run: > - ./scripts/unix/ctest_suite.sh regression --long -j "${CTEST_JOBS}" ${PDF_OPTION} + ./scripts/unix/ctest_suite.sh regression --long -j "${CTEST_JOBS}" --no-pdf --junit test-results/regression-long.xml - name: Run the demo cases against their baselines @@ -371,42 +360,6 @@ jobs: continue-on-error: true run: ./scripts/unix/ctest_suite.sh benchmark --junit test-results/benchmark.xml - # The report generators keep going when the PDF conversion fails, so the - # PDFs are checked here. Each is also copied to pdf-reports/ with its - # figures resampled to 150 dpi (lossless), for reading on screen; the - # full-resolution PDF stays in the reports artifact. - - name: Check and collect the PDF reports - if: ${{ !cancelled() && steps.build.conclusion == 'success' && matrix.pdf }} - run: | - reports="regression/report/regression_test_report.pdf" - if [[ "${FULL_SUITES}" == "true" ]]; then - reports="${reports} verification/report/verification_report.pdf comparison/report/comparison_test_report.pdf" - fi - mkdir -p pdf-reports - status=0 - for report in ${reports}; do - source_pdf="build/bin/Release/results/tests/${report}" - if [[ ! -s "${source_pdf}" ]]; then - echo "::error::PDF report missing or empty: ${report}" - status=1 - continue - fi - screen_pdf="pdf-reports/$(basename "${report}")" - if ! gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite \ - -dDownsampleColorImages=true -dColorImageDownsampleType=/Bicubic \ - -dColorImageResolution=150 -dColorImageDownsampleThreshold=1.0 \ - -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode \ - -dDownsampleGrayImages=true -dGrayImageDownsampleType=/Bicubic \ - -dGrayImageResolution=150 -dGrayImageDownsampleThreshold=1.0 \ - -dAutoFilterGrayImages=false -dGrayImageFilter=/FlateEncode \ - -sOutputFile="${screen_pdf}" "${source_pdf}" || [[ ! -s "${screen_pdf}" ]]; then - echo "::warning::could not resample ${report}; uploading the full-resolution PDF" - cp "${source_pdf}" "${screen_pdf}" - fi - echo "[OK] ${report}: $(du -h "${source_pdf}" | cut -f1) -> $(du -h "${screen_pdf}" | cut -f1)" - done - exit "${status}" - # CTest exits with 0 when a test is skipped. Fail unless every test ran. - name: Check that every test ran and passed if: ${{ !cancelled() && steps.build.conclusion == 'success' }} @@ -455,27 +408,18 @@ jobs: if-no-files-found: warn retention-days: 14 - # Markdown and PDF reports with the figures they refer to. - - name: Upload test reports + # Markdown reports with their figures, for the test-reports job, which + # converts them to PDF and then deletes this artifact. + - name: Hand over the reports if: ${{ !cancelled() && steps.build.conclusion == 'success' }} uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: - name: chrono-${{ matrix.id }}-reports + name: report-sources-${{ matrix.id }} path: | build/bin/Release/results/tests/*/report/ build/bin/Release/results/tests/**/plots/ if-no-files-found: warn - retention-days: 30 - - # The PDFs alone, at screen resolution: the download for reading the reports. - - name: Upload the PDF reports - if: ${{ !cancelled() && steps.build.conclusion == 'success' && matrix.pdf }} - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 - with: - name: pdf-reports - path: pdf-reports/ - if-no-files-found: warn - retention-days: 30 + retention-days: 1 # The Windows jobs use the PowerShell entry points under scripts/windows. # Eigen and HDF5 come from the vcpkg checkout on the runner image. @@ -866,25 +810,119 @@ jobs: if-no-files-found: warn retention-days: 14 - # Markdown reports with the figures they refer to. - - name: Upload test reports + # Markdown reports with their figures, for the test-reports job, which + # converts them to PDF and then deletes this artifact. + - name: Hand over the reports if: ${{ !cancelled() && steps.build.conclusion == 'success' }} uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: - name: chrono-windows-reports + name: report-sources-windows path: | build/bin/Release/results/tests/*/report/ build/bin/Release/results/tests/**/plots/ if-no-files-found: warn + retention-days: 1 + + # Converts the reports of all three platforms to PDF on one Linux runner, + # where pandoc and LaTeX are installed, and uploads them as one artifact, + # test-reports: /_test_report.pdf with the figures resampled + # to 150 dpi (lossless) for reading on screen. The regression reports are + # always included; verification and comparison with the full suites. + test-reports: + name: PDF test reports + if: ${{ !cancelled() }} + needs: [chrono, chrono-windows] + runs-on: ubuntu-24.04 + timeout-minutes: 30 + permissions: + contents: read + # To delete the report-sources-* artifacts once they are converted. + actions: write + steps: + - name: Check out the source + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ env.CHECKOUT_REF }} + persist-credentials: false + + - name: Install pandoc, LaTeX and Ghostscript + run: | + sudo apt-get update + sudo apt-get install --yes --no-install-recommends \ + pandoc texlive-xetex texlive-latex-recommended texlive-fonts-recommended lmodern ghostscript + + - name: Download the reports of each platform + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + pattern: report-sources-* + path: report-sources + + # The download makes one folder per artifact, report-sources/report-sources-. + - name: Convert the reports to PDF + run: | + mkdir -p sources + for folder in report-sources/report-sources-*; do + [[ -d "${folder}" ]] && mv "${folder}" "sources/${folder##*/report-sources-}" + done + ls sources + required="regression" + if [[ "${FULL_SUITES}" == "true" ]]; then + required="regression verification comparison" + fi + # A platform whose Chrono job failed has no reports; that job already + # fails the run, so only the platforms present are checked. + python3 scripts/ci/render_reports.py sources full-resolution --require ${required} + + - name: Resample the figures for reading on screen + run: | + mkdir -p test-reports + for source_pdf in full-resolution/*/*.pdf; do + platform="$(basename "$(dirname "${source_pdf}")")" + screen_pdf="test-reports/${platform}/$(basename "${source_pdf}")" + mkdir -p "$(dirname "${screen_pdf}")" + if ! gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite \ + -dDownsampleColorImages=true -dColorImageDownsampleType=/Bicubic \ + -dColorImageResolution=150 -dColorImageDownsampleThreshold=1.0 \ + -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode \ + -dDownsampleGrayImages=true -dGrayImageDownsampleType=/Bicubic \ + -dGrayImageResolution=150 -dGrayImageDownsampleThreshold=1.0 \ + -dAutoFilterGrayImages=false -dGrayImageFilter=/FlateEncode \ + -sOutputFile="${screen_pdf}" "${source_pdf}" || [[ ! -s "${screen_pdf}" ]]; then + echo "::warning::could not resample ${source_pdf}; uploading it at full resolution" + cp "${source_pdf}" "${screen_pdf}" + fi + echo "[OK] ${platform}/$(basename "${source_pdf}"): $(du -h "${source_pdf}" | cut -f1) -> $(du -h "${screen_pdf}" | cut -f1)" + done + + - name: Upload the PDF reports + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: test-reports + path: test-reports/ + if-no-files-found: error retention-days: 30 + # Best effort: a pull request from a fork gets a read-only token, and the + # artifacts then expire after one day instead. + - name: Delete the converted report sources + if: ${{ always() }} + env: + GH_TOKEN: ${{ github.token }} + run: | + ids="$(gh api "repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/artifacts" --paginate \ + --jq '.artifacts[] | select(.name | startswith("report-sources-")) | .id')" || ids="" + for id in ${ids}; do + gh api -X DELETE "repos/${GITHUB_REPOSITORY}/actions/artifacts/${id}" \ + || echo "::warning::could not delete artifact ${id}" + done + # One status for branch protection: passes only if every job above passed. # Requiring this job means the list of platforms can change without editing # the repository settings. all-checks: name: All checks if: ${{ always() }} - needs: [chrono-free, chrono, chrono-free-windows, chrono-windows] + needs: [chrono-free, chrono, chrono-free-windows, chrono-windows, test-reports] runs-on: ubuntu-24.04 timeout-minutes: 5 steps: diff --git a/scripts/ci/render_reports.py b/scripts/ci/render_reports.py new file mode 100644 index 0000000..a842e9b --- /dev/null +++ b/scripts/ci/render_reports.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +"""Render the Markdown test reports of several platforms as PDF. + +Usage: + python3 scripts/ci/render_reports.py [--require SUITE ...] + + holds one folder per platform (linux, macos, windows), each with the +layout of build/bin//results/tests: /report/.md and the +figures that the report refers to. For every report found, this writes +//_test_report.pdf with the same PDF settings as the +report generators (tests/utilities/report_generator.py), and the platform +added to the subtitle. + +The continuous integration workflow uses this to make the PDFs of all three +platforms on one Linux runner, where pandoc and LaTeX are installed. + +--require names suites whose report must exist for every platform folder; +a missing one fails the run. A report that is found but cannot be converted +always fails the run. + +Exit code 0 = all reports converted, 1 = a conversion failed or a required +report is missing, 2 = usage error. +""" +from __future__ import annotations + +import argparse +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "tests" / "utilities")) +from report_generator import generate_pdf # noqa: E402 + +# Suite -> (report path under the suite folder, title, subtitle); as in the +# generate_*_report.py scripts under tests/. +REPORTS = { + "regression": ("report/regression_test_report.md", "SEA-Stack Regression Test Report", + "Compares current outputs to stored reference data for core cases."), + "verification": ("report/verification_report.md", "SEA-Stack Verification Test Report", + "Cross-code verification of hydrodynamic simulation capabilities"), + "comparison": ("report/comparison_test_report.md", "SEA-Stack Comparison Test Report", + "Internal method comparisons within SEA-Stack"), +} +PLATFORM_NAMES = {"linux": "Linux", "macos": "macOS", "windows": "Windows"} + + +def main() -> int: + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument("sources", type=Path, help="folder with one sub-folder per platform") + parser.add_argument("output", type=Path, help="folder for /_test_report.pdf") + parser.add_argument("--require", nargs="*", default=[], choices=sorted(REPORTS), + help="suites whose report must exist for every platform") + args = parser.parse_args() + + platforms = sorted(p for p in args.sources.iterdir() if p.is_dir()) if args.sources.is_dir() else [] + if not platforms: + print(f"[FAIL] no platform folders in {args.sources}", file=sys.stderr) + return 1 + + problems = [] + for platform_dir in platforms: + platform = platform_dir.name + label = PLATFORM_NAMES.get(platform, platform) + for suite, (relative, title, subtitle) in REPORTS.items(): + markdown = platform_dir / suite / relative + if not markdown.is_file(): + if suite in args.require: + problems.append(f"{platform}: {suite} report not found ({markdown})") + continue + pdf = args.output / platform / f"{suite}_test_report.pdf" + pdf.parent.mkdir(parents=True, exist_ok=True) + result = generate_pdf(markdown, pdf, quiet=True, report_title=title, + report_subtitle=f"{subtitle} ({label})") + if result is None or not pdf.is_file() or pdf.stat().st_size == 0: + problems.append(f"{platform}: {suite} report could not be converted to PDF") + else: + print(f"[OK] {platform}/{pdf.name} ({pdf.stat().st_size / 1e6:.1f} MB)") + + for problem in problems: + print(f"::error::{problem}") + return 1 if problems else 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/tests/README.md b/tests/README.md index d147655..73941e1 100644 --- a/tests/README.md +++ b/tests/README.md @@ -71,8 +71,8 @@ The Chrono job also runs the **full suites** (verification, comparison, long reg - **Threads:** two tests run at a time, each with `OMP_NUM_THREADS=2`. - **Skipped tests fail the run.** CTest exits with 0 when a test returns its skip code, for example when a Python package is missing; `scripts/ci/check_ctest_junit.py` reads the JUnit report of each suite and fails unless every test ran and passed. The suite scripts write that report with `--junit FILE` (Unix) or `-Junit FILE` (Windows). - **Benchmarks do not fail the run.** Timings on shared runners are for information only. -- **Results:** each job uploads its JUnit reports and logs, and the Chrono job its Markdown reports with figures. The page of a workflow run shows each report's table of checks against limits for every platform. -- **PDF reports:** the Linux Chrono job writes the regression report as PDF on every run, and the verification and comparison reports with the full suites. The artifact `pdf-reports` holds the PDFs alone with their figures resampled to 150 dpi, for reading on screen; the full-resolution PDFs are in `chrono-linux-reports`. +- **Results:** each job uploads its JUnit reports and logs. The page of a workflow run shows each report's table of checks against limits for every platform. +- **PDF reports:** the artifact `test-reports` holds the reports of all three platforms as PDF, in the folders `linux`, `macos` and `windows`, with the figures resampled to 150 dpi for reading on screen. The regression reports are in every run; the verification and comparison reports come with the full suites. The Chrono jobs write the reports as Markdown, and a final job converts them on Linux, where pandoc and LaTeX are installed. - **Not covered:** the VSG GUI build and the release packages. ## Test-only environment variables From cc556354363a04751773c9be22b291d785af3935 Mon Sep 17 00:00:00 2001 From: David Ogden <12831266+dav-og@users.noreply.github.com> Date: Wed, 2 Dec 2026 17:16:55 +0000 Subject: [PATCH 4/4] Start a continuous integration run with the full suites.