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 21export THISDIR=`dirname $0` 22ARGV_COPY="$@" 23 24# We need to set CHROME_VALGRIND iff using Memcheck: 25# tools/valgrind-webrtc/webrtc_tests.sh --tool memcheck 26# or 27# tools/valgrind-webrtc/webrtc_tests.sh --tool=memcheck 28tool="memcheck" # Default to memcheck. 29while (( "$#" )) 30do 31 if [[ "$1" == "--tool" ]] 32 then 33 tool="$2" 34 shift 35 elif [[ "$1" =~ --tool=(.*) ]] 36 then 37 tool="${BASH_REMATCH[1]}" 38 fi 39 shift 40done 41 42NEEDS_VALGRIND=0 43NEEDS_DRMEMORY=0 44 45case "$tool" in 46 "memcheck") 47 NEEDS_VALGRIND=1 48 ;; 49 "drmemory" | "drmemory_light" | "drmemory_full" | "drmemory_pattern") 50 NEEDS_DRMEMORY=1 51 ;; 52esac 53 54# For WebRTC, we'll use the locate_valgrind.sh script in Chromium's Valgrind 55# scripts dir to locate the Valgrind framework install 56CHROME_VALGRIND_SCRIPTS=$THISDIR/../valgrind 57 58if [ "$NEEDS_VALGRIND" == "1" ] 59then 60 CHROME_VALGRIND=`sh $CHROME_VALGRIND_SCRIPTS/locate_valgrind.sh` 61 if [ "$CHROME_VALGRIND" = "" ] 62 then 63 # locate_valgrind.sh failed 64 exit 1 65 fi 66 echo "Using valgrind binaries from ${CHROME_VALGRIND}" 67 68 PATH="${CHROME_VALGRIND}/bin:$PATH" 69 # We need to set these variables to override default lib paths hard-coded into 70 # Valgrind binary. 71 export VALGRIND_LIB="$CHROME_VALGRIND/lib/valgrind" 72 export VALGRIND_LIB_INNER="$CHROME_VALGRIND/lib/valgrind" 73 74 # Clean up some /tmp directories that might be stale due to interrupted 75 # chrome_tests.py execution. 76 # FYI: 77 # -mtime +1 <- only print files modified more than 24h ago, 78 # -print0/-0 are needed to handle possible newlines in the filenames. 79 echo "Cleanup /tmp from Valgrind stuff" 80 find /tmp -maxdepth 1 \(\ 81 -name "vgdb-pipe-*" -or -name "vg_logs_*" -or -name "valgrind.*" \ 82 \) -mtime +1 -print0 | xargs -0 rm -rf 83fi 84 85if [ "$NEEDS_DRMEMORY" == "1" ] 86then 87 if [ -z "$DRMEMORY_COMMAND" ] 88 then 89 DRMEMORY_PATH="$THISDIR/../../third_party/drmemory" 90 DRMEMORY_SFX="$DRMEMORY_PATH/drmemory-windows-sfx.exe" 91 if [ ! -f "$DRMEMORY_SFX" ] 92 then 93 echo "Can't find Dr. Memory executables." 94 echo "See http://www.chromium.org/developers/how-tos/using-valgrind/dr-memory" 95 echo "for the instructions on how to get them." 96 exit 1 97 fi 98 99 chmod +x "$DRMEMORY_SFX" # Cygwin won't run it without +x. 100 "$DRMEMORY_SFX" -o"$DRMEMORY_PATH/unpacked" -y 101 export DRMEMORY_COMMAND="$DRMEMORY_PATH/unpacked/bin/drmemory.exe" 102 fi 103fi 104 105# Add Chrome's Valgrind scripts dir to the PYTHON_PATH since it contains 106# the scripts that are needed for this script to run 107PYTHONPATH=$THISDIR/../python/google:$CHROME_VALGRIND_SCRIPTS python \ 108 "$THISDIR/webrtc_tests.py" $ARGV_COPY 109