http-stress02-rmt.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/sh
  2. # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
  3. # Copyright (c) International Business Machines Corp., 2005
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License as
  7. # published by the Free Software Foundation; either version 2 of
  8. # the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it would be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write the Free Software Foundation,
  17. # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. #
  19. # Author: Mitsuru Chinen <mitch@jp.ibm.com>
  20. TCID="http-stress02-rmt"
  21. TST_TOTAL=1
  22. . test.sh
  23. tst_require_cmds awk curl
  24. if [ $# -ne 5 ]; then
  25. tst_brkm TBROK "Usage: $0 server_addr fname fsize duration connections"
  26. fi
  27. server_ipaddr="$1"
  28. filename="$2"
  29. filesize="$3"
  30. duration="$4"
  31. connections="$5"
  32. echo $server_ipaddr | grep -F ':' > /dev/null
  33. if [ $? -eq 0 ]; then
  34. server_ipaddr='['$server_ipaddr']'
  35. fi
  36. start_epoc=$(date +%s)
  37. while true ; do
  38. # Exit when the specified seconds have passed.
  39. current_epoc=$(date +%s)
  40. elapse_epoc=$(($current_epoc - $start_epoc))
  41. [ $elapse_epoc -ge $duration ] && break
  42. # Do not request the file over the specified quantity
  43. http_num=$(jobs | wc -l)
  44. if [ $http_num -ge $connections ]; then
  45. sleep 1
  46. continue;
  47. fi
  48. curl --noproxy '*' -s -g "http://$server_ipaddr/$filename" \
  49. -o /dev/null &
  50. done
  51. killall -qw -s SIGPIPE curl
  52. out=$(curl --noproxy '*' -sS -g "http://$server_ipaddr/$filename" -o /dev/null \
  53. -w "time=%{time_total} size=%{size_download} speed=%{speed_download}")
  54. tst_resm TINFO "stat: $out"
  55. recv_filesize=$(echo "$out" | awk '{print $2}')
  56. if [ $recv_filesize != "size=$filesize" ]; then
  57. tst_resm TINFO "expected file size '$filesize'"
  58. tst_brkm TBROK "Failed to get http://$server_ipaddr/$filename"
  59. fi
  60. tst_exit