[LTP] [PATCH 6/6] ftp/ftp01: Split the test function
Akihiko Odaki
akihiko.odaki@daynix.com
Thu Oct 20 14:07:41 CEST 2022
Suggested-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
testcases/network/tcp_cmds/ftp/ftp01.sh | 88 ++++++++++++++-----------
1 file changed, 49 insertions(+), 39 deletions(-)
diff --git a/testcases/network/tcp_cmds/ftp/ftp01.sh b/testcases/network/tcp_cmds/ftp/ftp01.sh
index 8c0cffdea..8bb659d54 100755
--- a/testcases/network/tcp_cmds/ftp/ftp01.sh
+++ b/testcases/network/tcp_cmds/ftp/ftp01.sh
@@ -49,56 +49,66 @@ do_setup()
{
TC=ftp
- ASCII_FILES=${ASCII_FILES:-"ascii.sm ascii.med ascii.lg ascii.jmb"}
- BIN_FILES=${BIN_FILES:-"bin.sm bin.med bin.lg bin.jmb"}
-
RUSER=${RUSER:-root}
}
do_test()
+{
+ case $1 in
+ 1) test_get binary;;
+ 2) test_get ascii;;
+ 3) test_put binary;;
+ 4) test_put ascii;;
+ esac
+}
+
+list_files()
+{
+ case $1 in
+ binary) echo 'ascii.sm ascii.med ascii.lg ascii.jmb';;
+ ascii) echo 'bin.sm bin.med bin.lg bin.jmb';;
+ esac
+}
+
+test_get()
{
local sum1 sum2
- for i in binary ascii; do
+ for file in $(list_files $1); do
+ {
+ echo user $RUSER $PASSWD
+ echo $1
+ 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
+}
- if [ $i = "binary" ]; then
- FILES=$BIN_FILES
- fi
- if [ $i = "ascii" ]; then
- FILES=$ASCII_FILES
- fi
- for j in $FILES; do
+test_put()
+{
+ local sum1 sum2
- for a in get put; do
- if [ $a = "get" ]; then
- {
- echo user $RUSER $PASSWD
- echo $i
- echo cd $TST_NET_DATAROOT
- echo $a $j
- echo quit
- } | ftp -nv $RHOST
- sum1="$(ls -l $j | awk '{print $5}')"
- sum2="$(ls -l $TST_NET_DATAROOT/$j | awk '{print $5}')"
- rm -f $j
- else
- {
- echo user $RUSER $PASSWD
- echo lcd $TST_NET_DATAROOT
- echo $i
- echo cd $TST_TMPDIR
- echo $a $j
- echo quit
- } | ftp -nv $RHOST
- sum1="$(tst_rhost_run -c "sum $TST_TMPDIR/$j" -s | awk '{print $1}')"
- sum2="$(sum $TST_NET_DATAROOT/$j | awk '{print $1}')"
- tst_rhost_run -c "rm -f $TST_TMPDIR/$j"
- fi
+ for file in $(list_files $1); do
+ {
+ echo user $RUSER $PASSWD
+ echo lcd $TST_NET_DATAROOT
+ echo $1
+ echo cd $TST_TMPDIR
+ echo post $file
+ echo quit
+ } | ftp -nv $RHOST
- EXPECT_PASS "[ '$sum1' = '$sum2' ]"
- done
- done
+ sum1="$(tst_rhost_run -c "sum $TST_TMPDIR/$file" -s | awk '{print $1}')"
+ sum2="$(sum $TST_NET_DATAROOT/$file | awk '{print $1}')"
+ tst_rhost_run -c "rm -f $TST_TMPDIR/$file"
+ EXPECT_PASS "[ '$sum1' = '$sum2' ]"
done
}
--
2.37.3
More information about the ltp
mailing list