public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/3] runltp: add a big loop device
@ 2013-11-21 11:44 Xiaoguang Wang
  2013-12-02 16:47 ` chrubis
  0 siblings, 1 reply; 2+ messages in thread
From: Xiaoguang Wang @ 2013-11-21 11:44 UTC (permalink / raw)
  To: ltp-list


Some tests, such as fs_ext4, need a big block device and
the original DEVICE is some small, so create a BIG_DEVICE
(default size 5GB).

Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
---
 runltp | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 63 insertions(+), 4 deletions(-)

diff --git a/runltp b/runltp
index 63c625f..f491beb 100755
--- a/runltp
+++ b/runltp
@@ -163,6 +163,9 @@ usage()
     -b DEVICE       Some tests require an unmounted block device
                     to run correctly.
     -B DEVICE_FS_TYPE The file system of test block devices.
+    -z BIG_DEVICE   Some tests require a big unmounted block device
+                    to run correctly.
+    -Z BIG_DEVICE_FS_TYPE The file system of the big device
 
 
     example: ${0##*/} -c 2 -i 2 -m 2,4,10240,1 -D 2,10,10240,1 -p -q  -l /tmp/result-log.$$ -o /tmp/result-output.$$ -C /tmp/result-failed.$$ -d ${PWD}
@@ -207,11 +210,12 @@ main()
     local PAN_COMMAND=""
     local DEFAULT_FILE_NAME_GENERATION_TIME=`date +"%Y_%b_%d-%Hh_%Mm_%Ss"`
     local DEVICE_FS_TYPE="ext2"
+    local BIG_DEVICE_FS_TYPE="ext2"
     local scenfile=
 
     version_date=$(cat "$LTPROOT/Version")
 
-    while getopts a:c:C:d:D:f:F:ehi:K:g:l:m:M:Nno:pqr:s:S:t:T:w:x:b:B: arg
+    while getopts a:c:C:d:D:f:F:ehi:K:g:l:m:M:Nno:pqr:s:S:t:T:w:x:b:B:z:Z: arg
     do  case $arg in
         a)  EMAIL_TO=$OPTARG
             ALT_EMAIL_OUT=1;;
@@ -424,6 +428,8 @@ main()
             INSTANCES="-x $OPTARG";;
         b) DEVICE=$OPTARG;;
         B) DEVICE_FS_TYPE=$OPTARG;;
+        z) BIG_DEVICE=$OPTARG;;
+        Z) BIG_DEVICE_FS_TYPE=$OPTARG;;
         \?) usage;;
         esac
     done
@@ -678,19 +684,37 @@ main()
     }
 
     if [ -n "$DEVICE" ]; then
-        sed -i "s|DEVICE|$DEVICE|"  ${TMP}/alltests
+        sed -i "s|\s+DEVICE\s+|$DEVICE|"  ${TMP}/alltests
         RC=$?
     else
         create_block
         if [ $? -eq 0 ]; then
-            sed -i "s|DEVICE|$DEVICE|"  ${TMP}/alltests
+            sed -i "s|\s+DEVICE\s+|$DEVICE|"  ${TMP}/alltests
             RC=$?
         else
             echo "no block device was specified on commandline."
             echo "Block device could not be created using loopback device"
             echo "Tests which require block device are disabled."
             echo "You can specify it with option -b"
-            sed -i "/DEVICE/d"  ${TMP}/alltests
+            sed -i "/\s+DEVICE\s+/d"  ${TMP}/alltests
+            RC=$?
+        fi
+    fi
+
+    if [ -n "$BIG_DEVICE" ]; then
+        sed -i "s|BIG_DEVICE|$BIG_DEVICE|"  ${TMP}/alltests
+        RC=$?
+    else
+        create_big_block
+        if [ $? -eq 0 ]; then
+            sed -i "s|BIG_DEVICE|$BIG_DEVICE|"  ${TMP}/alltests
+            RC=$?
+        else
+            echo "no big block device was specified on commandline."
+            echo "BIG block device could not be created using loopback device"
+            echo "Tests which require big block device are disabled."
+            echo "You can specify it with option -z"
+            sed -i "/BIG_DEVICE/d"  ${TMP}/alltests
             RC=$?
         fi
     fi
@@ -704,6 +728,10 @@ main()
         sed -i "s|DEVICE_FS_TYPE|$DEVICE_FS_TYPE|"  ${TMP}/alltests
     fi
 
+    if [ -n "$BIG_DEVICE" ]; then
+        sed -i "s|BIG_DEVICE_FS_TYPE|$BIG_DEVICE_FS_TYPE|"  ${TMP}/alltests
+    fi
+
     if [ $? -ne 0 ]; then
         echo "FATAL: error during processing alltests file by sed"
         exit 1
@@ -979,10 +1007,41 @@ create_block()
     fi
 }
 
+create_big_block()
+{
+    # In most systems, the /tmp is relatively small
+    # So create a big block device in LTPROOT
+    BIG_DEVICE_DIR=${LTPROOT}/big_device$$
+    mkdir -p $BIG_DEVICE_DIR
+    dd if=/dev/zero of=${BIG_DEVICE_DIR}/test.img bs=1kB count=5120000 #5G
+    if [ $? -ne 0 ]; then
+        echo "Failed to create loopback device image, please check disk space and re-run"
+        return 1
+    else
+        ##search for an unused loop dev
+        LOOP_BIG_DEV=$(losetup -f)
+        if [ $? -ne 0 ]; then
+            echo "no unused loop device is found"
+            return 1
+        else
+            ##attach the created file to loop dev.
+            losetup $LOOP_BIG_DEV ${BIG_DEVICE_DIR}/test.img
+            if [ $? -ne 0 ]; then
+                echo "losetup failed to create block device"
+                return 1
+            fi
+            BIG_DEVICE=$LOOP_BIG_DEV
+            return 0
+        fi
+    fi
+}
+
 cleanup()
 {
     [ "$LOOP_DEV" ] && losetup -d $LOOP_DEV
+    [ "$LOOP_BIG_DEV" ] && losetup -d $LOOP_BIG_DEV
     rm -rf ${TMP}
+    rm -rf ${BIG_DEVICE_DIR}
 }
 
 trap "cleanup" 0
-- 
1.8.2.1



------------------------------------------------------------------------------
Shape the Mobile Experience: Free Subscription
Software experts and developers: Be at the forefront of tech innovation.
Intel(R) Software Adrenaline delivers strategic insight and game-changing 
conversations that shape the rapidly evolving mobile landscape. Sign up now. 
http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH 1/3] runltp: add a big loop device
  2013-11-21 11:44 [LTP] [PATCH 1/3] runltp: add a big loop device Xiaoguang Wang
@ 2013-12-02 16:47 ` chrubis
  0 siblings, 0 replies; 2+ messages in thread
