summaryrefslogtreecommitdiff
path: root/test/tsan/test_output.sh
blob: c22258fa172dcf18438ac0d8071b630783ad62ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash

ulimit -s 8192
set -e # fail on any error

HERE=$(dirname $0)
TSAN_DIR=$(dirname $0)/../../lib/tsan
BLACKLIST=$HERE/Helpers/blacklist.txt

# Assume clang and clang++ are in path.
: ${CC:=clang}
: ${CXX:=clang++}
: ${FILECHECK:=FileCheck}

# TODO: add testing for all of -O0...-O3
CFLAGS="-fsanitize=thread -fsanitize-blacklist=$BLACKLIST -fPIE -O1 -g -Wall"
LDFLAGS="-pie -pthread -ldl -lrt -lm -Wl,--whole-archive $TSAN_DIR/rtl/libtsan.a -Wl,--no-whole-archive"

test_file() {
  SRC=$1
  COMPILER=$2
  echo ----- TESTING $(basename $1)
  OBJ=$SRC.o
  EXE=$SRC.exe
  $COMPILER $SRC $CFLAGS -c -o $OBJ
  $COMPILER $OBJ $LDFLAGS -o $EXE
  RES=$($EXE 2>&1 || true)
  printf "%s\n" "$RES" | $FILECHECK $SRC
  if [ "$3" == "" ]; then
    rm -f $EXE $OBJ
  fi
}

if [ "$1" == "" ]; then
  for c in $HERE/*.{c,cc}; do
    if [[ $c == */failing_* ]]; then
      echo SKIPPING FAILING TEST $c
      continue
    fi
    if [[ $c == */load_shared_lib.cc ]]; then
      echo TEST $c is not supported
      continue
    fi
    if [ "`grep "TSAN_OPTIONS" $c`" ]; then
      echo SKIPPING $c -- requires TSAN_OPTIONS
      continue
    fi
    COMPILER=$CXX
    case $c in
      *.c) COMPILER=$CC
    esac
    test_file $c $COMPILER &
  done
  for job in `jobs -p`; do
    wait $job || exit 1
  done
else
  test_file $HERE/$1 $CXX "DUMP"
fi