Add two functions tst_acquire_device() and tst_release_device() Signed-off-by: Zeng Linggang <zenglg...@cn.fujitsu.com> --- testcases/lib/test.sh | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
diff --git a/testcases/lib/test.sh b/testcases/lib/test.sh index 163c54b..5fc1477 100644 --- a/testcases/lib/test.sh +++ b/testcases/lib/test.sh @@ -193,6 +193,44 @@ 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} + 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_release_device() +{ + 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 Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list