public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
To: ltp-list@lists.sourceforge.net
Subject: [LTP] [PATCH 1/3] runltp: add a big loop device
Date: Thu, 21 Nov 2013 19:44:41 +0800	[thread overview]
Message-ID: <528DF229.4090409@cn.fujitsu.com> (raw)


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

             reply	other threads:[~2013-11-21 12:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-21 11:44 Xiaoguang Wang [this message]
2013-12-02 16:47 ` [LTP] [PATCH 1/3] runltp: add a big loop device chrubis

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=528DF229.4090409@cn.fujitsu.com \
    --to=wangxg.fnst@cn.fujitsu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox