Add two functions tst_acquire_device() and tst_release_device()
Signed-off-by: Zeng Linggang <[email protected]>
---
testcases/lib/test.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/testcases/lib/test.sh b/testcases/lib/test.sh
index 163c54b..e135c7c 100644
--- a/testcases/lib/test.sh
+++ b/testcases/lib/test.sh
@@ -193,6 +193,51 @@ ROD()
fi
}
+tst_acquire_device()
+{
+ if [ -z ${TST_TMPDIR} ]; then
+ tst_brkm "Use 'tst_tmpdir' before 'tst_acquire_device'"
+ fi
+
+ if [ -n "${LTP_DEV}" ]; then
+ tst_resm TINFO "Using test device LTP_DEV='${LTP_DEV}'"
+ if [ ! -b ${LTP_DEV} ]; then
+ tst_brkm TBROK "${LTP_DEV} is not a block device"
+ fi
+ TST_DEVICE=${LTP_DEV}
+ TST_DEVICE_FALG=0
+ return
+ fi
+
+ ROD_SILENT dd if=/dev/zero of=test_dev.img bs=1024 count=20480
+
+ TST_DEVICE=$(losetup -f)
+ if [ $? -ne 0 ]; then
+ tst_brkm TBROK "Couldn't find free loop device"
+ fi
+
+ tst_resm TINFO "Found free device '${TST_DEVICE}'"
+
+ ROD_SILENT losetup ${TST_DEVICE} test_dev.img
+
+ TST_DEVICE_FALG=1
+}
+
+tst_release_device()
+{
+ if [ ${TST_DEVICE_FALG} -eq 0 ]; then
+ return
+ fi
+
+ losetup -a | grep -q ${TST_DEVICE}
+ if [ $? -eq 0 ]; then
+ losetup -d ${TST_DEVICE}
+ if [ $? -ne 0 ];then
+ tst_resm TWARN "'losetup -d ${TST_DEVICE}' failed"
+ fi
+ fi
+}
+
# Check that test name is set
if [ -z "$TCID" ]; then
tst_brkm TBROK "TCID is not defined"
--
1.9.3
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list