1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
#
# $Id: functions,v 1.3 2002/11/01 11:40:56 okir Exp $
#
# Test functions for resmgr
#
# Copyright (C) 2002, Olaf Kirch <okir@lst.de>
#
export RESMGR_TEST_ROOT=${TMPDIR:-/tmp}/resmgrtest
export RESMGR_SOCKET=$RESMGR_TEST_ROOT/.socket
export RESMGR_PIDFILE=$RESMGR_TEST_ROOT/pid
export RESMGR_TESTUSERS=30
export verbose=false
export strace=
function resmgr_init {
rm -rf $RESMGR_TEST_ROOT
mkdir -m 755 -p $RESMGR_TEST_ROOT || exit 1
PATH=$PWD:$PATH
num=0
while [ $num -lt $RESMGR_TESTUSERS ]; do
user="test$num"
grep -qs "^$user:" /etc/passwd ||
echo "$user:x:77$num:100:resmgr:/:/bin/sh" >> /etc/passwd
let num=$num+1
done
test -x /usr/sbin/nscd && /usr/sbin/nscd -i passwd
trap resmgr_exit 0 1 2 15
}
function resmgr_exit {
resmgr_stop_daemon
rm -rf $RESMGR_TEST_ROOT
}
function log_info {
echo ":::$log_pid $*" >&2
}
function log_err {
echo "--- $*" >&2
}
function log_output {
func=$1
prefix=$2
echo "$3" | while read line; do
$func "$prefix$line"
done
}
function do_command {
local cmd
local output
$verbose && log_info $*
cmd=$1; shift
if [ $cmd = "-t" ]; then
output=
strace -fo trace.`basename $cmd` $cmd "$@" &
sleep 1
else
output=`$cmd "$@" 2>&1`
fi
if [ $? -ne 0 ]; then
log_err "Command failed: $cmd $*"
log_err "Exit status : $?"
log_output log_err "Output : " "$output"
return 1
fi
$verbose && log_output log_info " " "$output"
echo $output
}
function resmgr_start_daemon {
resmgr_stop_daemon
do_command $strace ./resmgrd -p $RESMGR_PIDFILE \
-s $RESMGR_SOCKET \
-f /dev/null $*
}
function resmgr_stop_daemon {
if test -r $RESMGR_PIDFILE; then
./resmgrd -dl $RESMGR_PIDFILE -k
fi
}
function resmgr_attach_debugger {
echo "*** Attaching debugger to resmgr daemon ***" >&2
gdb -n resmgrd `cat $RESMGR_PIDFILE`
}
function resmgr {
do_command ./resmgr -t "$@"
}
function run_test {
local test
for test; do
log_info "Running test $test"
. $test
done
}
function assert {
cmp=$1
match=$2
shift 2
output=`$@` || return 1
case $output in
$match) res=eq;;
*) res=ne;;
esac
if [ $cmp != $res ]; then
log_err "Test failed: command $*"
log_err "Expected: $match"
log_output \
log_err "Got: " "$output"
return 1
fi
}
|