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

Petr Vorel pvorel@suse.cz
Thu Oct 13 14:59:20 CEST 2022


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