public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP]  [PATCH v3] mv/mv_tests.sh: Add test02 to test 'mv -b'
@ 2015-04-24  1:44 Cui Bixuan
  2015-04-27 14:23 ` Cyril Hrubis
  0 siblings, 1 reply; 9+ messages in thread
From: Cui Bixuan @ 2015-04-24  1:44 UTC (permalink / raw)
  To: ltp-list; +Cc: ""@oracle.com, , huawei.com.lijinyue, zhuyanpeng

Add a new case to test 'mv -b':
* Create file1 and file2
* Mv -b file1 to file2
* Check backup file of file2

Signed-off-by: Cui Bixuan <cuibixuan@huawei.com>
Helped-by: Alexey Kodanev <alexey.kodanev@oracle.com>
---
v3: Add helped-by message.
v2: Changing the commit message and check the patch with 'checkpatch.pl' script

 .../commands/fileutils/mv/00_Descriptions.txt      |    3 +-
 testcases/commands/fileutils/mv/mv_tests.sh        |   84 ++++++++++++++++++++
 2 files changed, 86 insertions(+), 1 deletions(-)

diff --git a/testcases/commands/fileutils/mv/00_Descriptions.txt b/testcases/commands/fileutils/mv/00_Descriptions.txt
index 6d52868..57199bf 100644
--- a/testcases/commands/fileutils/mv/00_Descriptions.txt
+++ b/testcases/commands/fileutils/mv/00_Descriptions.txt
@@ -1,3 +1,4 @@
 test01
 	mv <dir1> <dir2> will move dir1 to dir2 and all its contents.
-
+test02
+	mv -b <file1> <file2> will move file1 to file2 and backup the file2.
diff --git a/testcases/commands/fileutils/mv/mv_tests.sh b/testcases/commands/fileutils/mv/mv_tests.sh
index 207e945..cda9901 100755
--- a/testcases/commands/fileutils/mv/mv_tests.sh
+++ b/testcases/commands/fileutils/mv/mv_tests.sh
@@ -24,6 +24,8 @@
 # Description:  Test basic functionality of mv command
 #				- Test #1:  mv <dir1> <dir2> will move dir1 to dir2 and all its
 #				            contents.
+#				- Test #2:  mv -b <file1> <file2> will move file1 to file2 and
+#					    backup the file2.
 #
 # Author:       Manoj Iyer, manjo@mail.utexas.edu
 #
@@ -238,6 +240,79 @@ test01()
 	return $RC
 }
 
+# Function:             test02
+#
+# Description   - Test #2: Test that mv -b <file1> <file2> will move
+#                 file1 to file2 and backup the file2.
+#               - create file1 and file2.
+#               - get the MD5 message of file2.
+#               - mv -b file1 to file2
+#               - get the MD5 message of backup file2.
+#               - compare  with MD5 messages.
+#
+# Return                - zero on success
+#               - non zero on failure. return value from commands ($RC)
+
+test02()
+{
+	RC=0                    # Return value from commands.
+	export TCID=mv02        # Name of the test case.
+	export TST_COUNT=1      # Test number.
+
+	tmpfile1=$LTPTMP/tst_mv.tmp/tmpfile1
+	tmpfile2=$LTPTMP/tst_mv.tmp/tmpfile2
+	backup_tmpfile2=$LTPTMP/tst_mv.tmp/tmpfile2~
+
+	$LTPBIN/tst_resm TINFO \
+		"Test #2: mv -b <file1> <file2> will move dir1 to dir2"
+
+	touch $tmpfile1 $tmpfile2 > $LTPTMP/tst_mv.err 2>&1 || RC=$?
+	if [ $RC -ne 0 ]
+	then
+		$LTPBIN/tst_brk TBROK $LTPTMP/tst_mv.err NULL \
+			"Test #2: can not touch file1 and file2. Reason:"
+		return $RC
+	fi
+
+	MD5_old=`md5sum $tmpfile2 |awk '{print $1}'` > $LTPTMP/tst_mv.err \
+		2>&1 || RC=$?
+	if [ $RC -ne 0 ]
+	then
+		$LTPBIN/tst_brk TBROK $LTPTMP/tst_mv.err NULL \
+			"Test #2: can't get the MD5 message of file2. Reason:"
+		return $RC
+	fi
+
+	mv -b $tmpfile1 $tmpfile2  > $LTPTMP/tst_mv.err 2>&1 || RC=$?
+	if [ $RC -ne 0 ]
+	then
+		$LTPBIN/tst_brk TBROK $LTPTMP/tst_mv.err NULL \
+			"Test #2: mv -b file1 file2 failed. Reason:"
+		return $RC
+	fi
+
+	# if mv  -b file1 file2 succeed,there will be "file2~" file
+
+	MD5_backup=`md5sum $tmpfile2 |awk '{print $1}'` > $LTPTMP/tst_mv.err \
+		2>&1 || RC=$?
+	if [ $RC -ne 0 ]
+	then
+		$LTPBIN/tst_brk TBROK $LTPTMP/tst_mv.err NULL \
+		"Test #2: can not get the MD5 message of backup file2. Reason:"
+		return $RC
+	fi
+
+	if [ "$MD5_old" != "$MD5_backup" ]
+	then
+		$LTPBIN/tst_resm TFAIL \
+			"Test #2: mv -b failed"
+		return $(($RC+1))
+	else
+		$LTPBIN/tst_resm TPASS "Test #2: mv -b success"
+	fi
+
+	return $RC
+}
 
 # Function:		main
 #
@@ -258,6 +333,15 @@ then
 	TFAILCNT=$(($TFAILCNT+1))
 fi
 
+rm -fr $LTPTMP/tst_mv.*
+
+init || return $RC      # Exit if initializing testcases fails.
+
+test02 || RC=$?
+if [ $RC -ne 0 ]
+then
+	TFAILCNT=$(($TFAILCNT+1))
+fi
 
 rm -fr $LTPTMP/tst_mv.*
 
-- 
1.6.0.2


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [LTP] [PATCH v3] mv/mv_tests.sh: Add test02 to test 'mv -b'
  2015-04-24  1:44 [LTP] [PATCH v3] mv/mv_tests.sh: Add test02 to test 'mv -b' Cui Bixuan
@ 2015-04-27 14:23 ` Cyril Hrubis
       [not found]   ` <55418B02.3080104@huawei.com>
  0 siblings, 1 reply; 9+ messages in thread
From: Cyril Hrubis @ 2015-04-27 14:23 UTC (permalink / raw)
  To: Cui Bixuan; +Cc: ltp-list

Hi!
The test as it is is messy and needs to be cleaned up before it gets new
testcases. Have a look at:

http://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#23-writing-a-testcase-in-shell

A few comments on the code follow:

> +# Function:             test02
> +#
> +# Description   - Test #2: Test that mv -b <file1> <file2> will move
> +#                 file1 to file2 and backup the file2.
> +#               - create file1 and file2.
> +#               - get the MD5 message of file2.
> +#               - mv -b file1 to file2
> +#               - get the MD5 message of backup file2.
> +#               - compare  with MD5 messages.

That is too much of comments, I can pretty much see what the code below
does. What should be here is that the test is testing mv -b
functionality.

> +# Return                - zero on success
> +#               - non zero on failure. return value from commands ($RC)
> +
> +test02()
> +{
> +	RC=0                    # Return value from commands.
> +	export TCID=mv02        # Name of the test case.
> +	export TST_COUNT=1      # Test number.

The TCID and TST_COUNT should be initialized only once in the test.

> +	tmpfile1=$LTPTMP/tst_mv.tmp/tmpfile1
> +	tmpfile2=$LTPTMP/tst_mv.tmp/tmpfile2
> +	backup_tmpfile2=$LTPTMP/tst_mv.tmp/tmpfile2~
> +
> +	$LTPBIN/tst_resm TINFO \
> +		"Test #2: mv -b <file1> <file2> will move dir1 to dir2"

The path to tst_resm must be in $PATH prior to the test execution, and
these should be executed without the global path.

> +	touch $tmpfile1 $tmpfile2 > $LTPTMP/tst_mv.err 2>&1 || RC=$?
> +	if [ $RC -ne 0 ]
> +	then
> +		$LTPBIN/tst_brk TBROK $LTPTMP/tst_mv.err NULL \
> +			"Test #2: can not touch file1 and file2. Reason:"
> +		return $RC
> +	fi
> +
> +	MD5_old=`md5sum $tmpfile2 |awk '{print $1}'` > $LTPTMP/tst_mv.err \
> +		2>&1 || RC=$?
> +	if [ $RC -ne 0 ]
> +	then
> +		$LTPBIN/tst_brk TBROK $LTPTMP/tst_mv.err NULL \
> +			"Test #2: can't get the MD5 message of file2. Reason:"
> +		return $RC
> +	fi
> +
> +	mv -b $tmpfile1 $tmpfile2  > $LTPTMP/tst_mv.err 2>&1 || RC=$?
> +	if [ $RC -ne 0 ]
> +	then
> +		$LTPBIN/tst_brk TBROK $LTPTMP/tst_mv.err NULL \
> +			"Test #2: mv -b file1 file2 failed. Reason:"
> +		return $RC
> +	fi
> +
> +	# if mv  -b file1 file2 succeed,there will be "file2~" file
> +
> +	MD5_backup=`md5sum $tmpfile2 |awk '{print $1}'` > $LTPTMP/tst_mv.err \
> +		2>&1 || RC=$?
> +	if [ $RC -ne 0 ]
> +	then
> +		$LTPBIN/tst_brk TBROK $LTPTMP/tst_mv.err NULL \
> +		"Test #2: can not get the MD5 message of backup file2. Reason:"
> +		return $RC
> +	fi
> +
> +	if [ "$MD5_old" != "$MD5_backup" ]
> +	then
> +		$LTPBIN/tst_resm TFAIL \
> +			"Test #2: mv -b failed"
> +		return $(($RC+1))
> +	else
> +		$LTPBIN/tst_resm TPASS "Test #2: mv -b success"
> +	fi
> +
> +	return $RC
> +}
>  
>  # Function:		main
>  #
> @@ -258,6 +333,15 @@ then
>  	TFAILCNT=$(($TFAILCNT+1))
>  fi
>  
> +rm -fr $LTPTMP/tst_mv.*

We have tst_tmpdir() and tst_rmdir() to simplify this.

> +init || return $RC      # Exit if initializing testcases fails.
> +
> +test02 || RC=$?
> +if [ $RC -ne 0 ]
> +then
> +	TFAILCNT=$(($TFAILCNT+1))
> +fi
>  
>  rm -fr $LTPTMP/tst_mv.*

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [LTP] [PATCH v3] mv/mv_tests.sh: Add test02 to test 'mv -b'
       [not found]   ` <55418B02.3080104@huawei.com>
