Skip to content
Open
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
121 changes: 99 additions & 22 deletions .github/workflows/_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ jobs:
unix: ${{ steps.set.outputs.unix }}
windows: ${{ steps.set.outputs.windows }}
tsan: ${{ steps.set.outputs.tsan }}
diag: ${{ steps.set.outputs.diag }}
lsan: ${{ steps.set.outputs.lsan }}
msan: ${{ steps.set.outputs.msan }}
has_unix: ${{ steps.set.outputs.has_unix }}
has_windows: ${{ steps.set.outputs.has_windows }}
has_tsan: ${{ steps.set.outputs.has_tsan }}
Expand All @@ -64,11 +67,14 @@ jobs:
# The lane names unix-macos14 and tsan-mac are kept as lane keys
# (select-lanes.sh, ci-ok and the lane contracts key on them); both
# run on macos-15 because GitHub retires the macos-14 image on 2026-11-02.
# List macos-15-intel FIRST so it claims scarce macOS runner slots
# (5 concurrent macOS jobs max on GitHub hosted) at t=0 of Wave 2
# instead of starving behind Ubuntu and arm64 macOS legs.
CORE_UNIX='[
{"os":"ubuntu-latest","cc":"gcc","cxx":"g++","lane":"unix-x86"},
{"os":"ubuntu-24.04-arm","cc":"gcc","cxx":"g++","lane":"unix-arm64"},
{"os":"macos-15-intel","cc":"cc","cxx":"c++","lane":"unix-macos-intel"},
{"os":"macos-15","cc":"cc","cxx":"c++","lane":"unix-macos14"},
{"os":"macos-15-intel","cc":"cc","cxx":"c++","lane":"unix-macos-intel"}
{"os":"ubuntu-latest","cc":"gcc","cxx":"g++","lane":"unix-x86"},
{"os":"ubuntu-24.04-arm","cc":"gcc","cxx":"g++","lane":"unix-arm64"}
]'
# Broad matrix legs are REQUIRED gates (no optional/continue-on-error
# escape hatches): the release dry run must be all-green, every platform.
Expand Down Expand Up @@ -121,36 +127,43 @@ jobs:
fi
# Suite sharding (opt-in via the shard_suites input): each platform's
# C-suite run is split across N runner jobs. CBM_TEST_SHARD="i/N"
# slices deterministically inside run-tests-parallel.sh; each
# shard's union guard proves it ran exactly its slice; shards are
# minted HERE from one expansion so a missing shard cannot be
# configured silently; and the shard-completeness job re-proves the
# cross-shard union at runtime. Ubuntu runners are plentiful (3
# shards); Windows gets 2 (every extra shard re-pays ~5 min of
# MSYS2 setup); macOS stays at 1 — mac legs are not the critical
# path and mac runner concurrency ceilings are the tightest.
# The pr profile shards less: a PR runs few legs and every shard
# re-pays its setup, so x86 and Windows run whole and only arm64,
# the slowest leg (~72 min unsharded), splits in two.
# slices deterministically via LPT bin-packing inside
# run-tests-parallel.sh; each shard's union guard proves it ran
# exactly its slice; shards are minted HERE from one expansion so a
# missing shard cannot be configured silently; and the
# shard-completeness job re-proves the cross-shard union at runtime.
case "$SHARD_PROFILE" in
standard) N_X86=3; N_ARM=3; N_WIN=2 ;;
pr) N_X86=1; N_ARM=2; N_WIN=1 ;;
standard) N_X86=3; N_ARM=2; N_MAC=2; N_MAC_INTEL=3; N_WIN=6; N_DIAG=2; N_LSAN=2; N_MSAN=2 ;;
pr) N_X86=2; N_ARM=2; N_MAC=2; N_MAC_INTEL=2; N_WIN=4; N_DIAG=2; N_LSAN=2; N_MSAN=2 ;;
*) echo "::error::unknown shard_profile '$SHARD_PROFILE'"; exit 1 ;;
esac
if [ "$SHARDS" = "true" ]; then
UNIX=$(jq -c --argjson x86 "$N_X86" --argjson arm "$N_ARM" '[.[] | . as $e
UNIX=$(jq -c --argjson x86 "$N_X86" --argjson arm "$N_ARM" \
--argjson mac "$N_MAC" --argjson mac_intel "$N_MAC_INTEL" '[.[] | . as $e
| (if ($e.os | startswith("ubuntu")) then
(if ($e.os | endswith("-arm")) then $arm else $x86 end)
elif ($e.os == "macos-15-intel") then $mac_intel
elif ($e.os | startswith("macos")) then $mac
else 1 end) as $n
| range(1; $n + 1) as $i
| $e + {shard: "\($i)/\($n)"}]' <<< "$UNIX")
WIN=$(jq -c --argjson n "$N_WIN" '[.[] | . as $e
| range(1; $n + 1) as $i
| $e + {shard: "\($i)/\($n)"}]' <<< "$WIN")
DIAG=$(jq -cn --argjson n "$N_DIAG" '[range(1; $n + 1) as $i | {shard: "\($i)/\($n)"}]')
LSAN=$(jq -cn --argjson n "$N_LSAN" '[range(1; $n + 1) as $i | {shard: "\($i)/\($n)"}]')
MSAN=$(jq -cn --argjson n "$N_MSAN" '[range(1; $n + 1) as $i | {shard: "\($i)/\($n)"}]')
else
DIAG='[{"shard":"1/1"}]'
LSAN='[{"shard":"1/1"}]'
MSAN='[{"shard":"1/1"}]'
fi
echo "unix={\"include\":$UNIX}" >> "$GITHUB_OUTPUT"
echo "windows={\"include\":$WIN}" >> "$GITHUB_OUTPUT"
echo "tsan={\"include\":$TSAN}" >> "$GITHUB_OUTPUT"
echo "diag={\"include\":$DIAG}" >> "$GITHUB_OUTPUT"
echo "lsan={\"include\":$LSAN}" >> "$GITHUB_OUTPUT"
echo "msan={\"include\":$MSAN}" >> "$GITHUB_OUTPUT"
# GitHub rejects an empty matrix, so a job whose legs were all
# deselected is skipped through these flags instead.
echo "has_unix=$(jq 'length > 0' <<< "$UNIX")" >> "$GITHUB_OUTPUT"
Expand Down Expand Up @@ -369,7 +382,11 @@ jobs:
# parallel suite — catches what an older compiler-rt can miss. Same
# canonical scripts/test.sh wave as every other leg.
test-diag:
needs: setup-matrix
if: ${{ inputs.lanes == 'all' || contains(fromJSON(inputs.lanes), 'diag') }}
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.setup-matrix.outputs.diag) }}
# Pinned for the same reason as the lint jobs: the pinned diagnostic
# toolchain below installs from llvm-toolchain-noble-21.
runs-on: ubuntu-24.04
Expand Down Expand Up @@ -405,23 +422,34 @@ jobs:
- name: Test (clang-21, ASan+UBSan + off-by-default ASan checks)
env:
ASAN_OPTIONS: "detect_stack_use_after_return=1:strict_string_checks=1:detect_stack_use_after_scope=1"
CBM_TEST_SHARD: ${{ matrix.shard }}
CBM_TEST_LEG: diag-clang21
CBM_SKIP_PERF: ${{ inputs.skip_perf && '1' || '' }}
run: |
scripts/test.sh CC=clang-21 CXX=clang++-21 \
SANITIZE="-fsanitize=address,undefined -fno-omit-frame-pointer -fno-optimize-sibling-calls"

