Home | History | Annotate | Download | only in ftp
      1 #!/bin/sh
      2 
      3 # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
      4 # Copyright (c) International Business Machines  Corp., 2005
      5 #
      6 # This program is free software; you can redistribute it and/or
      7 # modify it under the terms of the GNU General Public License as
      8 # published by the Free Software Foundation; either version 2 of
      9 # the License, or (at your option) any later version.
     10 #
     11 # This program is distributed in the hope that it would be useful,
     12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14 # GNU General Public License for more details.
     15 #
     16 # You should have received a copy of the GNU General Public License
     17 # along with this program; if not, write the Free Software Foundation,
     18 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     19 #
     20 # Author: Mitsuru Chinen <mitch (at] jp.ibm.com>
     21 
     22 TCID=ftp-upload-stress02-rmt
     23 TST_TOTAL=1
     24 TST_CLEANUP="cleanup"
     25 
     26 . test.sh
     27 
     28 tst_check_cmds killall
     29 
     30 server_ipaddr="$1"
     31 urldir="$2"
     32 filename="$3"
     33 filesize="$4"
     34 duration="$5"
     35 client_num="$6"
     36 
     37 cleanup()
     38 {
     39 	rm -f $filename
     40 }
     41 
     42 echo $server_ipaddr | grep ':' > /dev/null
     43 if [ $? -eq 0 ]; then
     44 	server_ipaddr='['$server_ipaddr']'
     45 fi
     46 
     47 # Create a file to upload
     48 echo -n "A" > $filename
     49 echo -n "Z" | dd of=$filename bs=1 seek=$(($filesize - 1)) > /dev/null 2>&1 || \
     50 	tst_brkm TBROK "Failed to create $filename"
     51 
     52 start_epoc=$(date +%s)
     53 while true ; do
     54 	# Exit when the specified seconds have passed.
     55 	current_epoc=$(date +%s)
     56 	elapse_epoc=$(($current_epoc - $start_epoc))
     57 	if [ $elapse_epoc -ge $duration ]; then
     58 		break
     59 	fi
     60 
     61 	num=0
     62 	while [ $num -lt $client_num ]; do
     63 		ps auxw | grep -l -- "curl.*${filename}${num}" >/dev/null 2>&1
     64 		if [ $? -eq 0 ]; then
     65 			num=$(($num + 1))
     66 			continue
     67 		fi
     68 		curl -s --noproxy '*' -u anonymous:ftp@ltp-ns.org -T $filename \
     69 			-g "ftp://${server_ipaddr}/${urldir}/${filename}${num}" &
     70 		num=$(($num + 1))
     71 	done
     72 done
     73 
     74 killall -qw -s SIGPIPE curl
     75 
     76 out=$(curl --noproxy '*' -sS -u anonymous:ftp@ltp-ns.org -T $filename \
     77 	-g "ftp://$server_ipaddr/$urldir/" \
     78 	-w "time=%{time_total} size=%{size_upload} speed=%{speed_upload}")
     79 
     80 tst_resm TINFO "stat: $out"
     81 send_filesize=$(echo "$out" | awk '{print $2}')
     82 
     83 if [ "$send_filesize" != "size=$filesize" ]; then
     84 	tst_resm TINFO "Expected file size '$filesize'"
     85 	tst_brkm TBROK "Failed to upload to ftp://$server_ipaddr/$urldir/"
     86 fi
     87 
     88 tst_exit
     89