@ 2015-04-30  7:02     ` Cyril Hrubis
  2015-04-30  8:58     ` [LTP] [PATCH 0/3] commands/fileutils/mv: cleanup and add new test Zeng Linggang
  1 sibling, 0 replies; 9+ messages in thread
From: Cyril Hrubis @ 2015-04-30  7:02 UTC (permalink / raw)
  To: Cui Bixuan; +Cc: ltp-list, zhanyongming, zhuyanpeng

Hi!
> >>  # Function:		main
> >>  #
> >> @@ -258,6 +333,15 @@ then
> >>  	TFAILCNT=$(($TFAILCNT+1))
> >>  fi
> >>  
> >> +rm -fr $LTPTMP/tst_mv.*
> > 
> > We have tst_tmpdir() and tst_rmdir() to simplify this.
> > 
> The case does not use test.sh library and can't call tst_tmpdir() there.
> The mv_test.sh was written long before.Maybe I should modity it by using
> test.sh library, what do you think?

Yes please. We usually fix testcases before we add new functionality.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 0/3] commands/fileutils/mv: cleanup and add new test
       [not found]   ` <55418B02.3080104@huawei.com>
  2015-04-30  7:02     ` Cyril Hrubis
@ 2015-04-30  8:58     ` Zeng Linggang
  2015-04-30  8:58       ` [LTP] [PATCH 1/3] commands/fileutils/mv: Some cleanup Zeng Linggang
                         ` (3 more replies)
  1 sibling, 4 replies; 9+ messages in thread
From: Zeng Linggang @ 2015-04-30  8:58 UTC (permalink / raw)
  To: cuibixuan; +Cc: ltp-list

Hi, Mr Cui

I have written some patches for mv tests(some cleanup and add new test),
that maybe save your some time.

 testcases/commands/fileutils/mv/mv_tests.sh | 263 ++++++++--------------------
 1 file changed, 73 insertions(+), 190 deletions(-)
 testcases/commands/fileutils/mv/00_Descriptions.txt | 3 ---
 1 file changed, 3 deletions(-)
 testcases/commands/fileutils/mv/mv_tests.sh | 40 ++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

Best regards,
zeng

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 1/3] commands/fileutils/mv: Some cleanup
  2015-04-30  8:58     ` [LTP] [PATCH 0/3] commands/fileutils/mv: cleanup and add new test Zeng Linggang
