Home | History | Annotate | Download | only in valgrind
      1 #!/bin/bash
      2 
      3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
      4 # Use of this source code is governed by a BSD-style license that can be
      5 # found in the LICENSE file.
      6 
      7 # Set up some paths and re-direct the arguments to chrome_tests.py
      8 
      9 export THISDIR=`dirname $0`
     10 ARGV_COPY="$@"
     11 
     12 # We need to set CHROME_VALGRIND iff using Memcheck or TSan-Valgrind:
     13 #   tools/valgrind/chrome_tests.sh --tool memcheck
     14 # or
     15 #   tools/valgrind/chrome_tests.sh --tool=memcheck
     16 # (same for "--tool=tsan")
     17 tool="memcheck"  # Default to memcheck.
     18 while (( "$#" ))
     19 do
     20   if [[ "$1" == "--tool" ]]
     21   then
     22     tool="$2"
     23     shift
     24   elif [[ "$1" =~ --tool=(.*) ]]
     25   then
     26     tool="${BASH_REMATCH[1]}"
     27   fi
     28   shift
     29 done
     30 
     31 NEEDS_VALGRIND=0
     32 NEEDS_DRMEMORY=0
     33 
     34 case "$tool" in
     35   "memcheck")
     36     NEEDS_VALGRIND=1
     37     ;;
     38   "tsan" | "tsan_rv")
     39     if [ "`uname -s`" == CYGWIN* ]
     40     then
     41       NEEDS_PIN=1
     42     else
     43       NEEDS_VALGRIND=1
     44     fi
     45     ;;
     46   "drmemory" | "drmemory_light" | "drmemory_full" | "drmemory_pattern")
     47     NEEDS_DRMEMORY=1
     48     ;;
     49 esac
     50 
     51 if [ "$NEEDS_VALGRIND" == "1" ]
     52 then
     53   CHROME_VALGRIND=`sh $THISDIR/locate_valgrind.sh`
     54   if [ "$CHROME_VALGRIND" = "" ]
     55   then
     56     # locate_valgrind.sh failed
     57     exit 1
     58   fi
     59   echo "Using valgrind binaries from ${CHROME_VALGRIND}"
     60 
     61   PATH="${CHROME_VALGRIND}/bin:$PATH"
     62   # We need to set these variables to override default lib paths hard-coded into
     63   # Valgrind binary.
     64   export VALGRIND_LIB="$CHROME_VALGRIND/lib/valgrind"
     65   export VALGRIND_LIB_INNER="$CHROME_VALGRIND/lib/valgrind"
     66 
     67   # Clean up some /tmp directories that might be stale due to interrupted
     68   # chrome_tests.py execution.
     69   # FYI:
     70   #   -mtime +1  <- only print files modified more than 24h ago,
     71   #   -print0/-0 are needed to handle possible newlines in the filenames.
     72   echo "Cleanup /tmp from Valgrind stuff"
     73   find /tmp -maxdepth 1 \(\
     74         -name "vgdb-pipe-*" -or -name "vg_logs_*" -or -name "valgrind.*" \
     75       \) -mtime +1 -print0 | xargs -0 rm -rf
     76 fi
     77 
     78 if [ "$NEEDS_DRMEMORY" == "1" ]
     79 then
     80   if [ -z "$DRMEMORY_COMMAND" ]
     81   then
     82     DRMEMORY_PATH="$THISDIR/../../third_party/drmemory"
     83     DRMEMORY_SFX="$DRMEMORY_PATH/drmemory-windows-sfx.exe"
     84     if [ ! -f "$DRMEMORY_SFX" ]
     85     then
     86       echo "Can't find Dr. Memory executables."
     87       echo "See http://www.chromium.org/developers/how-tos/using-valgrind/dr-memory"
     88       echo "for the instructions on how to get them."
     89       exit 1
     90     fi
     91 
     92     chmod +x "$DRMEMORY_SFX"  # Cygwin won't run it without +x.
     93     "$DRMEMORY_SFX" -o"$DRMEMORY_PATH/unpacked" -y
     94     export DRMEMORY_COMMAND="$DRMEMORY_PATH/unpacked/bin/drmemory.exe"
     95   fi
     96 fi
     97 
     98 if [ "$NEEDS_PIN" == "1" ]
     99 then
    100   if [ -z "$PIN_COMMAND" ]
    101   then
    102     # Set up PIN_COMMAND to invoke TSan.
    103     TSAN_PATH="$THISDIR/../../third_party/tsan"
    104     TSAN_SFX="$TSAN_PATH/tsan-x86-windows-sfx.exe"
    105     echo "$TSAN_SFX"
    106     if [ ! -f $TSAN_SFX ]
    107     then
    108       echo "Can't find ThreadSanitizer executables."
    109       echo "See http://www.chromium.org/developers/how-tos/using-valgrind/threadsanitizer/threadsanitizer-on-windows"
    110       echo "for the instructions on how to get them."
    111       exit 1
    112     fi
    113 
    114     chmod +x "$TSAN_SFX"  # Cygwin won't run it without +x.
    115     "$TSAN_SFX" -o"$TSAN_PATH"/unpacked -y
    116     export PIN_COMMAND="$TSAN_PATH/unpacked/tsan-x86-windows/tsan.bat"
    117   fi
    118 fi
    119 
    120 
    121 PYTHONPATH=$THISDIR/../python/google python \
    122            "$THISDIR/chrome_tests.py" $ARGV_COPY
    123