]> arthur.barton.de Git - ngircd-alex.git/blob - src/testsuite/stress-server.sh
Debian: require "telnet" or "telnet-ssl" for building
[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.16 2005/12/30 22:13:21 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 && MAX="$2" || MAX=-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 echo "      stressing server with $CLIENTS clients (be patient!):"
40
41 # read in functions
42 . ${srcdir}/functions.inc
43
44 # create scripts for expect(1)
45 no=0
46 while [ ${no} -lt $CLIENTS ]; do
47   cat ${srcdir}/stress-A.e > tests/${no}.e
48   echo "send \"nick test${no}\\r\"" >> tests/${no}.e
49   cat ${srcdir}/stress-B.e >> tests/${no}.e
50   no=`expr ${no} + 1`
51 done
52
53 # run first script and check if it succeeds
54 echo_n "      checking stress script ..."
55 expect tests/0.e > logs/stress-0.log 2> /dev/null
56 if [ $? -ne 0 ]; then
57   echo " failure!"
58   exit 1
59 else
60   echo " ok."
61 fi
62
63 no=0
64 while [ ${no} -lt $CLIENTS ]; do
65   expect tests/${no}.e > logs/stress-${no}.log 2> /dev/null &
66
67   no=`expr ${no} + 1`
68   echo "      started client $no/$CLIENTS."
69
70   [ $MAX -gt 0 ] && $srcdir/wait-tests.sh $MAX
71 done
72
73 echo_n "      waiting for clients to complete: ."
74 touch logs/check-idle.log
75 while true; do
76   expect ${srcdir}/check-idle.e >> logs/check-idle.log; res=$?
77   echo "====================" >> logs/check-idle.log
78   [ $res -ne 99 ] && break
79
80   # there are still clients connected. Wait ...
81   sleep 3
82   echo_n "."
83 done
84
85 [ $res -eq 0 ] && echo " ok." || echo " failure!"
86
87 exit $res
88
89 # -eof-