name: "Build Linux sanitizers" description: >- Build and test WSJT-X with GCC sanitizers on Linux x86_64. inputs: hamlib_branch: description: "Hamlib branch to build" required: true sanitizer: description: "Sanitizer mode: asan-ubsan or tsan" required: false default: "asan-ubsan" recache: description: "Force ccache to recompile and refresh cached objects" required: false default: "false" save_ccache: description: "Save compiled objects for trusted builds" required: false default: "false" run_tests: description: "Run sanitizer tests after compiling production and test targets" required: false default: "true" allow_stale_image: description: "Allow a previously promoted image when a dependency refresh changed the recipe" required: false default: "false" runs: using: "composite" steps: - name: Validate workflow inputs shell: bash env: HAMLIB_BRANCH: ${{ inputs.hamlib_branch }} run: .github/scripts/validate-ci-inputs.sh - name: Resolve sanitizer configuration id: sanitizer shell: bash env: SANITIZER: ${{ inputs.sanitizer }} run: | case "$SANITIZER" in asan-ubsan) echo "build_dir=wsjtx-sanitizer-build" >> "$GITHUB_OUTPUT" echo "ccache_dir=.ccache-sanitizers" >> "$GITHUB_OUTPUT" echo "cache_key=asan-ubsan-gcc" >> "$GITHUB_OUTPUT" echo "cmake_option=WSJT_ENABLE_ASAN_UBSAN" >> "$GITHUB_OUTPUT" echo "summary_name=Linux x86_64 ASan + UBSan" >> "$GITHUB_OUTPUT" echo "artifact_name=ctest-results-linux-x86_64-asan-ubsan" >> "$GITHUB_OUTPUT" echo "asan_options=detect_leaks=0:detect_stack_use_after_return=1:halt_on_error=1:abort_on_error=1" >> "$GITHUB_OUTPUT" echo "ubsan_options=halt_on_error=1:print_stacktrace=1" >> "$GITHUB_OUTPUT" echo "tsan_options=" >> "$GITHUB_OUTPUT" ;; tsan) echo "build_dir=wsjtx-tsan-build" >> "$GITHUB_OUTPUT" echo "ccache_dir=.ccache-tsan" >> "$GITHUB_OUTPUT" echo "cache_key=tsan-gcc" >> "$GITHUB_OUTPUT" echo "cmake_option=WSJT_ENABLE_TSAN" >> "$GITHUB_OUTPUT" echo "summary_name=Linux x86_64 TSan" >> "$GITHUB_OUTPUT" echo "artifact_name=ctest-results-linux-x86_64-tsan" >> "$GITHUB_OUTPUT" echo "asan_options=" >> "$GITHUB_OUTPUT" echo "ubsan_options=" >> "$GITHUB_OUTPUT" tsan_suppressions="${GITHUB_WORKSPACE}/tests/sanitizers/tsan.supp" if [ ! -f "$tsan_suppressions" ]; then echo "::error::TSan suppressions file not found: $tsan_suppressions" exit 1 fi echo "tsan_options=halt_on_error=0:second_deadlock_stack=1:suppressions=${tsan_suppressions}" >> "$GITHUB_OUTPUT" ;; *) echo "::error::Unsupported sanitizer mode: $SANITIZER" exit 1 ;; esac - name: Verify Linux CI image id: image shell: bash env: WSJTX_CI_IMAGE_ALLOW_RECIPE_MISMATCH: ${{ inputs.allow_stale_image }} run: | flavor=normal if [ "${{ inputs.sanitizer }}" = tsan ]; then flavor=tsan fi .github/scripts/verify-linux-ci-image.sh \ "$flavor" x86_64 "${{ inputs.hamlib_branch }}" - name: Export TSan dependency environment if: inputs.sanitizer == 'tsan' shell: bash run: | { echo "CC=gcc-13" echo "CXX=g++-13" echo "FC=gfortran-13" echo "TSAN_QT_PREFIX=${{ steps.image.outputs.qt_prefix }}" echo "TSAN_BOOST_PREFIX=${{ steps.image.outputs.boost_prefix }}" echo "TSAN_HAMLIB_PREFIX=${{ steps.image.outputs.hamlib_prefix }}" echo "TSAN_CMAKE_PREFIX_PATH=${{ steps.image.outputs.qt_prefix }};${{ steps.image.outputs.boost_prefix }};${{ steps.image.outputs.hamlib_prefix }}" echo "LD_LIBRARY_PATH=${{ steps.image.outputs.qt_prefix }}/lib:${{ steps.image.outputs.boost_prefix }}/lib:${LD_LIBRARY_PATH:-}" echo "PKG_CONFIG_PATH=${{ steps.image.outputs.qt_prefix }}/lib/pkgconfig:${{ steps.image.outputs.boost_prefix }}/lib/pkgconfig:${{ steps.image.outputs.hamlib_prefix }}/lib/pkgconfig:${PKG_CONFIG_PATH:-}" echo "QT_PLUGIN_PATH=${{ steps.image.outputs.qt_prefix }}/plugins" } >> "$GITHUB_ENV" echo "${{ steps.image.outputs.qt_prefix }}/bin" >> "$GITHUB_PATH" - name: Select ccache key id: ccache-key shell: bash env: RECACHE: ${{ inputs.recache }} run: .github/scripts/select-ccache-key-suffix.sh - name: Restore sanitizer objects id: ccache uses: actions/cache/restore@v5 with: path: ${{ steps.sanitizer.outputs.ccache_dir }} key: ccache-linux-x86_64-${{ steps.sanitizer.outputs.cache_key }}-${{ steps.image.outputs.ccache_compatibility_id }}-${{ steps.image.outputs.generation }}-${{ github.sha }}${{ steps.ccache-key.outputs.suffix }} restore-keys: | ccache-linux-x86_64-${{ steps.sanitizer.outputs.cache_key }}-${{ steps.image.outputs.ccache_compatibility_id }}-${{ steps.image.outputs.generation }}- ccache-linux-x86_64-${{ steps.sanitizer.outputs.cache_key }}-${{ steps.image.outputs.ccache_compatibility_id }}- - name: Configure ccache id: ccache-config shell: bash run: | export CCACHE_DIR="${GITHUB_WORKSPACE}/${{ steps.sanitizer.outputs.ccache_dir }}" export CCACHE_COMPILERCHECK="${{ steps.image.outputs.ccache_compiler_check }}" { echo "CCACHE_DIR=$CCACHE_DIR" echo "CCACHE_COMPILERCHECK=$CCACHE_COMPILERCHECK" } >> "$GITHUB_ENV" echo "ccache recache: ${{ inputs.recache }}" if [ "${{ inputs.recache }}" = "true" ]; then echo "CCACHE_RECACHE=1" >> "$GITHUB_ENV" echo "Forcing ccache recache for this run" fi mkdir -p "$CCACHE_DIR" ccache --version ccache --show-config ccache --zero-stats - name: Configure sanitizer build shell: bash run: | prefix_path="${{ steps.image.outputs.hamlib_prefix }}" compiler_args=() boost_args=() if [ "${{ inputs.sanitizer }}" = "tsan" ]; then prefix_path="$TSAN_CMAKE_PREFIX_PATH" compiler_args=( -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" -DCMAKE_Fortran_COMPILER="$FC" ) boost_args=( -DBOOST_ROOT="$TSAN_BOOST_PREFIX" -DBoost_NO_SYSTEM_PATHS=ON ) fi cmake -S . -B "${{ steps.sanitizer.outputs.build_dir }}" \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ -DCMAKE_PREFIX_PATH="$prefix_path" \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \ -DWSJT_GENERATE_DOCS=OFF \ -DWSJT_SKIP_MANPAGES=ON \ -DWSJT_ENABLE_TESTS=ON \ -DWSJT_ENABLE_GUI_SMOKE_TESTS=ON \ -D${{ steps.sanitizer.outputs.cmake_option }}=ON \ -DWSJT_BUILD_UTILS=OFF \ -DWSJT_FORTRAN_LIBRARY_VARIANTS=OPENMP_ONLY \ "${compiler_args[@]}" \ "${boost_args[@]}" \ -Wno-dev - name: Verify configured TSan dependency resolution if: inputs.sanitizer == 'tsan' shell: bash run: >- .github/scripts/verify-tsan-deps-linux.sh "$TSAN_QT_PREFIX" "$TSAN_BOOST_PREFIX" "$TSAN_HAMLIB_PREFIX" "${{ steps.sanitizer.outputs.build_dir }}/CMakeCache.txt" - name: Build sanitizer targets id: compile shell: bash run: | SECONDS=0 trap 'echo "duration_seconds=$SECONDS" >> "$GITHUB_OUTPUT"' EXIT cmake --build "${{ steps.sanitizer.outputs.build_dir }}" -j"$(nproc)" - name: Show ccache stats if: always() && steps.ccache-config.outcome == 'success' shell: bash run: ccache --show-stats | tee "$RUNNER_TEMP/sanitizer-ccache-stats.txt" - name: Verify sanitizer instrumentation id: instrumentation shell: bash run: >- python3 .github/scripts/verify-sanitizer-instrumentation.py "${{ steps.sanitizer.outputs.build_dir }}" --sanitizer "${{ inputs.sanitizer }}" - name: Verify linked TSan dependency runtime if: inputs.sanitizer == 'tsan' shell: bash run: >- .github/scripts/verify-tsan-deps-linux.sh "$TSAN_QT_PREFIX" "$TSAN_BOOST_PREFIX" "$TSAN_HAMLIB_PREFIX" "${{ steps.sanitizer.outputs.build_dir }}/CMakeCache.txt" "${{ steps.sanitizer.outputs.build_dir }}/wsjtx" - name: Prepare test scratch directory if: inputs.run_tests == 'true' shell: bash run: mkdir -p "${GITHUB_WORKSPACE}/${{ steps.sanitizer.outputs.build_dir }}/tmp" - name: Run tests id: ctest if: inputs.run_tests == 'true' continue-on-error: true shell: bash working-directory: ${{ steps.sanitizer.outputs.build_dir }} env: ASAN_OPTIONS: ${{ steps.sanitizer.outputs.asan_options }} UBSAN_OPTIONS: ${{ steps.sanitizer.outputs.ubsan_options }} TSAN_OPTIONS: ${{ steps.sanitizer.outputs.tsan_options }} QT_QPA_PLATFORM: xcb TMPDIR: ${{ github.workspace }}/${{ steps.sanitizer.outputs.build_dir }}/tmp run: >- xvfb-run -a -s "-screen 0 1280x1024x24" ctest --parallel 1 --output-on-failure --output-junit ctest-results.xml - name: Publish test summary if: always() && inputs.run_tests == 'true' && steps.ctest.outcome != 'skipped' shell: bash working-directory: ${{ steps.sanitizer.outputs.build_dir }} run: >- python3 ../.github/scripts/publish-ctest-summary.py "${{ steps.sanitizer.outputs.summary_name }}" >> "$GITHUB_STEP_SUMMARY" - name: Upload test results if: always() && inputs.run_tests == 'true' && steps.ctest.outcome != 'skipped' uses: actions/upload-artifact@v7 with: name: ${{ steps.sanitizer.outputs.artifact_name }} path: | ${{ steps.sanitizer.outputs.build_dir }}/ctest-results.xml ${{ steps.sanitizer.outputs.build_dir }}/Testing/Temporary/LastTest.log ${{ steps.sanitizer.outputs.build_dir }}/Testing/Golden/test_jt9_mtd_ft8_210703_133430*/stderr.txt if-no-files-found: ignore - name: Require sanitizer tests to pass if: always() && inputs.run_tests == 'true' shell: bash run: | failed=false if [ "${{ steps.ctest.outcome }}" != "success" ]; then echo "::error::CTest failed under ${{ steps.sanitizer.outputs.summary_name }}" failed=true fi if [ "$failed" = "true" ]; then exit 1 fi - name: Save sanitizer objects id: save-ccache if: inputs.save_ccache == 'true' && github.ref == 'refs/heads/develop' && steps.image.outputs.recipe_match == 'true' && steps.ccache.outputs.cache-hit != 'true' uses: actions/cache/save@v5 with: path: ${{ steps.sanitizer.outputs.ccache_dir }} key: ${{ steps.ccache.outputs.cache-primary-key }} - name: Summarize sanitizer cache if: always() shell: bash env: CACHE_STEPS: ${{ toJSON(steps) }} SAVE_CCACHE: ${{ inputs.save_ccache }} RUN_TESTS: ${{ inputs.run_tests }} run: | python3 - <<'PY' >> "$GITHUB_STEP_SUMMARY" import json import os from pathlib import Path steps = json.loads(os.environ["CACHE_STEPS"]) cache = steps.get("ccache", {}) outputs = cache.get("outputs", {}) image = steps.get("image", {}).get("outputs", {}) compile_step = steps.get("compile", {}) save = steps.get("save-ccache", {}).get("outcome", "skipped") exact = outputs.get("cache-hit") == "true" matched = outputs.get("cache-matched-key", "") restore = "exact hit" if exact else "fallback restore" if matched else "miss" if cache.get("outcome") != "success": restore = cache.get("outcome", "not run") if os.environ["SAVE_CCACHE"] != "true": publication = "disabled" elif os.environ["GITHUB_REF"] != "refs/heads/develop": publication = "skipped: cache writes require develop" elif image.get("recipe_match") == "false": publication = "skipped: image recipe mismatch" elif save != "skipped": publication = f"attempted (step: {save}); see cache action log for upload confirmation" elif any(step.get("outcome") in ("failure", "cancelled") for step in steps.values()): publication = "skipped: preceding failure or cancellation" elif exact: publication = "skipped: exact cache already exists" else: publication = "not attempted" tests = steps.get("ctest", {}).get("outcome", "not run") if os.environ["RUN_TESTS"] != "true": tests = "disabled (build-only warmer)" duration = compile_step.get("outputs", {}).get("duration_seconds", "unavailable") print("### Sanitizer compiler cache\n") rows = { "Source SHA": os.environ["GITHUB_SHA"], "Image generation": image.get("generation", "unavailable"), "Requested/save key": outputs.get("cache-primary-key", "unavailable"), "Matched key": matched or "none", "Restore": restore, "Compilation": compile_step.get("outcome", "not run"), "Compilation duration (seconds)": duration, "Instrumentation": steps.get("instrumentation", {}).get("outcome", "not run"), "Tests": tests, "Cache publication": publication, } print("| Item | Result |\n| --- | --- |") for label, value in rows.items(): print(f"| {label} | {value} |") stats = Path(os.environ["RUNNER_TEMP"]) / "sanitizer-ccache-stats.txt" if stats.is_file(): print("\n```text\n" + stats.read_text().rstrip() + "\n```") print("\nCompiler caching covers C/C++; Fortran compilation and linking still run.") print("Build-only warming does not establish that sanitizer tests pass.") PY