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