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] commands/mkswap: Added new testcase to test mkswap(8).
Date: Mon, 9 Nov 2015 14:54:05 +0800	[thread overview]
Message-ID: <5640430D.40903@cn.fujitsu.com> (raw)
In-Reply-To: <BLU436-SMTP1923895FA6B242E57BC28CDCF150@phx.gbl>

Hi!
Thanks for review!

On 2015/11/09 10:00, Lei Li wrote:
>> +setup()
>> +{
>> +    tst_require_root
>> +
>> +    tst_check_cmds losetup free mkswap
>> +
>> +    tst_tmpdir
>> +
>> +    TST_CLEANUP=cleanup
>> +
>> +    tst_acquire_device
>> +
>> +    local path=`losetup -a | grep "$TMPDIR"  | awk '{print $3}' | \
>> +        cut -d '(' -f2 | cut -d ')' -f1`
>> +    DEVICE_SIZE=$((`ls -l $path | awk '{print $5}'`/1024))
> Hi!
>     This testcase uses a loop device instead of a block device, but tst_acquire_device may offer you a block device, /opt/ltp/runltp -b /dev/sdb1 for example, then, "path" may be invilidate, and syntax error occurs in the line :
> 
> DEVICE_SIZE=$((`ls -l $path | awk '{print $5}'`/1024))
> 
> So, examination whether the "path" is validate is necessary.
> 

Indeed, I missed the condition of block device.
I think I could use DEVICE_SIZE=$((`blockdev --getsize64 $TST_DEVICE`/1024)) instead of via path.

>> +
>> +    PAGE_SIZE=`getconf PAGE_SIZE`
>> +}
>> +
>> +cleanup()
>> +{
>> +    tst_release_device
>> +
>> +    tst_rmdir
>> +}
>> +
>> +mkswap_verify()
>> +{
>> +    local ret=0
>> +
>> +    local before=`free | grep "Swap" | awk '{print $2}'`
>> +
>> +    if [ -z "$4" ]; then
>> +        local swapsize=$DEVICE_SIZE
>> +    else
>> +        local swapsize=$4
>> +    fi
>> +
>> +    if [ "$1" = "-p" ]; then
>> +        local pagesize=$2
>> +    else
>> +        local pagesize=$PAGE_SIZE
>> +    fi
>> +
>> +    if [ "$1" = "-L" ]; then
>> +        local swap_op="-L"
>> +        local swapfile=$2
>> +    elif [ "$1" = "-U" ]; then
>> +        local swap_op="-U"
>> +        local swapfile=$2
>> +    else
>> +        local swap_op=""
>> +        local swapfile=$3
>> +    fi
>> +
>> +    swapon $swap_op $swapfile 2>/dev/null
>> +    if [ $? -ne 0 ]; then
>> +        tst_resm TINFO "can not do swapon on $swapfile."
>> +        if [ $pagesize -ne $PAGE_SIZE ]; then
>> +            return $ret
>> +        fi
>> +
>> +        if [ $swapsize -gt $DEVICE_SIZE ]; then
>> +            return $ret
>> +        fi
>> +    fi
>> +
>> +    local after=`free | grep "Swap" | awk '{print $2}'`
>> +
>> +    local est=16
>> +    if [ $((after-before)) -lt $((swapsize-pagesize/1024-est)) ] || \
>> +        [ $((after-before)) -gt $((swapsize-pagesize/1024+est)) ]; then
>> +        ret=1
>> +    fi
> 
> How do you get this formula? I'm a newbie here :-)
> 

I just compare device size used for swap with the actual increment of swap.
The increment should be equal to the device size minus a page size, but in some cases, the result fluctuates.

>> +
>> +    swapoff $swap_op $swapfile 2>/dev/null
>> +    if [ $? -ne 0 ]; then
>> +        tst_resm TINFO "can not do swapoff on $swapfile."
>> +    fi
>> +
>> +    return $ret
>> +}
>> +
>> +mkswap_test()
>> +{
>> +    local mkswap_op=$1
>> +    local op_arg=$2
>> +    local device=$3
>> +    local size=$4
>> +
>> +    local mkswap_cmd="mkswap $mkswap_op $op_arg $device $size"
>> +
>> +    ${mkswap_cmd} >temp 2>&1
>> +    if [ $? -ne 0 ]; then
>> +        grep -q -E "unknown option|invalid option|Usage" temp
>> +        if [ $? -eq 0 ]; then
>> +            tst_resm TCONF "'${mkswap_cmd}' not supported."
>> +            return
>> +        else
>> +            tst_resm TFAIL "'${mkswap_cmd}' failed."
>> +            cat temp
>> +            return
>> +        fi
>> +    fi
>> +
>> +    if [ -n "$device" ]; then
>> +        mkswap_verify "$mkswap_op" "$op_arg" "$device" "$size"
>> +        if [ $? -ne 0 ]; then
>> +            tst_resm TFAIL "'${mkswap_cmd}' failed, not expected."
>> +            return
>> +        fi
>> +    fi
>> +
>> +    tst_resm TPASS "'${mkswap_cmd}' passed."
>> +}
>> +
>> +test1()
>> +{
>> +    mkswap_test "" "" "$TST_DEVICE"
>> +}
>> +
>> +test2()
>> +{
>> +    mkswap_test "" "" "$TST_DEVICE" "10000"
>> +}
>> +
>> +test3()
>> +{
>> +    mkswap_test "-f" "" "$TST_DEVICE" "30000"
>> +}
> The size of loop device is 20000 currently, but there is no guarantee that value will not be changed in the future. "10000" and "30000" may be inappropriate at that time.In my opinion, it is more reasonable like this:
> 
> test2()
> {
>     mkswap_test "" "" "$TST_DEVICE" "$((DEVICE_SIZE-10000))"
> }
> 
> test3()
> {
>     mkswap_test "-f" "" "$TST_DEVICE" "$((DEVICE_SIZE+10000))"
> }

Yes, it's more reasonably, thanks.

>> +
>> +test4()
>> +{
>> +    mkswap_test "-c" "" "$TST_DEVICE"
>> +}
>> +
>> +test5()
>> +{
>> +    mkswap_test "-p" "2048" "$TST_DEVICE"
>> +}
>> +
>> +test6()
>> +{
>> +    mkswap_test "-L" "testswap" "$TST_DEVICE"
>> +}
>> +
>> +test7()
>> +{
>> +    mkswap_test "-v1" "" "$TST_DEVICE"
>> +}
>> +
>> +test8()
>> +{
>> +    mkswap_test "-U" "ffffffff-ffff-ffff-ffff-ffffffffffff" "$TST_DEVICE"
>> +}
>> +
>> +test9()
>> +{
>> +    mkswap_test "-V"
>> +}
>> +
>> +test10()
>> +{
>> +    mkswap_test "-h"
>> +}
>> +
>> +setup
>> +
>> +for i in $(seq 1 ${TST_TOTAL})
>> +do
>> +    test$i
>> +done
>> +
>> +tst_exit
>>
> 

  reply	other threads:[~2015-11-09  6:54 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
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 [this message]
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=5640430D.40903@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