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