blob: 40c17123a6d90d6f812614f3ab52e8cafb1c6bfb [file] [log] [blame]
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +00001#!/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
21export THISDIR=`dirname $0`
22ARGV_COPY="$@"
23
24# We need to set CHROME_VALGRIND iff using Memcheck or TSan-Valgrind:
kjellander@webrtc.orgd1e7a9a2012-09-28 15:34:18 +000025# tools/valgrind-webrtc/webrtc_tests.sh --tool memcheck
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +000026# or
kjellander@webrtc.orgd1e7a9a2012-09-28 15:34:18 +000027# tools/valgrind-webrtc/webrtc_tests.sh --tool=memcheck
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +000028# (same for "--tool=tsan")
29tool="memcheck" # Default to memcheck.
30while (( "$#" ))
31do
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
41done
42
43NEEDS_VALGRIND=0
44NEEDS_DRMEMORY=0
45
46case "$tool" in
47 "memcheck")
48 NEEDS_VALGRIND=1
49 ;;
50 "tsan" | "tsan_rv")
kjellander@webrtc.orgd1e7a9a2012-09-28 15:34:18 +000051 if [ "`uname -s`" == CYGWIN* ]
52 then
53 NEEDS_PIN=1
54 else
55 NEEDS_VALGRIND=1
56 fi
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +000057 ;;
kjellander@webrtc.orgd1e7a9a2012-09-28 15:34:18 +000058 "drmemory" | "drmemory_light" | "drmemory_full" | "drmemory_pattern")
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +000059 NEEDS_DRMEMORY=1
60 ;;
61esac
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
65CHROME_VALGRIND_SCRIPTS=$THISDIR/../valgrind
66
67if [ "$NEEDS_VALGRIND" == "1" ]
68then
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.orgd1e7a9a2012-09-28 15:34:18 +000082
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.orgb5b155b2011-12-20 08:53:41 +000092fi
93
94if [ "$NEEDS_DRMEMORY" == "1" ]
95then
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
112fi
113
kjellander@webrtc.orgd1e7a9a2012-09-28 15:34:18 +0000114if [ "$NEEDS_PIN" == "1" ]
115then
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
134fi
135
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +0000136# Add Chrome's Valgrind scripts dir to the PYTHON_PATH since it contains
137# the scripts that are needed for this script to run
138PYTHONPATH=$THISDIR/../python/google:$CHROME_VALGRIND_SCRIPTS python \
139 "$THISDIR/webrtc_tests.py" $ARGV_COPY