Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | ulimit -s 8192 |
| 4 | set -e # fail on any error |
| 5 | |
| 6 | HERE=$(dirname $0) |
| 7 | TSAN_DIR=$(dirname $0)/../../lib/tsan |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 8 | |
| 9 | # Assume clang and clang++ are in path. |
| 10 | : ${CC:=clang} |
| 11 | : ${CXX:=clang++} |
| 12 | : ${FILECHECK:=FileCheck} |
| 13 | |
| 14 | # TODO: add testing for all of -O0...-O3 |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 15 | CFLAGS="-fsanitize=thread -O2 -g -Wall" |
| 16 | LDFLAGS="-pthread -ldl -lrt -lm -Wl,--whole-archive $TSAN_DIR/rtl/libtsan.a -Wl,--no-whole-archive" |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 17 | |
| 18 | test_file() { |
| 19 | SRC=$1 |
| 20 | COMPILER=$2 |
| 21 | echo ----- TESTING $(basename $1) |
| 22 | OBJ=$SRC.o |
| 23 | EXE=$SRC.exe |
| 24 | $COMPILER $SRC $CFLAGS -c -o $OBJ |
| 25 | $COMPILER $OBJ $LDFLAGS -o $EXE |
| 26 | RES=$($EXE 2>&1 || true) |
| 27 | printf "%s\n" "$RES" | $FILECHECK $SRC |
| 28 | if [ "$3" == "" ]; then |
| 29 | rm -f $EXE $OBJ |
| 30 | fi |
| 31 | } |
| 32 | |
| 33 | if [ "$1" == "" ]; then |
| 34 | for c in $HERE/*.{c,cc}; do |
| 35 | if [[ $c == */failing_* ]]; then |
| 36 | echo SKIPPING FAILING TEST $c |
| 37 | continue |
| 38 | fi |
| 39 | if [[ $c == */load_shared_lib.cc ]]; then |
| 40 | echo TEST $c is not supported |
| 41 | continue |
| 42 | fi |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 43 | if [[ $c == */*blacklist*.cc ]]; then |
| 44 | echo TEST $c is not supported |
| 45 | continue |
| 46 | fi |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 47 | if [ "`grep "TSAN_OPTIONS" $c`" ]; then |
| 48 | echo SKIPPING $c -- requires TSAN_OPTIONS |
| 49 | continue |
| 50 | fi |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 51 | if [ "`grep "XFAIL" $c`" ]; then |
| 52 | echo SKIPPING $c -- has XFAIL |
| 53 | continue |
| 54 | fi |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 55 | COMPILER=$CXX |
| 56 | case $c in |
| 57 | *.c) COMPILER=$CC |
| 58 | esac |
| 59 | test_file $c $COMPILER & |
| 60 | done |
| 61 | for job in `jobs -p`; do |
| 62 | wait $job || exit 1 |
| 63 | done |
| 64 | else |
| 65 | test_file $HERE/$1 $CXX "DUMP" |
| 66 | fi |