From: chrubis @ 2013-12-02 16:47 UTC (permalink / raw)
  To: Xiaoguang Wang; +Cc: ltp-list

Hi!
> Some tests, such as fs_ext4, need a big block device and
> the original DEVICE is some small, so create a BIG_DEVICE
> (default size 5GB).
> 
> Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
> ---
>  runltp | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 63 insertions(+), 4 deletions(-)
> 
> diff --git a/runltp b/runltp
> index 63c625f..f491beb 100755
> --- a/runltp
> +++ b/runltp
> @@ -163,6 +163,9 @@ usage()
>      -b DEVICE       Some tests require an unmounted block device
>                      to run correctly.
>      -B DEVICE_FS_TYPE The file system of test block devices.
> +    -z BIG_DEVICE   Some tests require a big unmounted block device
> +                    to run correctly.
> +    -Z BIG_DEVICE_FS_TYPE The file system of the big device
>  
>  
>      example: ${0##*/} -c 2 -i 2 -m 2,4,10240,1 -D 2,10,10240,1 -p -q  -l /tmp/result-log.$$ -o /tmp/result-output.$$ -C /tmp/result-failed.$$ -d ${PWD}
> @@ -207,11 +210,12 @@ main()
>      local PAN_COMMAND=""
>      local DEFAULT_FILE_NAME_GENERATION_TIME=`date +"%Y_%b_%d-%Hh_%Mm_%Ss"`
>      local DEVICE_FS_TYPE="ext2"
> +    local BIG_DEVICE_FS_TYPE="ext2"
>      local scenfile=
>  
>      version_date=$(cat "$LTPROOT/Version")
>  
> -    while getopts a:c:C:d:D:f:F:ehi:K:g:l:m:M:Nno:pqr:s:S:t:T:w:x:b:B: arg
> +    while getopts a:c:C:d:D:f:F:ehi:K:g:l:m:M:Nno:pqr:s:S:t:T:w:x:b:B:z:Z: arg
>      do  case $arg in
>          a)  EMAIL_TO=$OPTARG
>              ALT_EMAIL_OUT=1;;
> @@ -424,6 +428,8 @@ main()
>              INSTANCES="-x $OPTARG";;
>          b) DEVICE=$OPTARG;;
>          B) DEVICE_FS_TYPE=$OPTARG;;
> +        z) BIG_DEVICE=$OPTARG;;
> +        Z) BIG_DEVICE_FS_TYPE=$OPTARG;;
>          \?) usage;;
>          esac
>      done
> @@ -678,19 +684,37 @@ main()
>      }
>  
>      if [ -n "$DEVICE" ]; then
> -        sed -i "s|DEVICE|$DEVICE|"  ${TMP}/alltests
> +        sed -i "s|\s+DEVICE\s+|$DEVICE|"  ${TMP}/alltests