@ 2015-04-30  8:58       ` Zeng Linggang
  2015-05-04 15:44         ` Cyril Hrubis
  2015-04-30  8:58       ` [LTP] [PATCH 2/3] commands/fileutils/mv: Remove 00_Descriptions.txt Zeng Linggang
                         ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Zeng Linggang @ 2015-04-30  8:58 UTC (permalink / raw)
  To: cuibixuan; +Cc: ltp-list

* Delete some useless comments.
* Add 'TCID' and 'TST_TOTAL' global variables.
* Add test.sh.
* init() --> setup()
* Add cleanup().
* Use 'tst_check_cmds' and 'tst_tmpdir'.
* Use 'ROD_SILENT'.
* Use 'tst_resm' and 'trs_brkm' instead of 'tst_res' and 'tst_brk'.
* Use 'local' to define the variables as they are in functions.
* tst_mv.tmp --> tst_mv.old
* tst_mv.tmp1 --> tst_mv.new
* Some cleanup.

Signed-off-by: Cui Bixuan <cuibixuan@huawei.com>
Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/commands/fileutils/mv/mv_tests.sh | 263 ++++++++--------------------
 1 file changed, 73 insertions(+), 190 deletions(-)

diff --git a/testcases/commands/fileutils/mv/mv_tests.sh b/testcases/commands/fileutils/mv/mv_tests.sh
index 207e945..6c55d94 100755
--- a/testcases/commands/fileutils/mv/mv_tests.sh
+++ b/testcases/commands/fileutils/mv/mv_tests.sh
@@ -2,6 +2,7 @@
 ################################################################################
 ##                                                                            ##
 ## Copyright (c) International Business Machines  Corp., 2001                 ##
+## Author:       Manoj Iyer, manjo@mail.utexas.edu                            ##
 ##                                                                            ##
 ## This program is free software;  you can redistribute it and#or modify      ##
 ## it under the terms of the GNU General Public License as published by       ##
@@ -14,251 +15,133 @@
 ## for more details.                                                          ##
 ##                                                                            ##
 ## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
+## along with this program;  if not, write to the Free Software Foundation,   ##
+## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA           ##
 ##                                                                            ##
 ################################################################################
 #
-# File :        mv_test.sh
-#
 # Description:  Test basic functionality of mv command
-#				- Test #1:  mv <dir1> <dir2> will move dir1 to dir2 and all its
-#				            contents.
-#
-# Author:       Manoj Iyer, manjo@mail.utexas.edu
-#
-# History:      Feb 03 2003 - Created - Manoj Iyer.
+#		- Test #1:  mv <dir1> <dir2>
+#		  move dir1 to dir2 and all its contents.
 #
-# Function:		init
-#
-# Description:	- Check if command mv is available.
-#               - Create temprary directory, and temporary files.
-#               - Initialize environment variables.
-#
-# Return		- zero on success
-#               - non zero on failure. return value from commands ($RC)
-init()
-{
 
-	RC=0				# Return code from commands.
-	export TST_TOTAL=1	# total numner of tests in this file.
-	export TCID=mv	# this is the init function.
-	export TST_COUNT=0	# init identifier,
+TCID=mv01
+TST_TOTAL=1
+. test.sh
 
-	if [ -z "$LTPTMP" ] && [ -z "$TMPBASE" ]
-	then
-		LTPTMP=/tmp
-	else
-		LTPTMP=$TMPBASE
-	fi
-	if [ -z "$LTPBIN" ] && [ -z "$LTPROOT" ]
-	then
-		LTPBIN=./
-	else
-		LTPBIN=$LTPROOT/testcases/bin
-	fi
+setup()
+{
+	tst_check_cmds mv
 
+	tst_tmpdir
 
-	$LTPBIN/tst_resm TINFO "INIT: Inititalizing tests."
+	tst_resm TINFO "INIT: Inititalizing tests."
 
-	which mv > $LTPTMP/tst_mv.err 2>&1 || RC=$?
-	if [ $RC -ne 0 ]
-	then
-		$LTPBIN/tst_brk TBROK $LTPTMP/tst_mv.err NULL \
-			"Test #1: mv command does not exist. Reason:"
-		return $RC
-	fi
+	ROD_SILENT mkdir -p tst_mv.old
+}
 
-	mkdir -p $LTPTMP/tst_mv.tmp > $LTPTMP/tst_mv.err 2>&1 || RC=$?
-	if [ $RC -ne 0 ]
-	then
-		$LTPBIN/tst_brk TBROK $LTPTMP/tst_mv.err NULL \
-			"Test #1: failed creating temp directory. Reason:"
-		return $RC
-	fi
-	return $RC
+cleanup()
+{
+	tst_rmdir
 }
 
-# Function:		creat_dirnfiles
-#
-# Description:	- create N directories and fill each with M files
-#
-# Input:		$1 - test number
-#				$2 - number of directories to create
-#				$3 - number of file to create in each directory
-#				$4 - name of the base directory
-#
-# Return		- zero on success
-#               - non zero on failure. return value ($RC) from commands
 creat_dirnfiles()
 {
-    numdirs=$2	# number of directories to create
-    numfiles=$3 # number of file to create in each directory
-    dirname=$4  # name of the base directory
-	dircnt=0    # index into number of dirs created in loop
-	fcnt=0      # index into number of files created in loop
-	RC=0        # return value from commands
-
-	$LTPBIN/tst_resm TINFO "Test #$1: Creating $numdirs directories."
-	$LTPBIN/tst_resm TINFO "Test #$1: filling each dir with $numfiles files".
+	local numdirs=$2
+	local numfiles=$3
+	local dirname=$4
+	local dircnt=0
+	local fcnt=0
+
+	tst_resm TINFO "Test #$1: Creating $numdirs directories."
+	tst_resm TINFO "Test #$1: filling each dir with $numfiles files."
 	while [ $dircnt -lt $numdirs ]
 	do
 		dirname=$dirname/d.$dircnt
-        mkdir -p $dirname  > $LTPTMP/tst_mv.err 2>&1 || RC=$?
-		if [ $RC -ne 0 ]
-		then
-			$LTPBIN/tst_brk TBROK $LTPTMP/tst_mv.err NULL \
-			"Test #$1: while creating $numdirs dirs.  Reason"
-			return $RC
-		fi
+		ROD_SILENT mkdir -p $dirname
+
 		fcnt=0
-        while [ $fcnt -lt $numfiles ]
-        do
-			touch $dirname/f.$fcnt
-			if [ $RC -ne 0 ]
-			then
-				$LTPBIN/tst_brk TBROK $LTPTMP/tst_mv.err NULL \
-				"Test #$1: while creating $numdirs dirs.  Reason"
-				return $RC
-			fi
+		while [ $fcnt -lt $numfiles ]
+		do
+			ROD_SILENT touch $dirname/f.$fcnt
 			fcnt=$(($fcnt+1))
 		done
 		dircnt=$(($dircnt+1))
 	done
-	return $RC
 }
 
-
-# Function:		creat_expout
-#
-# Description:	- create expected output
-#
-# Input:		$1 - number of directories to create
-#				$2 - number of file to create in each directory
-#				$3 - name of the base directory
-#
-# Return		- zero on success
-#               - non zero on failure. return value ($RC) from commands
 creat_expout()
 {
-	numdir=$1	# number of directories to create
-	numfile=$2  # number of file to create in each directory
-	dirname=$3  # name of the base directory
-    dircnt=0    # index into dir created in loop
-    fcnt=0      # index into files created in loop
-	RC=0        # return code from commands
-
-	echo "$dirname:"  1>>$LTPTMP/tst_mv.exp
-	echo "d.$dircnt"  1>>$LTPTMP/tst_mv.exp
+	local numdir=$1
+	local numfile=$2
+	local dirname=$3
+	local dircnt=0
+	local fcnt=0
+
+	echo "$dirname:"  1>>tst_mv.exp
+	echo "d.$dircnt"  1>>tst_mv.exp
 	while [ $dircnt -lt $numdirs ]
 	do
 		dirname=$dirname/d.$dircnt
 		dircnt=$(($dircnt+1))
-		echo "$dirname:"  1>>$LTPTMP/tst_mv.exp
-		if [ $dircnt -lt $numdirs ]
-		then
-			echo "d.$dircnt" 1>>$LTPTMP/tst_mv.exp
+		echo "$dirname:"  1>>tst_mv.exp
+		if [ $dircnt -lt $numdirs ]; then
+			echo "d.$dircnt" 1>>tst_mv.exp
 		fi
+
 		fcnt=0
-        while [ $fcnt -lt $numfiles ]
-        do
-			echo "f.$fcnt " 1>>$LTPTMP/tst_mv.exp
+		while [ $fcnt -lt $numfiles ]
+		do
+			echo "f.$fcnt " 1>>tst_mv.exp
 			fcnt=$(($fcnt+1))
 		done
-		printf "\n\n" 1>>$LTPTMP/tst_mv.exp
-
+		printf "\n\n" 1>>tst_mv.exp
 	done
 }
 
-# Function:		test01
-#
-# Description	- Test #1: Test that mv <dir1> <dir2> will move
-#                 dir1 to dir2 and all its contents.
-#               - create N directories and fill each with M files.
-#               - mv dir1 to dir2
-#               - list contents of dir2 and save it to file - actual output
-#               - create expected output
-#               - compare expected output with actual output.
-#
-# Return		- zero on success
-#               - non zero on failure. return value from commands ($RC)
-
 test01()
 {
-	RC=0				# Return value from commands.
-	export TCID=mv01	# Name of the test case.
-	export TST_COUNT=1	# Test number.
 	numdirs=10
 	numfiles=10
 	dircnt=0
-    fcnt=0
+	fcnt=0
 
-	$LTPBIN/tst_resm TINFO \
-		"Test #1: mv <dir1> <dir2> will move dir1 to dir2 and all its contents"
-
-	creat_dirnfiles 1 $numdirs $numfiles $LTPTMP/tst_mv.tmp || RC=$?
-    if [ $RC -ne 0 ]
-	then
-		return $RC
-	fi
+	tst_resm TINFO "Test #1: mv <dir1> <dir2> will move dir1 to dir2 and" \
+		       "all its contents"
 
+	creat_dirnfiles 1 $numdirs $numfiles tst_mv.old
 
-	mv $LTPTMP/tst_mv.tmp $LTPTMP/tst_mv.tmp1 > $LTPTMP/tst_mv.err 2>&1 || RC=$?
-    if [ $RC -ne 0 ]
-	then
-		$LTPBIN/tst_res TFAIL $LTPTMP/tst_mv.err \
-		"Test #1: mv failed, mv command  returned $RC. Reason:"
-		return $RC
+	mv tst_mv.old tst_mv.new > tst_mv.err 2>&1
+	if [ $? -ne 0 ]; then
+		cat tst_mv.err
+		tst_brkm TFAIL "Test #1: 'mv tst_mv.old tst_mv.new' failed"
 	fi
 
-	$LTPBIN/tst_resm TINFO "Test #1: creating output file"
-	ls -R $LTPTMP/tst_mv.tmp1 > $LTPTMP/tst_mv.out 2>&1
+	tst_resm TINFO "Test #1: creating output file"
+	ls -R tst_mv.new > tst_mv.out 2>&1
 
-	$LTPBIN/tst_resm TINFO "Test #1: creating expected output file"
-	creat_expout $numdirs $numfiles $LTPTMP/tst_mv.tmp1
+	tst_resm TINFO "Test #1: creating expected output file"
+	creat_expout $numdirs $numfiles tst_mv.new
 
-	$LTPBIN/tst_resm TINFO \
-	    "Test #1: comparing expected out and actual output file"
-	diff -w -B -q $LTPTMP/tst_mv.out $LTPTMP/tst_mv.exp > $LTPTMP/tst_mv.err 2>&1 \
-		|| RC=$?
-	if [ $RC -ne 0 ]
-	then
-		$LTPBIN/tst_res TFAIL $LTPTMP/tst_mv.err \
-			"Test #1: mv failed. Reason:"
+	tst_resm TINFO "Test #1: comparing expected out and actual output file"
+	diff -w -B -q tst_mv.out tst_mv.exp > tst_mv.err 2>&1
+	if [ $? -ne 0 ]; then
+		cat tst_mv.err
+		tst_resm TFAIL "Test #1: mv failed."
 	else
-		$LTPBIN/tst_resm TINFO "Test #1: expected same as actual"
-		if [ -f $LTPTMP/tst_mv.tmp ]
-		then
-			$LTPBIN/tst_resm TFAIL ""Test #1: mv did not delete old directory"
-			return $(($RC+1))
+		tst_resm TINFO "Test #1: expected same as actual"
+		if [ -f tst_mv.old ]; then
+			tst_resm TFAIL "Test #1: mv did not delete old" \
+				       "directory"
 		else
-			$LTPBIN/tst_resm TPASS "Test #1: mv success"
+			tst_resm TPASS "Test #1: mv success"
 		fi
 	fi
-	return $RC
 }
 
+setup
+TST_CLEANUP=cleanup
 
-# Function:		main
-#
-# Description:	- Execute all tests, report results.
-#
-# Exit:			- zero on success
-# 				- non-zero on failure.
-
-
-TFAILCNT=0			# Set TFAILCNT to 0, increment on failure.
-RC=0				# Return code from tests.
-
-init || return $RC	# Exit if initializing testcases fails.
-
-test01 || RC=$?
-if [ $RC -ne 0 ]
-then
-	TFAILCNT=$(($TFAILCNT+1))
-fi
-
-
-rm -fr $LTPTMP/tst_mv.*
+test01
 
-exit $TFAILCNT
+tst_exit
-- 
1.8.3.1


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 2/3] commands/fileutils/mv: Remove 00_Descriptions.txt
  2015-04-30  8:58     ` [LTP] [PATCH 0/3] commands/fileutils/mv: cleanup and add new test Zeng Linggang
  2015-04-30  8:58       ` [LTP] [PATCH 1/3] commands/fileutils/mv: Some cleanup Zeng Linggang
@ 2015-04-30  8:58       ` Zeng Linggang
  2015-04-30  8:58       ` [LTP] [PATCH 3/3] commands/fileutils/mv: add new test for mv(1) Zeng Linggang
  2015-04-30  9:31       ` [LTP] [PATCH 0/3] commands/fileutils/mv: cleanup and add new test Cui Bixuan
  3 siblings, 0 replies; 9+ messages in thread
