15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#!/bin/sh
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Copyright (c) 2005, 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)# Runs the heap-checker unittest with various environment variables.
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# This is necessary because we turn on features like the heap profiler
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# and heap checker via environment variables.  This test makes sure
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# they all play well together.
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# We expect BINDIR and PPROF_PATH to be set in the environment.
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# If not, we set them to some reasonable values
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)BINDIR="${BINDIR:-.}"
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)PPROF_PATH="${PPROF_PATH:-$BINDIR/src/pprof}"
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)if [ "x$1" = "x-h" -o "$1" = "x--help" ]; then
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  echo "USAGE: $0 [unittest dir] [path to pprof]"
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  echo "       By default, unittest_dir=$BINDIR, pprof_path=$PPROF_PATH"
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  exit 1
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)fi
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)HEAP_CHECKER="${1:-$BINDIR}/heap-checker_unittest"
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)PPROF_PATH="${2:-$PPROF_PATH}"
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TMPDIR=/tmp/heap_check_info
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)rm -rf $TMPDIR || exit 2
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)mkdir $TMPDIR || exit 3
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# $1: value of heap-check env. var.
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)run_check() {
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    export PPROF_PATH="$PPROF_PATH"
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    [ -n "$1" ] && export HEAPCHECK="$1" || unset HEAPPROFILE
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    echo -n "Testing $HEAP_CHECKER with HEAPCHECK=$1 ... "
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if $HEAP_CHECKER > $TMPDIR/output 2>&1; then
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      echo "OK"
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    else
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      echo "FAILED"
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      echo "Output from the failed run:"
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      echo "----"
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      cat $TMPDIR/output
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      echo "----"      
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      exit 4
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    fi
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # If we set HEAPPROFILE, then we expect it to actually have emitted
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # a profile.  Check that it did.
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if [ -n "$HEAPPROFILE" ]; then
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      [ -e "$HEAPPROFILE.0001.heap" ] || exit 5
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    fi
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)run_check ""
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)run_check "local"
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)run_check "normal"
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)run_check "strict"
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)rm -rf $TMPDIR      # clean up
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)echo "PASS"
90