15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#!/bin/sh 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Copyright (c) 2009, Google Inc. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# All rights reserved. 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Redistribution and use in source and binary forms, with or without 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# modification, are permitted provided that the following conditions are 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# met: 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# * Redistributions of source code must retain the above copyright 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# notice, this list of conditions and the following disclaimer. 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# * Redistributions in binary form must reproduce the above 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# copyright notice, this list of conditions and the following disclaimer 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# in the documentation and/or other materials provided with the 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# distribution. 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# * Neither the name of Google Inc. nor the names of its 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# contributors may be used to endorse or promote products derived from 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# this software without specific prior written permission. 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# --- 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Author: Craig Silverstein 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)BINDIR="${BINDIR:-.}" 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)if [ "x$1" = "x-h" -o "x$1" = "x--help" ]; then 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) echo "USAGE: $0 [unittest dir]" 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) echo " By default, unittest_dir=$BINDIR" 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) exit 1 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)fi 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)DEBUGALLOCATION_TEST="${1:-$BINDIR/debugallocation_test}" 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)num_failures=0 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Run the i-th death test and make sure the test has the expected 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# regexp. We can depend on the first line of the output being 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Expected regex:<regex> 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Evaluates to "done" if we are not actually a death-test (so $1 is 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# too big a number, and we can stop). Evaluates to "" otherwise. 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Increments num_failures if the death test does not succeed. 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)OneDeathTest() { 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "$DEBUGALLOCATION_TEST" "$1" 2>&1 | { 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) regex_line='dummy' 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) # Normally the regex_line is the first line of output, but not 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) # always (if tcmalloc itself does any logging to stderr). 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) while test -n "$regex_line"; do 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) read regex_line 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) regex=`expr "$regex_line" : "Expected regex:\(.*\)"` 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test -n "$regex" && break # found the regex line 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) done 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test -z "$regex" && echo "done" || grep "$regex" 2>&1 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)death_test_num=0 # which death test to run 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)while :; do # same as 'while true', but more portable 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) echo -n "Running death test $death_test_num..." 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) output="`OneDeathTest $death_test_num`" 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case $output in 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) # Empty string means grep didn't find anything. 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "") echo "FAILED"; num_failures=`expr $num_failures + 1`;; 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "done"*) echo "done with death tests"; break;; 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) # Any other string means grep found something, like it ought to. 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *) echo "OK";; 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) esac 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) death_test_num=`expr $death_test_num + 1` 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)done 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Test the non-death parts of the test too 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)echo -n "Running non-death tests..." 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)if "$DEBUGALLOCATION_TEST"; then 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) echo "OK" 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)else 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) echo "FAILED" 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) num_failures=`expr $num_failures + 1` 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)fi 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)if [ "$num_failures" = 0 ]; then 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) echo "PASS" 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)else 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) echo "Failed with $num_failures failures" 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)fi 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)exit $num_failures 96