From: Zeng Linggang @ 2015-04-30  8:58 UTC (permalink / raw)
  To: cuibixuan; +Cc: ltp-list

I do *not* think this file is necessary, So remove it.

Signed-off-by: Cui Bixuan <cuibixuan@huawei.com>
Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/commands/fileutils/mv/00_Descriptions.txt | 3 ---
 1 file changed, 3 deletions(-)
 delete mode 100644 testcases/commands/fileutils/mv/00_Descriptions.txt

diff --git a/testcases/commands/fileutils/mv/00_Descriptions.txt b/testcases/commands/fileutils/mv/00_Descriptions.txt
deleted file mode 100644
index 6d52868..0000000
--- a/testcases/commands/fileutils/mv/00_Descriptions.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-test01
-	mv <dir1> <dir2> will move dir1 to dir2 and all its contents.
-
-- 
1.8.3.1


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 3/3] commands/fileutils/mv: add new test for mv(1)
  2015-04-30  8:58     ` [LTP] [PATCH 0/3] commands/fileutils/mv: cleanup and add new test Zeng Linggang
  2015-04-30  8:58       ` [LTP] [PATCH 1/3] commands/fileutils/mv: Some cleanup Zeng Linggang
  2015-04-30  8:58       ` [LTP] [PATCH 2/3] commands/fileutils/mv: Remove 00_Descriptions.txt Zeng Linggang
@ 2015-04-30  8:58       ` Zeng Linggang
  2015-04-30  9:31       ` [LTP] [PATCH 0/3] commands/fileutils/mv: cleanup and add new test Cui Bixuan
  3 siblings, 0 replies; 9+ messages in thread
From: Zeng Linggang @ 2015-04-30  8:58 UTC (permalink / raw)
  To: cuibixuan; +Cc: ltp-list

Add 'mv -b <file1> <file2>' test.

Signed-off-by: Cui Bixuan <cuibixuan@huawei.com>
Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/commands/fileutils/mv/mv_tests.sh | 40 ++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/testcases/commands/fileutils/mv/mv_tests.sh b/testcases/commands/fileutils/mv/mv_tests.sh
index 6c55d94..66f4056 100755
--- a/testcases/commands/fileutils/mv/mv_tests.sh
+++ b/testcases/commands/fileutils/mv/mv_tests.sh
@@ -23,10 +23,12 @@
 # Description:  Test basic functionality of mv command
 #		- Test #1:  mv <dir1> <dir2>
 #		  move dir1 to dir2 and all its contents.
+#		- Test #2:  mv -b <file1> <file2>
+#		  move file1 to file2 and backup the file2.
 #
 
 TCID=mv01
-TST_TOTAL=1
+TST_TOTAL=2
 . test.sh
 
 setup()
@@ -139,9 +141,45 @@ test01()
 	fi
 }
 
+test02()
+{
+	tst_resm TINFO "Test #2: mv -b <file1> <file2> will move dir1 to dir2"
+
+	ROD_SILENT touch tmpfile1 tmpfile2
+
+	MD5_old=$(md5sum tmpfile2 | awk '{print $1}')
+	if [ $? -ne 0 ]; then
+		tst_brkm TBROK "Test #2: can't get the MD5 message of file2."
+	fi
+
+	if [ -f "tmpfile2~" ]; then
+		tst_brkm TBROK "Test #2: file tmpfile2~ should not exists."
+	fi
+
+	mv -b tmpfile1 tmpfile2
+	if [ $? -ne 0 ]; then
+		tst_brkm TBROK "Test #2: 'mv -b tmpfile1 tmpfile2' failed."
+	fi
+
+	# if 'mv -b file1 file2' succeed, there will be "tmpfile2~" file.
+
+	MD5_backup=$(md5sum tmpfile2 | awk '{print $1}')
+	if [ $? -ne 0 ]; then
+		tst_brkm TBROK "Test #2: can not get the MD5 message of" \
+			       "backup file2."
+	fi
+
+	if [ "$MD5_old" == "$MD5_backup" -a -f "tmpfile2~" ]; then
+		tst_resm TPASS "Test #2: mv -b success"
+	else
+		tst_resm TFAIL "Test #2: mv -b failed"
+	fi
+}
+
 setup
 TST_CLEANUP=cleanup
 
 test01
+test02
 
 tst_exit
-- 
1.8.3.1


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [LTP] [PATCH 0/3] commands/fileutils/mv: cleanup and add new test
  2015-04-30  8:58     ` [LTP] [PATCH 0/3] commands/fileutils/mv: cleanup and add new test Zeng Linggang
                         ` (2 preceding siblings ...)
  2015-04-30  8:58       ` [LTP] [PATCH 3/3] commands/fileutils/mv: add new test for mv(1) Zeng Linggang
