]> arthur.barton.de Git - ngircd-alex.git/blob - src/testsuite/stress-server.sh
ngIRCd Release 27
[ngircd-alex.git] / src / testsuite / stress-server.sh
1 #!/bin/sh
2 #
3 # ngIRCd Test Suite
4 # Copyright (c)2001-2024 Alexander Barton (alex@barton.de) and Contributors.
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
13 # parse command line
14 [ "$1" -gt 0 ] 2>/dev/null && CLIENTS="$1" || CLIENTS=5
15 [ "$2" -gt 0 ] 2>/dev/null && MAX="$2" || MAX=-1
16
17 # detect source directory
18 [ -z "$srcdir" ] && srcdir=`dirname "$0"`
19 set -u
20
21 # get our name
22 name=`basename "$0"`
23
24 # create directories
25 [ -d logs ] || mkdir logs
26 [ -d tests ] || mkdir 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."
32         exit 77
33 fi
34 type telnet >/dev/null 2>&1
35 if [ $? -ne 0 ]; then
36         echo "${name}: \"telnet\" not found.";
37         exit 77
38 fi
39
40 # hello world! :-)
41 echo "stressing server with $CLIENTS clients (be patient!):"
42
43 # read in functions
44 . "${srcdir}/functions.inc"
45
46 # create scripts for expect(1)
47 no=0
48 while [ ${no} -lt $CLIENTS ]; do
49         cat "${srcdir}/stress-A.e" >tests/${no}.e
50         echo "send \"nick test${no}\\r\"" >>tests/${no}.e
51         cat "${srcdir}/stress-B.e" >>tests/${no}.e
52         no=`expr ${no} + 1`
53 done
54
55 # run first script and check if it succeeds
56 echo_n "checking stress script ..."
57 expect tests/0.e >logs/stress-0.log 2>/dev/null
58 if [ $? -ne 0 ]; then
59         echo " failure!"
60         exit 1
61 else
62         echo " ok."
63 fi
64
65 no=0
66 while [ ${no} -lt $CLIENTS ]; do
67         expect tests/${no}.e >logs/stress-${no}.log 2>/dev/null &
68
69         no=`expr ${no} + 1`
70         echo "started client $no/$CLIENTS."
71
72         [ $MAX -gt 0 ] && "$srcdir/wait-tests.sh" $MAX
73 done
74
75 echo_n "waiting for clients to complete: ."
76 touch logs/check-idle.log
77 while true; do
78         expect "${srcdir}/check-idle.e" >>logs/check-idle.log; res=$?
79         echo "====================" >>logs/check-idle.log
80         [ $res -ne 99 ] && break
81
82         # there are still clients connected. Wait ...
83         sleep 3
84         echo_n "."
85 done
86
87 [ $res -eq 0 ] && echo " ok." || echo " failure!"
88 exit $res