ftp-upload-stress02-rmt.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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=ftp-upload-stress02-rmt
  21. TST_TOTAL=1
  22. TST_CLEANUP="cleanup"
  23. . test.sh
  24. tst_require_cmds killall
  25. server_ipaddr="$1"
  26. urldir="$2"
  27. filename="$3"
  28. filesize="$4"
  29. duration="$5"
  30. client_num="$6"
  31. cleanup()
  32. {
  33. rm -f $filename
  34. }
  35. echo $server_ipaddr | grep ':' > /dev/null
  36. if [ $? -eq 0 ]; then
  37. server_ipaddr='['$server_ipaddr']'
  38. fi
  39. # Create a file to upload
  40. echo -n "A" > $filename
  41. echo -n "Z" | dd of=$filename bs=1 seek=$(($filesize - 1)) > /dev/null 2>&1 || \
  42. tst_brkm TBROK "Failed to create $filename"
  43. start_epoc=$(date +%s)
  44. while true ; do
  45. # Exit when the specified seconds have passed.
  46. current_epoc=$(date +%s)
  47. elapse_epoc=$(($current_epoc - $start_epoc))
  48. if [ $elapse_epoc -ge $duration ]; then
  49. break
  50. fi
  51. num=0
  52. while [ $num -lt $client_num ]; do
  53. ps auxw | grep -l -- "curl.*${filename}${num}" >/dev/null 2>&1
  54. if [ $? -eq 0 ]; then
  55. num=$(($num + 1))
  56. continue
  57. fi
  58. curl -s --noproxy '*' -u anonymous:ftp@ltp-ns.org -T $filename \
  59. -g "ftp://${server_ipaddr}/${urldir}/${filename}${num}" &
  60. num=$(($num + 1))
  61. done
  62. done
  63. killall -qw -s SIGPIPE curl
  64. out=$(curl --noproxy '*' -sS -u anonymous:ftp@ltp-ns.org -T $filename \
  65. -g "ftp://$server_ipaddr/$urldir/" \
  66. -w "time=%{time_total} size=%{size_upload} speed=%{speed_upload}")
  67. tst_resm TINFO "stat: $out"
  68. send_filesize=$(echo "$out" | awk '{print $2}')
  69. if [ "$send_filesize" != "size=$filesize" ]; then
  70. tst_resm TINFO "Expected file size '$filesize'"
  71. tst_brkm TBROK "Failed to upload to ftp://$server_ipaddr/$urldir/"
  72. fi
  73. tst_exit