@ 2015-04-30  9:31       ` Cui Bixuan
  3 siblings, 0 replies; 9+ messages in thread
From: Cui Bixuan @ 2015-04-30  9:31 UTC (permalink / raw)
  To: Zeng Linggang; +Cc: ltp-list

On 2015/4/30 16:58, Zeng Linggang wrote:
> Hi, Mr Cui
> 
> I have written some patches for mv tests(some cleanup and add new test),
> that maybe save your some time.
The patches look very nice (smile).

Thanks,
Cui Bixuan

> 
>  testcases/commands/fileutils/mv/mv_tests.sh | 263 ++++++++--------------------
>  1 file changed, 73 insertions(+), 190 deletions(-)
>  testcases/commands/fileutils/mv/00_Descriptions.txt | 3 ---
>  1 file changed, 3 deletions(-)
>  testcases/commands/fileutils/mv/mv_tests.sh | 40 ++++++++++++++++++++++++++++-
>  1 file changed, 39 insertions(+), 1 deletion(-)
> 
> Best regards,
> zeng
> 


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [LTP] [PATCH 1/3] commands/fileutils/mv: Some cleanup
  2015-04-30  8:58       ` [LTP] [PATCH 1/3] commands/fileutils/mv: Some cleanup Zeng Linggang
@ 2015-05-04 15:44         ` Cyril Hrubis
  0 siblings, 0 replies; 9+ messages in thread
From: Cyril Hrubis @ 2015-05-04 15:44 UTC (permalink / raw)
  To: Zeng Linggang; +Cc: ltp-list

Hi!
Pushed whole patchset, thanks.

BTW: It could have been simplified even more if the exfile was generated in
     the creat_dirfiles() function. :)

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-05-04 15:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-24  1:44 [LTP] [PATCH v3] mv/mv_tests.sh: Add test02 to test 'mv -b' Cui Bixuan
2015-04-27 14:23 ` Cyril Hrubis
     [not found]   ` <55418B02.3080104@huawei.com>
2015-04-30  7:02     ` Cyril Hrubis
2015-04-30  8:58     ` [LTP] [PATCH 0/3] commands/fileutils/mv: cleanup and add new test Zeng Linggang
2015-04-30  8:58       ` [LTP] [PATCH 1/3] commands/fileutils/mv: Some cleanup Zeng Linggang
2015-05-04 15:44         ` Cyril Hrubis
2015-04-30  8:58       ` [LTP] [PATCH 2/3] commands/fileutils/mv: Remove 00_Descriptions.txt Zeng Linggang
2015-04-30  8:58       ` [LTP] [PATCH 3/3] commands/fileutils/mv: add new test for mv(1) Zeng Linggang
2015-04-30  9:31       ` [LTP] [PATCH 0/3] commands/fileutils/mv: cleanup and add new test Cui Bixuan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox