diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..61374f5 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,842 @@ +# Continuous integration for SEA-Stack. +# +# Test suites and CTest labels are described in tests/README.md and +# tests/TEST_SUITES_REFERENCE.md. Each job uses the documented build and test +# entry points under scripts/, so a failure here can be reproduced locally with +# the same commands. +name: CI + +on: + push: + branches: + - dev + - main + - 'release/**' + pull_request: + types: [opened, synchronize, reopened, labeled] + # Nightly run of the full test suites on dev. Scheduled runs use the workflow + # file on the default branch. + schedule: + - cron: '17 2 * * *' + workflow_dispatch: + inputs: + full: + description: Run the full test suites (verification, comparison, long regression, demo cases, benchmarks) + type: boolean + default: true + +permissions: + contents: read + +concurrency: + group: ci-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +env: + # Thread counts are fixed so that results and timings are comparable between + # runs: 2 concurrent tests, each with 2 OpenMP threads. The standard Linux + # and Windows runners have 4 virtual CPUs and the macOS runners 3. + OMP_NUM_THREADS: '2' + OPENBLAS_NUM_THREADS: '1' + CTEST_JOBS: '2' + MPLBACKEND: Agg + # The full suites run nightly, on a manual run, and on a pull request that + # carries the label "full-tests". Other runs stop after the unit, regression + # and external tests. + FULL_SUITES: ${{ github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && inputs.full) || contains(github.event.pull_request.labels.*.name, 'full-tests') }} + # Scheduled runs test dev; every other run tests the commit that triggered it. + CHECKOUT_REF: ${{ github.event_name == 'schedule' && 'dev' || '' }} + +jobs: + chrono-free: + name: Chrono-free build and tests (${{ matrix.name }}) + runs-on: ${{ matrix.os }} + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + include: + - name: Linux + id: linux + os: ubuntu-24.04 + - name: macOS + id: macos + os: macos-15 + steps: + - name: Check out the source + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ env.CHECKOUT_REF }} + persist-credentials: false + + - name: Set up Python + uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 + with: + python-version: '3.12' + + - name: Install system packages (Linux) + if: ${{ runner.os == 'Linux' }} + run: | + sudo apt-get update + sudo apt-get install --yes --no-install-recommends \ + ninja-build libeigen3-dev libhdf5-dev + + # eigen@3 and libomp are keg-only, so CMake needs their prefixes. The + # macOS runner has 7 GB of memory: limit the build to 3 jobs. + - name: Install system packages (macOS) + if: ${{ runner.os == 'macOS' }} + run: | + brew install ninja eigen@3 hdf5 libomp + { + echo "CMAKE_PREFIX_PATH=$(brew --prefix eigen@3):$(brew --prefix hdf5):$(brew --prefix libomp)" + echo "CI_HDF5_DIR=$(brew --prefix hdf5)/lib/cmake/hdf5" + echo "CMAKE_BUILD_PARALLEL_LEVEL=3" + } >> "${GITHUB_ENV}" + + - name: Install Python packages + run: python3 -m pip install --requirement tests/regression/run_seastack/requirements.txt + + - name: Record the environment + run: | + echo "Runner: ${RUNNER_OS} ${RUNNER_ARCH}, image ${ImageOS:-unknown} ${ImageVersion:-unknown}" + echo "CPUs: $(getconf _NPROCESSORS_ONLN)" + if [[ "${RUNNER_OS}" == "macOS" ]]; then + sw_vers + sysctl -n machdep.cpu.brand_string hw.memsize + brew list --versions eigen@3 hdf5 libomp ninja + else + grep -m1 'model name' /proc/cpuinfo || true + free -g | sed -n '1,2p' + fi + df -h . + cmake --version | head -n 1 + echo "ninja $(ninja --version)" + c++ --version | head -n 1 + python3 --version + python3 -m pip list --format=freeze | grep -i -E '^(numpy|h5py|pyyaml|matplotlib)==' + echo "OMP_NUM_THREADS=${OMP_NUM_THREADS} CTEST_JOBS=${CTEST_JOBS}" + echo "CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH:-}" + + # build.sh passes PythonRoot to CMake, so the tests use the interpreter + # that has the packages installed above. + - name: Write build-config.json + run: | + printf '{"ChronoDir": "", "PythonRoot": "%s", "HDF5Dir": "%s", "Generator": ""}\n' \ + "${pythonLocation}" "${CI_HDF5_DIR:-}" > build-config.json + cat build-config.json + + - name: Build + id: build + run: ./scripts/unix/build.sh --no-chrono --external --verbose + + - name: Run the chrono-free tests + id: ctest + run: > + ctest --test-dir build -C Release -L chrono-free --no-tests=error + --output-on-failure -j "${CTEST_JOBS}" + --output-junit test-results/chrono-free.xml + + # 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.ctest.conclusion != 'skipped' }} + run: > + python3 scripts/ci/check_ctest_junit.py build/test-results/chrono-free.xml + --summary "${GITHUB_STEP_SUMMARY}" + + - name: Downstream-consumer check + if: ${{ !cancelled() && steps.build.conclusion == 'success' }} + run: ./scripts/unix/run_consumer_check.sh --work-dir "${RUNNER_TEMP}/consumer-check" + + - name: Record disk use + if: ${{ !cancelled() }} + run: | + df -h . + du -sh build || true + + - name: Upload test results + if: ${{ !cancelled() }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: chrono-free-${{ matrix.id }}-results + path: | + build/test-results/ + build/Testing/Temporary/LastTest.log + build/build-diagnostics.log + if-no-files-found: warn + retention-days: 14 + + chrono: + name: Chrono build and tests (${{ matrix.name }}) + runs-on: ${{ matrix.os }} + timeout-minutes: 240 + strategy: + fail-fast: false + matrix: + include: + - 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' || '' }} + steps: + - name: Check out the source + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ env.CHECKOUT_REF }} + submodules: recursive + persist-credentials: false + + - name: Set up Python + uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 + with: + python-version: '3.12' + + - name: Install system packages (Linux) + if: ${{ runner.os == 'Linux' }} + run: | + sudo apt-get update + sudo apt-get install --yes --no-install-recommends \ + ninja-build libeigen3-dev libhdf5-dev + + # eigen@3 and libomp are keg-only, so CMake needs their prefixes. The + # macOS runner has 7 GB of memory: limit the build to 3 jobs. + - name: Install system packages (macOS) + if: ${{ runner.os == 'macOS' }} + run: | + brew install ninja eigen@3 hdf5 libomp + { + echo "CMAKE_PREFIX_PATH=$(brew --prefix eigen@3):$(brew --prefix hdf5):$(brew --prefix libomp)" + echo "CI_HDF5_DIR=$(brew --prefix hdf5)/lib/cmake/hdf5" + echo "CMAKE_BUILD_PARALLEL_LEVEL=3" + } >> "${GITHUB_ENV}" + + # pytest runs tests/unit/python/test_demo_features.py, which is skipped without it. + - name: Install Python packages + run: | + python3 -m pip install --requirement tests/regression/run_seastack/requirements.txt + python3 -m pip install pytest + + - name: Record the environment + run: | + echo "Runner: ${RUNNER_OS} ${RUNNER_ARCH}, image ${ImageOS:-unknown} ${ImageVersion:-unknown}" + echo "CPUs: $(getconf _NPROCESSORS_ONLN)" + if [[ "${RUNNER_OS}" == "macOS" ]]; then + sw_vers + sysctl -n machdep.cpu.brand_string hw.memsize + brew list --versions eigen@3 hdf5 libomp ninja + else + grep -m1 'model name' /proc/cpuinfo || true + free -g | sed -n '1,2p' + fi + df -h . + cmake --version | head -n 1 + 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)==' + 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' + + # Chrono is built by scripts/unix/build_chrono.sh and reused until that + # script, the runner image, the compiler or (on macOS) the Homebrew + # libraries it links change. + - name: Locate the Chrono installation + id: chrono + run: | + toolchain="$( + { + c++ --version | head -n 1 + if [[ "${RUNNER_OS}" == "macOS" ]]; then + brew list --versions eigen@3 hdf5 libomp + fi + } | git hash-object --stdin | cut -c1-16 + )" + echo "prefix=${HOME}/seastack-deps/chrono-10.0.0" >> "${GITHUB_OUTPUT}" + echo "toolchain=${toolchain}" >> "${GITHUB_OUTPUT}" + + - name: Restore the Chrono installation + id: chrono-cache + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ steps.chrono.outputs.prefix }} + key: chrono-10.0.0-${{ matrix.os }}-${{ steps.chrono.outputs.toolchain }}-${{ hashFiles('scripts/unix/build_chrono.sh') }} + + - name: Build Chrono + if: ${{ steps.chrono-cache.outputs.cache-hit != 'true' }} + env: + CHRONO_PREFIX: ${{ steps.chrono.outputs.prefix }} + run: | + # Bash 3.2 (macOS): empty arrays are expanded with the ${a[@]+...} form. + options=() + if [[ "${RUNNER_OS}" == "macOS" ]]; then + options=(--jobs 3 -- + "-DEIGEN3_INCLUDE_DIR=$(brew --prefix eigen@3)/include/eigen3" + "-DHDF5_DIR=$(brew --prefix hdf5)/lib/cmake/hdf5" + "-DOpenMP_ROOT=$(brew --prefix libomp)") + fi + ./scripts/unix/build_chrono.sh --prefix "${CHRONO_PREFIX}" \ + --work-dir "${RUNNER_TEMP}/chrono-work" ${options[@]+"${options[@]}"} + rm -rf "${RUNNER_TEMP}/chrono-work" + du -sh "${CHRONO_PREFIX}" + + # Saved here, not at the end of the job, so that a test failure does not + # discard the Chrono build. + - name: Save the Chrono installation + if: ${{ steps.chrono-cache.outputs.cache-hit != 'true' }} + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ steps.chrono.outputs.prefix }} + key: ${{ steps.chrono-cache.outputs.cache-primary-key }} + + # On Linux the Chrono libraries are outside the system library path, so + # the test executables need LD_LIBRARY_PATH (docs/build/RELEASE_CHECKLIST.md). + - name: Write build-config.json + env: + CHRONO_PREFIX: ${{ steps.chrono.outputs.prefix }} + run: | + config_file="$(find "${CHRONO_PREFIX}" -name ChronoConfig.cmake -print | head -n 1)" + test -n "${config_file}" + printf '{"ChronoDir": "%s", "PythonRoot": "%s", "HDF5Dir": "%s", "Generator": ""}\n' \ + "$(dirname "${config_file}")" "${pythonLocation}" "${CI_HDF5_DIR:-}" > build-config.json + cat build-config.json + if [[ "${RUNNER_OS}" == "Linux" ]]; then + echo "LD_LIBRARY_PATH=${CHRONO_PREFIX}/lib" >> "${GITHUB_ENV}" + fi + + - name: Build + id: build + run: ./scripts/unix/build.sh --moordyn --external --demos --verbose + + - name: Run the unit tests + run: ./scripts/unix/ctest_suite.sh unit -j "${CTEST_JOBS}" --junit test-results/unit.xml + + - name: Run the regression tests + if: ${{ !cancelled() && steps.build.conclusion == 'success' }} + run: > + ./scripts/unix/ctest_suite.sh regression -j "${CTEST_JOBS}" --no-pdf + --junit test-results/regression.xml + + - name: Run the external-module tests + if: ${{ !cancelled() && steps.build.conclusion == 'success' }} + run: > + ctest --test-dir build -C Release -L '^external$' --no-tests=error + --output-on-failure -j "${CTEST_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: > + ./scripts/unix/ctest_suite.sh verification -j "${CTEST_JOBS}" ${PDF_OPTION} + --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} + --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} + --junit test-results/regression-long.xml + + - name: Run the demo cases against their baselines + if: ${{ !cancelled() && steps.build.conclusion == 'success' && env.FULL_SUITES == 'true' }} + run: > + python3 tests/regression/run_seastack/run_tests.py --all --quiet + --exe build/bin/Release/run_seastack + + # Wall-clock timings on shared runners are for information only, so this + # step does not fail the job. + - name: Run the benchmarks + if: ${{ !cancelled() && steps.build.conclusion == 'success' && env.FULL_SUITES == 'true' }} + 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 }} + run: | + 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 + echo "::error::PDF report missing or empty: ${report}" + status=1 + fi + 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' }} + run: | + suites="unit regression external" + if [[ "${FULL_SUITES}" == "true" ]]; then + suites="${suites} verification comparison regression-long" + fi + status=0 + for suite in ${suites}; do + python3 scripts/ci/check_ctest_junit.py "build/test-results/${suite}.xml" \ + --summary "${GITHUB_STEP_SUMMARY}" || status=1 + done + exit "${status}" + + - name: Record disk use + if: ${{ !cancelled() }} + run: | + df -h . + du -sh build || true + + - name: Upload test results + if: ${{ !cancelled() }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: chrono-${{ matrix.id }}-results + path: | + build/test-results/ + build/Testing/Temporary/LastTest.log + build/build-diagnostics.log + if-no-files-found: warn + retention-days: 14 + + # Markdown and PDF reports with the figures they refer to. + - name: Upload test reports + if: ${{ !cancelled() && steps.build.conclusion == 'success' }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: chrono-${{ matrix.id }}-reports + path: | + build/bin/Release/results/tests/*/report/ + build/bin/Release/results/tests/**/plots/ + 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: + name: Chrono-free build and tests (Windows) + runs-on: windows-2022 + timeout-minutes: 60 + steps: + - name: Check out the source + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ env.CHECKOUT_REF }} + persist-credentials: false + + - name: Set up Python + uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 + with: + python-version: '3.12' + + # Exports the Visual Studio x64 compiler environment (vcvars64.bat) to the + # following steps, so that CMake can use Ninja with cl. + - name: Set up the MSVC environment + run: | + $vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" + $vsPath = & $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath + $vcvars = Join-Path $vsPath 'VC\Auxiliary\Build\vcvars64.bat' + if (-not (Test-Path -LiteralPath $vcvars)) { throw "vcvars64.bat not found: $vcvars" } + $before = @{} + Get-ChildItem Env: | ForEach-Object { $before[$_.Name] = $_.Value } + cmd /c "`"$vcvars`" >nul 2>&1 && set" | ForEach-Object { + if ($_ -match '^([^=]+)=(.*)$' -and $before[$Matches[1]] -ne $Matches[2]) { + "$($Matches[1])=$($Matches[2])" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + } + } + + - name: Locate vcpkg + id: vcpkg + run: | + $root = $env:VCPKG_INSTALLATION_ROOT + $commit = git -c safe.directory=* -C $root rev-parse --short=12 HEAD + if ($LASTEXITCODE -ne 0) { throw "cannot read the vcpkg commit in $root" } + $archives = Join-Path $HOME 'seastack-deps\vcpkg-archives' + New-Item -ItemType Directory -Force -Path $archives | Out-Null + "commit=$commit" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append + "archives=$archives" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append + "VCPKG_DEFAULT_BINARY_CACHE=$archives" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + "VCPKG_INSTALLED=$(($root -replace '\\', '/'))/installed/x64-windows" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + + - name: Restore the vcpkg binary cache + id: vcpkg-cache + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ steps.vcpkg.outputs.archives }} + key: vcpkg-windows-2022-${{ steps.vcpkg.outputs.commit }}-eigen3-hdf5 + + - name: Install Eigen and HDF5 + run: | + & "$env:VCPKG_INSTALLATION_ROOT\vcpkg.exe" install eigen3:x64-windows "hdf5[cpp,hl,szip,zlib]:x64-windows" + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + & "$env:VCPKG_INSTALLATION_ROOT\vcpkg.exe" list + + - name: Save the vcpkg binary cache + if: ${{ steps.vcpkg-cache.outputs.cache-hit != 'true' }} + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ steps.vcpkg.outputs.archives }} + key: ${{ steps.vcpkg-cache.outputs.cache-primary-key }} + + - name: Install Python packages + run: python -m pip install --requirement tests/regression/run_seastack/requirements.txt + + - name: Record the environment + run: | + "Runner: $env:RUNNER_OS $env:RUNNER_ARCH, image $env:ImageOS $env:ImageVersion" + "CPUs: $([Environment]::ProcessorCount)" + (Get-CimInstance Win32_Processor).Name + "Memory: {0:N0} GB" -f ((Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory / 1GB) + Get-PSDrive -PSProvider FileSystem | Format-Table Name, @{n='Used (GB)';e={[int]($_.Used/1GB)}}, @{n='Free (GB)';e={[int]($_.Free/1GB)}} + cmake --version | Select-Object -First 1 + "ninja $(ninja --version)" + "MSVC tools $env:VCToolsVersion" + python --version + python -m pip list --format=freeze | Select-String -Pattern '^(numpy|h5py|pyyaml|matplotlib)==' | ForEach-Object { $_.Line } + "OMP_NUM_THREADS=$env:OMP_NUM_THREADS CTEST_JOBS=$env:CTEST_JOBS" + + # CMakePrefixPath lets the Chrono-free configure find Eigen in vcpkg. The + # HDF5 DLLs are not copied next to the tests in a Chrono-free build, so + # their folder goes on PATH (docs/build/BUILD_WINDOWS.md, Troubleshooting). + - name: Write build-config.json and add the HDF5 DLLs to PATH + run: | + "$($env:VCPKG_INSTALLED -replace '/', '\')\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + [ordered]@{ + ChronoDir = '' + PythonRoot = ($env:pythonLocation -replace '\\', '/') + HDF5Dir = "$env:VCPKG_INSTALLED/share/hdf5" + CMakePrefixPath = $env:VCPKG_INSTALLED + Generator = '' + } | ConvertTo-Json | Set-Content -Encoding ascii build-config.json + Get-Content build-config.json + + - name: Build + id: build + run: .\scripts\windows\build.ps1 -NoChrono -External -Verbose + + - name: Run the chrono-free tests + id: ctest + run: .\scripts\windows\run_chrono_free_tests.ps1 -j $env:CTEST_JOBS -Junit test-results/chrono-free.xml + + # 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.ctest.conclusion != 'skipped' }} + run: python scripts/ci/check_ctest_junit.py build/test-results/chrono-free.xml --summary $env:GITHUB_STEP_SUMMARY + + - name: Downstream-consumer check + if: ${{ !cancelled() && steps.build.conclusion == 'success' }} + run: .\scripts\windows\run_consumer_check.ps1 -WorkDir (Join-Path $env:RUNNER_TEMP 'consumer-check') + + - name: Upload test results + if: ${{ !cancelled() }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: chrono-free-windows-results + path: | + build/test-results/ + build/Testing/Temporary/LastTest.log + build/build-diagnostics.log + if-no-files-found: warn + retention-days: 14 + + chrono-windows: + name: Chrono build and tests (Windows) + runs-on: windows-2022 + timeout-minutes: 240 + steps: + - name: Check out the source + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ env.CHECKOUT_REF }} + submodules: recursive + persist-credentials: false + + - name: Set up Python + uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 + with: + python-version: '3.12' + + # Exports the Visual Studio x64 compiler environment (vcvars64.bat) to the + # following steps, so that CMake can use Ninja with cl. + - name: Set up the MSVC environment + run: | + $vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" + $vsPath = & $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath + $vcvars = Join-Path $vsPath 'VC\Auxiliary\Build\vcvars64.bat' + if (-not (Test-Path -LiteralPath $vcvars)) { throw "vcvars64.bat not found: $vcvars" } + $before = @{} + Get-ChildItem Env: | ForEach-Object { $before[$_.Name] = $_.Value } + cmd /c "`"$vcvars`" >nul 2>&1 && set" | ForEach-Object { + if ($_ -match '^([^=]+)=(.*)$' -and $before[$Matches[1]] -ne $Matches[2]) { + "$($Matches[1])=$($Matches[2])" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + } + } + + - name: Locate vcpkg and the Chrono installation + id: deps + run: | + $root = $env:VCPKG_INSTALLATION_ROOT + $commit = git -c safe.directory=* -C $root rev-parse --short=12 HEAD + if ($LASTEXITCODE -ne 0) { throw "cannot read the vcpkg commit in $root" } + $archives = Join-Path $HOME 'seastack-deps\vcpkg-archives' + New-Item -ItemType Directory -Force -Path $archives | Out-Null + "commit=$commit" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append + "archives=$archives" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append + "chrono=$(Join-Path $HOME 'seastack-deps\chrono-10.0.0')" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append + "msvc=$env:VCToolsVersion" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append + "VCPKG_DEFAULT_BINARY_CACHE=$archives" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + "VCPKG_INSTALLED=$(($root -replace '\\', '/'))/installed/x64-windows" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + + - name: Restore the vcpkg binary cache + id: vcpkg-cache + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ steps.deps.outputs.archives }} + key: vcpkg-windows-2022-${{ steps.deps.outputs.commit }}-eigen3-hdf5 + + - name: Install Eigen and HDF5 + run: | + & "$env:VCPKG_INSTALLATION_ROOT\vcpkg.exe" install eigen3:x64-windows "hdf5[cpp,hl,szip,zlib]:x64-windows" + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + & "$env:VCPKG_INSTALLATION_ROOT\vcpkg.exe" list + + - name: Save the vcpkg binary cache + if: ${{ steps.vcpkg-cache.outputs.cache-hit != 'true' }} + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + 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. + - 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 + + - name: Record the environment + run: | + "Runner: $env:RUNNER_OS $env:RUNNER_ARCH, image $env:ImageOS $env:ImageVersion" + "CPUs: $([Environment]::ProcessorCount)" + (Get-CimInstance Win32_Processor).Name + "Memory: {0:N0} GB" -f ((Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory / 1GB) + Get-PSDrive -PSProvider FileSystem | Format-Table Name, @{n='Used (GB)';e={[int]($_.Used/1GB)}}, @{n='Free (GB)';e={[int]($_.Free/1GB)}} + cmake --version | Select-Object -First 1 + "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 } + "OMP_NUM_THREADS=$env:OMP_NUM_THREADS CTEST_JOBS=$env:CTEST_JOBS FULL_SUITES=$env:FULL_SUITES" + git log -1 --format='Source: %H %s' + + # Chrono is built by scripts/windows/build_chrono.ps1 and reused until that + # script, the HDF5 shim, the compiler or the vcpkg checkout changes. + - name: Restore the Chrono installation + id: chrono-cache + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ steps.deps.outputs.chrono }} + key: chrono-10.0.0-windows-2022-msvc${{ steps.deps.outputs.msvc }}-vcpkg${{ steps.deps.outputs.commit }}-${{ hashFiles('scripts/windows/build_chrono.ps1', 'cmake/ChronoHdf5ToolsShim.cmake') }} + + - name: Build Chrono + if: ${{ steps.chrono-cache.outputs.cache-hit != 'true' }} + env: + CHRONO_PREFIX: ${{ steps.deps.outputs.chrono }} + run: | + $work = Join-Path $env:RUNNER_TEMP 'chrono-work' + # The log is uploaded with the test results, so a failed Chrono build can be diagnosed. + $log = Join-Path $env:GITHUB_WORKSPACE 'chrono-build.log' + .\scripts\windows\build_chrono.ps1 -Prefix $env:CHRONO_PREFIX -WorkDir $work -VcpkgRoot $env:VCPKG_INSTALLATION_ROOT *>&1 | + Tee-Object -FilePath $log + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + # Removing the work folder frees disk space; a locked file there must not fail the job. + Remove-Item -Recurse -Force $work -ErrorAction SilentlyContinue + exit 0 + + # Saved here, not at the end of the job, so that a test failure does not + # discard the Chrono build. + - name: Save the Chrono installation + if: ${{ steps.chrono-cache.outputs.cache-hit != 'true' }} + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ steps.deps.outputs.chrono }} + key: ${{ steps.chrono-cache.outputs.cache-primary-key }} + + - name: Write build-config.json + env: + CHRONO_PREFIX: ${{ steps.deps.outputs.chrono }} + run: | + $config = Get-ChildItem -LiteralPath $env:CHRONO_PREFIX -Recurse -File | + Where-Object { $_.Name -in 'ChronoConfig.cmake', 'chrono-config.cmake' } | Select-Object -First 1 + if (-not $config) { throw "no Chrono package config under $env:CHRONO_PREFIX" } + # CMakePrefixPath lets vcpkg's HDF5 package find its ZLIB dependency + # (docs/build/BUILD_WINDOWS.md, section 2). + [ordered]@{ + ChronoDir = ($config.DirectoryName -replace '\\', '/') + PythonRoot = ($env:pythonLocation -replace '\\', '/') + HDF5Dir = "$env:VCPKG_INSTALLED/share/hdf5" + CMakePrefixPath = $env:VCPKG_INSTALLED + Generator = '' + } | ConvertTo-Json | Set-Content -Encoding ascii build-config.json + Get-Content build-config.json + + - name: Build + id: build + run: .\scripts\windows\build.ps1 -MoorDyn -External -Demos -Verbose + + # The test programs load the vcpkg DLLs from the output folder, where + # build.ps1 copies them. Fail with a clear message if a DLL staged from + # vcpkg imports another vcpkg DLL that was not staged (for example after + # vcpkg renames a library), instead of letting every test stop with + # 0xc0000135. The listing is uploaded with the test results. + - name: Check the staged vcpkg DLLs + if: ${{ !cancelled() && steps.build.conclusion == 'success' }} + run: | + $bin = 'build\bin\Release' + $vcpkgBin = "$($env:VCPKG_INSTALLED -replace '/', '\')\bin" + New-Item -ItemType Directory -Force -Path 'build\test-results' | Out-Null + $report = 'build\test-results\staged-dlls.txt' + $staged = @(Get-ChildItem $bin -Filter *.dll | ForEach-Object { $_.Name }) + $vcpkgDlls = @(Get-ChildItem $vcpkgBin -Filter *.dll | ForEach-Object { $_.Name }) + "DLLs in $bin after build.ps1:" | Out-File $report -Encoding utf8 + $staged | Sort-Object | Out-File $report -Encoding utf8 -Append + "DLLs in ${vcpkgBin}:" | Out-File $report -Encoding utf8 -Append + $vcpkgDlls | Sort-Object | Out-File $report -Encoding utf8 -Append + $missing = @() + foreach ($dll in ($staged | Where-Object { $_ -in $vcpkgDlls })) { + $imports = @(dumpbin /nologo /dependents (Join-Path $bin $dll) | + Where-Object { $_ -match '^\s+\S+\.dll\s*$' } | ForEach-Object { $_.Trim() }) + "Imports of ${dll}: $($imports -join ', ')" | Out-File $report -Encoding utf8 -Append + foreach ($import in $imports) { + if ($import -in $vcpkgDlls -and $import -notin $staged) { $missing += "$dll imports $import" } + } + } + Get-Content $report + if ($missing) { + $missing | ForEach-Object { "::error::vcpkg DLL not staged next to the tests: $_" } + exit 1 + } + "[OK] every vcpkg DLL imported by a staged vcpkg DLL is staged" + + - name: Run the unit tests + run: .\scripts\windows\run_unit_tests.ps1 -j $env:CTEST_JOBS -Junit test-results/unit.xml + + - name: Run the regression tests + if: ${{ !cancelled() && steps.build.conclusion == 'success' }} + run: .\scripts\windows\run_regression_tests.ps1 -j $env:CTEST_JOBS -NoPdf -Junit test-results/regression.xml + + - name: Run the external-module tests + if: ${{ !cancelled() && steps.build.conclusion == 'success' }} + run: > + ctest --test-dir build -C Release -L '^external$' --no-tests=error + --output-on-failure -j $env:CTEST_JOBS + --output-junit test-results/external.xml + + # ---- Full suites (see FULL_SUITES above); Markdown reports only ---- + - name: Run the verification tests + if: ${{ !cancelled() && steps.build.conclusion == 'success' && env.FULL_SUITES == 'true' }} + run: .\scripts\windows\run_verification_tests.ps1 -j $env:CTEST_JOBS -NoPdf -Junit test-results/verification.xml + + - name: Run the comparison tests + if: ${{ !cancelled() && steps.build.conclusion == 'success' && env.FULL_SUITES == 'true' }} + run: .\scripts\windows\run_comparison_tests.ps1 -j $env:CTEST_JOBS -NoPdf -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\windows\run_regression_tests.ps1 -Long -j $env:CTEST_JOBS -NoPdf -Junit test-results/regression-long.xml + + - name: Run the demo cases against their baselines + if: ${{ !cancelled() && steps.build.conclusion == 'success' && env.FULL_SUITES == 'true' }} + run: > + python tests/regression/run_seastack/run_tests.py --all --quiet + --exe build/bin/Release/run_seastack.exe + + # Wall-clock timings on shared runners are for information only, so this + # step does not fail the job. + - name: Run the benchmarks + if: ${{ !cancelled() && steps.build.conclusion == 'success' && env.FULL_SUITES == 'true' }} + continue-on-error: true + run: .\scripts\windows\run_benchmarks.ps1 + + # 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' }} + run: | + $suites = @('unit', 'regression', 'external') + if ($env:FULL_SUITES -eq 'true') { $suites += 'verification', 'comparison', 'regression-long' } + $status = 0 + foreach ($suite in $suites) { + python scripts/ci/check_ctest_junit.py "build/test-results/$suite.xml" --summary $env:GITHUB_STEP_SUMMARY + if ($LASTEXITCODE -ne 0) { $status = 1 } + } + exit $status + + - name: Upload test results + if: ${{ !cancelled() }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: chrono-windows-results + path: | + build/test-results/ + build/Testing/Temporary/LastTest.log + build/build-diagnostics.log + chrono-build.log + if-no-files-found: warn + retention-days: 14 + + # Markdown reports with the figures they refer to. + - name: Upload test reports + if: ${{ !cancelled() && steps.build.conclusion == 'success' }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: chrono-windows-reports + path: | + build/bin/Release/results/tests/*/report/ + build/bin/Release/results/tests/**/plots/ + if-no-files-found: warn + retention-days: 30 + + # 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] + runs-on: ubuntu-24.04 + timeout-minutes: 5 + steps: + - name: Require every job to have passed + env: + RESULTS: ${{ join(needs.*.result, ' ') }} + run: | + echo "Job results: ${RESULTS}" + for result in ${RESULTS}; do + if [[ "${result}" != "success" ]]; then + echo "::error::a job did not pass (${result})" + exit 1 + fi + done diff --git a/CMakeLists.txt b/CMakeLists.txt index 29228cd..156251c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -838,12 +838,14 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") endif() endif() endforeach() - # vcpkg-style HDF5: zlib1.dll / szip.dll sit next to hdf5.dll but are not + # vcpkg-style HDF5: the zlib and szip DLLs sit next to hdf5.dll but are not # separate imported targets; install them so staged installs and CPack run. + # vcpkg's zlib DLL is zlib1.dll in older releases and libz.dll in newer ones; + # only the files that exist are installed. get_target_property(_hdf5_main_dll hdf5::hdf5-shared IMPORTED_LOCATION_RELEASE) if(_hdf5_main_dll AND EXISTS "${_hdf5_main_dll}") get_filename_component(_hdf5_peer_dir "${_hdf5_main_dll}" DIRECTORY) - foreach(_hdf5_peer_dll IN ITEMS zlib1.dll szip.dll) + foreach(_hdf5_peer_dll IN ITEMS zlib1.dll libz.dll szip.dll) set(_hdf5_peer "${_hdf5_peer_dir}/${_hdf5_peer_dll}") if(EXISTS "${_hdf5_peer}") install(FILES "${_hdf5_peer}" DESTINATION bin COMPONENT runtime) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ea26f9b..9dc8e5f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -139,6 +139,20 @@ See [tests/README.md](tests/README.md) for suite overview and how to run tests. For per-case tables and CI-style `ctest` usage, see [tests/TEST_SUITES_REFERENCE.md](tests/TEST_SUITES_REFERENCE.md). +### Continuous integration + +Every pull request is built and tested on Linux, macOS and Windows by GitHub +Actions ([`.github/workflows/ci.yml`](.github/workflows/ci.yml)). The jobs run +the same build and test scripts as a local build, so a failure can be +reproduced with the commands shown in the job log. What runs, and when, is +described in [tests/README.md](tests/README.md#continuous-integration). + +- A run fails if a test fails **or is skipped**. +- Add the label **`full-tests`** to a pull request to also run the + verification, comparison and long regression suites before merging. +- If a test fails on one platform only, report it in the pull request. Do not + regenerate reference data or widen a tolerance to make the run pass. + ## License diff --git a/cmake/ChronoHdf5ToolsShim.cmake b/cmake/ChronoHdf5ToolsShim.cmake new file mode 100644 index 0000000..536f61f --- /dev/null +++ b/cmake/ChronoHdf5ToolsShim.cmake @@ -0,0 +1,25 @@ +# HDF5 "tools" target shim for building Project Chrono 10.0.0 (not used by the +# SEA-Stack build itself). +# +# Chrono links hdf5::hdf5_tools-shared (or -static) whenever the HDF5 package +# config provides hdf5::hdf5-shared (or -static). Some HDF5 packages, vcpkg's +# among them, do not export the tools target, and the Chrono configure then +# stops with "target hdf5::hdf5_tools-shared was not found". +# +# Pass this file to the Chrono configure so that it runs right after project(): +# -DCMAKE_PROJECT_INCLUDE=/cmake/ChronoHdf5ToolsShim.cmake +# scripts/windows/build_chrono.ps1 does this. It defines the missing target as +# an interface to the main HDF5 library; targets that exist are left untouched. + +find_package(hdf5 CONFIG QUIET) + +foreach(_seastack_hdf5_kind shared static) + if(TARGET hdf5::hdf5-${_seastack_hdf5_kind} + AND NOT TARGET hdf5::hdf5_tools-${_seastack_hdf5_kind}) + add_library(hdf5::hdf5_tools-${_seastack_hdf5_kind} INTERFACE IMPORTED GLOBAL) + set_target_properties(hdf5::hdf5_tools-${_seastack_hdf5_kind} PROPERTIES + INTERFACE_LINK_LIBRARIES hdf5::hdf5-${_seastack_hdf5_kind}) + message(STATUS "ChronoHdf5ToolsShim: defined hdf5::hdf5_tools-${_seastack_hdf5_kind}") + endif() +endforeach() +unset(_seastack_hdf5_kind) diff --git a/docs/build/BUILD_CHRONO.md b/docs/build/BUILD_CHRONO.md index a8837f7..16df259 100644 --- a/docs/build/BUILD_CHRONO.md +++ b/docs/build/BUILD_CHRONO.md @@ -57,15 +57,24 @@ SEA-Stack’s `build-config.example.json` uses an **install** prefix path such a ## Windows example (Visual Studio + vcpkg HDF5 / Eigen) -Prerequisites (see [BUILD_WINDOWS.md](BUILD_WINDOWS.md)): Visual Studio C++ workload, CMake, and vcpkg packages such as `hdf5[cpp]:x64-windows` and Eigen if not supplied elsewhere. +Prerequisites (see [BUILD_WINDOWS.md](BUILD_WINDOWS.md)): Visual Studio C++ workload, CMake, and vcpkg packages such as `hdf5[cpp,hl]:x64-windows` and `eigen3:x64-windows` if not supplied elsewhere. Chrono links the HDF5 high-level libraries, so the `hl` feature is needed as well as `cpp`. -Configure Chrono (adjust paths): +[`scripts/windows/build_chrono.ps1`](../../scripts/windows/build_chrono.ps1) runs the recipe below for the pinned `10.0.0` tag from a Visual Studio x64 developer shell: + +```powershell +.\scripts\windows\build_chrono.ps1 -Prefix C:/path/to/chrono-install -VcpkgRoot C:/path/to/vcpkg +``` + +It also turns off the optional Python parser (`CMAKE_DISABLE_FIND_PACKAGE_Python3=ON`), so no Chrono library links Python. The continuous integration workflow builds Chrono with the same script. + +To configure Chrono by hand (adjust paths): ```powershell cmake -S C:/path/to/chrono-src -B C:/path/to/chrono-build ` -G "Visual Studio 17 2022" -A x64 ` -DCMAKE_INSTALL_PREFIX=C:/path/to/chrono-install ` -DCMAKE_TOOLCHAIN_FILE=C:/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake ` + -DCMAKE_PROJECT_INCLUDE=C:/path/to/sea-stack/cmake/ChronoHdf5ToolsShim.cmake ` -DBUILD_SHARED_LIBS=ON ` -DCH_ENABLE_MODULE_PARSERS=ON ` -DCH_ENABLE_HDF5=ON ` @@ -88,6 +97,8 @@ Then in `build-config.json`: "ChronoDir": "C:/path/to/chrono-install/cmake" ``` +**`CMAKE_PROJECT_INCLUDE`** is needed with vcpkg's HDF5: Chrono 10.0.0 links a target named `hdf5::hdf5_tools-shared`, which that package does not export, and the configure otherwise stops with *"target was not found"*. [`cmake/ChronoHdf5ToolsShim.cmake`](../../cmake/ChronoHdf5ToolsShim.cmake) defines the missing target and leaves existing targets untouched. + If you do **not** use the vcpkg toolchain when configuring Chrono, you must still ensure **HDF5**, **ZLIB**, and other transitive dependencies are discoverable (e.g. `CMAKE_PREFIX_PATH` pointing at `vcpkg/installed/x64-windows`). Using **`CMAKE_TOOLCHAIN_FILE`** is the most reproducible approach on Windows. --- @@ -134,6 +145,18 @@ cmake --build /path/to/chrono-build --parallel cmake --install /path/to/chrono-build ``` +[`scripts/unix/build_chrono.sh`](../../scripts/unix/build_chrono.sh) runs this +recipe for the pinned `10.0.0` tag and checks the result: + +```bash +./scripts/unix/build_chrono.sh --prefix /path/to/chrono-install # headless +./scripts/unix/build_chrono.sh --prefix /path/to/chrono-install --vsg --prefix-path /path/to/vsg-install +``` + +It also turns off the optional Python parser +(`CMAKE_DISABLE_FIND_PACKAGE_Python3=ON`), so no Chrono library links Python. +The continuous integration workflow builds Chrono with the same script. + Notes: - **`CH_USE_SIMD=OFF`** is what keeps `-march=native` out of Chrono objects and @@ -185,6 +208,18 @@ If you will build a redistributable macOS ZIP (`--package`), add these two optio - **`CMAKE_DISABLE_FIND_PACKAGE_Python3=ON`**: Chrono's Parsers module auto-detects Python and, if found, links `libChrono_parsers` against it (on the release build Mac it found the Command Line Tools Python 3.9). SEA-Stack only uses the YAML parser, but that link would make the package require the build machine's Python install. With this option `CHRONO_HAS_PYTHON` is undefined in `ChConfigParsers.h`, and no Chrono library links Python. - **`CH_USE_EIGEN_OPENMP=OFF`**: the macOS v1.0.0 Chrono libraries were built with Eigen's internal OpenMP parallelism off (`EIGEN_DONT_PARALLELIZE`), as in the earlier release candidates. Keep it off so the package matches the tested build. +`scripts/unix/build_chrono.sh` applies both options on macOS. With Homebrew, pass the locations of the keg-only Eigen 3 and libomp, and of HDF5: + +```bash +export CMAKE_PREFIX_PATH="$(brew --prefix eigen@3):$(brew --prefix hdf5):$(brew --prefix libomp)" +./scripts/unix/build_chrono.sh --prefix /path/to/chrono-install -- \ + "-DEIGEN3_INCLUDE_DIR=$(brew --prefix eigen@3)/include/eigen3" \ + "-DHDF5_DIR=$(brew --prefix hdf5)/lib/cmake/hdf5" \ + "-DOpenMP_ROOT=$(brew --prefix libomp)" +``` + +The script also sets `CMAKE_INSTALL_NAME_DIR` to the `lib` folder of the install prefix. Chrono 10.0.0 otherwise installs its libraries with a bare file name as install name, and a program linked against the installation stops with *"dyld: Library not loaded: libChrono_core.dylib"*. A Chrono build tree does not have this problem. + Use a separate Chrono build directory for this configuration and point `ChronoDir` at it. The SEA-Stack packaging step aborts if any bundled library still references a path outside the package. --- diff --git a/scripts/README.md b/scripts/README.md index dbedeb1..fbe8bf9 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -4,6 +4,7 @@ |----------|-----| | [`unix/`](unix/) | Bash drivers for **macOS and Linux** (build, CTest wrappers, demo smoke). | | [`windows/`](windows/) | **PowerShell** equivalents for Windows. | +| [`ci/`](ci/) | Helpers for the continuous integration workflows in `.github/workflows/`. | | Repo root of `scripts/` | Cross-platform **Python** helpers (`seastack_build_prepare.py`, `validate_campaign_schema.py`). | From the **sea-stack** repository root: diff --git a/scripts/ci/check_ctest_junit.py b/scripts/ci/check_ctest_junit.py new file mode 100644 index 0000000..73a65a0 --- /dev/null +++ b/scripts/ci/check_ctest_junit.py @@ -0,0 +1,136 @@ +#!/usr/bin/env python3 +"""Check a CTest JUnit report: every registered test must have run and passed. + +Usage: + python3 scripts/ci/check_ctest_junit.py [--summary FILE] [--slowest N] + +Write the report with `ctest --output-junit `. + +CTest exits with 0 when a test is skipped, for example when a Python test +returns its SKIP_RETURN_CODE because a package is missing. On a continuous +integration runner every dependency is expected to be installed, so a skipped +test means that the run did not check what it claims to check. This script +fails when: + - the report contains no tests; + - a test failed; + - a test was skipped, disabled or not run. + +--summary appends a Markdown summary to FILE (for example the file named by +GITHUB_STEP_SUMMARY). --slowest sets how many of the slowest tests are listed +(default 10). + +Exit code 0 = pass, 1 = fail, 2 = usage error or unreadable report. +Standard library only. +""" +from __future__ import annotations + +import argparse +import sys +import xml.etree.ElementTree as ET +from pathlib import Path +from typing import NamedTuple + + +class TestResult(NamedTuple): + name: str + outcome: str # "passed", "failed" or "not run" + detail: str + seconds: float + + +def classify(case: ET.Element) -> TestResult: + """Map one element to passed / failed / not run.""" + name = case.get("name", "") + status = case.get("status", "") + try: + seconds = float(case.get("time", "0") or 0.0) + except ValueError: + seconds = 0.0 + + failure = case.find("failure") + if failure is None: + failure = case.find("error") + skipped = case.find("skipped") + + if status == "run" and failure is None and skipped is None: + return TestResult(name, "passed", "", seconds) + if status == "fail" or failure is not None: + message = failure.get("message", "") if failure is not None else "" + return TestResult(name, "failed", message, seconds) + message = skipped.get("message", "") if skipped is not None else "" + return TestResult(name, "not run", message or f"status={status or 'missing'}", seconds) + + +def read_results(report: Path) -> list[TestResult]: + root = ET.parse(report).getroot() + return [classify(case) for case in root.iter("testcase")] + + +def markdown_summary(title: str, results: list[TestResult], slowest: int) -> str: + passed = sum(r.outcome == "passed" for r in results) + failed = [r for r in results if r.outcome == "failed"] + not_run = [r for r in results if r.outcome == "not run"] + total_seconds = sum(r.seconds for r in results) + + lines = [ + f"### {title}", + "", + "| Tests | Passed | Failed | Skipped or not run | Summed test time |", + "|------:|-------:|-------:|-------------------:|-----------------:|", + f"| {len(results)} | {passed} | {len(failed)} | {len(not_run)} | {total_seconds:.1f} s |", + "", + ] + problems = failed + not_run + if problems: + lines += ["| Test | Outcome | Detail |", "|------|---------|--------|"] + lines += [f"| `{r.name}` | {r.outcome} | {r.detail} |" for r in problems] + lines.append("") + if slowest > 0 and results: + ranked = sorted(results, key=lambda r: r.seconds, reverse=True)[:slowest] + lines += ["| Slowest tests | Time |", "|---------------|-----:|"] + lines += [f"| `{r.name}` | {r.seconds:.1f} s |" for r in ranked] + lines.append("") + return "\n".join(lines) + "\n" + + +def main() -> int: + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument("report", type=Path, help="JUnit XML written by ctest --output-junit") + parser.add_argument("--summary", type=Path, help="append a Markdown summary to this file") + parser.add_argument("--slowest", type=int, default=10, help="number of slowest tests to list") + args = parser.parse_args() + + if not args.report.is_file(): + print(f"[FAIL] JUnit report not found: {args.report}", file=sys.stderr) + return 2 + try: + results = read_results(args.report) + except ET.ParseError as error: + print(f"[FAIL] cannot parse {args.report}: {error}", file=sys.stderr) + return 2 + + summary = markdown_summary(f"CTest results: {args.report.stem}", results, args.slowest) + if args.summary is not None: + with args.summary.open("a", encoding="utf-8") as handle: + handle.write(summary) + + failed = [r for r in results if r.outcome == "failed"] + not_run = [r for r in results if r.outcome == "not run"] + passed = len(results) - len(failed) - len(not_run) + print(f"{args.report}: {len(results)} tests, {passed} passed, " + f"{len(failed)} failed, {len(not_run)} skipped or not run") + for result in failed + not_run: + print(f" [{result.outcome}] {result.name}: {result.detail}") + + if not results: + print("[FAIL] the report contains no tests", file=sys.stderr) + return 1 + if failed or not_run: + print("[FAIL] every registered test must run and pass", file=sys.stderr) + return 1 + print("[OK] every registered test ran and passed") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/scripts/unix/build_chrono.sh b/scripts/unix/build_chrono.sh new file mode 100755 index 0000000..769071d --- /dev/null +++ b/scripts/unix/build_chrono.sh @@ -0,0 +1,161 @@ +#!/usr/bin/env bash +# Build and install Project Chrono for SEA-Stack on macOS/Linux. +# +# Implements the portable recipe in docs/build/BUILD_CHRONO.md: release tag +# 10.0.0, Parsers + HDF5 + OpenMP, CH_USE_SIMD=OFF and a 16-byte Eigen +# alignment (the Eigen ABI contract of SEAStack::Core), no Python link. On +# macOS, Eigen's internal OpenMP parallelism is off (CH_USE_EIGEN_OPENMP=OFF), +# as in the released macOS packages. +# +# Usage: scripts/unix/build_chrono.sh --prefix DIR [options] [-- CMAKE_ARG...] +# --prefix DIR Install prefix (required), e.g. /opt/chrono-10.0.0 +# --work-dir DIR Source and build directory +# (default: ${TMPDIR:-/tmp}/seastack-chrono-10.0.0) +# --vsg Enable the Chrono VSG module (needs VSG, vsgXchange and +# vsgImGui; pass their install prefix with --prefix-path) +# --prefix-path PATH Extra CMAKE_PREFIX_PATH (e.g. the VSG install prefix) +# --jobs N Parallel build jobs (default: CMake/Ninja default) +# -h, --help This help +# -- CMAKE_ARG... Extra arguments for the Chrono CMake configure, e.g. on +# macOS with Homebrew: +# -- "-DEIGEN3_INCLUDE_DIR=$(brew --prefix eigen@3)/include/eigen3" +# "-DOpenMP_ROOT=$(brew --prefix libomp)" +# +# Prerequisites: git, cmake, a C++17 compiler, Eigen3, HDF5 and OpenMP (see +# docs/build/BUILD_MACOS.md). Ninja is used when it is on PATH. +# +# After a successful run, set "ChronoDir" in build-config.json to the directory +# printed at the end (the one that contains ChronoConfig.cmake). +set -euo pipefail + +CHRONO_REPOSITORY="https://github.com/projectchrono/chrono.git" +CHRONO_TAG="10.0.0" +# Commit of the 10.0.0 tag. The checkout is verified against it because a +# Chrono main build can also report version 10.0.0. +CHRONO_COMMIT="9faf13dd8f1128dd75ed233a9627027b0422c3f7" + +PREFIX="" +WORK_DIR="${TMPDIR:-/tmp}/seastack-chrono-${CHRONO_TAG}" +ENABLE_VSG=OFF +PREFIX_PATH="" +JOBS="" +EXTRA_CMAKE_ARGS=() + +usage() { sed -n '2,28p' "$0" | sed 's/^# \{0,1\}//'; } +fail() { echo "[FAIL] $*" >&2; exit 1; } + +while [[ $# -gt 0 ]]; do + case "$1" in + --prefix) PREFIX="$2"; shift 2 ;; + --work-dir) WORK_DIR="$2"; shift 2 ;; + --vsg) ENABLE_VSG=ON; shift ;; + --prefix-path) PREFIX_PATH="$2"; shift 2 ;; + --jobs) JOBS="$2"; shift 2 ;; + --) shift; EXTRA_CMAKE_ARGS=("$@"); break ;; + -h|--help) usage; exit 0 ;; + *) echo "[FAIL] unknown argument: $1" >&2; usage >&2; exit 2 ;; + esac +done + +[[ -n "${PREFIX}" ]] || { echo "[FAIL] --prefix is required" >&2; usage >&2; exit 2; } +command -v git >/dev/null || fail "git not on PATH" +command -v cmake >/dev/null || fail "cmake not on PATH" + +# Absolute prefix: it is written into the installed libraries on macOS. +mkdir -p "${PREFIX}" +PREFIX="$(cd "${PREFIX}" && pwd)" + +SOURCE_DIR="${WORK_DIR}/chrono" +BUILD_DIR="${WORK_DIR}/build" + +echo "Chrono tag: ${CHRONO_TAG} (${CHRONO_COMMIT})" +echo "Install prefix: ${PREFIX}" +echo "Work dir: ${WORK_DIR}" +echo "VSG module: ${ENABLE_VSG}" + +echo "" +echo ">> Source" +if [[ ! -d "${SOURCE_DIR}/.git" ]]; then + mkdir -p "${WORK_DIR}" + git clone --depth 1 --branch "${CHRONO_TAG}" "${CHRONO_REPOSITORY}" "${SOURCE_DIR}" +fi +actual_commit="$(git -C "${SOURCE_DIR}" rev-parse HEAD)" +if [[ "${actual_commit}" != "${CHRONO_COMMIT}" ]]; then + fail "${SOURCE_DIR} is at ${actual_commit}, expected ${CHRONO_COMMIT} (tag ${CHRONO_TAG})" +fi +echo " [OK] ${SOURCE_DIR} at ${actual_commit}" + +echo "" +echo ">> Configure" +cmake_args=( + -S "${SOURCE_DIR}" + -B "${BUILD_DIR}" + -DCMAKE_BUILD_TYPE=Release + "-DCMAKE_INSTALL_PREFIX=${PREFIX}" + "-DCMAKE_CXX_FLAGS=-DEIGEN_MAX_ALIGN_BYTES=16 -DEIGEN_MAX_STATIC_ALIGN_BYTES=16" + -DBUILD_SHARED_LIBS=ON + -DBUILD_TESTING=OFF + -DBUILD_DEMOS=OFF + -DBUILD_BENCHMARKING=OFF + -DCH_ENABLE_MODULE_PARSERS=ON + -DCH_ENABLE_HDF5=ON + -DCH_ENABLE_OPENMP=ON + "-DCH_ENABLE_MODULE_VSG=${ENABLE_VSG}" + -DCH_USE_SIMD=OFF + -DCMAKE_DISABLE_FIND_PACKAGE_Python3=ON +) +if [[ "$(uname -s)" == "Darwin" ]]; then + cmake_args+=(-DCH_USE_EIGEN_OPENMP=OFF) + # Chrono 10.0.0 installs its libraries with a bare file name as install name + # (libChrono_core.dylib), so programs linked against the installation fail to + # start with "dyld: Library not loaded". Record the absolute path instead. + cmake_args+=("-DCMAKE_INSTALL_NAME_DIR=${PREFIX}/lib") +fi +if command -v ninja >/dev/null; then + cmake_args+=(-G Ninja) +fi +if [[ -n "${PREFIX_PATH}" ]]; then + cmake_args+=("-DCMAKE_PREFIX_PATH=${PREFIX_PATH}") +fi +# Bash 3.2 (macOS) with set -u: an empty array must not be expanded directly. +cmake "${cmake_args[@]}" ${EXTRA_CMAKE_ARGS[@]+"${EXTRA_CMAKE_ARGS[@]}"} + +echo "" +echo ">> Build" +if [[ -n "${JOBS}" ]]; then + cmake --build "${BUILD_DIR}" --parallel "${JOBS}" +else + cmake --build "${BUILD_DIR}" --parallel +fi + +echo "" +echo ">> Install" +cmake --install "${BUILD_DIR}" + +echo "" +echo ">> Verify" +config_file="$(find "${PREFIX}" \( -name ChronoConfig.cmake -o -name chrono-config.cmake \) -print | head -n 1)" +[[ -n "${config_file}" ]] || fail "no Chrono package config found under ${PREFIX}" +chrono_dir="$(dirname "${config_file}")" +# The installed targets must not export native-architecture flags: they would +# raise Eigen's default alignment in every target that links Chrono. +if grep -R -l -E -e '-m(arch|tune)=native' "${chrono_dir}" >/dev/null 2>&1; then + fail "the installed Chrono package exports -march=native / -mtune=native (${chrono_dir})" +fi +echo " [OK] no -march=native / -mtune=native in the exported targets" +if [[ "$(uname -s)" == "Darwin" ]]; then + # Every installed library, and every library it depends on, must be recorded + # by an absolute or @-relative path (see CMAKE_INSTALL_NAME_DIR above). + for dylib in "${PREFIX}"/lib/*.dylib; do + [[ -e "${dylib}" ]] || fail "no libraries found under ${PREFIX}/lib" + [[ -L "${dylib}" ]] && continue + bare_names="$(otool -L "${dylib}" | tail -n +2 | awk '{print $1}' | grep -v -E '^(/|@)' || true)" + if [[ -n "${bare_names}" ]]; then + fail "${dylib} records a library without a path: ${bare_names}" + fi + done + echo " [OK] installed libraries are recorded by path" +fi +echo "" +echo "Chrono ${CHRONO_TAG} installed." +echo "ChronoDir: ${chrono_dir}" diff --git a/scripts/unix/ctest_suite.sh b/scripts/unix/ctest_suite.sh index d43b759..b3cffa3 100755 --- a/scripts/unix/ctest_suite.sh +++ b/scripts/unix/ctest_suite.sh @@ -18,6 +18,7 @@ RECOMPARE=0 LONG=0 BASELINE="" NO_PYTHON=0 +JUNIT="" usage() { cat <&2; usage >&2; exit 1 ;; esac @@ -101,16 +105,17 @@ fi # Bash 3.2 (macOS default) with set -u: expanding "${arr[@]}" on an empty array # triggers "unbound variable" and aborts before ctest runs. Branch on flags instead. +# ${JUNIT:+...} expands to nothing when --junit was not given. inv_ctest() { if [[ "${QUIET}" -eq 1 ]]; then (cd "${REPO_ROOT}" && ctest -C "${BUILD_TYPE}" --test-dir "${BUILD_PATH}" \ - --output-on-failure -Q "$@") + --output-on-failure -Q ${JUNIT:+--output-junit "${JUNIT}"} "$@") elif [[ "${VERBOSE}" -eq 1 ]]; then (cd "${REPO_ROOT}" && ctest -C "${BUILD_TYPE}" --test-dir "${BUILD_PATH}" \ - --output-on-failure -V "$@") + --output-on-failure -V ${JUNIT:+--output-junit "${JUNIT}"} "$@") else (cd "${REPO_ROOT}" && ctest -C "${BUILD_TYPE}" --test-dir "${BUILD_PATH}" \ - --output-on-failure "$@") + --output-on-failure ${JUNIT:+--output-junit "${JUNIT}"} "$@") fi } diff --git a/scripts/windows/build.ps1 b/scripts/windows/build.ps1 index f46460c..c28a7a9 100644 --- a/scripts/windows/build.ps1 +++ b/scripts/windows/build.ps1 @@ -935,7 +935,8 @@ if ($useChrono -and $chronoContent) { $hdf5Root = Split-Path (Split-Path $Matches[1]) $hdf5BinDir = Join-Path $hdf5Root "bin" if (Test-Path -LiteralPath $hdf5BinDir) { - $hdf5Dlls = Get-ChildItem -Path $hdf5BinDir -Include "hdf5*.dll", "szip*.dll", "zlib*.dll" -Recurse -ErrorAction SilentlyContinue + # vcpkg's zlib DLL is zlib1.dll in older releases and libz.dll in newer ones. + $hdf5Dlls = Get-ChildItem -Path $hdf5BinDir -Include "hdf5*.dll", "szip*.dll", "zlib*.dll", "libz.dll" -Recurse -ErrorAction SilentlyContinue $copiedCount = 0 foreach ($dll in $hdf5Dlls) { $destDll = Join-Path $binPath $dll.Name @@ -1003,8 +1004,10 @@ Write-SeaStackStep "Verifying outputs" $binDir = Join-Path $buildDir "bin\$BuildType" if (Test-Path -LiteralPath $binDir) { - $exes = Get-ChildItem -Path $binDir -Filter "*.exe" -ErrorAction SilentlyContinue - $dlls = Get-ChildItem -Path $binDir -Filter "*.dll" -ErrorAction SilentlyContinue + # @(...) keeps .Count valid under strict mode when there are no (or one) matches, + # e.g. no DLLs after a clean Chrono-free build. + $exes = @(Get-ChildItem -Path $binDir -Filter "*.exe" -ErrorAction SilentlyContinue) + $dlls = @(Get-ChildItem -Path $binDir -Filter "*.dll" -ErrorAction SilentlyContinue) Write-Detail ('Output: ' + $binDir) Write-Detail "Executables: $($exes.Count) DLLs: $($dlls.Count)" diff --git a/scripts/windows/build_chrono.ps1 b/scripts/windows/build_chrono.ps1 new file mode 100644 index 0000000..f92bc11 --- /dev/null +++ b/scripts/windows/build_chrono.ps1 @@ -0,0 +1,150 @@ +<# +.SYNOPSIS + Build and install Project Chrono for SEA-Stack on Windows. + +.DESCRIPTION + Implements the recipe in docs/build/BUILD_CHRONO.md: release tag 10.0.0, + shared libraries, Parsers + HDF5 + OpenMP, no Python link. Counterpart of + scripts/unix/build_chrono.sh. + + Eigen3 and HDF5 are taken from vcpkg (triplet x64-windows) when -VcpkgRoot is + given, for example after: + vcpkg install eigen3:x64-windows hdf5[cpp]:x64-windows + + Run from a Visual Studio x64 developer shell. Ninja is used when cl and ninja + are both on PATH; otherwise CMake's default generator (Visual Studio). + + After a successful run, set "ChronoDir" in build-config.json to the directory + printed at the end (the one that contains the Chrono package config file). + +.PARAMETER Prefix + Install prefix (required), e.g. C:/deps/chrono-10.0.0. + +.PARAMETER WorkDir + Source and build directory. Default: %TEMP%\seastack-chrono-10.0.0. + +.PARAMETER VcpkgRoot + vcpkg root directory. Its CMake toolchain file is passed to the Chrono configure. + +.PARAMETER PrefixPath + Extra CMAKE_PREFIX_PATH (e.g. the VSG install prefix). + +.PARAMETER VSG + Enable the Chrono VSG module (needs VSG, vsgXchange and vsgImGui). + +.PARAMETER Jobs + Parallel build jobs (default: the build tool's default). + +.PARAMETER CMakeArgs + Extra arguments for the Chrono CMake configure. + +.EXAMPLE + .\scripts\windows\build_chrono.ps1 -Prefix C:/deps/chrono-10.0.0 -VcpkgRoot C:/vcpkg +#> +param( + [Parameter(Mandatory)][string]$Prefix, + [string]$WorkDir = "", + [string]$VcpkgRoot = "", + [string]$PrefixPath = "", + [switch]$VSG, + [int]$Jobs = 0, + [string[]]$CMakeArgs = @() +) +# Native tools write progress to stderr; failures are detected via exit codes below. +$ErrorActionPreference = 'Continue' + +$ChronoRepository = "https://github.com/projectchrono/chrono.git" +$ChronoTag = "10.0.0" +# Commit of the 10.0.0 tag. The checkout is verified against it because a +# Chrono main build can also report version 10.0.0. +$ChronoCommit = "9faf13dd8f1128dd75ed233a9627027b0422c3f7" + +function Fail([string]$msg) { Write-Host "[FAIL] $msg" -ForegroundColor Red; exit 1 } + +foreach ($tool in 'git', 'cmake') { + if (-not (Get-Command $tool -ErrorAction SilentlyContinue)) { Fail "$tool not on PATH" } +} + +if (-not $WorkDir) { $WorkDir = Join-Path $env:TEMP "seastack-chrono-$ChronoTag" } +New-Item -ItemType Directory -Force -Path $Prefix, $WorkDir | Out-Null +$Prefix = (Resolve-Path -LiteralPath $Prefix).Path -replace '\\', '/' +$WorkDir = (Resolve-Path -LiteralPath $WorkDir).Path +$sourceDir = Join-Path $WorkDir "chrono" +$buildDir = Join-Path $WorkDir "build" +$enableVsg = if ($VSG) { 'ON' } else { 'OFF' } + +Write-Host "Chrono tag: $ChronoTag ($ChronoCommit)" +Write-Host "Install prefix: $Prefix" +Write-Host "Work dir: $WorkDir" +Write-Host "VSG module: $enableVsg" + +Write-Host "`n>> Source" +if (-not (Test-Path -LiteralPath (Join-Path $sourceDir ".git"))) { + & git clone --depth 1 --branch $ChronoTag $ChronoRepository $sourceDir + if ($LASTEXITCODE -ne 0) { Fail "git clone" } +} +$actualCommit = (& git -C $sourceDir rev-parse HEAD) +if ($actualCommit -ne $ChronoCommit) { + Fail "$sourceDir is at $actualCommit, expected $ChronoCommit (tag $ChronoTag)" +} +Write-Host " [OK] $sourceDir at $actualCommit" + +Write-Host "`n>> Configure" +$configureArgs = @( + '-S', $sourceDir, + '-B', $buildDir, + '-DCMAKE_BUILD_TYPE=Release', + "-DCMAKE_INSTALL_PREFIX=$Prefix", + '-DBUILD_SHARED_LIBS=ON', + '-DBUILD_TESTING=OFF', + '-DBUILD_DEMOS=OFF', + '-DBUILD_BENCHMARKING=OFF', + '-DCH_ENABLE_MODULE_PARSERS=ON', + '-DCH_ENABLE_HDF5=ON', + '-DCH_ENABLE_OPENMP=ON', + "-DCH_ENABLE_MODULE_VSG=$enableVsg", + '-DCMAKE_DISABLE_FIND_PACKAGE_Python3=ON' +) +if ((Get-Command cl -ErrorAction SilentlyContinue) -and (Get-Command ninja -ErrorAction SilentlyContinue)) { + $configureArgs += @('-G', 'Ninja') +} +if ($VcpkgRoot) { + $toolchain = Join-Path $VcpkgRoot "scripts\buildsystems\vcpkg.cmake" + if (-not (Test-Path -LiteralPath $toolchain)) { Fail "vcpkg toolchain file not found: $toolchain" } + $configureArgs += @("-DCMAKE_TOOLCHAIN_FILE=$($toolchain -replace '\\', '/')", '-DVCPKG_TARGET_TRIPLET=x64-windows') +} +# Chrono links an HDF5 "tools" target that vcpkg's HDF5 does not export. +$hdf5Shim = (Join-Path $PSScriptRoot "..\..\cmake\ChronoHdf5ToolsShim.cmake") +if (-not (Test-Path -LiteralPath $hdf5Shim)) { Fail "HDF5 shim not found: $hdf5Shim" } +$configureArgs += "-DCMAKE_PROJECT_INCLUDE=$((Resolve-Path -LiteralPath $hdf5Shim).Path -replace '\\', '/')" +if ($PrefixPath) { $configureArgs += "-DCMAKE_PREFIX_PATH=$PrefixPath" } +$configureArgs += $CMakeArgs +& cmake @configureArgs +if ($LASTEXITCODE -ne 0) { Fail "Chrono configure" } + +Write-Host "`n>> Build" +$buildArgs = @('--build', $buildDir, '--config', 'Release', '--parallel') +if ($Jobs -gt 0) { $buildArgs += "$Jobs" } +& cmake @buildArgs +if ($LASTEXITCODE -ne 0) { Fail "Chrono build" } + +Write-Host "`n>> Install" +& cmake --install $buildDir --config Release +if ($LASTEXITCODE -ne 0) { Fail "Chrono install" } + +Write-Host "`n>> Verify" +$configFile = Get-ChildItem -LiteralPath $Prefix -Recurse -File | + Where-Object { $_.Name -in 'ChronoConfig.cmake', 'chrono-config.cmake' } | + Select-Object -First 1 +if (-not $configFile) { Fail "no Chrono package config found under $Prefix" } +$chronoDir = $configFile.DirectoryName -replace '\\', '/' +foreach ($dll in 'Chrono_core.dll', 'Chrono_parsers.dll') { + if (-not (Get-ChildItem -LiteralPath $Prefix -Recurse -File -Filter $dll | Select-Object -First 1)) { + Fail "$dll not found under $Prefix" + } +} +Write-Host " [OK] Chrono_core.dll and Chrono_parsers.dll installed" + +Write-Host "`nChrono $ChronoTag installed." +Write-Host "ChronoDir: $chronoDir" +exit 0 diff --git a/scripts/windows/run_chrono_free_tests.ps1 b/scripts/windows/run_chrono_free_tests.ps1 index 5363dfb..6ca54c1 100644 --- a/scripts/windows/run_chrono_free_tests.ps1 +++ b/scripts/windows/run_chrono_free_tests.ps1 @@ -16,6 +16,7 @@ param( [ValidateSet("Release", "Debug", "RelWithDebInfo", "MinSizeRel")] [string]$BuildType = "Release", [int]$j = 0, + [string]$Junit = "", [switch]$Quiet, [switch]$Verbose, [switch]$Help @@ -36,6 +37,7 @@ if ($Help) { Write-Host " -BuildDir Build directory (default: build)" Write-Host " -BuildType Release|Debug|RelWithDebInfo|MinSizeRel (default: Release)" Write-Host " -j Parallel workers (0 = all processors)" + Write-Host " -Junit Also write a JUnit XML report (ctest --output-junit); a relative path is taken from the build directory" Write-Host " -Quiet Minimal ctest output (-Q)" Write-Host " -Verbose Extra ctest detail (-V)" Write-Host " (default) Live ctest lines; parallel 'Start N:' lines are hidden" @@ -71,6 +73,9 @@ $ctestArgs = @( "-j", $workers, "--output-on-failure" ) +if ($Junit) { + $ctestArgs += @("--output-junit", $Junit) +} Push-Location $repoRoot try { diff --git a/scripts/windows/run_comparison_tests.ps1 b/scripts/windows/run_comparison_tests.ps1 index f4e6754..05f9caa 100644 --- a/scripts/windows/run_comparison_tests.ps1 +++ b/scripts/windows/run_comparison_tests.ps1 @@ -24,6 +24,7 @@ param( [ValidateSet("Release", "Debug", "RelWithDebInfo", "MinSizeRel")] [string]$BuildType = "Release", [int]$j = 0, + [string]$Junit = "", [switch]$NoPdf, [switch]$Quiet, [switch]$Verbose, @@ -47,6 +48,7 @@ if ($Help) { Write-Host " -BuildDir Build directory (default: build)" Write-Host " -BuildType Release|Debug|RelWithDebInfo|MinSizeRel (default: Release)" Write-Host " -j Parallel workers (0 = all processors)" + Write-Host " -Junit Also write a JUnit XML report (ctest --output-junit); a relative path is taken from the build directory" Write-Host " -NoPdf Do not pass --pdf (default: --pdf if pandoc is on PATH)" Write-Host " -Quiet Minimal ctest output (-Q)" Write-Host " -Verbose Extra ctest detail (-V) and full Python report output" @@ -85,6 +87,9 @@ $ctestArgs = @( "-j", $workers, "--output-on-failure" ) +if ($Junit) { + $ctestArgs += @("--output-junit", $Junit) +} Write-Step "Running comparison tests ($workers workers; report via Python after ctest)" diff --git a/scripts/windows/run_regression_tests.ps1 b/scripts/windows/run_regression_tests.ps1 index a3b551b..3145070 100644 --- a/scripts/windows/run_regression_tests.ps1 +++ b/scripts/windows/run_regression_tests.ps1 @@ -21,6 +21,7 @@ param( [ValidateSet("Release", "Debug", "RelWithDebInfo", "MinSizeRel")] [string]$BuildType = "Release", [int]$j = 0, # 0 = auto-detect (all processors), otherwise use specified count + [string]$Junit = "", # Also write a JUnit XML report (ctest --output-junit) [string]$Filter, # Filter by model (sphere, oswec, f3of, rm3) [switch]$Recompare, # Re-run comparison tests to regenerate plots [switch]$Long, # Set SEASTACK_LONG_TESTS=1 for this run only @@ -46,6 +47,7 @@ if ($Help) { Write-Host " -BuildDir Build directory (default: build)" Write-Host " -BuildType Release|Debug|RelWithDebInfo|MinSizeRel (default: Release)" Write-Host " -j Number of parallel workers (default: all available processors)" + Write-Host " -Junit Also write a JUnit XML report (ctest --output-junit); a relative path is taken from the build directory" Write-Host " -Filter Filter by family (CTest prefix test_regression__)" Write-Host " -Recompare Re-run comparison tests to regenerate plots" Write-Host " -Long Enable long regression tests (SEASTACK_LONG_TESTS=1 for this run)" @@ -92,6 +94,9 @@ $ctestArgs = @( "-j", $workers, "--output-on-failure" ) +if ($Junit) { + $ctestArgs += @("--output-junit", $Junit) +} if ($Filter) { $ctestArgs += @("-R", "^test_regression_${Filter}_") diff --git a/scripts/windows/run_unit_tests.ps1 b/scripts/windows/run_unit_tests.ps1 index fe7b6ba..4afcc55 100644 --- a/scripts/windows/run_unit_tests.ps1 +++ b/scripts/windows/run_unit_tests.ps1 @@ -16,6 +16,7 @@ param( [ValidateSet("Release", "Debug", "RelWithDebInfo", "MinSizeRel")] [string]$BuildType = "Release", [int]$j = 0, + [string]$Junit = "", [switch]$Quiet, [switch]$Verbose, [switch]$Help @@ -31,11 +32,12 @@ $repoRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $MyInvoca if ($Help) { Write-Host "`nSEA-Stack Unit Test Runner" -ForegroundColor Cyan Write-Host "==========================" -ForegroundColor Cyan - Write-Host "`nRuns CTest tests with label `unit`.`n" + Write-Host "`nRuns CTest tests with label unit.`n" Write-Host "OPTIONS:" -ForegroundColor Yellow Write-Host " -BuildDir Build directory (default: build)" Write-Host " -BuildType Release|Debug|RelWithDebInfo|MinSizeRel (default: Release)" Write-Host " -j Parallel workers (0 = all processors)" + Write-Host " -Junit Also write a JUnit XML report (ctest --output-junit); a relative path is taken from the build directory" Write-Host " -Quiet Minimal ctest output (-Q)" Write-Host " -Verbose Extra ctest detail (-V)" Write-Host " (default) Live ctest lines; parallel 'Start N:' lines are hidden" @@ -71,6 +73,9 @@ $ctestArgs = @( "-j", $workers, "--output-on-failure" ) +if ($Junit) { + $ctestArgs += @("--output-junit", $Junit) +} Push-Location $repoRoot try { diff --git a/scripts/windows/run_verification_tests.ps1 b/scripts/windows/run_verification_tests.ps1 index 5f18c0a..71b22fe 100644 --- a/scripts/windows/run_verification_tests.ps1 +++ b/scripts/windows/run_verification_tests.ps1 @@ -24,6 +24,7 @@ param( [ValidateSet("Release", "Debug", "RelWithDebInfo", "MinSizeRel")] [string]$BuildType = "Release", [int]$j = 0, + [string]$Junit = "", [switch]$NoPdf, [switch]$Quiet, [switch]$Verbose, @@ -47,6 +48,7 @@ if ($Help) { Write-Host " -BuildDir Build directory (default: build)" Write-Host " -BuildType Release|Debug|RelWithDebInfo|MinSizeRel (default: Release)" Write-Host " -j Parallel workers (0 = all processors)" + Write-Host " -Junit Also write a JUnit XML report (ctest --output-junit); a relative path is taken from the build directory" Write-Host " -NoPdf Do not pass --pdf (default: --pdf if pandoc is on PATH)" Write-Host " -Quiet Minimal ctest output (-Q)" Write-Host " -Verbose Extra ctest detail (-V) and full Python report output" @@ -85,6 +87,9 @@ $ctestArgs = @( "-j", $workers, "--output-on-failure" ) +if ($Junit) { + $ctestArgs += @("--output-junit", $Junit) +} Write-Step "Running verification tests ($workers workers; report via Python after ctest)" diff --git a/tests/README.md b/tests/README.md index b04acd3..6f9ea1e 100644 --- a/tests/README.md +++ b/tests/README.md @@ -29,15 +29,16 @@ Verification compares against **external or multi-code** reference data under `d Unit tests exercise libraries with assertions. **Chrono-free** tests omit Chrono DLLs; useful when you only need the non-Chrono stack. -| Track / suite | Purpose | Typical CI | CTest label(s) | -|---------------|---------|------------|----------------| -| Unit | Library checks | Every commit | `unit` | -| Chrono-free | No Chrono | Every commit | `chrono-free` | -| Core regression | vs `ss_ref_*.txt` | Every commit (fast) | `regression` | -| Consistency | Internal self-validation | Every commit | `regression;consistency` | -| Verification | Cross-code / multi-code | Nightly / on-demand | `verification` | -| Comparison | Method vs method (internal) | On-demand | `comparison` | -| Benchmark | Performance timing | On-demand | `benchmark` | +| Track / suite | Purpose | Continuous integration | CTest label(s) | +|---------------|---------|------------------------|----------------| +| Unit | Library checks | Every pull request | `unit` | +| Chrono-free | No Chrono | Every pull request | `chrono-free` | +| Core regression | vs `ss_ref_*.txt` | Every pull request | `regression` | +| Consistency | Internal self-validation | Every pull request | `regression;consistency` | +| External modules | External PTO and controller runs | Every pull request | `external` | +| Verification | Cross-code / multi-code | Nightly / on request | `verification` | +| Comparison | Method vs method (internal) | Nightly / on request | `comparison` | +| Benchmark | Performance timing | Nightly / on request (for information) | `benchmark` | ## Run the main test suites @@ -56,6 +57,23 @@ Unit tests exercise libraries with assertions. **Chrono-free** tests omit Chrono Verbose ctest output, `-BuildType`/Release notes, and **raw `ctest` vs PowerShell** behavior for verification/comparison reports: [TEST_SUITES_REFERENCE.md](TEST_SUITES_REFERENCE.md). +## Continuous integration + +GitHub Actions builds and tests SEA-Stack on Linux, macOS and Windows ([`.github/workflows/ci.yml`](../.github/workflows/ci.yml)). Each platform has two jobs, which call the scripts in the tables above: + +| Job | Build | Tests | +|-----|-------|-------| +| Chrono-free | `--no-chrono --external` / `-NoChrono -External` | `chrono-free` label and the downstream-consumer check | +| Chrono | Headless Chrono 10.0.0 built by `scripts/unix/build_chrono.sh` or `scripts/windows/build_chrono.ps1`, with MoorDyn, external modules and demos; no VSG | `unit`, `regression` and `external` labels | + +The Chrono job also runs the **full suites** (verification, comparison, long regression, the demo cases through `run_tests.py --all`, 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). +- **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. +- **Not covered:** the VSG GUI build and the release packages. + ## Test-only environment variables `run_seastack` reads two variables that exist only so that tests can provoke diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 8c79edc..82a4904 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -370,8 +370,10 @@ if(TARGET seastack_external) --exe $ ) # Four ~600 s irregular-wave Chrono runs (3 demos + native twin). + # Same time limit as the regression suite: the 300 s limit of the + # unit tests is too short for these runs on a slow machine. set_tests_properties(test_external_pto_rm3_regression PROPERTIES - LABELS "external;chrono" COST 120 SKIP_RETURN_CODE 77) + LABELS "external;chrono" COST 120 SKIP_RETURN_CODE 77 TIMEOUT 1800) # On Windows, run_seastack needs Chrono/HDF5/VSG DLLs (VSG is loaded # even with --nogui) plus a `python` interpreter (the demos spawn # `python .py`). We pass these directories to the test script