Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/build-clang-x86_64.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: "Build: x86_64 (Clang)"

# Both configurations, as CORELIB_PLAN §12.1 requires — see the GCC workflow for
# why the Release leg is worth its runtime. `fail-fast: false` keeps one red leg
# from hiding the other's result.

on:
push:
branches: [ main ]
Expand All @@ -10,6 +14,11 @@ jobs:
build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
build_type: [ Debug, Release ]

steps:
- name: Checkout repository
uses: actions/checkout@v7
Expand All @@ -23,7 +32,7 @@ jobs:
- name: Configure with CMake
run: |
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DCMAKE_CXX_COMPILER=clang++

- name: Build project
Expand Down
15 changes: 13 additions & 2 deletions .github/workflows/build-gcc-x86_64.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: "Build: x86_64 (GCC)"

# CORELIB_PLAN §12.1 requires both a debug and a release configuration to be
# built and tested: Release is -O3 -DNDEBUG, where strict-aliasing or UB in the
# varint window fast paths and optimiser-visible use of an uninitialised field
# first become observable. `fail-fast: false` keeps one red leg from hiding the
# other's result.

on:
push:
branches: [ main ]
Expand All @@ -10,6 +16,11 @@ jobs:
build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
build_type: [ Debug, Release ]

steps:
- name: Checkout repository
uses: actions/checkout@v7
Expand All @@ -23,7 +34,7 @@ jobs:
- name: Configure with CMake
run: |
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DCMAKE_CXX_COMPILER=g++

- name: Build project
Expand All @@ -38,7 +49,7 @@ jobs:
- name: Configure (strict UTF-8 OFF)
run: |
cmake -S . -B build-utf8-off \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DCMAKE_CXX_COMPILER=g++ \
-DCMAKE_CXX_FLAGS="-DSOFAB_STRICT_UTF8=0"

Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ C backend.
### Built with the following compilers

