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-stress
     23 TST_TOTAL=2
     24 TST_CLEANUP="cleanup"
     25 
     26 TST_USE_LEGACY_API=1
     27 . tst_net.sh
     28 
     29 # Big file size to upload (byte)
     30 UPLOAD_BIGFILESIZE=${UPLOAD_BIGFILESIZE:-2147483647}  # 2GB - 1
     31 # Regular file size to upload(byte)
     32 UPLOAD_REGFILESIZE=${UPLOAD_REGFILESIZE:-1024}     # 1K byte
     33 
     34 cleanup()
     35 {
     36 	rm -f $FTP_UPLOAD_DIR/ftp_file*
     37 	rm -f $FTP_UPLOAD_DIR/ftp_reg_file*
     38 	tst_rmdir
     39 	pkill vsftpd
     40 }
     41 
     42 setup()
     43 {
     44 	tst_require_root
     45 	tst_test_cmds pkill vsftpd
     46 	tst_tmpdir
     47 
     48 	tst_resm TINFO "run FTP over IPv$TST_IPVER"
     49 
     50 	trap "tst_brkm TBROK 'test interrupted'" INT
     51 
     52 	[ -d "$FTP_UPLOAD_DIR" ] || \
     53 		tst_brkm TCONF "Start ftp server and set FTP_UPLOAD_DIR var"
     54 
     55 	chmod o+w $FTP_UPLOAD_DIR
     56 
     57 	getenforce 2> /dev/null | grep -q Enforcing
     58 	if [ $? -eq 0 ]; then
     59 		tst_resm TINFO "configuring SELinux FTP parameters"
     60 		tst_test_cmds chcon setsebool
     61 		setsebool allow_ftpd_anon_write 1 || \
     62 			tst_brkm TBROK "Failed to allow ftpd anonymous write"
     63 		chcon -R -t public_content_rw_t $FTP_UPLOAD_DIR || \
     64 			tst_brkm TBROK "Failed to apply public_content_rw_t"
     65 	fi
     66 
     67 	tst_resm TINFO "restart vsftpd with custom options"
     68 	pkill vsftpd
     69 	touch vsftpd.conf
     70 
     71 	local ip_opt="-olisten=YES -olisten_ipv6=NO"
     72 	[ $TST_IPV6 ] && ip_opt="-olisten=NO -olisten_ipv6=YES"
     73 
     74 	upload_opt="-owrite_enable=YES -oanon_upload_enable=YES"
     75 
     76 	vsftpd $ip_opt $upload_opt -oanonymous_enable=YES vsftpd.conf
     77 }
     78 
     79 test01()
     80 {
     81 	tst_resm TINFO "upload file with size '$UPLOAD_BIGFILESIZE'"
     82 
     83 	# Run the script at the remote host
     84 	tst_rhost_run -s -c "ftp-upload-stress01-rmt $(tst_ipaddr) \
     85 		$FTP_UPLOAD_URLDIR ftp_file $UPLOAD_BIGFILESIZE"
     86 
     87 	tst_resm TPASS "Test is finished successfully"
     88 }
     89 
     90 test02()
     91 {
     92 	tst_resm TINFO "Upload data asynchronously in $NS_DURATION sec"
     93 
     94 	tst_rhost_run -s -c "ftp-upload-stress02-rmt \
     95 		$(tst_ipaddr) $FTP_UPLOAD_URLDIR ftp_reg_file \
     96 		$UPLOAD_REGFILESIZE $NS_DURATION $CONNECTION_TOTAL"
     97 
     98 	tst_resm TPASS "Test is finished successfully"
     99 }
    100 
    101 setup
    102 
    103 test01
    104 test02
    105 
    106 tst_exit
    107