tobogganSe connecter

louise

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

91 lignes · 4411 octetsBrut · Historique
1#!/usr/bin/env bash
2# ThreadSanitizer (ADR 0004, Revision 5): the runtime's unit tests, then
3# native programs on several threads, with the runtime and Rust's standard
4# library instrumented. It needs a nightly toolchain with rust-src, and
5# clang. On the forge, .toboggan/workflows/tsan.yml runs it; locally,
6# run it alone or with `LOUISE_CI_TSAN=1 scripts/ci.sh`.
7#
8# - The runtime is built with `-Zsanitizer=thread -Zbuild-std` and
9# `--cfg louise_rt_tsan`, which announces fiber switches to TSan (fiber.rs),
10# and without mimalloc, whose C code is not instrumented.
11# - Generated C is built with `-fsanitize=thread`, but without TSan's
12# function entry/exit hooks: they do not pair up across `musttail` calls,
13# so an endless tail-recursive loop overflows TSan's shadow call stack.
14# Accesses are still checked; reports show fewer C frames.
15# - `-g1`, not `-g`: full debug information makes clang's
16# LiveDebugVariables pass use memory quadratic in a function's size —
17# msgpack.lse's 13,000-line main needed 6.5 GB, and the forge's OOM
18# killer stopped clang, which said nothing (the empty "the C compiler
19# failed:"). Line tables alone still give a report file:line through
20# the generated `#line` map.
21# - scripts/tsan.supp lists the suppressions, each with its reason.
22# - TSan's shadow call stack holds 64Ki frames per fiber, without a bounds
23# check: deeper recursion through instrumented (runtime) frames silently
24# corrupts TSan's own memory, which shows as CHECK failures in its
25# allocator, bogus reports or hangs. Programs that recurse that deep are
26# skipped (SKIP, with the reason); ASan and the differential tests still
27# run them.
28set -euo pipefail
29cd "$(dirname "$0")/.."
30
31toolchain="${LOUISE_TSAN_TOOLCHAIN:-nightly-2026-09-20}"
32threads="${LOUISE_THREADS:-4}"
33root="$PWD"
34target="$root/target/tsan"
35out="$root/target/tsan-programs"
36mkdir -p "$out" "$root/target/tmp"
37# Builds write large temporary files: keep them off a small /tmp.
38export TMPDIR="$root/target/tmp"
39export TSAN_OPTIONS="suppressions=$root/scripts/tsan.supp ${TSAN_OPTIONS:-}"
40tsan_rust() {
41 RUSTFLAGS="-Zsanitizer=thread --cfg louise_rt_tsan" CARGO_TARGET_DIR="$target" \
42 cargo "+$toolchain" "$@" -Zbuild-std --target x86_64-unknown-linux-gnu \
43 -p louise_rt --no-default-features --features stats,crypto,tls
44}
45
46echo "tsan: runtime unit tests"
47tsan_rust test --quiet --lib
48tsan_rust build --quiet
49cargo build --quiet --release -p louise
50
51export LOUISE_LIB_DIR="$target/x86_64-unknown-linux-gnu/debug"
52export LOUISE_CC=clang
53export LOUISE_CFLAGS="-O1 -g1 -fsanitize=thread -mllvm -tsan-instrument-func-entry-exit=0"
54# generators.lse: `total` handles 20,000 yields with a non-tail
55# `x + resume(())`, about 80,000 instrumented runtime frames deep.
56SKIP=(generators)
57failed=0
58check() { # program threads
59 local program="$1" n="$2" name expected code
60 name="$(basename "$program" .lse)"
61 if [[ " ${SKIP[*]} " == *" $name "* ]]; then
62 echo "tsan: $name skipped (recursion deeper than TSan's shadow stack)"
63 return
64 fi
65 (cd "$(dirname "$program")" && "$root/target/release/louise" build "$program" -o "$out/$name") >/dev/null
66 expected=0
67 if grep -q '^//! panic:' "$program"; then expected=101; fi
68 code=0
69 LOUISE_LEAKS=1 LOUISE_THREADS="$n" timeout 600 "$out/$name" >/dev/null 2>"$out/$name.err" || code=$?
70 if grep -q 'WARNING: ThreadSanitizer' "$out/$name.err" || [ "$code" != "$expected" ] \
71 || ! grep -q '^louise: live blocks: 0$' "$out/$name.err"; then
72 echo "tsan: $name ($n threads): exit $code (expected $expected)"
73 head -60 "$out/$name.err"
74 failed=1
75 else
76 echo "tsan: $name ok ($n threads)"
77 fi
78}
79for program in tests/run/*.lse; do check "$root/$program" "$threads"; done
80for program in tests/stress/*.lse tests/bench/messages.lse tests/bench/fanin.lse tests/bench/timers.lse; do
81 check "$root/$program" 8
82done
83# Distribution end to end: two processes, the transport's threads and
84# TLS, built against the TSan runtime as the programs above (the leak
85# oracle and exit codes are the tests'; TSan's report exits 66).
86echo "tsan: distribution end to end"
87LOUISE_THREADS="$threads" cargo test --quiet -p louise --test dist || failed=1
88if [ "$failed" != 0 ]; then echo "tsan: failures"; exit 1; fi
89echo "tsan: no reports"
90# The instrumented-std target dir is peak disk on a runner, not a cache.
91[ "${CI:-}" = true ] && rm -rf "$target" || true