- name: Shard manifest (completeness proof)
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: shard-manifest-diag-${{ strategy.job-index }}
path: build/c/test-logs/shard-manifest.txt
if-no-files-found: warn

# Same step as in test-unix: the complete logs of the suites that did
# not end green, only when the job failed.
- name: Failing suite logs
if: failure()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: suite-logs-diag
name: suite-logs-diag-${{ strategy.job-index }}
path: build/c/test-logs/failed/
retention-days: 7
if-no-files-found: warn

- name: Compiler cache (save)
if: always()
if: always() && (matrix.shard == null || startsWith(matrix.shard, '1/'))
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ github.workspace }}/.ccache
Expand Down Expand Up @@ -451,7 +479,11 @@ jobs:
# Per-cause detail lives in scripts/msan.sh, which is the single authoritative
# list both venues now share.
test-msan:
needs: setup-matrix
if: ${{ inputs.lanes == 'all' || contains(fromJSON(inputs.lanes), 'msan') }}
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.setup-matrix.outputs.msan) }}
runs-on: ubuntu-latest
timeout-minutes: 180
steps:
Expand All @@ -462,28 +494,62 @@ jobs:
with:
path: /tmp/.buildx-msan
key: buildx-msan-${{ hashFiles('test-infrastructure/Dockerfile.msan') }}
restore-keys: |
buildx-msan-

