blob: 3c9c0e96ffd65fc4289af3fac11c0020ed3233a1 [file] [log] [blame]
Austin Schuh745610d2015-09-06 18:19:50 -07001#!/bin/sh
2
3# Copyright (c) 2005, 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#
35# Runs the heap-checker unittest with various environment variables.
36# This is necessary because we turn on features like the heap profiler
37# and heap checker via environment variables. This test makes sure
38# they all play well together.
39
40# We expect BINDIR and PPROF_PATH to be set in the environment.
41# If not, we set them to some reasonable values
42BINDIR="${BINDIR:-.}"
43PPROF_PATH="${PPROF_PATH:-$BINDIR/src/pprof}"
44
45if [ "x$1" = "x-h" -o "$1" = "x--help" ]; then
46 echo "USAGE: $0 [unittest dir] [path to pprof]"
47 echo " By default, unittest_dir=$BINDIR, pprof_path=$PPROF_PATH"
48 exit 1
49fi
50
51HEAP_CHECKER="${1:-$BINDIR/heap-checker_unittest}"
52PPROF_PATH="${2:-$PPROF_PATH}"
53
54TMPDIR=/tmp/heap_check_info
55rm -rf $TMPDIR || exit 2
56mkdir $TMPDIR || exit 3
57
58# $1: value of heap-check env. var.
59run_check() {
60 export PPROF_PATH="$PPROF_PATH"
61 [ -n "$1" ] && export HEAPCHECK="$1" || unset HEAPPROFILE
62
63 echo -n "Testing $HEAP_CHECKER with HEAPCHECK=$1 ... "
64 if $HEAP_CHECKER > $TMPDIR/output 2>&1; then
65 echo "OK"
66 else
67 echo "FAILED"
68 echo "Output from the failed run:"
69 echo "----"
70 cat $TMPDIR/output
71 echo "----"
72 exit 4
73 fi
74
75 # If we set HEAPPROFILE, then we expect it to actually have emitted
76 # a profile. Check that it did.
77 if [ -n "$HEAPPROFILE" ]; then
78 [ -e "$HEAPPROFILE.0001.heap" ] || exit 5
79 fi
80}
81
82run_check ""
83run_check "local"
84run_check "normal"
85run_check "strict"
86
87rm -rf $TMPDIR # clean up
88
89echo "PASS"