Non-native targets are built and run under [QEMU](https://www.qemu.org/)
user-mode emulation in CI, reproducible locally without the real hardware.
user-mode emulation in CI, reproducible locally without the real hardware. Both
x86_64 legs build and run the full suite twice — in `Debug` **and** in `Release`
(`-O3 -DNDEBUG`) — so a defect only the optimiser exposes cannot ship green.

| Target | Status |
| - | - |
Expand Down Expand Up @@ -673,7 +675,12 @@ Always give `--parallel` an explicit job count. Bare `--parallel` defers to the
native build tool's default, and with the Unix Makefiles generator that is
`make -j` with *no* limit — one compiler per translation unit, all at once.

Three suites run under CTest:
Run it in both configurations — `-DCMAKE_BUILD_TYPE=Debug` and
`-DCMAKE_BUILD_TYPE=Release` — which is what CI does; a Release-only defect
(strict aliasing, UB the optimiser acts on, an uninitialised field) is invisible
to a Debug-only run.

Four suites run under CTest:

- **`test_roundtrip`** — encode/decode/nested/chunked/skip checks plus the
three-valued decode outcome (§7: COMPLETE / INCOMPLETE / INVALID), malformed-input
Expand Down Expand Up @@ -712,6 +719,15 @@ Three suites run under CTest:
drives `run_callgrind.sh` end to end against a stub `valgrind`, so it needs no
Valgrind and still proves a failing measurement aborts the table with the
captured diagnostic. Skipped when the build did not produce the `bench` binary.
- **`test_ci_workflows`** — the one check aimed at CI rather than at the
library: which configurations get built is a property of
`.github/workflows/`, so no C++ test can notice when a leg disappears. It
requires that the workflows running CTest cover both `Debug` and `Release`,
that a testing workflow never configures CMake without a build type (the empty
default is neither: no optimisation, no `NDEBUG`), and that a workflow using a
strategy matrix sets `fail-fast: false`. `${{ matrix.build_type }}` is resolved
against the workflow's own `build_type:` axis. Skipped in a source tree
without `.github/workflows/`.

### Coverage and API docs

Expand Down
9 changes: 9 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ target_compile_options(test_vectors PRIVATE -Wall -Wextra -Werror)
target_link_libraries(test_vectors PRIVATE sofab_cpp)
add_test(NAME test_vectors COMMAND test_vectors)

# CORELIB_PLAN §12.1 requires the suite to run against a debug *and* a release
# build. Which configurations CI builds is a property of the workflow files, so
# a Release-only defect cannot be caught from inside the C++ suites — this check
# reads .github/workflows/ and fails when a required leg is missing.
add_test(NAME test_ci_workflows
COMMAND bash ${CMAKE_CURRENT_LIST_DIR}/test_ci_workflows.sh
${PROJECT_SOURCE_DIR}/.github/workflows)
set_tests_properties(test_ci_workflows PROPERTIES SKIP_RETURN_CODE 77)

if(SOFAB_ENABLE_COVERAGE)
target_link_libraries(test_roundtrip PRIVATE sofab_coverage)
target_link_libraries(test_vectors PRIVATE sofab_coverage)
Expand Down
125 changes: 125 additions & 0 deletions test/test_ci_workflows.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/usr/bin/env bash
#
# SofaBuffers pure-C++20 — guards the CI build matrix against CORELIB_PLAN §12.1.
#
# §12.1's required steps say the library is "built in both debug and release
# configurations" and the full suite run against each. That is a property of the
# workflow files, not of the library, so no amount of C++ testing can catch its
# loss: a Release-only defect (strict aliasing or UB the optimiser acts on in the
# varint window fast paths, an uninitialised field NDEBUG makes visible) ships
# green when every workflow configures Debug. This test reads
# `.github/workflows/` and requires that
#
# 1. the workflows that build and run CTest cover *both* CMAKE_BUILD_TYPE=Debug
# and CMAKE_BUILD_TYPE=Release,
# 2. every configure step in a testing workflow names a build type (an unset
# CMAKE_BUILD_TYPE is neither: no -O, no NDEBUG, and silently so), and
# 3. a workflow that uses a strategy matrix sets `fail-fast: false`, so one red
# leg does not hide the others' results (§12.1, "Matrix build").
#
# `${{ matrix.build_type }}` is resolved against the workflow's own
# `build_type: [ ... ]` matrix axis, so the matrix shape §12.1 prescribes counts
# as covering every type it lists.
#
# Usage: test_ci_workflows.sh <workflows-dir>
#
# SPDX-License-Identifier: MIT
set -uo pipefail

WF_DIR="${1:?usage: test_ci_workflows.sh <workflows-dir>}"

# CTest maps 77 to "skipped" (SKIP_RETURN_CODE): a source tree without the
# workflow directory (release tarball, vendored copy) has nothing to check.
if [ ! -d "$WF_DIR" ]; then
echo "SKIP: no workflow directory at $WF_DIR"
exit 77
fi

fails=0
fail() { echo "FAIL: $*" >&2; fails=$((fails + 1)); }
ok() { echo " ok: $*"; }

shopt -s nullglob
workflows=("$WF_DIR"/*.yaml "$WF_DIR"/*.yml)
shopt -u nullglob

if [ ${#workflows[@]} -eq 0 ]; then
fail "no workflow files under $WF_DIR"
exit 1
fi

# Build types configured by workflows that also run the test suite.
tested_types=""

for wf in "${workflows[@]}"; do
name="$(basename "$wf")"

# Does this workflow run the suite? Only those owe §12.1 a build type.
runs_ctest=no
grep -qE '(^|[^[:alnum:]_./-])ctest([^[:alnum:]_-]|$)' "$wf" && runs_ctest=yes

# The matrix axis a `${{ matrix.build_type }}` reference resolves against.
matrix_types="$(grep -oE 'build_type:[[:space:]]*\[[^]]*\]' "$wf" \
| sed 's/.*\[//; s/\]//; s/[",]/ /g')"

# `fail-fast: false` is mandatory wherever a matrix is used (§12.1).
if grep -qE '^[[:space:]]*matrix:[[:space:]]*$' "$wf"; then
if grep -qE '^[[:space:]]*fail-fast:[[:space:]]*false[[:space:]]*$' "$wf"; then
ok "$name: strategy matrix sets fail-fast: false"
else
fail "$name: uses a strategy matrix without 'fail-fast: false' (§12.1)"
fi
fi

saw_configure=no
while IFS= read -r line; do
saw_configure=yes
value="${line#*-DCMAKE_BUILD_TYPE=}"
value="${value%% \\*}" # drop a line continuation
value="$(printf '%s' "$value" | sed 's/[[:space:]]*$//')"
case "$value" in
*matrix.build_type*)
if [ -z "$matrix_types" ]; then
fail "$name: uses \${{ matrix.build_type }} with no 'build_type: [ ... ]' axis"
else
ok "$name: build types from the matrix axis:$(printf ' %s' $matrix_types)"
[ "$runs_ctest" = yes ] && tested_types="$tested_types $matrix_types"
fi
;;
"")
fail "$name: -DCMAKE_BUILD_TYPE= with an empty value"
;;
*'${{'*)
fail "$name: build type '$value' comes from an expression this check cannot resolve"
;;
*)
ok "$name: configures $value"
[ "$runs_ctest" = yes ] && tested_types="$tested_types $value"
;;
esac
done < <(grep -F -- '-DCMAKE_BUILD_TYPE=' "$wf")

# A testing workflow that configures CMake without a build type gets the
# empty default: no optimisation, no NDEBUG, and it looks like neither leg.
if [ "$runs_ctest" = yes ] && [ "$saw_configure" = no ]; then
fail "$name: runs ctest but never sets -DCMAKE_BUILD_TYPE"
fi
done

for want in Debug Release; do
found=no
for have in $tested_types; do
[ "$have" = "$want" ] && found=yes
done
if [ "$found" = yes ]; then
ok "some workflow builds and tests $want"
else
fail "no workflow builds and tests CMAKE_BUILD_TYPE=$want (CORELIB_PLAN §12.1 step 4)"
fi
done

if [ "$fails" -ne 0 ]; then
echo "test_ci_workflows: $fails failure(s)" >&2
exit 1
fi
echo "test_ci_workflows: all checks passed"