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: Thu, 12 Nov 2015 11:27:24 +0800	[thread overview]
Message-ID: <5644071C.1060202@cn.fujitsu.com> (raw)
In-Reply-To: <BLU436-SMTP8601D757580F449BE1A80CF130@phx.gbl>

Hi!

On 2015/11/11 11:45, Lei Li wrote:
>> 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.
> 
> Hi
>   I read the code of mkswap, find nothing about the fluctuation but
> the exact value(as you mentioned above, device size minus a page size).
> And the fluctuation didn't show up in all of my test result.Would you
> please give me some proof about the fluctuation ?
> 

Yes, in most of my environment, there is no fluctuation but the exact value,
but for example, on my RHEL5.11GA, the result is not exactly equal to the value somehow,
maybe the result is slightly different in some kernels.

Best Regards,
Guangwen Feng

> Thanks.

      reply	other threads:[~2015-11-12  3:27 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
2015-11-11  3:45     ` Lei Li
2015-11-12  3:27       ` Guangwen Feng [this message]

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=5644071C.1060202@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