blob: 0f94ad0848963a00e13a86186d87bc02737a5d7c [file] [log] [blame]
Austin Schuh745610d2015-09-06 18:19:50 -07001#!/bin/sh
2
3# Copyright (c) 2009, Google Inc.
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met:
9#
10# * Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# * Redistributions in binary form must reproduce the above
13# copyright notice, this list of conditions and the following disclaimer
14# in the documentation and/or other materials provided with the
15# distribution.
16# * Neither the name of Google Inc. nor the names of its
17# contributors may be used to endorse or promote products derived from
18# this software without specific prior written permission.
19#
20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31#
32# ---
33# Author: Craig Silverstein
34
35BINDIR="${BINDIR:-.}"
Brian Silverman20350ac2021-11-17 18:19:55 -080036# We expect PPROF_PATH to be set in the environment.
37# If not, we set it to some reasonable value
38export PPROF_PATH="${PPROF_PATH:-$BINDIR/src/pprof}"
Austin Schuh745610d2015-09-06 18:19:50 -070039
40if [ "x$1" = "x-h" -o "x$1" = "x--help" ]; then
41 echo "USAGE: $0 [unittest dir]"
42 echo " By default, unittest_dir=$BINDIR"
43 exit 1
44fi
45
46DEBUGALLOCATION_TEST="${1:-$BINDIR/debugallocation_test}"
47
48num_failures=0
49
50# Run the i-th death test and make sure the test has the expected
51# regexp. We can depend on the first line of the output being
52# Expected regex:<regex>
53# Evaluates to "done" if we are not actually a death-test (so $1 is
54# too big a number, and we can stop). Evaluates to "" otherwise.
55# Increments num_failures if the death test does not succeed.
56OneDeathTest() {
57 "$DEBUGALLOCATION_TEST" "$1" 2>&1 | {
58 regex_line='dummy'
59 # Normally the regex_line is the first line of output, but not
60 # always (if tcmalloc itself does any logging to stderr).
61 while test -n "$regex_line"; do
62 read regex_line
63 regex=`expr "$regex_line" : "Expected regex:\(.*\)"`
64 test -n "$regex" && break # found the regex line
65 done
66 test -z "$regex" && echo "done" || grep "$regex" 2>&1
67 }
68}
69
70death_test_num=0 # which death test to run
71while :; do # same as 'while true', but more portable
72 echo -n "Running death test $death_test_num..."
73 output="`OneDeathTest $death_test_num`"
74 case $output in
75 # Empty string means grep didn't find anything.
76 "") echo "FAILED"; num_failures=`expr $num_failures + 1`;;
77 "done"*) echo "done with death tests"; break;;
78 # Any other string means grep found something, like it ought to.
79 *) echo "OK";;
80 esac
81 death_test_num=`expr $death_test_num + 1`
82done
83
84# Test the non-death parts of the test too
85echo -n "Running non-death tests..."
86if "$DEBUGALLOCATION_TEST"; then
87 echo "OK"
88else
89 echo "FAILED"
90 num_failures=`expr $num_failures + 1`
91fi
92
93if [ "$num_failures" = 0 ]; then
94 echo "PASS"
95else
96 echo "Failed with $num_failures failures"
97fi
98exit $num_failures