- name: Build MSan image (cached layers)
run: scripts/ci/msan-lane.sh build

- name: Compiler cache (content-verified, restore)
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ github.workspace }}/.ccache
key: ccache-msan-${{ github.ref }}-${{ github.sha }}
restore-keys: |
ccache-msan-${{ github.ref }}-
ccache-msan-

- name: MSan suite (exclusions per scripts/msan.sh)
# Reduce mmap ASLR entropy on the host first, as the TSan leg does: with
# the runner kernel's higher default the MSan runtime tries to re-exec
# itself with ADDR_NO_RANDOMIZE, which the container's seccomp profile
# refuses, and it aborts ("CHECK failed: msan_linux.cpp:193 ...
# personality") before any test runs. The container shares this kernel.
env:
CBM_TEST_SHARD: ${{ matrix.shard }}
CBM_TEST_LEG: msan-clang21
CBM_SKIP_PERF: ${{ inputs.skip_perf && '1' || '' }}
run: |
sudo sysctl -w vm.mmap_rnd_bits=28 || true
scripts/ci/msan-lane.sh run

- name: Shard manifest (completeness proof)
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: shard-manifest-msan-${{ strategy.job-index }}
path: build/msan/test-logs/shard-manifest.txt
if-no-files-found: warn

- name: Compiler cache (save)
if: always() && (matrix.shard == null || startsWith(matrix.shard, '1/'))
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ github.workspace }}/.ccache
key: ccache-msan-${{ github.ref }}-${{ github.sha }}

# macOS leak coverage. LeakSanitizer runs by default under ASan on Linux, so
# test-unix's ubuntu legs have always had it; on macOS it is off by default
# and Apple's clang refuses to turn it on, which left an entire platform with
# zero leak detection. Upstream (Homebrew) LLVM supports LSan on darwin/arm64,
# so this leg is the ordinary ASan suite built with that toolchain and run
# with detect_leaks=1. Mirrors the local `make -f Makefile.cbm test-lsan`.
test-lsan-macos:
needs: setup-matrix
if: ${{ inputs.lanes == 'all' || contains(fromJSON(inputs.lanes), 'lsan-macos') }}
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.setup-matrix.outputs.lsan) }}
runs-on: macos-latest
timeout-minutes: 120
steps:
Expand All @@ -510,23 +576,34 @@ jobs:
- name: Test (Homebrew clang, ASan + LeakSanitizer)
env:
ASAN_OPTIONS: "detect_leaks=1:halt_on_error=1"
CBM_TEST_SHARD: ${{ matrix.shard }}
CBM_TEST_LEG: lsan-macos
CBM_SKIP_PERF: ${{ inputs.skip_perf && '1' || '' }}
run: |
LLVM_PREFIX="$(brew --prefix llvm@22)"
scripts/test.sh CC="$LLVM_PREFIX/bin/clang" CXX="$LLVM_PREFIX/bin/clang++"

- name: Shard manifest (completeness proof)
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: shard-manifest-lsan-macos-${{ strategy.job-index }}
path: build/c/test-logs/shard-manifest.txt
if-no-files-found: warn

# Same step as in test-unix: the complete logs of the suites that did
# not end green, only when the job failed.
- name: Failing suite logs
if: failure()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: suite-logs-lsan-macos
name: suite-logs-lsan-macos-${{ strategy.job-index }}
path: build/c/test-logs/failed/
retention-days: 7
if-no-files-found: warn

