1#!/bin/bash 2 3# Where to install Valgrind with ThreadSanitizer. 4VALGRIND_INST_ROOT="$1" 5SVN_ROOT="$2" 6 7if [ "$VALGRIND_INST_ROOT" == "" ]; then 8 echo "Usage: $0 /tsan/installation/path [svn/root/dir]" 9 exit 10fi 11 12if [ "$SVN_ROOT" == "" ]; then 13# Get ThreadSanitizer. This will create directory 'drt' 14 svn co http://data-race-test.googlecode.com/svn/trunk drt || exit 1 15 cd drt || exit 1 16else 17 cd $SVN_ROOT || exit 1 18fi 19 20TOPDIR=`pwd` 21 22VG_ARCH=$(uname -m | sed -e "s/i.86/x86/;s/x86_64/amd64/;s/arm.*/arm/") 23 24# Translate OS to valgrind-style identifiers 25OS=`uname -s` 26if [ "$OS" == "Linux" ]; then 27 VG_OS="linux" 28elif [ "$OS" == "Darwin" ]; then 29 VG_OS="darwin" 30fi 31 32if ! echo -n "$OS $VG_ARCH" | \ 33 grep "\(Linux \(amd64\|x86\)\)\|Darwin x86" >/dev/null 34then 35 echo "ThreadSanitizer is not yet supported on $OS $VG_ARCH" 36 exit 1 37fi 38 39echo ------------------------------------------------ 40echo Building ThreadSanitizer for $OS $VG_ARCH 41echo ------------------------------------------------ 42sleep 1 43 44# Build Valgind. 45cd $TOPDIR/third_party || exit 1 46./update_valgrind.sh || exit 1 47./build_and_install_valgrind.sh $VALGRIND_INST_ROOT || exit 1 48 49cd $TOPDIR/tsan || exit 1 50make -s -j4 OFFLINE= GTEST_ROOT= PIN_ROOT= VALGRIND_INST_ROOT=$VALGRIND_INST_ROOT || exit 1 51# Build the self contained binaries. 52make self-contained OS=$VG_OS ARCH=$VG_ARCH VALGRIND_INST_ROOT=$VALGRIND_INST_ROOT || exit 1 53 54TSAN=$TOPDIR/tsan/bin/tsan-$VG_ARCH-$VG_OS-self-contained.sh 55 56# Test 57cd $TOPDIR/unittest || exit 1 58make all -s -j4 OS=${VG_OS} ARCH=${VG_ARCH} OPT=1 STATIC=0 || exit 1 59$TSAN --color bin/demo_tests-${VG_OS}-${VG_ARCH}-O1 --gtest_filter="DemoTests.RaceReportDemoTest" || exit 1 60 61# Done 62echo "ThreadSanitizer is built: $TSAN" 63