]> arthur.barton.de Git - ngircd-alex.git/blob - src/testsuite/stress-server.sh
Added preliminary README text.
[ngircd-alex.git] / src / testsuite / stress-server.sh
1 #!/bin/sh
2 #
3 # ngIRCd Test Suite
4 # Copyright (c)2002-2004 by Alexander Barton (alex@barton.de)
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 # Please read the file COPYING, README and AUTHORS for more information.
11 #
12 # $Id: stress-server.sh,v 1.9 2004/09/04 13:58:31 alex Exp $
13 #
14
15 # detect source directory
16 [ -z "$srcdir" ] && srcdir=`dirname $0`
17
18 # parse command line
19 [ "$1" -gt 0 ] 2> /dev/null && CLIENTS="$1" || CLIENTS=5
20 [ "$2" -gt 0 ] 2> /dev/null && LOOPS="$2" || LOOPS=1
21
22 # get our name
23 name=`basename $0`
24
25 # create directories
26 mkdir -p logs tests
27
28 # test for required external tools
29 type expect > /dev/null 2>&1
30 if [ $? -ne 0 ]; then
31   echo "      ${name}: \"expect\" not found.";  exit 77
32 fi
33 type telnet > /dev/null 2>&1
34 if [ $? -ne 0 ]; then
35   echo "      ${name}: \"telnet\" not found.";  exit 77
36 fi
37
38 # hello world! :-)
39 [ $LOOPS -gt 1 ] \
40   && echo "      stressing server with $CLIENTS clients in $LOOPS loops (be patient!):" \
41   || echo "      stressing server with $CLIENTS clients (be patient!):"
42
43 # create scripts for expect(1)
44 no=0
45 while [ ${no} -lt $CLIENTS ]; do
46   cat ${srcdir}/stress-A.e > tests/${no}.e
47   echo "send \"nick test${no}\\r\"" >> tests/${no}.e
48   cat ${srcdir}/stress-B.e >> tests/${no}.e
49   no=`expr ${no} + 1`
50 done
51
52 # main loop ...
53 loop=0
54 while [ ${loop} -lt $LOOPS ]; do
55   no=0
56   loop=`expr ${loop} + 1`
57   while [ ${no} -lt $CLIENTS ]; do
58     expect tests/${no}.e > logs/stress-${no}.log 2> /dev/null &
59     no=`expr ${no} + 1`
60   done
61   if [ $LOOPS -gt 1 ]; then
62     echo "      loop $loop/$LOOPS: started $no clients."
63     echo -n "      loop $loop/$LOOPS: waiting for clients to complete: "
64   else
65     echo "      started $no clients."
66     echo -n "      waiting for clients to complete: "
67   fi
68
69   res=3
70   touch logs/check-idle.log
71   while true; do
72     expect ${srcdir}/check-idle.e >> logs/check-idle.log; res=$?
73     echo "====================" >> logs/check-idle.log
74     [ $res -ne 99 ] && break
75
76     # there are still clients connected. Wait ...
77     sleep 1
78     echo -n "."
79   done
80
81   if [ $res -ne 0 ]; then
82     echo " ERROR!"
83     break
84   fi
85   echo " done."
86 done
87
88 exit $res
89
90 # -eof-