Actually I've been thinking how can we get rid of the ugly sed lines and
what about we:

1. Export the devices as shell variables:

   export LTP_SMALL_DEV="$DEVICE"
   export LTP_BIG_DEV="$BIG_DEVICE"

2. Change the runtest files to use $LTP_SMALL_DEV and $LTP_BIG_DEV

We would still need to disable some testcases if devices are not
available, but we will get rid of this ulgy part.

>          RC=$?
>      else
>          create_block
>          if [ $? -eq 0 ]; then
> -            sed -i "s|DEVICE|$DEVICE|"  ${TMP}/alltests
> +            sed -i "s|\s+DEVICE\s+|$DEVICE|"  ${TMP}/alltests
>              RC=$?
>          else
>              echo "no block device was specified on commandline."
>              echo "Block device could not be created using loopback device"
>              echo "Tests which require block device are disabled."
>              echo "You can specify it with option -b"
> -            sed -i "/DEVICE/d"  ${TMP}/alltests
> +            sed -i "/\s+DEVICE\s+/d"  ${TMP}/alltests
> +            RC=$?
> +        fi
> +    fi
> +
> +    if [ -n "$BIG_DEVICE" ]; then
> +        sed -i "s|BIG_DEVICE|$BIG_DEVICE|"  ${TMP}/alltests
> +        RC=$?
> +    else
> +        create_big_block
> +        if [ $? -eq 0 ]; then
> +            sed -i "s|BIG_DEVICE|$BIG_DEVICE|"  ${TMP}/alltests
> +            RC=$?
> +        else
> +            echo "no big block device was specified on commandline."
> +            echo "BIG block device could not be created using loopback device"
> +            echo "Tests which require big block device are disabled."
> +            echo "You can specify it with option -z"
> +            sed -i "/BIG_DEVICE/d"  ${TMP}/alltests
>              RC=$?
>          fi
>      fi
> @@ -704,6 +728,10 @@ main()
>          sed -i "s|DEVICE_FS_TYPE|$DEVICE_FS_TYPE|"  ${TMP}/alltests
>      fi
>  
> +    if [ -n "$BIG_DEVICE" ]; then
> +        sed -i "s|BIG_DEVICE_FS_TYPE|$BIG_DEVICE_FS_TYPE|"  ${TMP}/alltests
> +    fi
> +
>      if [ $? -ne 0 ]; then
>          echo "FATAL: error during processing alltests file by sed"
>          exit 1
> @@ -979,10 +1007,41 @@ create_block()
>      fi
>  }
>  
> +create_big_block()
> +{
> +    # In most systems, the /tmp is relatively small
> +    # So create a big block device in LTPROOT
> +    BIG_DEVICE_DIR=${LTPROOT}/big_device$$

Using LTPROOT is wrong too. There are (embedded) systems that have the
LTPROOT mounted readonly or too small.

I guess that the only option here is to skip the testcases unless user
has specified device or directory to create it.

> +    mkdir -p $BIG_DEVICE_DIR
> +    dd if=/dev/zero of=${BIG_DEVICE_DIR}/test.img bs=1kB count=5120000 #5G
> +    if [ $? -ne 0 ]; then
> +        echo "Failed to create loopback device image, please check disk space and re-run"
> +        return 1
> +    else
> +        ##search for an unused loop dev
> +        LOOP_BIG_DEV=$(losetup -f)
> +        if [ $? -ne 0 ]; then
> +            echo "no unused loop device is found"
> +            return 1
> +        else
> +            ##attach the created file to loop dev.
> +            losetup $LOOP_BIG_DEV ${BIG_DEVICE_DIR}/test.img
> +            if [ $? -ne 0 ]; then
> +                echo "losetup failed to create block device"
> +                return 1
> +            fi
> +            BIG_DEVICE=$LOOP_BIG_DEV
> +            return 0
> +        fi
> +    fi
> +}
> +
>  cleanup()
>  {
>      [ "$LOOP_DEV" ] && losetup -d $LOOP_DEV
> +    [ "$LOOP_BIG_DEV" ] && losetup -d $LOOP_BIG_DEV
>      rm -rf ${TMP}
> +    rm -rf ${BIG_DEVICE_DIR}
>  }

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349351&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2013-12-02 16:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-21 11:44 [LTP] [PATCH 1/3] runltp: add a big loop device Xiaoguang Wang
2013-12-02 16:47 ` chrubis

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