r15873: Use short signal names to placate ksh trap. bash seems to accept either
[Samba.git] / source / script / tests / test_functions.sh
blobf263677bfcfc2e0a1f0d8fa8a49f186d114434b1
2 samba3_stop_sig_term() {
3 RET=0
4 kill -USR1 `cat $PIDDIR/timelimit.nmbd.pid` >/dev/null 2>&1 || \
5 kill -ALRM `cat $PIDDIR/timelimit.nmbd.pid` || RET=$?
7 kill -USR1 `cat $PIDDIR/timelimit.smbd.pid` >/dev/null 2>&1 || \
8 kill -ALRM `cat $PIDDIR/timelimit.smbd.pid` || RET=$?
10 return $RET;
13 samba3_stop_sig_kill() {
14 kill -ALRM `cat $PIDDIR/timelimit.nmbd.pid` >/dev/null 2>&1
15 kill -ALRM `cat $PIDDIR/timelimit.smbd.pid` >/dev/null 2>&1
16 return 0;
19 samba3_check_or_start() {
20 if [ -n "$SERVER_TEST_FIFO" ];then
22 trap samba3_stop_sig_kill INT QUIT
23 trap samba3_stop_sig_kill TERM
25 if [ -p "$SERVER_TEST_FIFO" ];then
26 return 0;
29 if [ -n "$SOCKET_WRAPPER_DIR" ];then
30 if [ -d "$SOCKET_WRAPPER_DIR" ]; then
31 rm -f $SOCKET_WRAPPER_DIR/*
32 else
33 mkdir -p $SOCKET_WRAPPER_DIR
37 rm -f $SERVER_TEST_FIFO
38 mkfifo $SERVER_TEST_FIFO
40 rm -f $NMBD_TEST_LOG
41 echo -n "STARTING NMBD..."
43 if ! test -n "$NMBD_MAXTIME"; then
44 NMBD_MAXTIME=2700
46 timelimit $NMBD_MAXTIME $NMBD_VALGRIND $SRCDIR/bin/nmbd -F -S --no-process-group -d0 -s $SERVERCONFFILE > $NMBD_TEST_LOG 2>&1 &
47 TIMELIMIT_NMBD_PID=$!
48 echo $TIMELIMIT_NMBD_PID > $PIDDIR/timelimit.nmbd.pid
49 wait $TIMELIMIT_NMBD_PID
50 ret=$?;
51 rm -f $SERVER_TEST_FIFO
52 if [ -n "$SOCKET_WRAPPER_DIR" -a -d "$SOCKET_WRAPPER_DIR" ]; then
53 rm -f $SOCKET_WRAPPER_DIR/*
55 if [ x"$ret" = x"0" ];then
56 echo "nmbd exits with status $ret";
57 echo "nmbd exits with status $ret" >>$NMBD_TEST_LOG;
58 elif [ x"$ret" = x"137" ];then
59 echo "nmbd got SIGXCPU and exits with status $ret!"
60 echo "nmbd got SIGXCPU and exits with status $ret!">>$NMBD_TEST_LOG;
61 else
62 echo "nmbd failed with status $ret!"
63 echo "nmbd failed with status $ret!">>$NMBD_TEST_LOG;
65 exit $ret;
66 ) || exit $? &) 2>/dev/null || exit $?
67 echo "DONE"
69 rm -f $SMBD_TEST_LOG
70 echo -n "STARTING SMBD..."
72 if ! test -n "$SMBD_MAXTIME"; then
73 SMBD_MAXTIME=2700
75 timelimit $SMBD_MAXTIME $SMBD_VALGRIND $SRCDIR/bin/smbd -F -S --no-process-group -d0 -s $SERVERCONFFILE > $SMBD_TEST_LOG 2>&1 &
76 TIMELIMIT_SMBD_PID=$!
77 echo $TIMELIMIT_SMBD_PID > $PIDDIR/timelimit.smbd.pid
78 wait $TIMELIMIT_SMBD_PID
79 ret=$?;
80 rm -f $SERVER_TEST_FIFO
81 if [ -n "$SOCKET_WRAPPER_DIR" -a -d "$SOCKET_WRAPPER_DIR" ]; then
82 rm -f $SOCKET_WRAPPER_DIR/*
84 if [ x"$ret" = x"0" ];then
85 echo "smbd exits with status $ret";
86 echo "smbd exits with status $ret" >>$SMBD_TEST_LOG;
87 elif [ x"$ret" = x"137" ];then
88 echo "smbd got SIGXCPU and exits with status $ret!"
89 echo "smbd got SIGXCPU and exits with status $ret!">>$SMBD_TEST_LOG;
90 else
91 echo "smbd failed with status $ret!"
92 echo "smbd failed with status $ret!">>$SMBD_TEST_LOG;
94 exit $ret;
95 ) || exit $? &) 2>/dev/null || exit $?
96 echo "DONE"
98 return 0;
101 samba3_nmbd_test_log() {
102 if [ -n "$NMBD_TEST_LOG" ];then
103 if [ -r "$NMBD_TEST_LOG" ];then
104 return 0;
107 return 1;
110 samba3_smbd_test_log() {
111 if [ -n "$SMBD_TEST_LOG" ];then
112 if [ -r "$SMBD_TEST_LOG" ];then
113 return 0;
116 return 1;
119 samba3_check_only() {
120 if [ -n "$SERVER_TEST_FIFO" ];then
121 if [ -p "$SERVER_TEST_FIFO" ];then
122 return 0;
124 return 1;
126 return 0;
129 testit() {
130 if [ -z "$PREFIX" ]; then
131 PREFIX=test_prefix
132 mkdir -p $PREFIX
134 name=$1
135 shift 1
136 SERVERS_ARE_UP="no"
137 TEST_LOG="$PREFIX/test_log.$$"
138 trap "rm -f $TEST_LOG" EXIT
139 cmdline="$*"
141 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
142 echo "--==--==--==--==--==--==--==--==--==--==--"
143 echo "Running test $name (level 0 stdout)"
144 echo "--==--==--==--==--==--==--==--==--==--==--"
145 date
146 echo "Testing $name"
147 else
148 echo "Testing $name ($failed)"
151 samba3_check_only && SERVERS_ARE_UP="yes"
152 if [ x"$SERVERS_ARE_UP" != x"yes" ];then
153 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
154 echo "SERVERS are down! Skipping: $cmdline"
155 echo "=========================================="
156 echo "TEST SKIPPED: $name (reason SERVERS are down)"
157 echo "=========================================="
158 else
159 echo "TEST SKIPPED: $name (reason SERVERS are down)"
161 return 1
164 ( $cmdline > $TEST_LOG 2>&1 )
165 status=$?
166 if [ x"$status" != x"0" ]; then
167 echo "TEST OUTPUT:"
168 cat $TEST_LOG;
169 samba3_nmbd_test_log && echo "NMBD OUTPUT:";
170 samba3_nmbd_test_log && cat $NMBD_TEST_LOG;
171 samba3_smbd_test_log && echo "SMBD OUTPUT:";
172 samba3_smbd_test_log && cat $SMBD_TEST_LOG;
173 rm -f $TEST_LOG;
174 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
175 echo "=========================================="
176 echo "TEST FAILED: $name (status $status)"
177 echo "=========================================="
178 else
179 echo "TEST FAILED: $cmdline (status $status)"
181 return 1;
183 rm -f $TEST_LOG;
184 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
185 echo "ALL OK: $cmdline"
186 echo "=========================================="
187 echo "TEST PASSED: $name"
188 echo "=========================================="
190 return 0;
193 testok() {
194 name=`basename $1`
195 failed=$2
197 if [ x"$failed" = x"0" ];then
199 else
200 echo "$failed TESTS FAILED or SKIPPED ($name)";
202 exit $failed
205 teststatus() {
206 name=`basename $1`
207 failed=$2
209 if [ x"$failed" = x"0" ];then
210 echo "TEST STATUS: $failed";
211 else
212 echo "TEST STATUS: $failed";
214 exit $failed
217 if [ -z "$VALGRIND" ]; then
218 MALLOC_CHECK_=2
219 export MALLOC_CHECK_