- name: Compiler cache (save)
if: always()
if: always() && (matrix.shard == null || startsWith(matrix.shard, '1/'))
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ github.workspace }}/.ccache
Expand Down Expand Up @@ -731,7 +808,7 @@ jobs:
# catches it. Runs and gates on unsharded topologies too (every leg then
# contributes one 1/1 manifest whose slice must equal the full list).
shard-completeness:
needs: [test-unix, test-windows]
needs: [test-unix, test-windows, test-diag, test-lsan-macos, test-msan]
if: always()
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down
45 changes: 39 additions & 6 deletions Makefile.cbm
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
# build path (build.sh, test.sh, direct make) and is part of each command line.
# Detected from the compiler's target, not the host, so a cross compiler run
# on a Mac is left untouched.
# Probe compiler predefined macros once instead of spawning 4 separate
# $(CC) -dM -E invocations on every make startup (significant on Windows).
CC_DEFINES := $(shell echo | $(CC) $(ARCHFLAGS) -dM -E - 2>/dev/null)
MACOS_MIN_VERSION := 14.0
IS_APPLE_TARGET := $(shell echo | $(CC) $(ARCHFLAGS) -dM -E - 2>/dev/null | grep -q '__APPLE__' && echo yes || echo no)
IS_APPLE_TARGET := $(if $(findstring __APPLE__,$(CC_DEFINES)),yes,no)
MACOS_MIN_FLAGS :=
ifeq ($(IS_APPLE_TARGET),yes)
MACOS_MIN_FLAGS := -mmacosx-version-min=$(MACOS_MIN_VERSION)
Expand All @@ -52,7 +55,7 @@ TS_SRC = $(CBM_DIR)/vendored/ts_runtime/src

# GCC-only warning suppressions (Clang rejects unknown -Wno-* with -Werror).
# Detect GCC by checking for __GNUC__ without __clang__ — handles all versions.
IS_GCC := $(shell echo | $(CC) -dM -E - 2>/dev/null | grep -q '__GNUC__' && ! echo | $(CC) -dM -E - 2>/dev/null | grep -q '__clang__' && echo yes || echo no)
IS_GCC := $(if $(and $(findstring __GNUC__,$(CC_DEFINES)),$(if $(findstring __clang__,$(CC_DEFINES)),,yes)),yes,no)
GCC_ONLY_FLAGS :=
ifeq ($(IS_GCC),yes)
GCC_ONLY_FLAGS := -Wno-format-truncation -Wno-unused-result \
Expand Down Expand Up @@ -171,7 +174,7 @@ CXXFLAGS_TSAN = $(CXXFLAGS_COMMON) -DCBM_SANITIZED_BUILD=1 -g -O1 \
# advapi32 (owner-only activation-candidate ACLs), plus
# --allow-multiple-definition (MinGW CRT symbol clashes).
# Auto-detected via compiler; no manual override needed.
IS_MINGW := $(shell echo | $(CC) -dM -E - 2>/dev/null | grep -q 'define _WIN32 ' && echo yes || echo no)
IS_MINGW := $(if $(findstring define _WIN32 ,$(CC_DEFINES)),yes,no)
WIN32_LIBS :=
# Route Windows allocations through mimalloc (#581). mimalloc's own static
# override is gated on _MSC_VER, which clang/MinGW never defines, so it
Expand Down Expand Up @@ -1346,8 +1349,37 @@ $(BUILD_DIR)/test-runner-tsan: $(ALL_TEST_SRCS) $(PROD_SRCS) $(EXTRACTION_SRCS)

test-tsan: $(BUILD_DIR)/test-runner-tsan
@echo "ThreadSanitizer workers: 4"
cd $(CURDIR) && CBM_WORKERS=4 TSAN_OPTIONS="$(TSAN_OPTIONS)" \
$(BUILD_DIR)/test-runner-tsan $(TEST_TSAN_SUITES)
@cd $(CURDIR) && set -e; \
pipe_suites=""; other_suites=""; daemon_suites=""; \
for s in $(TEST_TSAN_SUITES); do \
case "$$s" in \
watcher|httpd|subprocess|mcp|mcp_supervisor|mcp_mutation_guard|daemon|daemon_*) daemon_suites="$$daemon_suites $$s" ;; \
pipeline) pipe_suites="$$pipe_suites $$s" ;; \
*) other_suites="$$other_suites $$s" ;; \
esac; \
done; \
if [ -n "$$pipe_suites" ] && [ -n "$$other_suites" ]; then \
tmpdir=$$(mktemp -d "$${TMPDIR:-/tmp}/cbm-tsan.XXXXXX"); \
trap 'rm -rf "$$tmpdir"' EXIT; \
CBM_WORKERS=4 TSAN_OPTIONS="$(TSAN_OPTIONS)" \
$(BUILD_DIR)/test-runner-tsan $$pipe_suites >"$$tmpdir/pipe.log" 2>&1 & \
pid_pipe=$$!; \
CBM_WORKERS=4 TSAN_OPTIONS="$(TSAN_OPTIONS)" \
$(BUILD_DIR)/test-runner-tsan $$other_suites >"$$tmpdir/other.log" 2>&1 & \
pid_other=$$!; \
rc1=0; rc2=0; \
wait "$$pid_pipe" || rc1=$$?; \
wait "$$pid_other" || rc2=$$?; \
cat "$$tmpdir/pipe.log" "$$tmpdir/other.log"; \
if [ "$$rc1" -ne 0 ] || [ "$$rc2" -ne 0 ]; then exit 1; fi; \
elif [ -n "$$pipe_suites$$other_suites" ]; then \
CBM_WORKERS=4 TSAN_OPTIONS="$(TSAN_OPTIONS)" \
$(BUILD_DIR)/test-runner-tsan $$pipe_suites $$other_suites; \
fi; \
if [ -n "$$daemon_suites" ]; then \
CBM_WORKERS=4 TSAN_OPTIONS="$(TSAN_OPTIONS)" \
$(BUILD_DIR)/test-runner-tsan $$daemon_suites; \
fi

