|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# Helper script to build and run the concurrency reproducer under ThreadSanitizer. |
| 5 | +# Produces logs: tsan_mutex_disabled.log and tsan_mutex_enabled.log |
| 6 | + |
| 7 | +ROOT_DIR=$(cd "$(dirname "$0")/.." && pwd) |
| 8 | +BUILD_DIR_DISABLED="$ROOT_DIR/build.mutex_disabled" |
| 9 | +BUILD_DIR_ENABLED="$ROOT_DIR/build.mutex_enabled" |
| 10 | + |
| 11 | +clang++ --version >/dev/null 2>&1 || { echo "clang++ not found in PATH"; exit 1; } |
| 12 | + |
| 13 | +# Vulnerable build (mutex disabled) |
| 14 | +mkdir -p "$BUILD_DIR_DISABLED" |
| 15 | +cmake -S "$ROOT_DIR" -B "$BUILD_DIR_DISABLED" -G Ninja \ |
| 16 | + -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \ |
| 17 | + -DARGS_DISABLE_PARSE_MUTEX=1 \ |
| 18 | + -DCMAKE_BUILD_TYPE=Debug \ |
| 19 | + -DCMAKE_CXX_FLAGS='-fsanitize=thread -g -fno-omit-frame-pointer' \ |
| 20 | + -DCMAKE_EXE_LINKER_FLAGS='-fsanitize=thread' |
| 21 | +cmake --build "$BUILD_DIR_DISABLED" --parallel |
| 22 | + |
| 23 | +echo "Running reproducer with ARGS_DISABLE_PARSE_MUTEX=1 (expect races)" |
| 24 | +"$BUILD_DIR_DISABLED/argstest-concurrency_reproducer" 2>&1 | tee "$ROOT_DIR/tsan_mutex_disabled.log" || true |
| 25 | + |
| 26 | +# Fixed build (mutex enabled) |
| 27 | +mkdir -p "$BUILD_DIR_ENABLED" |
| 28 | +cmake -S "$ROOT_DIR" -B "$BUILD_DIR_ENABLED" -G Ninja \ |
| 29 | + -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \ |
| 30 | + -DARGS_DISABLE_PARSE_MUTEX=0 \ |
| 31 | + -DCMAKE_BUILD_TYPE=Debug \ |
| 32 | + -DCMAKE_CXX_FLAGS='-fsanitize=thread -g -fno-omit-frame-pointer' \ |
| 33 | + -DCMAKE_EXE_LINKER_FLAGS='-fsanitize=thread' |
| 34 | +cmake --build "$BUILD_DIR_ENABLED" --parallel |
| 35 | + |
| 36 | +echo "Running reproducer with mutex enabled (expect clean)" |
| 37 | +"$BUILD_DIR_ENABLED/argstest-concurrency_reproducer" 2>&1 | tee "$ROOT_DIR/tsan_mutex_enabled.log" || true |
| 38 | + |
| 39 | +echo "Logs saved to: $ROOT_DIR/tsan_mutex_disabled.log and $ROOT_DIR/tsan_mutex_enabled.log" |
0 commit comments