Skip to content
suit Artifact [2849961a82]
Login

Artifact [2849961a82]

Artifact 2849961a82b9dc847788b2f2fa3dca1407590eecb616c549ed0dee1225f4c45e:


#!/bin/sh
# The whole local gate, one run after another, stopping at the first failure.
# The first run is the cheap one: it builds everything with both compilers
# (warnings are errors) and runs every fuzz target once, so a compile error or
# a fuzz finding stops the gate in minutes rather than after the long suites.
#   rm -rf build/dev; make check-build CC=gcc-16;
#   rm -rf build/dev; make check-build; make fuzz  -> build/fast.log
#   rm -rf build/dev; make check CC=gcc-16        -> build/check-gcc.log
#   rm -rf build/dev; make all                    -> build/all.log
#   (umask 002; env -u USER -u LOGNAME make check) -> build/check-nouser.log
#     (umask 002 is the forge runner's: files the tests make are group-writable)
#   (umask 027; make check)                       -> build/check-umask.log
# The last two reuse the dev build that `make all` just made: same compiler,
# same flags, so make finds nothing to rebuild. Then, for each run that
# started, its exit status, its seconds and its summary lines.
# usage: gate.sh   (env: GATE_GCC, the second compiler; default gcc-16)
set -u
gcc=${GATE_GCC:-gcc-16}
if ! command -v "$gcc" >/dev/null 2>&1; then
    echo "gate: $gcc is not installed; the first run needs it" >&2
    exit 1
fi
mkdir -p build
done_runs=

report() {
    for n in $done_runs; do
        printf '%s: exit %s, %ss\n' "$n" "$(cat "build/$n.rc")" "$(cat "build/$n.sec")"
        grep -E '^(unit: [0-9]+ checks|[a-z_]+\.sh: [0-9]+ cases), [0-9]+ failed$' "build/$n.log" | head -16
        grep -E '^fuzz [a-z]+: (number_of_executed_units|mutation loop)' "build/$n.log" | head -16
        grep '^skip ' "build/$n.log" | sort -u | head -5
    done
}

# run NAME COMMAND...: output to build/NAME.log, status to build/NAME.rc
run() {
    n=$1; shift
    echo "gate: $n"
    start=$(date +%s)
    "$@" >"build/$n.log" 2>&1
    echo $? >"build/$n.rc"
    echo $(($(date +%s) - start)) >"build/$n.sec"
    done_runs="$done_runs $n"
    [ "$(cat "build/$n.rc")" = 0 ]
}

run fast sh -c "rm -rf build/dev && make check-build CC=$gcc && rm -rf build/dev && make check-build && make fuzz" &&
run check-gcc sh -c "rm -rf build/dev; make check CC=$gcc" &&
run all sh -c 'rm -rf build/dev; make all' &&
run check-nouser sh -c 'umask 002; env -u USER -u LOGNAME make check' &&
run check-umask sh -c 'umask 027; make check'
rc=$?
report
[ $rc = 0 ] && echo "gate: passed" || echo "gate: FAILED" >&2
exit $rc