All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Cui Bixuan <cuibixuan@huawei.com>
Cc: ltp-list@lists.sourceforge.net
Subject: Re: [LTP] [PATCH v3] mv/mv_tests.sh: Add test02 to test 'mv -b'
Date: Mon, 27 Apr 2015 16:23:07 +0200	[thread overview]
Message-ID: <20150427142307.GC10567@rei.suse.de> (raw)
In-Reply-To: <1429839868-2011-1-git-send-email-cuibixuan@huawei.com>

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

  reply	other threads:[~2015-04-27 14:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
     [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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150427142307.GC10567@rei.suse.de \
    --to=chrubis@suse.cz \
    --cc=cuibixuan@huawei.com \
    --cc=ltp-list@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.