
louise
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#1197 · main · 10 min 35 s
1Étoiles
0Forks
0Issues
| 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. |
| 28 | set -euo pipefail |
| 29 | cd "$(dirname "$0")/.." |
| 30 | |
| 31 | toolchain="${LOUISE_TSAN_TOOLCHAIN:-nightly-2026-09-20}" |
| 32 | threads="${LOUISE_THREADS:-4}" |
| 33 | root="$PWD" |
| 34 | target="$root/target/tsan" |
| 35 | out="$root/target/tsan-programs" |
| 36 | mkdir -p "$out" "$root/target/tmp" |
| 37 | # Builds write large temporary files: keep them off a small /tmp. |
| 38 | export TMPDIR="$root/target/tmp" |
| 39 | export TSAN_OPTIONS="suppressions=$root/scripts/tsan.supp ${TSAN_OPTIONS:-}" |
| 40 | tsan_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 | |
| 46 | echo "tsan: runtime unit tests" |
| 47 | tsan_rust test --quiet --lib |
| 48 | tsan_rust build --quiet |
| 49 | cargo build --quiet --release -p louise |
| 50 | |
| 51 | export LOUISE_LIB_DIR="$target/x86_64-unknown-linux-gnu/debug" |
| 52 | export LOUISE_CC=clang |
| 53 | export 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. |
| 56 | SKIP=(generators) |
| 57 | failed=0 |
| 58 | check() { # 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 | } |
| 79 | for program in tests/run/*.lse; do check "$root/$program" "$threads"; done |
| 80 | for program in tests/stress/*.lse tests/bench/messages.lse tests/bench/fanin.lse tests/bench/timers.lse; do |
| 81 | check "$root/$program" 8 |
| 82 | done |
| 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). |
| 86 | echo "tsan: distribution end to end" |
| 87 | LOUISE_THREADS="$threads" cargo test --quiet -p louise --test dist || failed=1 |
| 88 | if [ "$failed" != 0 ]; then echo "tsan: failures"; exit 1; fi |
| 89 | echo "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 |