diff --git a/cmake/local-ci/lanes.json b/cmake/local-ci/lanes.json new file mode 100644 index 00000000..e2e50ac3 --- /dev/null +++ b/cmake/local-ci/lanes.json @@ -0,0 +1,196 @@ +{ + "schema": 1, + "comment": "The local CI matrix (#346): one entry per lane the GitHub workflows expand to. test/cmake/CheckLocalCi.cmake fails when it drifts from .github/workflows.", + "mddlog": { + "repository": "ambroise-leclerc/mddlog", + "ref": "5b43265664d83c3b7135d328f611e685792a1b02", + "cmake_window": "4.0 to 4.3" + }, + "workflows": { + "BuildAndTest.yml": { + "jobs": ["desktop", "sanitizers", "web-integration"], + "matrices": { + "desktop": {"key": "platform", "values": ["linux-gcc-webkitgtk", "windows-msvc-webview2", "macos-clang-wkwebview"]}, + "sanitizers": {"key": "sanitizer", "values": ["address-undefined", "thread"]}, + "web-integration": {"key": "compiler", "values": ["gcc", "clang"]} + } + }, + "MddlogIntegration.yml": { + "jobs": ["clang", "sanitizers"], + "matrices": { + "sanitizers": {"key": "name", "values": ["address-undefined", "thread"]} + } + } + }, + "local_differences": { + "parallelism": "GitHub builds with --parallel 2; local lanes use the jobs limit of the machine (4 compilations on Windows).", + "cache": "GitHub restores actions/cache and sccache; local lanes keep persistent CPM_SOURCE_CACHE and ccache volumes.", + "toolchain": "GitHub installs toolchains per run; local machines are prepared once (docs/LOCAL_CI.md).", + "runner_images": "ubuntu-26.04, ubuntu-24.04, windows-2025 and macos-26 runner images are replaced by pinned containers and the host systems.", + "github_only_steps": [ + "actions/upload-artifact (logs are collected by the orchestrator)", + "mozilla-actions/sccache-action (ccache replaces sccache)", + "actions/cache", + "Collect coverage upload (no Codecov step exists in the workflows; coverage.info and lcov --list stay local)", + "Cut the public network: applied to the lane container instead of the host firewall" + ] + }, + "lanes": [ + { + "id": "desktop-linux-gcc-webkitgtk", + "workflow": "BuildAndTest.yml", "job": "desktop", "matrix": "linux-gcc-webkitgtk", + "machine": "RyzenLinux", "runtime": "container:linux-ubuntu26", + "compiler": {"family": "gcc", "version": "16", "marker": "gcc-16"}, + "cmake_version": "4.4.4", "build_type": "Debug", + "options": ["-DWEBFRONT_EMBED_WEBKITGTK=ON", "-DWEBFRONT_WEBTEST_FRONTEND=WebKitGTK", "-DENABLE_COVERAGE=ON"], + "common_options": ["-DWEBFRONT_EMBED_CEF=OFF", "-DENABLE_TESTING=ON", "-DCMAKE_CXX_SCAN_FOR_MODULES=OFF"], + "workflow_options": ["-DENABLE_CACHE=OFF", "-DCMAKE_CXX_COMPILER_LAUNCHER=sccache"], + "targets": [], + "ctest": {"labels": [], "exclude_labels": [], "args": ["--no-tests=error", "--output-on-failure", "--parallel", "4"], "workflow_args": ["--repeat", "until-fail:${{github.event_name=='workflow_dispatch'&&inputs.repeat_desktop_tests&&'3'||'1'}}", "--output-junit", "@workspace@/build/test-results.xml"]}, + "env": {"WEBKIT_DISABLE_SANDBOX_THIS_IS_DANGEROUS": "1"}, + "extra_steps": ["lcov-coverage"], + "evidence": ["libwebkitgtk-6.0-dev", "lcov --list coverage.info", "--gcov-tool gcov-16", "--no-tests=error"] + }, + { + "id": "desktop-windows-msvc-webview2", + "workflow": "BuildAndTest.yml", "job": "desktop", "matrix": "windows-msvc-webview2", + "machine": "CurmudgeonWindows", "runtime": "native:msvc", + "compiler": {"family": "msvc", "version": "latest", "marker": "msvc-dev-cmd"}, + "cmake_version": "4.4.4", "build_type": "Release", + "options": ["-DWEBFRONT_EMBED_WEBVIEW2=ON", "-DWEBFRONT_WEBTEST_FRONTEND=WebView2"], + "common_options": ["-DWEBFRONT_EMBED_CEF=OFF", "-DENABLE_TESTING=ON", "-DCMAKE_CXX_SCAN_FOR_MODULES=OFF"], + "workflow_options": ["-DENABLE_CACHE=OFF", "-DCMAKE_CXX_COMPILER_LAUNCHER=sccache"], + "targets": [], + "ctest": {"labels": [], "exclude_labels": [], "args": ["--no-tests=error", "--output-on-failure", "--parallel", "4"], "workflow_args": ["--repeat", "until-fail:${{github.event_name=='workflow_dispatch'&&inputs.repeat_desktop_tests&&'3'||'1'}}", "--output-junit", "@workspace@/build/test-results.xml"]}, + "env": {}, + "interactive_session": "required", + "extra_steps": ["webview2-runtime-check"], + "evidence": ["Ensure WebView2 Evergreen runtime", "--no-tests=error"] + }, + { + "id": "desktop-macos-clang-wkwebview", + "workflow": "BuildAndTest.yml", "job": "desktop", "matrix": "macos-clang-wkwebview", + "machine": "Mac", "runtime": "native:appleclang", + "compiler": {"family": "appleclang", "version": "xcode-latest", "marker": "xcode-version: latest"}, + "cmake_version": "4.4.4", "build_type": "Release", + "options": ["-DWEBFRONT_EMBED_WKWEBVIEW=ON", "-DWEBFRONT_WEBTEST_FRONTEND=WKWebView"], + "common_options": ["-DWEBFRONT_EMBED_CEF=OFF", "-DENABLE_TESTING=ON", "-DCMAKE_CXX_SCAN_FOR_MODULES=OFF"], + "workflow_options": ["-DENABLE_CACHE=OFF", "-DCMAKE_CXX_COMPILER_LAUNCHER=sccache"], + "targets": [], + "ctest": {"labels": [], "exclude_labels": [], "args": ["--no-tests=error", "--output-on-failure", "--parallel", "4"], "workflow_args": ["--repeat", "until-fail:${{github.event_name=='workflow_dispatch'&&inputs.repeat_desktop_tests&&'3'||'1'}}", "--output-junit", "@workspace@/build/test-results.xml"]}, + "env": {}, + "interactive_session": "required", + "report": ["xcode-version"], + "evidence": ["--no-tests=error"] + }, + { + "id": "sanitizers-address-undefined", + "workflow": "BuildAndTest.yml", "job": "sanitizers", "matrix": "address-undefined", + "machine": "RyzenLinux", "runtime": "container:linux-ubuntu24-clang23", + "compiler": {"family": "clang", "version": "23", "marker": "clang-23"}, + "cmake_version": "4.4.4", "build_type": "RelWithDebInfo", + "options": ["-DENABLE_SANITIZER_ADDRESS=ON", "-DENABLE_SANITIZER_UNDEFINED_BEHAVIOR=ON", "-DENABLE_FUZZING=ON"], + "common_options": ["-DWEBFRONT_EMBED_CEF=OFF", "-DWEBFRONT_BUILD_EXAMPLES=OFF", "-DENABLE_TESTING=ON", "-DENABLE_CACHE=OFF"], + "targets": [], + "ctest": {"labels": [], "exclude_labels": [], "args": ["--no-tests=error", "--output-on-failure", "--parallel", "4"], "workflow_args": ["--output-junit", "@workspace@/build-sanitizers/test-results.xml"]}, + "env": {"ASAN_OPTIONS": "detect_leaks=1:abort_on_error=1", "UBSAN_OPTIONS": "print_stacktrace=1:halt_on_error=1"}, + "fuzz_decoders": ["messages", "http", "websocket", "gzip"], + "fuzz_seconds": 30, + "evidence": ["for decoder in messages http websocket gzip", "-max_total_time=30", "libclang-rt-23-dev"] + }, + { + "id": "sanitizers-thread", + "workflow": "BuildAndTest.yml", "job": "sanitizers", "matrix": "thread", + "machine": "RyzenLinux", "runtime": "container:linux-ubuntu24-clang23", + "compiler": {"family": "clang", "version": "23", "marker": "clang-23"}, + "cmake_version": "4.4.4", "build_type": "RelWithDebInfo", + "options": ["-DCMAKE_CXX_FLAGS=-stdlib=libc++", "-DENABLE_SANITIZER_THREAD=ON"], + "common_options": ["-DWEBFRONT_EMBED_CEF=OFF", "-DWEBFRONT_BUILD_EXAMPLES=OFF", "-DENABLE_TESTING=ON", "-DENABLE_CACHE=OFF"], + "targets": [], + "ctest": {"labels": [], "exclude_labels": [], "args": ["--no-tests=error", "--output-on-failure", "--parallel", "4"], "workflow_args": ["--output-junit", "@workspace@/build-sanitizers/test-results.xml"]}, + "env": {"TSAN_OPTIONS": "halt_on_error=1:second_deadlock_stack=1"}, + "host_requirements": {"sysctl": {"vm.mmap_rnd_bits": "28"}}, + "evidence": ["vm.mmap_rnd_bits=28", "libc++-23-dev"] + }, + { + "id": "web-integration-gcc", + "workflow": "BuildAndTest.yml", "job": "web-integration", "matrix": "gcc", + "machine": "RyzenLinux", "runtime": "container:linux-ubuntu24-clang23", + "compiler": {"family": "gcc", "version": "ubuntu-24.04-default", "marker": ""}, + "cmake_version": "4.4.4", "build_type": "Release", + "options": ["-DWEBFRONT_EMBED_CEF=ON"], + "common_options": ["-DWEBFRONT_BUILD_EXAMPLES=OFF", "-DENABLE_TESTING=ON"], + "targets": ["webtest", "developer_integration", "webfront-wf"], + "ctest": {"labels": ["web-integration"], "exclude_labels": [], "args": ["--no-tests=error", "--output-on-failure", "--parallel", "4"], "workflow_args": ["--output-junit", "@workspace@/build-cef/test-results.xml"]}, + "env": {}, + "container": {"shm_size": "1g", "network_after_provisioning": "none"}, + "report": ["effective-compiler"], + "evidence": ["--target webtest developer_integration webfront-wf", "-L web-integration", "iptables -A OUTPUT ! -o lo -j REJECT"] + }, + { + "id": "web-integration-clang", + "workflow": "BuildAndTest.yml", "job": "web-integration", "matrix": "clang", + "machine": "RyzenLinux", "runtime": "container:linux-ubuntu24-clang23", + "compiler": {"family": "clang", "version": "23", "marker": "clang-23"}, + "cmake_version": "4.4.4", "build_type": "Release", + "options": ["-DWEBFRONT_EMBED_CEF=ON"], + "common_options": ["-DWEBFRONT_BUILD_EXAMPLES=OFF", "-DENABLE_TESTING=ON"], + "targets": ["webtest", "developer_integration", "webfront-wf"], + "ctest": {"labels": ["web-integration"], "exclude_labels": [], "args": ["--no-tests=error", "--output-on-failure", "--parallel", "4"], "workflow_args": ["--output-junit", "@workspace@/build-cef/test-results.xml"]}, + "env": {"CC": "clang-23", "CXX": "clang++-23"}, + "container": {"shm_size": "1g", "network_after_provisioning": "none"}, + "evidence": ["--target webtest developer_integration webfront-wf", "-L web-integration", "lld-23"] + }, + { + "id": "mddlog-clang-source-install", + "workflow": "MddlogIntegration.yml", "job": "clang", "matrix": "", + "machine": "RyzenLinux", "runtime": "container:linux-ubuntu-clang21-libcxx", + "compiler": {"family": "clang", "version": "21", "marker": "clang-21"}, + "cmake_version": "4.3.1", "build_type": "Release", + "options": ["-DWEBFRONT_USE_MDDLOG=ON", "-DWEBFRONT_BUILD_EXAMPLES=OFF", "-DENABLE_TESTING=ON", "-DENABLE_CACHE=OFF"], + "common_options": [], + "targets": [], + "ctest": {"labels": [], "exclude_labels": [], "args": ["--no-tests=error", "--output-on-failure"]}, + "env": {}, + "modes": ["source", "installed"], + "configure_variants": [["-DWEBFRONT_MDDLOG_SOURCE_DIR=@workspace@/dependencies/mddlog"], ["-DCMAKE_PREFIX_PATH=@workspace@/mddlog-install"]], + "toolchain_file": "dependencies/mddlog/cmake/toolchains/linux-clang21-libcxx.cmake", + "evidence": ["-DWEBFRONT_MDDLOG_SOURCE_DIR=", "-DCMAKE_PREFIX_PATH=", "cmake --install build-mddlog-source/mddlog", "linux-clang21-libcxx.cmake"] + }, + { + "id": "mddlog-sanitizers-address-undefined", + "workflow": "MddlogIntegration.yml", "job": "sanitizers", "matrix": "address-undefined", + "machine": "RyzenLinux", "runtime": "container:linux-ubuntu-clang21-libcxx", + "compiler": {"family": "clang", "version": "21", "marker": "clang-21"}, + "cmake_version": "4.3.1", "build_type": "RelWithDebInfo", + "options": ["-DWEBFRONT_USE_MDDLOG=ON", "-DWEBFRONT_BUILD_EXAMPLES=OFF", "-DENABLE_TESTING=ON", "-DENABLE_CACHE=OFF"], + "common_options": [], + "toolchain_file": "dependencies/mddlog/cmake/toolchains/linux-clang21-libcxx.cmake", + "configure_variants": [["-DWEBFRONT_MDDLOG_SOURCE_DIR=@workspace@/dependencies/mddlog", "-DCMAKE_CXX_FLAGS=-stdlib=libc++ -fsanitize=address,undefined -fno-sanitize-recover=undefined -fno-omit-frame-pointer", "-DCMAKE_EXE_LINKER_FLAGS=-fsanitize=address,undefined -fno-sanitize-recover=undefined"]], + "targets": ["tests"], + "ctest": {"labels": [], "exclude_labels": [], "args": []}, + "catch2_direct": [["[transport],[weblink]", "--order", "rand", "x5"], ["--order", "rand"]], + "env": {"ASAN_OPTIONS": "detect_leaks=1:abort_on_error=1", "UBSAN_OPTIONS": "print_stacktrace=1:halt_on_error=1"}, + "sanitizer_flags": "-fsanitize=address,undefined -fno-sanitize-recover=undefined", + "evidence": ["for iteration in 1 2 3 4 5", "--target tests", "[transport],[weblink]"] + }, + { + "id": "mddlog-sanitizers-thread", + "workflow": "MddlogIntegration.yml", "job": "sanitizers", "matrix": "thread", + "machine": "RyzenLinux", "runtime": "container:linux-ubuntu-clang21-libcxx", + "compiler": {"family": "clang", "version": "21", "marker": "clang-21"}, + "cmake_version": "4.3.1", "build_type": "RelWithDebInfo", + "options": ["-DWEBFRONT_USE_MDDLOG=ON", "-DWEBFRONT_BUILD_EXAMPLES=OFF", "-DENABLE_TESTING=ON", "-DENABLE_CACHE=OFF"], + "common_options": [], + "toolchain_file": "dependencies/mddlog/cmake/toolchains/linux-clang21-libcxx.cmake", + "configure_variants": [["-DWEBFRONT_MDDLOG_SOURCE_DIR=@workspace@/dependencies/mddlog", "-DCMAKE_CXX_FLAGS=-stdlib=libc++ -fsanitize=thread -fno-omit-frame-pointer", "-DCMAKE_EXE_LINKER_FLAGS=-fsanitize=thread"]], + "targets": ["tests"], + "ctest": {"labels": [], "exclude_labels": [], "args": []}, + "catch2_direct": [["[transport],[weblink]", "--order", "rand", "x5"], ["--order", "rand"]], + "env": {"TSAN_OPTIONS": "halt_on_error=1:second_deadlock_stack=1"}, + "sanitizer_flags": "-fsanitize=thread", + "host_requirements": {"sysctl": {"vm.mmap_rnd_bits": "28"}}, + "evidence": ["vm.mmap_rnd_bits=28", "--target tests"] + } + ] +} diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 10238d0d..c84d27da 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Local CI matrix, step 1 of 3 (#346): `cmake/local-ci/lanes.json` describes the ten lanes of `BuildAndTest.yml` and `MddlogIntegration.yml` (machine, toolchain, CMake, options, targets, CTest labels), `docs/LOCAL_CI.md` documents them and their differences with GitHub, and the offline CTest cases `LocalCiLanesMatchWorkflows` and `LocalCiLanesRejectDrift` fail when the lanes and the workflows diverge. Command options are compared in both directions for each matrix variant; extra matrix axes and exclusions are rejected explicitly. The orchestrator, the Linux containers and the Windows and macOS sessions follow in steps 2 and 3. + - The README animation draws the C++ application inside the image, beside the WebFront window (#359): it is no longer cropped by the table column on narrow screens and in the GitHub app, and weighs 0.4 MB instead of 1.2 MB. The code stays in the README as text, in a collapsed block; `docs/tools/render-life-bootstrap.py` reads it from there. - The manifest and the lock of the repository move to `js/developer/` (#354): the driver and the CI select them with `--manifest-dir js/developer`, and the closed list of the root loses two entries (9 left). diff --git a/docs/LOCAL_CI.md b/docs/LOCAL_CI.md new file mode 100644 index 00000000..d437a037 --- /dev/null +++ b/docs/LOCAL_CI.md @@ -0,0 +1,89 @@ +# Local CI matrix + +Story #346: run the whole CI matrix of WebFront from a development machine, over SSH, on three machines of the local network +(`RyzenLinux`, `CurmudgeonWindows`, `Mac`), to validate a commit before pushing it. The machines stay under the sole control of +their owner: no self-hosted GitHub runner, no inbound connection from GitHub, no GitHub secret on the machines. GitHub CI remains the +reference for pull requests. + +## State of the delivery + +The story is delivered in three verifiable steps; a partial step does not close it. + +| Step | Content | State | +| --- | --- | --- | +| 1 | The ten lanes in `cmake/local-ci/lanes.json` and the offline drift check `LocalCiLanesMatchWorkflows` | delivered | +| 2 | Commit transport, provisioning without GitHub access, Linux containers and the orchestrator | not started | +| 3 | Native Windows and macOS sessions, result collection, full qualification and timings | not started | + +## The lanes + +`BuildAndTest.yml` expands to seven lanes and `MddlogIntegration.yml` to three. The workflows' trigger conditions (push, schedule, +manual dispatch) do not exempt the local matrix from the extended lanes: a full run selects all ten. + +| Lane | GitHub job | Machine | Toolchain | CMake | +| --- | --- | --- | --- | --- | +| `desktop-linux-gcc-webkitgtk` | `desktop` / `linux-gcc-webkitgtk` | `RyzenLinux` (container) | GCC 16, Debug, coverage, WebKitGTK | 4.4.4 | +| `desktop-windows-msvc-webview2` | `desktop` / `windows-msvc-webview2` | `CurmudgeonWindows` (native) | MSVC, Release, WebView2 | 4.4.4 | +| `desktop-macos-clang-wkwebview` | `desktop` / `macos-clang-wkwebview` | `Mac` (native) | AppleClang (latest Xcode), Release, WKWebView | 4.4.4 | +| `sanitizers-address-undefined` | `sanitizers` / `address-undefined` | `RyzenLinux` (container) | Clang 23, ASan+UBSan, fuzzing of four decoders | 4.4.4 | +| `sanitizers-thread` | `sanitizers` / `thread` | `RyzenLinux` (container) | Clang 23, TSan, libc++, `vm.mmap_rnd_bits=28` on the host | 4.4.4 | +| `web-integration-gcc` | `web-integration` / `gcc` | `RyzenLinux` (container) | GCC of Ubuntu 24.04 (effective version reported, not GCC 16), CEF | 4.4.4 | +| `web-integration-clang` | `web-integration` / `clang` | `RyzenLinux` (container) | Clang 23, CEF | 4.4.4 | +| `mddlog-clang-source-install` | `clang` | `RyzenLinux` (container) | Clang 21, libc++, source then installed mddlog | 4.3.1 | +| `mddlog-sanitizers-address-undefined` | `sanitizers` / `address-undefined` | `RyzenLinux` (container) | Clang 21, libc++, ASan+UBSan, Catch2 run directly | 4.3.1 | +| `mddlog-sanitizers-thread` | `sanitizers` / `thread` | `RyzenLinux` (container) | Clang 21, libc++, TSan, Catch2 run directly | 4.3.1 | + +mddlog lanes use the revision pinned in `MddlogIntegration.yml`; CMake 4.3.1 stays in the qualified 4.0 to 4.3 window. + +## Drift check + +`cmake/local-ci/lanes.json` is the single source. The CTest case `LocalCiLanesMatchWorkflows` runs +`test/cmake/CheckLocalCi.cmake` offline on the workflows as text and fails when: + +- a workflow job or matrix value has no lane, or a lane matches no job or matrix value; duplicate values, additional matrix axes, + exclusions and unsupported matrix syntax are rejected explicitly; +- the build type, an option, a target, a CTest label or argument, a sanitizer flag, an environment variable, a sysctl, the fuzzed + decoders or their duration, the compiler or the pinned CMake version of a lane differs from its job; +- the mddlog revision or repository of a lane differs from the workflow; +- this document does not name a lane; +- the declaration of the local differences below is removed. + +Configure options, build targets and CTest arguments are compared in both directions, after substituting the selected matrix row +and the sanitizer's string conditional. An additional option or test filter is drift too. Each switch keeps its operand during +comparison. Every configuration must have a build and, for CTest lanes, a test invocation on the same build directory. The mddlog +source and installed modes are checked separately; direct Catch2 arguments and repeat counts are checked as well. + +The reader supports the workflows' current block mappings, a single inline matrix axis with optional `include` rows, or an +`include`-only matrix. It reads scalar, folded and literal `run` scripts and direct `cmake`, `ctest` and Catch2 command lines. +It is not a general YAML or shell interpreter: a new matrix shape or unresolved matrix expression in a checked command must be +supported explicitly before the check can pass. Other evidence (compiler setup, environment and provisioning steps) remains a +textual check. + +`LocalCiLanesRejectDrift` mutates copies of the workflows and of the lanes, checking additions, removals, swapped sanitizer rows, +new axes and lost test invocations. It also checks that harmless argument and matrix-row reordering passes. +Workflows with CRLF line endings exercise both the mutation reader and the checker; CMake's `file(READ)` already normalizes them. + +The command metadata in `lanes.json` uses these fields: + +- `options` and `common_options` are the configuration's CMake definitions; `build_type` supplies `CMAKE_BUILD_TYPE`. +- `workflow_options` records the GitHub-specific cache definitions, checked exactly despite the declared local cache difference. +- `toolchain_file` supplies `CMAKE_TOOLCHAIN_FILE`. `configure_variants` adds each configure invocation's definitions in workflow + order (one variant by default), including source versus installed mddlog paths and sanitizer flags. +- `ctest.workflow_args` records GitHub's JUnit output and optional desktop repetition, in addition to `ctest.args` and the labels. +- `@workspace@` normalizes `github.workspace` paths. Other GitHub expressions are compared literally with whitespace removed; + the checker does not evaluate event-dependent desktop repetition. + +## Known differences with GitHub + +- Parallelism: GitHub builds with `--parallel 2`; local lanes use the jobs limit of their machine (4 simultaneous compilations on + Windows). +- Cache: GitHub restores `actions/cache` and sccache; local lanes keep persistent CPM and ccache volumes. The gain is to be measured, + not assumed. The desktop's `ENABLE_CACHE=OFF` and explicit sccache launcher are recorded in `workflow_options`. +- Reports and repetition: GitHub's JUnit paths and the desktop's event-dependent `--repeat` are recorded in `ctest.workflow_args`; + local result collection and stability-run selection belong to the orchestrator delivered in the later steps. +- Toolchains: GitHub installs them per run; local machines are prepared once. +- Runner images: `ubuntu-26.04`, `ubuntu-24.04`, `windows-2025` and `macos-26` are replaced by pinned containers and by the host + systems. The effective compiler and, on macOS, the selected Xcode are reported and compared with the `latest` of the runner. +- Steps with no local equivalent: artifact uploads (the orchestrator collects the logs), `sccache-action`, `actions/cache`, and the + isolation of the public network, which applies to the lane container instead of the host firewall. The workflows contain no Codecov, + Gist or badge step; coverage stays local as `coverage.info` and `lcov --list`. diff --git a/test/cmake/CheckLocalCi.cmake b/test/cmake/CheckLocalCi.cmake new file mode 100644 index 00000000..42fde5c5 --- /dev/null +++ b/test/cmake/CheckLocalCi.cmake @@ -0,0 +1,352 @@ +# The local CI matrix (cmake/local-ci/lanes.json, #346) has to describe every lane the GitHub workflows expand to: it fails on a job +# without lane, a lane without job, a different matrix, CMake version, compiler, option, target, CTest label, test step or mddlog +# revision. The local differences (cache, parallelism, toolchain, runner images, GitHub-only steps) are declared in the file and +# documented in docs/LOCAL_CI.md, which has to name every lane. Offline: the workflows are read as text. +# cmake -DROOT= [-DWORKFLOWS_DIR=] [-DLANES_FILE=] [-DDOC_FILE=] -P test/cmake/CheckLocalCi.cmake +cmake_minimum_required(VERSION 3.31) +include("${CMAKE_CURRENT_LIST_DIR}/LocalCiCommands.cmake") + +if(NOT ROOT) + message(FATAL_ERROR "ROOT is required") +endif() +if(NOT WORKFLOWS_DIR) + set(WORKFLOWS_DIR "${ROOT}/.github/workflows") +endif() +if(NOT LANES_FILE) + set(LANES_FILE "${ROOT}/cmake/local-ci/lanes.json") +endif() +if(NOT DOC_FILE) + set(DOC_FILE "${ROOT}/docs/LOCAL_CI.md") +endif() + +# A global property, so that checks made inside helper functions are not lost with their scope. +set_property(GLOBAL PROPERTY local_ci_problems "") +function(report message) + set_property(GLOBAL APPEND_STRING PROPERTY local_ci_problems "\n - ${message}") +endfunction() + +if(NOT EXISTS "${LANES_FILE}") + message(FATAL_ERROR "Missing ${LANES_FILE}") +endif() +file(READ "${LANES_FILE}" lanes_json) +string(JSON schema GET "${lanes_json}" schema) +if(NOT schema EQUAL 1) + message(FATAL_ERROR "Unsupported lanes.json schema: ${schema}") +endif() + +# The mandatory declaration of the local differences. +foreach(difference parallelism cache toolchain runner_images) + string(JSON text ERROR_VARIABLE err GET "${lanes_json}" local_differences ${difference}) + if(err OR text STREQUAL "") + report("local_differences.${difference} is not declared") + endif() +endforeach() +string(JSON github_only ERROR_VARIABLE err LENGTH "${lanes_json}" local_differences github_only_steps) +if(err OR github_only EQUAL 0) + report("local_differences.github_only_steps is not declared") +endif() + +# Splits the jobs: section of a workflow into one text per job (written to _), and returns the job names. +function(read_jobs workflow out_names prefix) + file(READ "${WORKFLOWS_DIR}/${workflow}" text) + string(FIND "${text}" "\njobs:\n" start) + if(start EQUAL -1) + message(FATAL_ERROR "${workflow} has no jobs: section") + endif() + string(SUBSTRING "${text}" ${start} -1 jobs_text) + string(REGEX MATCHALL "\n [A-Za-z][A-Za-z0-9_-]*:\n" headers "${jobs_text}") + set(names "") + set(positions "") + foreach(header IN LISTS headers) + string(FIND "${jobs_text}" "${header}" position) + string(STRIP "${header}" stripped) + string(REGEX REPLACE ":$" "" job "${stripped}") + list(APPEND names "${job}") + list(APPEND positions ${position}) + endforeach() + list(LENGTH names count) + set(index 0) + foreach(job IN LISTS names) + list(GET positions ${index} begin) + math(EXPR next "${index} + 1") + if(next LESS count) + list(GET positions ${next} finish) + else() + string(LENGTH "${jobs_text}" finish) + endif() + math(EXPR size "${finish} - ${begin}") + string(SUBSTRING "${jobs_text}" ${begin} ${size} block) + set(${prefix}_${job} "${block}" PARENT_SCOPE) + math(EXPR index "${index} + 1") + endforeach() + set(${out_names} "${names}" PARENT_SCOPE) +endfunction() + +# The values of a matrix: an inline list `key: [a, b]` or the `- key: value` entries of an include list. +function(matrix_values block key out) + set(values "") + if(block MATCHES "[ \n]${key}: \\[([^]\n]*)\\]") + string(REPLACE "," ";" values "${CMAKE_MATCH_1}") + else() + # Only the strategy: step names are `- name:` entries too. + string(FIND "${block}" "matrix:" from) + string(FIND "${block}" "\n steps:" to) + set(strategy "") + if(from GREATER -1 AND to GREATER from) + math(EXPR size "${to} - ${from}") + string(SUBSTRING "${block}" ${from} ${size} strategy) + endif() + string(REGEX MATCHALL "- ${key}: [A-Za-z0-9_-]+" entries "${strategy}") + foreach(entry IN LISTS entries) + string(REGEX REPLACE "^- ${key}: " "" value "${entry}") + list(APPEND values "${value}") + endforeach() + endif() + set(cleaned "") + foreach(value IN LISTS values) + string(STRIP "${value}" value) + list(APPEND cleaned "${value}") + endforeach() + set(${out} "${cleaned}" PARENT_SCOPE) +endfunction() + +function(require_text block lane what text) + string(FIND "${block}" "${text}" found) + if(found EQUAL -1) + report("lane ${lane}: ${what} '${text}' is not in the workflow job") + endif() +endfunction() + +function(json_strings json out) + string(JSON count ERROR_VARIABLE err LENGTH "${json}") + set(items "") + if(NOT err AND count GREATER 0) + math(EXPR last "${count} - 1") + foreach(i RANGE ${last}) + string(JSON item GET "${json}" ${i}) + list(APPEND items "${item}") + endforeach() + endif() + set(${out} "${items}" PARENT_SCOPE) +endfunction() + +# Jobs and matrices of every workflow against the declaration. +string(JSON lane_count LENGTH "${lanes_json}" lanes) +math(EXPR lane_last "${lane_count} - 1") +string(JSON workflow_count LENGTH "${lanes_json}" workflows) +math(EXPR workflow_last "${workflow_count} - 1") +set(lane_ids "") +set(lane_keys "") +foreach(i RANGE ${lane_last}) + string(JSON id GET "${lanes_json}" lanes ${i} id) + string(JSON workflow GET "${lanes_json}" lanes ${i} workflow) + string(JSON job GET "${lanes_json}" lanes ${i} job) + string(JSON matrix GET "${lanes_json}" lanes ${i} matrix) + list(APPEND lane_ids "${id}") + list(APPEND lane_keys "${workflow}|${job}|${matrix}") +endforeach() +list(LENGTH lane_ids id_count) +list(REMOVE_DUPLICATES lane_ids) +list(LENGTH lane_ids unique_ids) +if(NOT id_count EQUAL unique_ids) + report("lane ids are not unique") +endif() + +set(expected_keys "") +foreach(w RANGE ${workflow_last}) + string(JSON workflow MEMBER "${lanes_json}" workflows ${w}) + if(NOT EXISTS "${WORKFLOWS_DIR}/${workflow}") + report("workflow ${workflow} is declared but missing") + continue() + endif() + read_jobs("${workflow}" actual_jobs "job_${w}") + string(JSON declared_json GET "${lanes_json}" workflows "${workflow}" jobs) + json_strings("${declared_json}" declared_jobs) + foreach(job IN LISTS actual_jobs) + if(NOT job IN_LIST declared_jobs) + report("${workflow}: job '${job}' has no lane declaration") + endif() + endforeach() + foreach(job IN LISTS declared_jobs) + if(NOT job IN_LIST actual_jobs) + report("${workflow}: declared job '${job}' does not exist") + continue() + endif() + string(JSON matrix_json ERROR_VARIABLE err GET "${lanes_json}" workflows "${workflow}" matrices "${job}") + if(err OR matrix_json STREQUAL "" OR matrix_json MATCHES "NOTFOUND") + list(APPEND expected_keys "${workflow}|${job}|") + if("${job_${w}_${job}}" MATCHES "matrix:") + report("${workflow}: job '${job}' has a matrix that is not declared") + endif() + continue() + endif() + string(JSON key GET "${matrix_json}" key) + string(JSON values_json GET "${matrix_json}" values) + json_strings("${values_json}" declared_values) + lane_matrix("${job_${w}_${job}}" "${key}" "" unused_entry unused_block) + matrix_values("${job_${w}_${job}}" "${key}" actual_values) + list(LENGTH actual_values actual_count) + set(unique_values "${actual_values}") + list(REMOVE_DUPLICATES unique_values) + list(LENGTH unique_values unique_count) + if(NOT actual_count EQUAL unique_count) + report("${workflow}: ${job} matrix has duplicate values") + endif() + foreach(value IN LISTS actual_values) + if(NOT value IN_LIST declared_values) + report("${workflow}: ${job} matrix value '${value}' has no lane declaration") + endif() + endforeach() + foreach(value IN LISTS declared_values) + if(NOT value IN_LIST actual_values) + report("${workflow}: declared ${job} matrix value '${value}' does not exist") + endif() + list(APPEND expected_keys "${workflow}|${job}|${value}") + endforeach() + endforeach() +endforeach() +foreach(key IN LISTS expected_keys) + list(FIND lane_keys "${key}" first) + if(first EQUAL -1) + report("no lane for ${key}") + endif() +endforeach() +foreach(key IN LISTS lane_keys) + if(NOT key IN_LIST expected_keys) + report("lane ${key} matches no job or matrix value") + endif() +endforeach() +list(LENGTH lane_keys key_count) +list(REMOVE_DUPLICATES lane_keys) +list(LENGTH lane_keys unique_keys) +if(NOT key_count EQUAL unique_keys) + report("two lanes describe the same job and matrix value") +endif() + +# Every lane against the text of its job. +foreach(i RANGE ${lane_last}) + string(JSON id GET "${lanes_json}" lanes ${i} id) + string(JSON workflow GET "${lanes_json}" lanes ${i} workflow) + string(JSON job GET "${lanes_json}" lanes ${i} job) + string(JSON matrix GET "${lanes_json}" lanes ${i} matrix) + string(JSON build_type GET "${lanes_json}" lanes ${i} build_type) + string(JSON cmake_version GET "${lanes_json}" lanes ${i} cmake_version) + string(JSON marker GET "${lanes_json}" lanes ${i} compiler marker) + string(JSON machine GET "${lanes_json}" lanes ${i} machine) + if(NOT machine MATCHES "^(RyzenLinux|CurmudgeonWindows|Mac)$") + report("lane ${id}: unknown machine '${machine}'") + endif() + set(block "") + foreach(w RANGE ${workflow_last}) + string(JSON name MEMBER "${lanes_json}" workflows ${w}) + if(name STREQUAL workflow AND DEFINED job_${w}_${job}) + set(block "${job_${w}_${job}}") + set(workflow_index ${w}) + endif() + endforeach() + if(block STREQUAL "") + continue() + endif() + + set(entry "${block}") + if(NOT matrix STREQUAL "") + string(JSON key GET "${lanes_json}" workflows "${workflow}" matrices "${job}" key) + lane_matrix("${block}" "${key}" "${matrix}" entry block) + endif() + string(JSON lane GET "${lanes_json}" lanes ${i}) + check_lane_commands("${block}" "${lane}") + + if(entry MATCHES "build_type: ([A-Za-z]+)") + if(NOT CMAKE_MATCH_1 STREQUAL build_type) + report("lane ${id}: build type ${build_type}, workflow has ${CMAKE_MATCH_1}") + endif() + else() + require_text("${block}" "${id}" "build type" "-DCMAKE_BUILD_TYPE=${build_type}") + endif() + + # CMake versions: every setup-cmake of the job. + string(REGEX MATCHALL "[ ]version: '[0-9.]+'" versions "${block}") + if(NOT versions) + report("lane ${id}: the job installs no pinned CMake") + endif() + foreach(version IN LISTS versions) + if(NOT version MATCHES "'${cmake_version}'") + report("lane ${id}: CMake ${cmake_version}, workflow has ${version}") + endif() + endforeach() + + if(NOT marker STREQUAL "") + require_text("${block}" "${id}" "compiler" "${marker}") + endif() + + string(JSON env_json GET "${lanes_json}" lanes ${i} env) + string(JSON env_count LENGTH "${env_json}") + if(env_count GREATER 0) + math(EXPR env_last "${env_count} - 1") + foreach(e RANGE ${env_last}) + string(JSON env_key MEMBER "${env_json}" ${e}) + string(JSON env_value GET "${env_json}" "${env_key}") + require_text("${block}" "${id}" "environment variable" "${env_key}") + require_text("${block}" "${id}" "environment value" "${env_value}") + endforeach() + endif() + + string(JSON flags ERROR_VARIABLE err GET "${lanes_json}" lanes ${i} sanitizer_flags) + if(NOT err) + require_text("${block}" "${id}" "sanitizer flags" "${flags}") + endif() + string(JSON sysctl_json ERROR_VARIABLE err GET "${lanes_json}" lanes ${i} host_requirements sysctl) + if(NOT err) + string(JSON sysctl_key MEMBER "${sysctl_json}" 0) + string(JSON sysctl_value GET "${sysctl_json}" "${sysctl_key}") + require_text("${block}" "${id}" "sysctl" "${sysctl_key}=${sysctl_value}") + endif() + + string(JSON fuzz_json ERROR_VARIABLE err GET "${lanes_json}" lanes ${i} fuzz_decoders) + if(NOT err) + json_strings("${fuzz_json}" decoders) + string(REPLACE ";" " " decoder_text "${decoders}") + require_text("${block}" "${id}" "fuzzed decoders" "for decoder in ${decoder_text}") + string(JSON fuzz_seconds GET "${lanes_json}" lanes ${i} fuzz_seconds) + require_text("${block}" "${id}" "fuzz duration" "-max_total_time=${fuzz_seconds}") + endif() + + string(JSON evidence_json GET "${lanes_json}" lanes ${i} evidence) + json_strings("${evidence_json}" evidence) + foreach(text IN LISTS evidence) + require_text("${block}" "${id}" "step" "${text}") + endforeach() + + # The pinned mddlog revision of the Mddlog workflow. + if(workflow STREQUAL "MddlogIntegration.yml") + string(JSON mddlog_ref GET "${lanes_json}" mddlog ref) + string(JSON mddlog_repository GET "${lanes_json}" mddlog repository) + require_text("${block}" "${id}" "mddlog revision" "ref: ${mddlog_ref}") + require_text("${block}" "${id}" "mddlog repository" "repository: ${mddlog_repository}") + string(REGEX MATCHALL "ref: [0-9a-f]+" refs "${block}") + foreach(ref IN LISTS refs) + if(NOT ref STREQUAL "ref: ${mddlog_ref}") + report("lane ${id}: workflow pins ${ref}, lanes.json pins ${mddlog_ref}") + endif() + endforeach() + endif() +endforeach() + +# The documentation names every lane. +if(EXISTS "${DOC_FILE}") + file(READ "${DOC_FILE}" doc) + foreach(id IN LISTS lane_ids) + string(FIND "${doc}" "`${id}`" found) + if(found EQUAL -1) + report("${DOC_FILE} does not document lane ${id}") + endif() + endforeach() +else() + report("missing ${DOC_FILE}") +endif() + +get_property(problems GLOBAL PROPERTY local_ci_problems) +if(problems) + message(FATAL_ERROR "cmake/local-ci/lanes.json drifted from the workflows:${problems}") +endif() +message(STATUS "${lane_count} local CI lanes match ${WORKFLOWS_DIR}") diff --git a/test/cmake/CheckLocalCiNegative.cmake b/test/cmake/CheckLocalCiNegative.cmake new file mode 100644 index 00000000..641bf03c --- /dev/null +++ b/test/cmake/CheckLocalCiNegative.cmake @@ -0,0 +1,139 @@ +# Proves that CheckLocalCi.cmake rejects drift and accepts equivalent command/matrix layouts. +# cmake -DROOT= -DWORK_DIR= -P test/cmake/CheckLocalCiNegative.cmake +cmake_minimum_required(VERSION 3.31) + +if(NOT ROOT OR NOT WORK_DIR) + message(FATAL_ERROR "ROOT and WORK_DIR are required") +endif() + +function(crlf_workflows dir) + foreach(workflow BuildAndTest.yml MddlogIntegration.yml) + file(READ "${dir}/workflows/${workflow}" text) + string(REPLACE "\n" "\r\n" text "${text}") + file(WRITE "${dir}/workflows/${workflow}" "${text}") + endforeach() +endfunction() + +# Mutate copies by replacing `from` with `to`. A nonempty `expect` requires failure +# with that diagnostic; an empty one requires success. An optional CRLF argument +# exercises both the mutation reader and the checker with Windows line endings. +function(check_mutation name file from to expect) + set(dir "${WORK_DIR}/${name}") + file(REMOVE_RECURSE "${dir}") + file(MAKE_DIRECTORY "${dir}/workflows") + file(COPY "${ROOT}/.github/workflows/BuildAndTest.yml" "${ROOT}/.github/workflows/MddlogIntegration.yml" DESTINATION "${dir}/workflows") + file(COPY "${ROOT}/cmake/local-ci/lanes.json" DESTINATION "${dir}") + file(COPY "${ROOT}/docs/LOCAL_CI.md" DESTINATION "${dir}") + if(file STREQUAL "lanes.json" OR file STREQUAL "LOCAL_CI.md") + set(target "${dir}/${file}") + else() + set(target "${dir}/workflows/${file}") + endif() + if(ARGV5 STREQUAL "CRLF") + crlf_workflows("${dir}") + endif() + # file(READ) already normalizes CRLF, including in the minimum CMake 3.31. + file(READ "${target}" text) + string(FIND "${text}" "${from}" found) + if(found EQUAL -1) + message(FATAL_ERROR "${name}: '${from}' is not in ${file}, the mutation proves nothing") + endif() + string(REPLACE "${from}" "${to}" text "${text}") + file(WRITE "${target}" "${text}") + if(ARGV5 STREQUAL "CRLF") + crlf_workflows("${dir}") + endif() + execute_process(COMMAND "${CMAKE_COMMAND}" -DROOT=${ROOT} -DWORKFLOWS_DIR=${dir}/workflows + -DLANES_FILE=${dir}/lanes.json -DDOC_FILE=${dir}/LOCAL_CI.md -P "${CMAKE_CURRENT_LIST_DIR}/CheckLocalCi.cmake" + RESULT_VARIABLE result OUTPUT_VARIABLE out ERROR_VARIABLE err) + if(expect STREQUAL "") + if(NOT result EQUAL 0) + message(FATAL_ERROR "${name}: equivalent workflow was rejected:\n${out}${err}") + endif() + return() + endif() + if(result EQUAL 0) + message(FATAL_ERROR "${name}: the drift was not rejected") + endif() + string(FIND "${out}${err}" "${expect}" reported) + if(reported EQUAL -1) + message(FATAL_ERROR "${name}: expected '${expect}' in:\n${out}${err}") + endif() +endfunction() + +check_mutation(new-job BuildAndTest.yml "\n web-integration:\n" "\n extra-job:\n runs-on: x\n steps: []\n\n web-integration:\n" "extra-job") +check_mutation(matrix-value BuildAndTest.yml "sanitizer: [address-undefined, thread]" "sanitizer: [address-undefined, thread, memory]" "memory") +check_mutation(cmake-version BuildAndTest.yml "version: '4.4.4'" "version: '4.4.3'" "4.4.3") +check_mutation(mddlog-ref MddlogIntegration.yml "ref: 5b43265664d83c3b7135d328f611e685792a1b02" "ref: 0000000000000000000000000000000000000000" "mddlog") +check_mutation(compiler BuildAndTest.yml "clang-23" "clang-24" "clang-23") +check_mutation(option BuildAndTest.yml "-DENABLE_COVERAGE=ON" "-DENABLE_COVERAGE=OFF" "-DENABLE_COVERAGE=ON") +check_mutation(ctest-label BuildAndTest.yml "-L web-integration" "-L web" "-L web-integration") +check_mutation(lane-removed lanes.json + "\"job\": \"web-integration\", \"matrix\": \"gcc\"" + "\"job\": \"web-integration\", \"matrix\": \"gcc-old\"" + "no lane for BuildAndTest.yml|web-integration|gcc") +check_mutation(undocumented-lane LOCAL_CI.md "`sanitizers-thread`" "`sanitizers-tsan`" "sanitizers-thread") + +# Compare both directions: additions and removal from either side are drift too. +check_mutation(extra-option BuildAndTest.yml "-DENABLE_COVERAGE=ON" "-DENABLE_COVERAGE=ON -DENABLE_SANITIZER_ADDRESS=ON" "configure options") +check_mutation(extra-ctest-filter BuildAndTest.yml "ctest --test-dir build -C" "ctest --test-dir build -L web-integration -C" "CTest arguments") +check_mutation(extra-ctest-exclude BuildAndTest.yml "ctest --test-dir build -C" "ctest --test-dir build -LE web-integration -C" "CTest arguments") +check_mutation(extra-ctest-regex BuildAndTest.yml "ctest --test-dir build -C" "ctest --test-dir build -R transport -C" "CTest arguments") +check_mutation(ctest-parallel-operand BuildAndTest.yml "--no-tests=error --parallel 4" "--no-tests=error --parallel 3" "CTest arguments") +check_mutation(extra-target BuildAndTest.yml "--target webtest developer_integration webfront-wf" "--target webtest developer_integration webfront-wf tests" "build targets") +check_mutation(removed-declared-option lanes.json "\"-DENABLE_COVERAGE=ON\"" "\"-DENABLE_COVERAGE=OFF\"" "configure options") + +# The flags still occur in the job, but belong to the wrong matrix rows. +check_mutation(swapped-sanitizers MddlogIntegration.yml + "- name: address-undefined\n flags: -fsanitize=address,undefined -fno-sanitize-recover=undefined\n - name: thread\n flags: -fsanitize=thread" + "- name: address-undefined\n flags: -fsanitize=thread\n - name: thread\n flags: -fsanitize=address,undefined -fno-sanitize-recover=undefined" + "configure options") +check_mutation(swapped-sanitizer-branches BuildAndTest.yml + "matrix.sanitizer == 'thread' &&" "matrix.sanitizer == 'address-undefined' &&" "configure options") +check_mutation(unresolved-matrix-command BuildAndTest.yml + "matrix.options }}" "matrix.unknown_options }}" "unsupported command expression") + +# Additional axes and exclusions need explicit support, not a partial expansion. +check_mutation(extra-inline-axis BuildAndTest.yml + "compiler: [gcc, clang]" "compiler: [gcc, clang]\n optimization: [O1, O2]" "unsupported matrix field 'optimization'") +check_mutation(extra-block-axis BuildAndTest.yml + "compiler: [gcc, clang]" "compiler: [gcc, clang]\n optimization:\n - O1\n - O2" "unsupported matrix field 'optimization'") +check_mutation(matrix-exclusion BuildAndTest.yml + "compiler: [gcc, clang]" "compiler: [gcc, clang]\n exclude:\n - compiler: clang" "unsupported matrix field 'exclude'") + +# Every execution mode must keep its own commands, not merely evidence elsewhere. +check_mutation(installed-tests-removed MddlogIntegration.yml + "run: ctest --test-dir build-mddlog-install --output-on-failure --no-tests=error" + "run: echo tests skipped" "ctests count") +check_mutation(installed-option-changed MddlogIntegration.yml + [[-DCMAKE_PREFIX_PATH=${{ github.workspace }}/mddlog-install]] + [[-DCMAKE_PREFIX_PATH=${{ github.workspace }}/wrong-install]] "configure options") +check_mutation(catch-order-changed MddlogIntegration.yml + "--order rand" "--order lex" "Catch2 arguments") +check_mutation(catch-full-suite-removed MddlogIntegration.yml + "run: ./build-sanitized/test/unit/tests --order rand" "run: echo tests skipped" "catch_calls count") +check_mutation(catch-repeat-changed MddlogIntegration.yml + "for iteration in 1 2 3 4 5; do" "for iteration in 1 2 3; do" "Catch2 arguments") + +check_mutation(extra-target-equals BuildAndTest.yml + "cmake --build build --config" "cmake --build build --target=tests --config" "build targets") +check_mutation(installed-tests-wrong-directory MddlogIntegration.yml + "ctest --test-dir build-mddlog-install" "ctest --test-dir build-mddlog-source" "configured and tested directories") +check_mutation(duplicate-matrix-value BuildAndTest.yml + "compiler: [gcc, clang]" "compiler: [gcc, clang, clang]" "matrix has duplicate values") +check_mutation(ctest-repeat-changed BuildAndTest.yml + "until-fail:" "until-pass:" "CTest arguments") +check_mutation(comment-cannot-replace-option BuildAndTest.yml + "options: -DWEBFRONT_EMBED_WEBVIEW2=ON -DWEBFRONT_WEBTEST_FRONTEND=WebView2" + "# -DWEBFRONT_EMBED_WEBVIEW2=ON\n options: -DWEBFRONT_WEBTEST_FRONTEND=WebView2" "configure options") + +# Equivalent layouts must stay valid: ordering and shell quoting are not drift. +check_mutation(reordered-ctest-options BuildAndTest.yml + "--output-on-failure --no-tests=error" "--no-tests=error --output-on-failure" "") +check_mutation(quoted-cmake-option BuildAndTest.yml + "-DENABLE_COVERAGE=ON" "'-DENABLE_COVERAGE=ON'" "") +check_mutation(reordered-matrix-rows MddlogIntegration.yml + "- name: address-undefined\n flags: -fsanitize=address,undefined -fno-sanitize-recover=undefined\n - name: thread\n flags: -fsanitize=thread" + "- name: thread\n flags: -fsanitize=thread\n - name: address-undefined\n flags: -fsanitize=address,undefined -fno-sanitize-recover=undefined" "") +check_mutation(crlf-workflows BuildAndTest.yml + "matrix:\n compiler: [gcc, clang]" "matrix:\n compiler: [gcc, clang]" "" CRLF) diff --git a/test/cmake/LocalCiCommands.cmake b/test/cmake/LocalCiCommands.cmake new file mode 100644 index 00000000..c59c5a6c --- /dev/null +++ b/test/cmake/LocalCiCommands.cmake @@ -0,0 +1,361 @@ +# Deliberately bounded readers for the workflow syntax used by the local CI lanes. +# They never evaluate shell code or GitHub expressions. New matrix shapes must be +# taught to the checker rather than silently reducing the number of checked lanes. +function(lane_matrix block key value out_entry out_block) + string(REPLACE ";" "\\;" lines "${block}") + string(REPLACE "\n" ";" lines "${lines}") + set(in_matrix FALSE) + set(selected FALSE) + set(entry "") + set(matrix_text "") + foreach(line IN LISTS lines) + if(line STREQUAL " matrix:") + set(in_matrix TRUE) + string(APPEND matrix_text "${line}\n") + continue() + endif() + if(NOT in_matrix) + continue() + endif() + if(line MATCHES "^ *[^ #]" AND NOT line MATCHES "^ ") + set(in_matrix FALSE) + continue() + endif() + string(APPEND matrix_text "${line}\n") + if(line MATCHES "^ ([A-Za-z_][A-Za-z0-9_-]*): *(.*)$") + set(field "${CMAKE_MATCH_1}") + set(contents "${CMAKE_MATCH_2}") + if(NOT field STREQUAL key AND NOT field STREQUAL "include") + report("unsupported matrix field '${field}': declare and support every matrix axis") + elseif(field STREQUAL key AND NOT contents MATCHES "^\\[[^]]+\\]$") + report("unsupported matrix axis '${key}': expected an inline list") + elseif(field STREQUAL "include" AND NOT contents STREQUAL "") + report("unsupported matrix include: expected a block list") + endif() + elseif(line MATCHES "^ *- ([A-Za-z_][A-Za-z0-9_-]*): *([A-Za-z0-9_-]+)$") + if(NOT CMAKE_MATCH_1 STREQUAL key) + report("unsupported matrix include key '${CMAKE_MATCH_1}', expected '${key}'") + endif() + if(CMAKE_MATCH_2 STREQUAL value) + set(selected TRUE) + else() + set(selected FALSE) + endif() + elseif(NOT line MATCHES "^ *(#.*)?$" AND NOT line MATCHES "^ +[A-Za-z_][A-Za-z0-9_-]*: .+$") + report("unsupported matrix syntax: ${line}") + endif() + if(selected) + string(APPEND entry "${line}\n") + endif() + endforeach() + if(matrix_text STREQUAL "") + report("unsupported or missing matrix block") + endif() + string(REPLACE "${matrix_text}" "" resolved "${block}") + + # Resolve only the selected row and the simple string-valued conditional used + # by the sanitizer configure command. Other expressions fail in command_tokens. + set(conditional "\\$\\{\\{ *matrix\\.([A-Za-z_-]+) == '([^']*)' && '([^']*)' \\|\\| '([^']*)' *\\}\\}") + while(resolved MATCHES "${conditional}") + set(expression "${CMAKE_MATCH_0}") + if(NOT CMAKE_MATCH_1 STREQUAL key) + report("unsupported matrix condition: ${expression}") + break() + endif() + if(CMAKE_MATCH_2 STREQUAL value) + set(replacement "${CMAKE_MATCH_3}") + else() + set(replacement "${CMAKE_MATCH_4}") + endif() + string(REPLACE "${expression}" "${replacement}" resolved "${resolved}") + endwhile() + string(REGEX MATCHALL "\\$\\{\\{ *matrix\\.[A-Za-z_-]+ *\\}\\}" expressions "${resolved}") + foreach(expression IN LISTS expressions) + string(REGEX MATCH "matrix\\.([A-Za-z_-]+)" unused "${expression}") + set(field "${CMAKE_MATCH_1}") + if(field STREQUAL key) + set(replacement "${value}") + elseif(entry MATCHES "\n *${field}: ([^\n]*)") + set(replacement "${CMAKE_MATCH_1}") + else() + continue() + endif() + string(REPLACE "${expression}" "${replacement}" resolved "${resolved}") + endforeach() + set(${out_entry} "${entry}" PARENT_SCOPE) + set(${out_block} "${resolved}" PARENT_SCOPE) +endfunction() + +function(json_quote value out) + string(REPLACE "\\" "\\\\" value "${value}") + string(REPLACE "\"" "\\\"" value "${value}") + string(REPLACE "\n" "\\n" value "${value}") + string(REPLACE "\r" "\\r" value "${value}") + string(REPLACE "\t" "\\t" value "${value}") + set(${out} "\"${value}\"" PARENT_SCOPE) +endfunction() + +# Collect run scalars, folding >- and preserving literal | scripts. YAML keys and +# comments cannot masquerade as executed command arguments. +function(workflow_scripts block out) + string(REPLACE ";" "\\;" lines "${block}\nEND") + string(REPLACE "\n" ";" lines "${lines}") + set(scripts "[]") + set(active FALSE) + foreach(line IN LISTS lines) + if(active) + string(REGEX MATCH "^ *" indent "${line}") + string(LENGTH "${indent}" width) + if(line MATCHES "^ *$" OR width GREATER run_indent) + string(STRIP "${line}" content) + string(APPEND script "${content}${separator}") + continue() + endif() + json_quote("${script}" quoted) + string(JSON count LENGTH "${scripts}") + string(JSON scripts SET "${scripts}" ${count} "${quoted}") + set(active FALSE) + endif() + if(line MATCHES "^( *)run: *(.*)$") + string(LENGTH "${CMAKE_MATCH_1}" run_indent) + set(script "${CMAKE_MATCH_2}") + if(script MATCHES "^[>|][-+]?$") + if(script MATCHES "^>") + set(separator " ") + else() + set(separator "\n") + endif() + set(script "") + set(active TRUE) + else() + json_quote("${script}" quoted) + string(JSON count LENGTH "${scripts}") + string(JSON scripts SET "${scripts}" ${count} "${quoted}") + endif() + endif() + endforeach() + set(${out} "${scripts}" PARENT_SCOPE) +endfunction() + +function(command_tokens command lane out) + # Workspace paths vary locally. Compact the remaining expressions to keep + # them single tokens; their exact contents are still compared to lanes.json. + string(REGEX REPLACE "\\$\\{\\{ *github\\.workspace *\\}\\}" "@workspace@" command "${command}") + string(REGEX MATCHALL "\\$\\{\\{[^}]*\\}\\}" expressions "${command}") + set(index 0) + foreach(expression IN LISTS expressions) + if(expression MATCHES "matrix\\.") + report("lane ${lane}: unsupported command expression ${expression}") + endif() + string(REPLACE " " "" expression_${index} "${expression}") + string(REPLACE "${expression}" "@expression${index}@" command "${command}") + math(EXPR index "${index} + 1") + endforeach() + separate_arguments(tokens UNIX_COMMAND "${command}") + while(index GREATER 0) + math(EXPR index "${index} - 1") + string(REPLACE "@expression${index}@" "${expression_${index}}" tokens "${tokens}") + endwhile() + set(${out} "${tokens}" PARENT_SCOPE) +endfunction() + +function(compare_arguments lane what expected actual) + # Argument order is irrelevant for these option lists, but duplicates and + # values are significant (including the operand of a CTest filter). + list(SORT expected) + list(SORT actual) + if(NOT "${expected}" STREQUAL "${actual}") + report("lane ${lane}: ${what} differ: expected [${expected}], workflow [${actual}]") + endif() +endfunction() + +# Keep each CTest switch attached to its operand before comparing option sets. +function(option_pairs tokens out) + set(pairs "") + while(tokens) + list(POP_FRONT tokens token) + if(token MATCHES "^-" AND NOT token MATCHES "=" AND tokens) + list(GET tokens 0 next) + if(NOT next MATCHES "^-") + list(POP_FRONT tokens next) + string(APPEND token "=${next}") + endif() + endif() + list(APPEND pairs "${token}") + endwhile() + set(${out} "${pairs}" PARENT_SCOPE) +endfunction() + +function(check_lane_commands block lane) + string(JSON id GET "${lane}" id) + string(JSON build_type GET "${lane}" build_type) + set(expected_options "-DCMAKE_BUILD_TYPE=${build_type}") + foreach(field options common_options workflow_options) + string(JSON array ERROR_VARIABLE err GET "${lane}" ${field}) + if(NOT err) + json_strings("${array}" items) + list(APPEND expected_options ${items}) + endif() + endforeach() + string(JSON toolchain ERROR_VARIABLE err GET "${lane}" toolchain_file) + if(NOT err) + list(APPEND expected_options "-DCMAKE_TOOLCHAIN_FILE=@workspace@/${toolchain}") + endif() + string(JSON variants ERROR_VARIABLE err GET "${lane}" configure_variants) + if(err) + set(variants "[[]]") + endif() + string(JSON configure_count LENGTH "${variants}") + string(JSON array GET "${lane}" targets) + json_strings("${array}" expected_targets) + string(JSON array GET "${lane}" ctest args) + json_strings("${array}" expected_ctest) + if(expected_ctest) + set(ctest_count ${configure_count}) + else() + set(ctest_count 0) + endif() + foreach(field labels exclude_labels workflow_args) + string(JSON array ERROR_VARIABLE err GET "${lane}" ctest ${field}) + if(NOT err) + json_strings("${array}" items) + foreach(item IN LISTS items) + if(field STREQUAL "labels") + list(APPEND expected_ctest "-L" "${item}") + elseif(field STREQUAL "exclude_labels") + list(APPEND expected_ctest "-LE" "${item}") + else() + list(APPEND expected_ctest "${item}") + endif() + endforeach() + endif() + endforeach() + option_pairs("${expected_ctest}" expected_ctest) + set(configures 0) + set(builds 0) + set(ctests 0) + set(catch_calls 0) + set(configure_dirs "") + set(build_dirs "") + set(ctest_dirs "") + workflow_scripts("${block}" scripts) + string(JSON count LENGTH "${scripts}") + if(count EQUAL 0) + report("lane ${id}: no run commands") + return() + endif() + math(EXPR last "${count} - 1") + foreach(i RANGE ${last}) + string(JSON script GET "${scripts}" ${i}) + string(REPLACE "\\\n" " " script "${script}") + string(REPLACE ";" "\\;" lines "${script}") + string(REPLACE "\n" ";" lines "${lines}") + foreach(line IN LISTS lines) + string(STRIP "${line}" line) + if(NOT line MATCHES "^(cmake |ctest |\\./[^ ]+/test/unit/tests )") + continue() + endif() + command_tokens("${line}" "${id}" tokens) + list(POP_FRONT tokens program) + if(program STREQUAL "cmake" AND NOT line MATCHES "^cmake --") + set(actual_options "") + set(was_build_dir FALSE) + foreach(token IN LISTS tokens) + if(was_build_dir) + list(APPEND configure_dirs "${token}") + endif() + if(token STREQUAL "-B") + set(was_build_dir TRUE) + else() + set(was_build_dir FALSE) + endif() + if(token MATCHES "^-D") + list(APPEND actual_options "${token}") + endif() + endforeach() + set(expected "${expected_options}") + if(configures LESS configure_count) + string(JSON array GET "${variants}" ${configures}) + json_strings("${array}" items) + list(APPEND expected ${items}) + endif() + compare_arguments("${id}" "configure options" "${expected}" "${actual_options}") + math(EXPR configures "${configures} + 1") + elseif(program STREQUAL "cmake" AND line MATCHES "^cmake --build ") + list(GET tokens 1 directory) + list(APPEND build_dirs "${directory}") + set(targets "") + set(in_targets FALSE) + foreach(token IN LISTS tokens) + if(token STREQUAL "--target") + set(in_targets TRUE) + elseif(token MATCHES "^--target=(.+)$") + list(APPEND targets "${CMAKE_MATCH_1}") + set(in_targets TRUE) + elseif(token MATCHES "^-") + set(in_targets FALSE) + elseif(in_targets) + list(APPEND targets "${token}") + endif() + endforeach() + compare_arguments("${id}" "build targets" "${expected_targets}" "${targets}") + math(EXPR builds "${builds} + 1") + elseif(program STREQUAL "ctest") + set(actual "") + while(tokens) + list(POP_FRONT tokens token) + if(token STREQUAL "--test-dir" OR token STREQUAL "-C") + if(NOT tokens) + report("lane ${id}: CTest ${token} has no operand") + break() + endif() + list(POP_FRONT tokens operand) + if(token STREQUAL "--test-dir") + list(APPEND ctest_dirs "${operand}") + endif() + if(token STREQUAL "-C" AND NOT operand STREQUAL build_type) + report("lane ${id}: CTest configuration ${operand}, expected ${build_type}") + endif() + else() + list(APPEND actual "${token}") + endif() + endwhile() + option_pairs("${actual}" actual) + compare_arguments("${id}" "CTest arguments" "${expected_ctest}" "${actual}") + math(EXPR ctests "${ctests} + 1") + elseif(program MATCHES "/test/unit/tests$") + string(JSON array ERROR_VARIABLE err GET "${lane}" catch2_direct ${catch_calls}) + if(err) + report("lane ${id}: undeclared Catch2 command") + else() + json_strings("${array}" expected) + if(script MATCHES "for iteration in ([0-9 ]+); do") + separate_arguments(iterations UNIX_COMMAND "${CMAKE_MATCH_1}") + list(LENGTH iterations repeats) + list(APPEND tokens "x${repeats}") + endif() + option_pairs("${expected}" expected) + option_pairs("${tokens}" actual) + compare_arguments("${id}" "Catch2 arguments" "${expected}" "${actual}") + endif() + math(EXPR catch_calls "${catch_calls} + 1") + endif() + endforeach() + endforeach() + compare_arguments("${id}" "configured and built directories" "${configure_dirs}" "${build_dirs}") + if(ctest_count GREATER 0) + compare_arguments("${id}" "configured and tested directories" "${configure_dirs}" "${ctest_dirs}") + endif() + string(JSON catch_count ERROR_VARIABLE err LENGTH "${lane}" catch2_direct) + if(err) + set(catch_count 0) + endif() + foreach(pair "configures|${configure_count}" "builds|${configure_count}" "ctests|${ctest_count}" "catch_calls|${catch_count}") + string(REPLACE "|" ";" pair "${pair}") + list(GET pair 0 field) + list(GET pair 1 expected) + if(NOT ${field} EQUAL expected) + report("lane ${id}: ${field} count ${${field}}, expected ${expected}") + endif() + endforeach() +endfunction() diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index cfffa92e..19eb3a1d 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -80,6 +80,12 @@ add_test(NAME RepositoryLayoutRejectsVendoredSources COMMAND ${CMAKE_COMMAND} -DROOT=${PROJECT_SOURCE_DIR} -DGIT_EXECUTABLE=${GIT_EXECUTABLE} -DWORK_DIR=${CMAKE_CURRENT_BINARY_DIR}/layout-negative -P ${PROJECT_SOURCE_DIR}/test/cmake/CheckRepositoryLayoutNegative.cmake) +# The local CI matrix (#346) has to keep describing the lanes of the GitHub workflows. +add_test(NAME LocalCiLanesMatchWorkflows + COMMAND ${CMAKE_COMMAND} -DROOT=${PROJECT_SOURCE_DIR} -P ${PROJECT_SOURCE_DIR}/test/cmake/CheckLocalCi.cmake) +add_test(NAME LocalCiLanesRejectDrift + COMMAND ${CMAKE_COMMAND} -DROOT=${PROJECT_SOURCE_DIR} -DWORK_DIR=${CMAKE_CURRENT_BINARY_DIR}/local-ci-negative + -P ${PROJECT_SOURCE_DIR}/test/cmake/CheckLocalCiNegative.cmake) add_test(NAME NewcomerDocsMatchExamples COMMAND ${CMAKE_COMMAND} -DROOT=${PROJECT_SOURCE_DIR} -P ${PROJECT_SOURCE_DIR}/test/cmake/CheckNewcomerDocs.cmake) add_test(NAME FrontendSelection