stress-server.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. # detect source directory
  15. [ -z "$srcdir" ] && srcdir=`dirname $0`
  16. # parse command line
  17. [ "$1" -gt 0 ] 2> /dev/null && CLIENTS="$1" || CLIENTS=5
  18. [ "$2" -gt 0 ] 2> /dev/null && MAX="$2" || MAX=-1
  19. # get our name
  20. name=`basename $0`
  21. # create directories
  22. mkdir -p logs tests
  23. # test for required external tools
  24. type expect > /dev/null 2>&1
  25. if [ $? -ne 0 ]; then
  26. echo " ${name}: \"expect\" not found."; exit 77
  27. fi
  28. type telnet > /dev/null 2>&1
  29. if [ $? -ne 0 ]; then
  30. echo " ${name}: \"telnet\" not found."; exit 77
  31. fi
  32. # hello world! :-)
  33. echo " stressing server with $CLIENTS clients (be patient!):"
  34. # read in functions
  35. . ${srcdir}/functions.inc
  36. # create scripts for expect(1)
  37. no=0
  38. while [ ${no} -lt $CLIENTS ]; do
  39. cat ${srcdir}/stress-A.e > tests/${no}.e
  40. echo "send \"nick test${no}\\r\"" >> tests/${no}.e
  41. cat ${srcdir}/stress-B.e >> tests/${no}.e
  42. no=`expr ${no} + 1`
  43. done
  44. # run first script and check if it succeeds
  45. echo_n " checking stress script ..."
  46. expect tests/0.e > logs/stress-0.log 2> /dev/null
  47. if [ $? -ne 0 ]; then
  48. echo " failure!"
  49. exit 1
  50. else
  51. echo " ok."
  52. fi
  53. no=0
  54. while [ ${no} -lt $CLIENTS ]; do
  55. expect tests/${no}.e > logs/stress-${no}.log 2> /dev/null &
  56. no=`expr ${no} + 1`
  57. echo " started client $no/$CLIENTS."
  58. [ $MAX -gt 0 ] && $srcdir/wait-tests.sh $MAX
  59. done
  60. echo_n " waiting for clients to complete: ."
  61. touch logs/check-idle.log
  62. while true; do
  63. expect ${srcdir}/check-idle.e >> logs/check-idle.log; res=$?
  64. echo "====================" >> logs/check-idle.log
  65. [ $res -ne 99 ] && break
  66. # there are still clients connected. Wait ...
  67. sleep 3
  68. echo_n "."
  69. done
  70. [ $res -eq 0 ] && echo " ok." || echo " failure!"
  71. exit $res
  72. # -eof-