[LTP] [PATCH] ftp/ftp01: Use tst_net.sh

Akihiko Odaki akihiko.odaki@daynix.com
Thu Oct 20 14:24:06 CEST 2022


Hi Petr,

Thanks for reviewing. I have sent the new version with changes 
accordingly to your comments though I forgot to name it "v2".  Please 
check it.

Regarding paths to ASCII_FILES and BIN_FILES, the patch refers to 
$TST_NET_DATAROOT so it produces correct paths, prefixed with 
"$LTPROOT/testcases/bin/datafiles".

I guess your test failure is related to the error message "Not 
connected" rather than the path to files. The below is the output I got 
with v2:

[  320.638778] LTP: starting ftp (ftp01.sh)
ftp01 1 TINFO: timeout per run is 0h 5m 0s
Connected to 10.0.2.15 (10.0.2.15).
220 (vsFTPd 3.0.5)
331 Please specify the password.
230 Login successful.
200 Switching to Binary mode.
250 Directory successfully changed.
local: ascii.sm remote: ascii.sm
227 Entering Passive Mode (10,0,2,15,35,3).
150 Opening BINARY mode data connection for ascii.sm (220 bytes).
226 Transfer complete.
220 bytes received in 4.1e-05 secs (5365.85 Kbytes/sec)
221 Goodbye.
ftp01 1 TPASS: [ '220' = '220' ] passed as expected

Regards,
Akihiko Odaki

On 2022/10/13 21:59, Petr Vorel wrote:
> Hi Akihiko,
> 
>> This allows to use SSH rather than RSH.
> 
> Thanks for your work. First of all, code is not working, because ASCII_FILES and
> BIN_FILES are in "$LTPROOT/testcases/bin/datafiles. have look at approach in
> testcases/network/nfs/nfs_stress/nfs02.sh:
> LTP_DATAFILES="$LTPROOT/testcases/bin/datafiles"
> 
> Otherwise it fails:
> 
> ftp01 1 TINFO: timeout per run is 0h 5m 0s
> Not connected.
> Not connected.
> Not connected.
> Not connected.
> ls: cannot access 'bin.sm': No such file or directory
> ls: cannot access '/opt/ltp/testcases/bin/datafiles/bin.sm': No such file or directory
> ftp01 1 TINFO: Test Successful doing ftp get bin.sm binary
> Not connected.
> ftp: Can't chdir `/opt/ltp/testcases/bin/datafiles': No such file or directory
> Not connected.
> Not connected.
> Not connected.
> ftp01 1 TBROK: 'sum /tmp/LTP_ftp01.e9NUSqkHa3/bin.sm' failed on '': 'sum: /tmp/LTP_ftp01.e9NUSqkHa3/bin.sm: No such file or directory'
> ftp01 1 TINFO: AppArmor enabled, this may affect test results
> ftp01 1 TINFO: it can be disabled with TST_DISABLE_APPARMOR=1 (requires super/root)
> ftp01 1 TINFO: loaded AppArmor profiles: none
> 
> ...
> 
> Or have I miss something? >
> When we convert file to use LTP new API (shell API in this case:
> https://github.com/linux-test-project/ltp/wiki/Shell-Test-API)
> we do cleanup the code.
> 
> NFS tests or other shell tests which use tst_net.sh and *not* set
> TST_USE_LEGACY_API=1 (i.e. rewritten to use LTP new shell API) are good
> examples.
> 
> ftp01.sh requires at least this cleanup:
> * remove useless comments like "FUNCTION:  do_setup"
> * code cleanup of do_test: having several loops is really crazy,
> how about write functions and pass them parameters?
> * please use $( ... ) instead of ` ... `.
> * use local to declare new variables
> * I'd remove sleep option
> * replace GPL with:
> # SPDX-License-Identifier: GPL-2.0-or-later
> * update copyright
> 
> Proper API use
> * tst_require_cmds should be replaced by TST_NEEDS_CMDS at the top.
> Even if you keep to use tst_require_cmds awk ftp
> this line is useless (1) tst_brk quits testing 2) we use ssh, why to mention
> .rhosts?):
> [ $? = 0 ] || tst_brk TBROK "Check .rhosts file on remote machine."
> * instead of "for i in binary ascii; do" I'd use:
> 
> TST_TESTFUNC=do_test
> TST_CNT=4
> TST_NEEDS_TMPDIR=1
> LTP_DATAFILES="$LTPROOT/testcases/bin/datafiles"
> 
> test_ftp()
> {
> 	for j in $*; do
> 	done
> }
> 
> do_test()
> {
>      case $1 in
>      1) test_get $BIN_FILES;;
>      2) test_get $ASCII_FILES;;
>      3) test_put $BIN_FILES;;
>      4) test_put $ASCII_FILES;;
>      esac
> }
> 
> test_get()
> {
> 	local sum1 sum2
> 
> 	for file in $*; do
> 		{
> 			echo "user $RUSER $PASSWD"
> 			echo "$i"
> 			echo "cd $TST_NET_DATAROOT"
> 			echo "get $file"
> 			echo "quit"
> 		} | ftp -nv $RHOST
> 
> 		sum1="$(ls -l $file | awk '{print $5}')"
> 		sum2="$(ls -l $TST_NET_DATAROOT/$file | awk '{print $5}')"
> 		rm -f $file
> 		EXPECT_PASS "[ '$sum1' = '$sum2' ]"
> 	done
> }
> 
> 
> Kind regards,
> Petr


More information about the ltp mailing list