1#!/bin/bash
2
3ulimit -s 8192
4set -e # fail on any error
5
6ROOTDIR=$(dirname $0)/..
7BLACKLIST=$ROOTDIR/lit_tests/Helpers/blacklist.txt
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
15CFLAGS="-fsanitize=thread -fsanitize-blacklist=$BLACKLIST -fPIE -O1 -g -Wall"
16LDFLAGS="-pie -lpthread -ldl $ROOTDIR/rtl/libtsan.a"
17
18test_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
33if [ "$1" == "" ]; then
34  for c in $ROOTDIR/lit_tests/*.{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
43    if [ "`grep "TSAN_OPTIONS" $c`" ]; then
44      echo SKIPPING $c -- requires TSAN_OPTIONS
45      continue
46    fi
47    COMPILER=$CXX
48    case $c in
49      *.c) COMPILER=$CC
50    esac
51    test_file $c $COMPILER &
52  done
53  for job in `jobs -p`; do
54    wait $job || exit 1
55  done
56else
57  test_file $ROOTDIR/lit_tests/$1 $CXX "DUMP"
58fi
59