stress-server.sh 2.1 KB

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