test_threading.sh (2040B)
1 #!/bin/sh 2 # Builds the thread dump with and without -pthread and diffs the signatures. 3 # A ThreadSanitizer build runs too, and is skipped when it does not build. 4 set -eu 5 HERE=$(cd "$(dirname "$0")" && pwd) 6 ROOT=$(cd "${HERE}/.." && pwd) 7 . "${HERE}/_tap.sh" 8 9 CC=${CC:-cc} 10 11 tap_begin "sfinx threading" 12 13 HASH_FIRST="${ROOT}/lib/finwo/keccak-fast/src/keccak-fast.c" 14 HASH="${HASH_FIRST} ${ROOT}/lib/finwo/keccak-fast/src/backend/*.c" 15 if [ ! -f "${HASH_FIRST}" ]; then 16 (cd "${ROOT}" && dep install) >/dev/null 2>&1 || true 17 fi 18 19 TMP=$(mktemp -d) 20 trap 'rm -rf "${TMP}"' EXIT 21 22 build() { 23 out=$1 24 shift 25 "${CC}" -Wall -Wextra -O2 "$@" -I"${ROOT}" -I"${ROOT}/src" -I"${ROOT}/lib/.dep/include" \ 26 "${HERE}/ref/thread_dump.c" ${HASH} -o "${out}" 27 } 28 29 if build "${TMP}/threaded" -pthread >"${TMP}/b1.log" 2>&1; then 30 tap 1 "threaded dump builds" "" 31 else 32 tap 0 "threaded dump builds" "$(cat "${TMP}/b1.log")" 33 fi 34 if build "${TMP}/plain" >"${TMP}/b2.log" 2>&1; then 35 tap 1 "plain dump builds" "" 36 else 37 tap 0 "plain dump builds" "$(cat "${TMP}/b2.log")" 38 fi 39 40 "${TMP}/threaded" >"${TMP}/a" 2>/dev/null || true 41 "${TMP}/plain" >"${TMP}/b" 2>/dev/null || true 42 if [ -s "${TMP}/a" ] && cmp -s "${TMP}/a" "${TMP}/b"; then 43 tap 1 "threaded and plain signatures match" "" 44 else 45 tap 0 "threaded and plain signatures match" "dump outputs differ or are empty" 46 fi 47 48 if build "${TMP}/tsan" -pthread -fsanitize=thread >"${TMP}/b3.log" 2>&1; then 49 set +e 50 TSAN_OPTIONS="halt_on_error=1" "${TMP}/tsan" >"${TMP}/t.log" 2>&1 51 tsan_status=$? 52 set -e 53 if [ "${tsan_status}" -eq 0 ]; then 54 tap 1 "thread sanitizer reports no races" "" 55 elif [ "${tsan_status}" -ge 128 ]; then 56 TAP_NO=$((TAP_NO + 1)) 57 printf 'ok %s - thread sanitizer available # SKIP runtime crashed (signal %s)\n' "${TAP_NO}" "$((tsan_status - 128))" 58 else 59 tap 0 "thread sanitizer reports no races" "$(tail -n 5 "${TMP}/t.log" 2>/dev/null || true)" 60 fi 61 else 62 TAP_NO=$((TAP_NO + 1)) 63 printf 'ok %s - thread sanitizer available # SKIP TSan build failed\n' "${TAP_NO}" 64 fi 65 66 tap_plan