# Real-binary POSIX lifecycle smoke. The endpoint is deliberately account-wide;
# an explicit Make invocation requires a clean rendezvous and fails rather than
Expand Down Expand Up @@ -1479,7 +1511,8 @@ clean-c:

# clang-tidy and clang-format: use Homebrew LLVM on macOS, overridable via make args
# e.g. make lint-format CLANG_FORMAT=clang-format-18
LLVM_BIN := $(shell brew --prefix llvm 2>/dev/null)/bin
# Lazy (=) so non-lint targets do not invoke `brew --prefix` on every make run.
LLVM_BIN = $(shell brew --prefix llvm 2>/dev/null)/bin
CLANG_TIDY ?= $(shell [ -x "$(LLVM_BIN)/clang-tidy" ] && echo "$(LLVM_BIN)/clang-tidy" || echo clang-tidy)
CLANG_FORMAT ?= $(shell [ -x "$(LLVM_BIN)/clang-format" ] && echo "$(LLVM_BIN)/clang-format" || echo clang-format)
CPPCHECK ?= cppcheck
Expand Down
10 changes: 9 additions & 1 deletion scripts/ci/msan-lane.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ run_suite() {
# Only `cli` is still excluded, and scripts/msan.sh warns that the lane is
# partial while anything is.
echo "=== MSan suite (exclusions per scripts/msan.sh) ==="
docker run --rm -v "$PWD:/src" -w /src "$IMAGE"
env_args=()
[ -n "${CBM_SKIP_PERF:-}" ] && env_args+=(-e "CBM_SKIP_PERF=$CBM_SKIP_PERF")
[ -n "${CBM_MSAN_JOBS:-}" ] && env_args+=(-e "CBM_MSAN_JOBS=$CBM_MSAN_JOBS")
[ -n "${CBM_TEST_SHARD:-}" ] && env_args+=(-e "CBM_TEST_SHARD=$CBM_TEST_SHARD")
[ -n "${CBM_TEST_LEG:-}" ] && env_args+=(-e "CBM_TEST_LEG=$CBM_TEST_LEG")
[ -n "${CCACHE_MAXSIZE:-}" ] && env_args+=(-e "CCACHE_MAXSIZE=$CCACHE_MAXSIZE")
[ -n "${CBM_NO_CCACHE:-}" ] && env_args+=(-e "CBM_NO_CCACHE=$CBM_NO_CCACHE")
docker run --rm -v "$PWD:/src" -w /src -e "CCACHE_DIR=/src/.ccache" \
"${env_args[@]+"${env_args[@]}"}" "$IMAGE"
}

case "$MODE" in
Expand Down
6 changes: 6 additions & 0 deletions scripts/ci/require-all-green.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ if 'LANES' in os.environ:
def lane_of(name):
if name in single:
return single[name]
if name.startswith('test / test-diag ('):
return 'diag'
if name.startswith('test / test-lsan-macos ('):
return 'lsan-macos'
if name.startswith('test / test-msan ('):
return 'msan'
if name.startswith('test / test-package-wrappers'):
return 'pkg-wrappers'
if name == 'memwaste' or name.startswith('memwaste / '):
Expand Down
Loading
Loading