• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3ulimit -s 8192
4set -e # fail on any error
5
6ROOTDIR=$(dirname $0)/..
7
8# Assuming clang is in path.
9CC=clang
10CXX=clang++
11
12# TODO: add testing for all of -O0...-O3
13CFLAGS="-fthread-sanitizer -fPIE -O1 -g -fno-builtin -Wall"
14LDFLAGS="-pie -lpthread -ldl $ROOTDIR/rtl/libtsan.a"
15
16test_file() {
17  SRC=$1
18  COMPILER=$2
19  echo ----- TESTING $(basename $1)
20  OBJ=$SRC.o
21  EXE=$SRC.exe
22  $COMPILER $SRC $CFLAGS -c -o $OBJ
23  $COMPILER $OBJ $LDFLAGS -o $EXE
24  RES=$(TSAN_OPTIONS="atexit_sleep_ms=0" $EXE 2>&1 || true)
25  if [ "$3" != "" ]; then
26    printf "%s\n" "$RES"
27  fi
28  printf "%s\n" "$RES" | FileCheck $SRC
29  if [ "$3" == "" ]; then
30    rm -f $EXE $OBJ
31  fi
32}
33
34if [ "$1" == "" ]; then
35  for c in $ROOTDIR/output_tests/*.{c,cc}; do
36    if [[ $c == */failing_* ]]; then
37      echo SKIPPING FAILING TEST $c
38      continue
39    fi
40    COMPILER=$CXX
41    case $c in
42      *.c) COMPILER=$CC
43    esac
44    test_file $c $COMPILER
45  done
46  wait
47else
48  test_file $ROOTDIR/output_tests/$1 $CXX "DUMP"
49fi
50