From: Zhang Jin <jy_zhang...@cn.fujitsu.com>

Add two functions tst_acquire_device() and tst_release_device()

Signed-off-by: Zhang Jin <jy_zhang...@cn.fujitsu.com>
Signed-off-by: Zeng Linggang <zenglg...@cn.fujitsu.com>
---
 testcases/lib/test.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/testcases/lib/test.sh b/testcases/lib/test.sh
index 163c54b..3e6f742 100644
--- a/testcases/lib/test.sh
+++ b/testcases/lib/test.sh
@@ -193,6 +193,50 @@ ROD()
        fi
 }
 
+tst_acquire_device()
+{
+       local dd_size=$1
+       local testdevice=$2
+       local mntpoint=$3
+
+       ROD_SILENT dd if=/dev/zero of=testimg bs=1M count=${dd_size}
+
+       ROD_SILENT losetup ${testdevice} testimg
+
+       ROD_SILENT mkfs.ext2 ${testdevice}
+
+       ROD_SILENT mkdir -p ${mntpoint}
+
+       ROD_SILENT mount ${testdevice} ${mntpoint}
+}
+
+tst_release_device()
+{
+       local mntpoint=$1
+
+       grep -q ${mntpoint} /proc/self/mounts
+       if [ $? -eq 0 ]; then
+               umount ${mntpoint}
+               if [ $? -ne 0 ];then
+                       tst_resm TWARN "'umount ${mntpoint}' failed"
+               fi
+       fi
+
+       losetup -a | grep -q ${mntpoint}
+       if [ $? -eq 0 ]; then
+               losetup -d ${mntpoint}
+               if [ $? -ne 0 ];then
+                       tst_resm TWARN "'losetup -d ${mntpoint}' failed"
+               fi
+       fi
+
+       if [ -d ${mntpoint} ]; then
+               rm -r ${mntpoint}
+       fi
+
+       rm testimg
+}
+
 # Check that test name is set
 if [ -z "$TCID" ]; then
        tst_brkm TBROK "TCID is not defined"
-- 
1.9.3


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to