#!/bin/sh
###############################################################################
# run_test.sh
#
# run tests
#
# ---------------------------------------------------------------------------
# stacktrace - Stacktrace printer.
#   (C) 2008-2009 Gerardo García Peña <gerardo@kung-foo.net>
#
#   This program is free software; you can redistribute it and/or modify it
#   under the terms of the GNU General Public License as published by the Free
#   Software Foundation; either version 2 of the License, or (at your option)
#   any later version.
#
#   This program is distributed in the hope that it will be useful, but WITHOUT
#   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
#   more details.
#
#   You should have received a copy of the GNU General Public License along
#   with this program; if not, write to the Free Software Foundation, Inc., 51
#   Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
#
###############################################################################

echo "Installing signal handlers..."
for i in HUP  INT  QUIT ILL  ABRT \
         FPE  SEGV PIPE ALRM TERM \
         USR1 USR2 CHLD CONT TSTP \
         TTIN TTOU; do
  echo "  - $i"
  trap "echo Trapped SIG$i" "$i"
done

echo "Testing dynamic preload (press CTRL+C when you get bored)..."
LD_PRELOAD=./stacktrace.so ./test peperoni falcon siberet

echo "Testing static library (press CTRL+C when you get bored)..."
./stest peperoni falcon siberet

while test "$R" != "y" -a "$R" != "n"; do
  printf "Have you seen any stacktrace [y/n]? "
  read R
done

if [ "$R" = "y" ]; then
  echo "Everything seems ok."
  exit 0
else
  echo "Bad luck."
  exit 1
fi
