public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3] commands/mkswap: Added new testcase to test mkswap(8).
Date: Tue, 17 Nov 2015 10:22:03 +0800	[thread overview]
Message-ID: <564A8F4B.4070504@cn.fujitsu.com> (raw)
In-Reply-To: <20151116163110.GG17888@rei.suse.cz>

Hi!

Thanks for your review!
I will modify the test case according to your suggestion.

Best Regards,
Guangwen Feng

On 2015/11/17 00:31, Cyril Hrubis wrote:
> Hi!
>> +TCID=mkswap01
>> +TST_TOTAL=10
>> +. test.sh
>> +
>> +setup()
>> +{
>> +	tst_require_root
>> +
>> +	tst_check_cmds blkid blockdev free mkswap
>                         ^
> 			uuidgen is missing here
> 
>> +	tst_tmpdir
>> +
>> +	TST_CLEANUP=cleanup
>> +
>> +	tst_acquire_device
>> +
>> +	UUID=`uuidgen`
>> +
>> +	DEVICE_SIZE=$((`blockdev --getsize64 $TST_DEVICE`/1024))
>> +
>> +	PAGE_SIZE=`getconf PAGE_SIZE`
>> +}
>> +
>> +cleanup()
>> +{
>> +	tst_release_device
>> +
>> +	tst_rmdir
>> +}
>> +
>> +mkswap_verify()
>> +{
>> +	local mkswap_op=$1
>> +	local op_arg=$2
>> +	local device=$3
>> +	local size=$4
>> +
>> +	local ret=0
>> +
>> +	local before=`free | grep "Swap" | awk '{print $2}'`
> 
> We can do better with:
> 
> awk '/SwapTotal/ {print $2}' /proc/meminfo
> 
> No need to call free and no need to use grep :).
> 
>> +	local swapsize=${4:-$DEVICE_SIZE}
>> +
>> +	if [ "$mkswap_op" = "-p" ]; then
>> +		local pagesize=$op_arg
>> +	else
>> +		local pagesize=$PAGE_SIZE
>> +	fi
>> +
>> +	if [ "$mkswap_op" = "-L" ] || [ "$mkswap_op" = "-U" ]; then
>> +		local swapfile=$op_arg
>> +	else
>> +		mkswap_op=
>> +		local swapfile=$device
>> +	fi
> 
> Can you actually pass the device for the test instead of passing
> $TST_DEVICE which is kind of pointles when you can use $TST_DEVICE in
> the mkswap_test() for the mkswap command?
> 
>> +	swapon $mkswap_op $swapfile 2>/dev/null
>> +	if [ $? -ne 0 ]; then
>> +		tst_resm TINFO "Can not do swapon on $swapfile."
>> +		if [ $pagesize -ne $PAGE_SIZE ]; then
>> +			tst_resm TINFO "Page size specified by 'mkswap -p' \
>> +is not equal to system's page size."
>> +			tst_resm TINFO "Swapon failed expectedly."
>> +			return $ret
>                               ^
>                         Just do return 0 here, it's more confusing as
> 			it should be as this is.
>> +		fi
>> +
>> +		if [ $swapsize -gt $DEVICE_SIZE ]; then
>> +			tst_resm TINFO "Device size specified by 'mkswap' \
>> +greater than real size."
>> +			tst_resm TINFO "Swapon failed expectedly."
>> +			return $ret
> 
> Here as well.
> 
>> +		fi
>> +
>> +		tst_resm TINFO "Swapon failed unexpectedly."
>> +		return 1
>> +	fi
>> +
>> +	local after=`free | grep "Swap" | awk '{print $2}'`
> 
> Here you can simplify the command as well.
> 
>> +	local est=16
> 
> You shoud intialize the ret=0 here.
> 
>> +	if [ $((after-before)) -lt $((swapsize-pagesize/1024-est)) ] || \
>> +		[ $((after-before)) -gt $((swapsize-pagesize/1024+est)) ]; then
>> +		ret=1
>> +	fi
> 
> What is the story behind the est? It should probably be worth comment
> when the size could be 16kB off or at least on which system does this
> happens.
> 
> And I would compute the difference only once and store it to a variable,
> but that is minor.
> 
>> +	swapoff $mkswap_op $swapfile 2>/dev/null
>> +	if [ $? -ne 0 ]; then
>> +		tst_resm TINFO "Can not do swapoff on $swapfile."
>> +	fi
>> +
>> +	return $ret
> 
> Otherwise it looks good.
> 

  reply	other threads:[~2015-11-17  2:22 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-05  3:03 [LTP] [PATCH] commands/mkswap: Added new testcase to test mkswap(8) Guangwen Feng
2015-11-05 11:41 ` Alexey Kodanev
2015-11-06  5:17   ` Guangwen Feng
2015-11-06 11:54     ` Alexey Kodanev
2015-11-09  8:02       ` [LTP] [PATCH v2] " Guangwen Feng
2015-11-11  4:50         ` Lei Li
2015-11-12  3:32           ` Guangwen Feng
2015-11-11  9:44         ` Alexey Kodanev
2015-11-12  3:36           ` Guangwen Feng
2015-11-12  8:23             ` [LTP] [PATCH v3] " Guangwen Feng
2015-11-16 16:31               ` Cyril Hrubis
2015-11-17  2:22                 ` Guangwen Feng [this message]
2015-11-18  9:12                   ` [LTP] [PATCH v4] " Guangwen Feng
2015-11-19 13:41                     ` Cyril Hrubis
2015-11-20  5:36                       ` Guangwen Feng
2015-11-20  6:04                         ` [LTP] [PATCH v5] " Guangwen Feng
2015-11-24 16:26                           ` Cyril Hrubis
2015-11-09  2:00 ` [LTP] [PATCH] " Lei Li
2015-11-09  6:54   ` Guangwen Feng
2015-11-11  3:45     ` Lei Li
2015-11-12  3:27       ` Guangwen Feng

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=564A8F4B.4070504@cn.fujitsu.com \
    --to=fenggw-fnst@cn.fujitsu.com \
    --cc=ltp@lists.linux.it \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox