diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f2ac3ef..7004a3f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,8 +74,11 @@ jobs: with: python-version: '3.12' + # Normally under two minutes. The limit stops a hung installation from + # holding the job until the job's own time limit. - name: Install system packages (Linux) if: ${{ runner.os == 'Linux' }} + timeout-minutes: 10 run: | sudo apt-get update sudo apt-get install --yes --no-install-recommends \ @@ -194,8 +197,11 @@ jobs: with: python-version: '3.12' + # Normally under two minutes. The limit stops a hung installation from + # holding the job until the job's own time limit. - name: Install system packages (Linux) if: ${{ runner.os == 'Linux' }} + timeout-minutes: 10 run: | sudo apt-get update sudo apt-get install --yes --no-install-recommends \ @@ -213,11 +219,14 @@ jobs: echo "CMAKE_BUILD_PARALLEL_LEVEL=3" } >> "${GITHUB_ENV}" - # pytest runs tests/unit/python/test_demo_features.py, which is skipped without it. + # tests/unit/python/test_demo_features.py runs under pytest and tests the + # demo feature tools, which need MHKiT. It reports itself as skipped when + # pytest is missing or when pytest skips any of its tests. - name: Install Python packages run: | python3 -m pip install --requirement tests/regression/run_seastack/requirements.txt python3 -m pip install pytest + python3 -m pip install --requirement data/demos/run_seastack/features/requirements.txt - name: Record the environment run: | @@ -236,7 +245,7 @@ jobs: echo "ninja $(ninja --version)" c++ --version | head -n 1 python3 --version - python3 -m pip list --format=freeze | grep -i -E '^(numpy|h5py|pyyaml|matplotlib|pytest)==' + python3 -m pip list --format=freeze | grep -i -E '^(numpy|h5py|pyyaml|matplotlib|pytest|mhkit|scipy|pandas|ruamel\.yaml)==' echo "OMP_NUM_THREADS=${OMP_NUM_THREADS} CTEST_JOBS=${CTEST_JOBS} FULL_SUITES=${FULL_SUITES}" echo "CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH:-}" git log -1 --format='Source: %H %s' @@ -626,12 +635,16 @@ jobs: path: ${{ steps.deps.outputs.archives }} key: ${{ steps.vcpkg-cache.outputs.cache-primary-key }} - # pytest runs tests/unit/python/test_demo_features.py, which is skipped without it. + # tests/unit/python/test_demo_features.py runs under pytest and tests the + # demo feature tools, which need MHKiT. It reports itself as skipped when + # pytest is missing or when pytest skips any of its tests. - name: Install Python packages run: | python -m pip install --requirement tests/regression/run_seastack/requirements.txt if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } python -m pip install pytest + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + python -m pip install --requirement data/demos/run_seastack/features/requirements.txt - name: Record the environment run: | @@ -644,7 +657,7 @@ jobs: "ninja $(ninja --version)" "MSVC tools $env:VCToolsVersion" python --version - python -m pip list --format=freeze | Select-String -Pattern '^(numpy|h5py|pyyaml|matplotlib|pytest)==' | ForEach-Object { $_.Line } + python -m pip list --format=freeze | Select-String -Pattern '^(numpy|h5py|pyyaml|matplotlib|pytest|mhkit|scipy|pandas|ruamel\.yaml)==' | ForEach-Object { $_.Line } "OMP_NUM_THREADS=$env:OMP_NUM_THREADS CTEST_JOBS=$env:CTEST_JOBS FULL_SUITES=$env:FULL_SUITES" git log -1 --format='Source: %H %s' @@ -863,7 +876,10 @@ jobs: ref: ${{ env.CHECKOUT_REF }} persist-credentials: false + # Normally under two minutes. The limit stops a hung installation from + # holding the job until the job's own time limit. - name: Install pandoc, LaTeX and Ghostscript + timeout-minutes: 10 run: | sudo apt-get update sudo apt-get install --yes --no-install-recommends \ @@ -924,13 +940,13 @@ jobs: retention-days: 30 overwrite: true - # The sources are deleted only when both Chrono jobs passed. Otherwise a - # re-run of a failed or unstarted job runs this job again, which then + # The sources are deleted only when the steps above succeeded and both + # Chrono jobs passed. Otherwise a re-run of this job or of a Chrono job # needs the sources of every platform; they expire after one day. # 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() && needs.chrono.result == 'success' && needs.chrono-windows.result == 'success' }} + if: ${{ success() && needs.chrono.result == 'success' && needs.chrono-windows.result == 'success' }} env: GH_TOKEN: ${{ github.token }} run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 156251c..ca35141 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -524,7 +524,8 @@ if(TARGET external_pto_example) endif() # ── Tests ──────────────────────────────────────────────────────────────────── -# Helper (Windows): set TEST_ENVIRONMENT so ctest finds Chrono/HDF5 DLLs +# Helper (Windows): set SEASTACK_TEST_DLL_DIRS, the directories with the +# Chrono, HDF5 and MoorDyn DLLs, in the order in which they go on PATH. function(seastack_configure_test_environment) set(DLL_DIRS "") set(SEASTACK_DLL_DIRS "${CMAKE_BINARY_DIR}/bin/Release;${CMAKE_BINARY_DIR}/bin/RelWithDebInfo;${CMAKE_BINARY_DIR}/bin/MinSizeRel;${CMAKE_BINARY_DIR}/bin/Debug") @@ -557,7 +558,36 @@ function(seastack_configure_test_environment) if(SEASTACK_ENABLE_MOORING AND TARGET moordyn) list(APPEND DLL_DIRS "$") endif() - set(TEST_ENVIRONMENT "PATH=${DLL_DIRS};$ENV{PATH}" PARENT_SCOPE) + list(REMOVE_DUPLICATES DLL_DIRS) + set(SEASTACK_TEST_DLL_DIRS "${DLL_DIRS}" PARENT_SCOPE) +endfunction() + +# Helper (Windows): put the directories of SEASTACK_TEST_DLL_DIRS in front of +# the PATH that ctest runs TEST_NAME with. Does nothing when the list is not +# defined (other platforms and Chrono-free builds). +function(seastack_prepend_test_dll_path TEST_NAME) + if(NOT DEFINED SEASTACK_TEST_DLL_DIRS) + return() + endif() + if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.22") + # Each entry puts one directory in front of PATH, so the last entry + # ends up first: add the directories in reverse order. + set(_dirs ${SEASTACK_TEST_DLL_DIRS}) + list(REVERSE _dirs) + foreach(_dir IN LISTS _dirs) + set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT_MODIFICATION + "PATH=path_list_prepend:${_dir}") + endforeach() + else() + # ENVIRONMENT is a semicolon-separated list of VAR=VALUE entries. The + # separators inside the PATH value are escaped so that it stays one + # entry; unescaped, PATH would be the first directory alone. The PATH + # of the configure step is recorded here, not that of the test run. + file(TO_CMAKE_PATH "$ENV{PATH}" _configure_path) + set(_path ${SEASTACK_TEST_DLL_DIRS} ${_configure_path}) + string(REPLACE ";" "\\;" _path "${_path}") + set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "PATH=${_path}") + endif() endfunction() if(SEASTACK_ENABLE_TESTS) diff --git a/tests/README.md b/tests/README.md index b9025d4..83e6ff3 100644 --- a/tests/README.md +++ b/tests/README.md @@ -69,7 +69,7 @@ GitHub Actions builds and tests SEA-Stack on Linux, macOS and Windows ([`.github The Chrono job also runs the **full suites** (verification, comparison, long regression, the demo cases through `run_tests.py --all` and `--extended`, and the benchmarks) every night on `dev`, on a manual run of the workflow, and on a pull request that carries the label `full-tests`. - **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). +- **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). `test_demo_features_python` runs under pytest and returns the skip code when pytest skips any of its tests, so the Chrono jobs install MHKiT from `data/demos/run_seastack/features/requirements.txt`. - **Benchmarks do not fail the run.** Timings on shared runners are for information only. - **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. diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 5a2bf3e..44b2755 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -13,9 +13,7 @@ function(build_unit_test TEST_NAME) ) set_tests_properties(${TEST_NAME} PROPERTIES LABELS "unit" COST 1) # On Windows, prepend DLL search paths so Chrono/HDF5 DLLs are found (same as legacy project) - if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND DEFINED TEST_ENVIRONMENT) - set_tests_properties(${TEST_NAME} PROPERTIES ENVIRONMENT "${TEST_ENVIRONMENT}") - endif() + seastack_prepend_test_dll_path(${TEST_NAME}) endfunction() # Windows: an unactivated conda interpreter cannot load numpy/h5py DLLs unless @@ -425,8 +423,8 @@ if(TARGET seastack_external) endif() endif() -# Demo feature tools (h5_reader.py, MHKiT_writer.py). Writer tests skip -# without MHKiT; exit code 77 = pytest not installed. +# Demo feature tools (h5_reader.py, MHKiT_writer.py). Exit code 77 = pytest +# not installed, or pytest skipped a test (the writer tests without MHKiT). find_package(Python3 COMPONENTS Interpreter QUIET) if(Python3_FOUND) add_test(NAME test_sampled_history @@ -483,9 +481,7 @@ add_test( COMMAND $ ) set_tests_properties(test_doctor PROPERTIES LABELS "unit;chrono-free" COST 1) -if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND DEFINED TEST_ENVIRONMENT) - set_tests_properties(test_doctor PROPERTIES ENVIRONMENT "${TEST_ENVIRONMENT}") -endif() +seastack_prepend_test_dll_path(test_doctor) # Excitation ramp accumulation test (Chrono-free, HDF5-free) # Regression test for the excitation ramp bug where ComputeFromTFData() @@ -583,9 +579,7 @@ if(TARGET Chrono::Chrono_core AND TARGET SEAStack::Core) WORKING_DIRECTORY "$" COMMAND $) set_tests_properties(test_eigen_allocator_abi PROPERTIES LABELS "unit;chrono" COST 1) - if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND DEFINED TEST_ENVIRONMENT) - set_tests_properties(test_eigen_allocator_abi PROPERTIES ENVIRONMENT "${TEST_ENVIRONMENT}") - endif() + seastack_prepend_test_dll_path(test_eigen_allocator_abi) endif() # Constant-coefficient (regular-wave) radiation: H5 scaling, matching, builder, diff --git a/tests/unit/python/test_demo_features.py b/tests/unit/python/test_demo_features.py index e557fd2..7c2fd00 100644 --- a/tests/unit/python/test_demo_features.py +++ b/tests/unit/python/test_demo_features.py @@ -5,8 +5,9 @@ ruamel.yaml, PyYAML). Its tests are skipped when MHKiT is not installed; nothing here downloads NDBC data. -Run with pytest, or as a script (CTest): exit code 77 means pytest is -missing and the test is skipped. +Run with pytest, or as a script (CTest). As a script, exit code 77 means that +pytest is missing or that pytest skipped at least one test; CTest then reports +the test as skipped, not as passed. Analytic references: - Significant wave height Hm0 = 4 * sqrt(m0), m0 = integral S(f) df. @@ -294,5 +295,23 @@ def test_writer_spectrum_file_end_to_end(writer, tmp_path): assert list((case / "outputs").glob("results*.h5")), "run_seastack wrote no results file" +class _SkipRecorder: + """pytest plugin: collects the tests that were skipped.""" + + def __init__(self): + self.skipped = [] + + def pytest_runtest_logreport(self, report): + if report.skipped: + self.skipped.append(report.nodeid) + + if __name__ == "__main__": - sys.exit(pytest.main([__file__, "-q", "-rs"])) + recorder = _SkipRecorder() + status = pytest.main([__file__, "-q", "-rs"], plugins=[recorder]) + if status == 0 and recorder.skipped: + # A run that left tests out must not count as passed: report it to + # CTest as skipped (SKIP_RETURN_CODE). + print(f"{len(recorder.skipped)} test(s) skipped; reporting test_demo_features as skipped") + sys.exit(77) + sys.exit(status)