Skip to contentSkip to conversation

commands/mkfs: Added new testcase to test mkfs(8) command.

PATCH New Guangwen Feng 3 participants 12 messages Oct 28, 2015 – Nov 5, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 commands/mkfs: Added new testcase to test mkfs(8) command.

Test mkfs(8) command with some basic options.

---
 runtest/commands                  |  10 ++
 testcases/commands/mkfs/Makefile  |  24 ++++
 testcases/commands/mkfs/mkfs01.sh | 236 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 270 insertions(+)
 create mode 100644 testcases/commands/mkfs/Makefile
 create mode 100755 testcases/commands/mkfs/mkfs01.sh
runtest/commands +10 -0
index e5260ba..6c0485b 100644
@@ -28,3 +28,13 @@ df01_xfs df01.sh -f xfs
 df01_vfat df01.sh -f vfat
 df01_exfat df01.sh -f exfat
 df01_ntfs df01.sh -f ntfs
+mkfs01 mkfs01.sh
+mkfs01_ext2 mkfs01.sh -f ext2
+mkfs01_ext3 mkfs01.sh -f ext3
+mkfs01_ext4 mkfs01.sh -f ext4
+mkfs01_xfs mkfs01.sh -f xfs
+mkfs01_btrfs mkfs01.sh -f btrfs
+mkfs01_minix mkfs01.sh -f minix
+mkfs01_msdos mkfs01.sh -f msdos
+mkfs01_vfat mkfs01.sh -f vfat
+mkfs01_ntfs mkfs01.sh -f ntfs
testcases/commands/mkfs/Makefile new file +24 -0
new file mode 100644
index 0000000..6099017
@@ -0,0 +1,24 @@
+#
+#    commands/mkfs testcases Makefile.
+#
+#    Copyright (c) 2015 Fujitsu Ltd.
+#    Author:Guangwen Feng <[email protected]>
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+
+top_srcdir		?= ../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_TARGETS		:= mkfs01.sh
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/commands/mkfs/mkfs01.sh new file +236 -0

236 lines not on this page · raw message

Signature · 1 line
1.8.4.2
#1 lore raw

PATCH 1/1 commands/mkfs: Added new testcase to test mkfs(8) command.

Quoted 52 lines
testcases/commands/mkfs/mkfs01.sh new file +52 -0
+#!/bin/sh
+#
+# Copyright (c) 2015 Fujitsu Ltd.
+# Author: Guangwen Feng <[email protected]>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+# the GNU General Public License for more details.
+#
+# Test mkfs command with some basic options.
+#
+
+TCID=mkfs01
+TST_TOTAL=5
+. test.sh
+
+setup()
+{
+	tst_require_root
+
+	tst_check_cmds blkid df
+
+	if [ -n "$FS_TYPE" ]; then
+		tst_check_cmds mkfs.${FS_TYPE}
+	fi
+
+	tst_tmpdir
+
+	TST_CLEANUP="cleanup"
+
+	ROD_SILENT mkdir -p mntpoint
+}
+
+cleanup()
+{
+	tst_release_device
+
+	tst_rmdir
+}
+
+mkfs_mount()
+{
+	mount ${TST_DEVICE} mntpoint
+	local ret=$?
+	if [ $ret -eq 32 ]; then
+		tst_brkm TCONF "Cannot mount ${FS_TYPE}, missing driver?"

testcases/commands/mkfs/mkfs01.sh line 62

Quoted 10 lines
testcases/commands/mkfs/mkfs01.sh new file +10 -0
+	fi
+
+	if [ $ret -ne 0 ]; then
+		tst_brkm TBROK "Failed to mount device: mount exit = $ret"
+	fi
+}
+
+mkfs_umount()
+{
+	grep -q ${TST_DEVICE} /proc/self/mounts

^
Why not just /proc/mounts?

Quoted 13 lines
testcases/commands/mkfs/mkfs01.sh new file +13 -0
+	if [ $? -eq 0 ]; then
+		umount ${TST_DEVICE}
+		if [ $? -ne 0 ];then
+			tst_resm TWARN "'umount ${TST_DEVICE}' failed"
+		fi
+	else
+		tst_resm TINFO "${TST_DEVICE} is not mounted"
+	fi
+}
+
+usage()
+{
+	cat << EOF

testcases/commands/mkfs/mkfs01.sh line 85

Quoted 10 lines
testcases/commands/mkfs/mkfs01.sh new file +10 -0
+	usage: $0 [-f <ext2|ext3|ext4|vfat|...>]
+
+	OPTIONS
+		-f	Specify the type of filesystem to be built. If not
+			specified, the default filesystem type (currently ext2)
+			is used.
+		-h	Display help text and exit.
+
+EOF
+	tst_brkm TCONF "Display help text or unknown options"

^
I would rather make this TWARN, because when runtest entries became corrupted somehow the test would start reporting TCONF And that may end up being undetected for quite some time.

testcases/commands/mkfs/mkfs01.sh line 94

Quoted 9 lines
testcases/commands/mkfs/mkfs01.sh new file +9 -0
+}
+
+mkfs_verify()
+{
+	if [ -z "$1" ]; then
+		blkid | grep "$2" | grep -q "ext2"
+	else
+		blkid | grep "$2" | grep -q "$1"
+	fi

You can actually pass the device to blkid as a parameter instead of grepping it in the output.

testcases/commands/mkfs/mkfs01.sh line 100

Quoted 6 lines
testcases/commands/mkfs/mkfs01.sh new file +6 -0
+}
+
+mkfs_check()
+{
+	mkfs_mount
+	local blocknum=`df -aT | grep "$1" | awk '{print $3}'`

You can pass the mount point to the df instead of greping the device.

testcases/commands/mkfs/mkfs01.sh line 105

Quoted 5 lines
testcases/commands/mkfs/mkfs01.sh new file +5 -0
+	mkfs_umount
+
+	if [ $blocknum -gt "$2" ]; then
+		return 1
+	fi

So the size we get as $2 is in kB and df -T reports 1k blocks shouldn't these be equal, or are there any reserved block in play?

testcases/commands/mkfs/mkfs01.sh line 117

Quoted 12 lines
testcases/commands/mkfs/mkfs01.sh new file +12 -0
+}
+
+mkfs_test()
+{
+	local mkfs_op=$1
+	local fs_type=$2
+	local fs_op=$3
+	local device=$4
+	local size=$5
+
+	if [ -n "$fs_type" ]; then
+		mkfs_op="-t"

Why are you adding the flags by the tiniest bits?

Why don't you rather do:

	mkfs_op="-t $fs_type"

Which is far more logical.

testcases/commands/mkfs/mkfs01.sh line 121

Quoted 4 lines
testcases/commands/mkfs/mkfs01.sh new file +4 -0
+	fi
+
+	if [ "$fs_type" = "xfs" ] || [ "$fs_type" = "btrfs" ]; then
+		fs_op+=" -f"

This is bashism. You have to do fs_op="$fs_op -f" instead.

testcases/commands/mkfs/mkfs01.sh line 125

Quoted 4 lines
testcases/commands/mkfs/mkfs01.sh new file +4 -0
+	fi
+
+	local mkfs_cmd="mkfs $mkfs_op $fs_type $fs_op $device $size"
+	mkfs_cmd=`echo "$mkfs_cmd" | sed 's/\s\+/ /g'`

This is just cosmetic, isn't it? I would just omit it.

testcases/commands/mkfs/mkfs01.sh line 130

Quoted 4 lines
testcases/commands/mkfs/mkfs01.sh new file +4 -0
+	echo ${fs_op} | grep -q "\-c"
+	if [ $? -eq 0 ] && [ "$fs_type" = "ntfs" ]; then
+		tst_resm TCONF "'${mkfs_cmd}' not supported."
+		return 32

This is fairly misleading. It would be better to use return 0 in case when you just need to exit the function. Because returning different values and ingoring them later is misleading.

testcases/commands/mkfs/mkfs01.sh line 136

Quoted 6 lines
testcases/commands/mkfs/mkfs01.sh new file +6 -0
+	fi
+
+	if [ -n "$size" ]; then
+		if [ "$fs_type" = "xfs" ] || [ "$fs_type" = "btrfs" ]; then
+			tst_resm TCONF "'${mkfs_cmd}' not supported."
+			return 32

Here as well.

Quoted 12 lines
testcases/commands/mkfs/mkfs01.sh new file +12 -0
+		fi
+	fi
+
+	${mkfs_cmd} >temp 2>&1
+	if [ $? -ne 0 ]; then
+		grep -q -E "unknown option | invalid option" temp
+		if [ $? -eq 0 ]; then
+			tst_resm TCONF "'${mkfs_cmd}' not supported."
+			return 32
+		else
+			tst_resm TFAIL "'${mkfs_cmd}' failed."
+			cat temp

testcases/commands/mkfs/mkfs01.sh line 158

Quoted 10 lines
testcases/commands/mkfs/mkfs01.sh new file +10 -0
+			return 1
+		fi
+	fi
+
+	if [ -n "$device" ]; then
+		mkfs_verify "$fs_type" "$device"
+		if [ $? -ne 0 ]; then
+			tst_resm TFAIL "'${mkfs_cmd}' failed, not expected."
+			return 1
+		fi

We should name the function better, mkfs_verify_type() comes to mind.

testcases/commands/mkfs/mkfs01.sh line 167

Quoted 9 lines
testcases/commands/mkfs/mkfs01.sh new file +9 -0
+	fi
+
+	if [ -n "$size" ]; then
+		mkfs_check "$device" "$size"
+		if [ $? -ne 0 ]; then
+			tst_resm TFAIL "'${mkfs_cmd}' failed, not expected."
+			return 1
+		fi
+	fi

Here as well, mkfs_verify_size would be better.

Quoted 7 lines
testcases/commands/mkfs/mkfs01.sh new file +7 -0
+	tst_resm TPASS "'${mkfs_cmd}' passed."
+}
+
+test1()
+{
+	tst_acquire_device
+

testcases/commands/mkfs/mkfs01.sh line 185

Quoted 10 lines
testcases/commands/mkfs/mkfs01.sh new file +10 -0
+	mkfs_test "$MKFS_OP" "$FS_TYPE" "$FS_OP" "$TST_DEVICE"
+
+	tst_release_device
+}
+
+test2()
+{
+	tst_acquire_device
+
+	mkfs_test "$MKFS_OP" "$FS_TYPE" "$FS_OP" "$TST_DEVICE" "10000"

Can you just pass empty string when it should be empty instead of passing empty global variable?

It's more confusing than it could be this way.

testcases/commands/mkfs/mkfs01.sh line 197

Quoted 11 lines
testcases/commands/mkfs/mkfs01.sh new file +11 -0
+	tst_release_device
+}
+
+test3()
+{
+	tst_acquire_device
+
+	mkfs_test "$MKFS_OP" "$FS_TYPE" "-c" "$TST_DEVICE"
+
+	tst_release_device
+}

Why don't we acquire device once in the setup and release it in the cleanup?

Quoted 20 lines
testcases/commands/mkfs/mkfs01.sh new file +20 -0
+test4()
+{
+	mkfs_test "-V"
+}
+
+test5()
+{
+	mkfs_test "-h"
+}
+
+MKFS_OP=""
+FS_TYPE=""
+FS_OP=""
+
+if [ $# -ne 0 ]; then
+	while getopts f:h OPTION; do
+		case $OPTION in
+		f)
+			FS_TYPE=$OPTARG;;
+		h)

testcases/commands/mkfs/mkfs01.sh line 228

Quoted 10 lines
testcases/commands/mkfs/mkfs01.sh new file +10 -0
+			usage;;
+		?)
+			usage;;
+		esac
+	done
+
+	if [ -z "$FS_TYPE" ]; then
+		usage
+	fi
+fi

Eh, why just not:

while getopts f:h OPTION; do

        case $OPTION in
        f)
                FS_TYPE=$OPTARG;;
        h)
                usage;;
        ?)
                usage;;
        esac

done

Quoted 13 lines
testcases/commands/mkfs/mkfs01.sh new file +7 -0
+setup
+for i in $(seq 1 ${TST_TOTAL})
+do
+	test$i
+done
+
+tst_exit
Signature · 5 lines
1.8.4.2


-- 
Mailing list info: http://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
#2 lore raw

PATCH 1/1 commands/mkfs: Added new testcase to test mkfs(8) command.

Hi!

Thanks for your review.
I will modify the test case according to your suggestion.

Best Regards,
Guangwen Feng

Quoted 309 lines · Cyril Hrubis
Quoted 52 lines
testcases/commands/mkfs/mkfs01.sh new file +52 -0
+#!/bin/sh
+#
+# Copyright (c) 2015 Fujitsu Ltd.
+# Author: Guangwen Feng <[email protected]>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+# the GNU General Public License for more details.
+#
+# Test mkfs command with some basic options.
+#
+
+TCID=mkfs01
+TST_TOTAL=5
+. test.sh
+
+setup()
+{
+	tst_require_root
+
+	tst_check_cmds blkid df
+
+	if [ -n "$FS_TYPE" ]; then
+		tst_check_cmds mkfs.${FS_TYPE}
+	fi
+
+	tst_tmpdir
+
+	TST_CLEANUP="cleanup"
+
+	ROD_SILENT mkdir -p mntpoint
+}
+
+cleanup()
+{
+	tst_release_device
+
+	tst_rmdir
+}
+
+mkfs_mount()
+{
+	mount ${TST_DEVICE} mntpoint
+	local ret=$?
+	if [ $ret -eq 32 ]; then
+		tst_brkm TCONF "Cannot mount ${FS_TYPE}, missing driver?"

testcases/commands/mkfs/mkfs01.sh line 62

Quoted 10 lines
testcases/commands/mkfs/mkfs01.sh new file +10 -0
+	fi
+
+	if [ $ret -ne 0 ]; then
+		tst_brkm TBROK "Failed to mount device: mount exit = $ret"
+	fi
+}
+
+mkfs_umount()
+{
+	grep -q ${TST_DEVICE} /proc/self/mounts

^
Why not just /proc/mounts?

Quoted 13 lines
testcases/commands/mkfs/mkfs01.sh new file +13 -0
+	if [ $? -eq 0 ]; then
+		umount ${TST_DEVICE}
+		if [ $? -ne 0 ];then
+			tst_resm TWARN "'umount ${TST_DEVICE}' failed"
+		fi
+	else
+		tst_resm TINFO "${TST_DEVICE} is not mounted"
+	fi
+}
+
+usage()
+{
+	cat << EOF

testcases/commands/mkfs/mkfs01.sh line 85

Quoted 10 lines
testcases/commands/mkfs/mkfs01.sh new file +10 -0
+	usage: $0 [-f <ext2|ext3|ext4|vfat|...>]
+
+	OPTIONS
+		-f	Specify the type of filesystem to be built. If not
+			specified, the default filesystem type (currently ext2)
+			is used.
+		-h	Display help text and exit.
+
+EOF
+	tst_brkm TCONF "Display help text or unknown options"

^
I would rather make this TWARN, because when runtest entries became corrupted somehow the test would start reporting TCONF And that may end up being undetected for quite some time.

testcases/commands/mkfs/mkfs01.sh line 94

Quoted 9 lines
testcases/commands/mkfs/mkfs01.sh new file +9 -0
+}
+
+mkfs_verify()
+{
+	if [ -z "$1" ]; then
+		blkid | grep "$2" | grep -q "ext2"
+	else
+		blkid | grep "$2" | grep -q "$1"
+	fi

You can actually pass the device to blkid as a parameter instead of grepping it in the output.

testcases/commands/mkfs/mkfs01.sh line 100

Quoted 6 lines
testcases/commands/mkfs/mkfs01.sh new file +6 -0
+}
+
+mkfs_check()
+{
+	mkfs_mount
+	local blocknum=`df -aT | grep "$1" | awk '{print $3}'`

You can pass the mount point to the df instead of greping the device.

testcases/commands/mkfs/mkfs01.sh line 105

Quoted 5 lines
testcases/commands/mkfs/mkfs01.sh new file +5 -0
+	mkfs_umount
+
+	if [ $blocknum -gt "$2" ]; then
+		return 1
+	fi

So the size we get as $2 is in kB and df -T reports 1k blocks shouldn't these be equal, or are there any reserved block in play?

testcases/commands/mkfs/mkfs01.sh line 117

Quoted 12 lines
testcases/commands/mkfs/mkfs01.sh new file +12 -0
+}
+
+mkfs_test()
+{
+	local mkfs_op=$1
+	local fs_type=$2
+	local fs_op=$3
+	local device=$4
+	local size=$5
+
+	if [ -n "$fs_type" ]; then
+		mkfs_op="-t"

Why are you adding the flags by the tiniest bits?

Why don't you rather do:

	mkfs_op="-t $fs_type"

Which is far more logical.

testcases/commands/mkfs/mkfs01.sh line 121

Quoted 4 lines
testcases/commands/mkfs/mkfs01.sh new file +4 -0
+	fi
+
+	if [ "$fs_type" = "xfs" ] || [ "$fs_type" = "btrfs" ]; then
+		fs_op+=" -f"

This is bashism. You have to do fs_op="$fs_op -f" instead.

testcases/commands/mkfs/mkfs01.sh line 125

Quoted 4 lines
testcases/commands/mkfs/mkfs01.sh new file +4 -0
+	fi
+
+	local mkfs_cmd="mkfs $mkfs_op $fs_type $fs_op $device $size"
+	mkfs_cmd=`echo "$mkfs_cmd" | sed 's/\s\+/ /g'`

This is just cosmetic, isn't it? I would just omit it.

testcases/commands/mkfs/mkfs01.sh line 130

Quoted 4 lines
testcases/commands/mkfs/mkfs01.sh new file +4 -0
+	echo ${fs_op} | grep -q "\-c"
+	if [ $? -eq 0 ] && [ "$fs_type" = "ntfs" ]; then
+		tst_resm TCONF "'${mkfs_cmd}' not supported."
+		return 32

This is fairly misleading. It would be better to use return 0 in case when you just need to exit the function. Because returning different values and ingoring them later is misleading.

testcases/commands/mkfs/mkfs01.sh line 136

Quoted 6 lines
testcases/commands/mkfs/mkfs01.sh new file +6 -0
+	fi
+
+	if [ -n "$size" ]; then
+		if [ "$fs_type" = "xfs" ] || [ "$fs_type" = "btrfs" ]; then
+			tst_resm TCONF "'${mkfs_cmd}' not supported."
+			return 32

Here as well.

Quoted 12 lines
testcases/commands/mkfs/mkfs01.sh new file +12 -0
+		fi
+	fi
+
+	${mkfs_cmd} >temp 2>&1
+	if [ $? -ne 0 ]; then
+		grep -q -E "unknown option | invalid option" temp
+		if [ $? -eq 0 ]; then
+			tst_resm TCONF "'${mkfs_cmd}' not supported."
+			return 32
+		else
+			tst_resm TFAIL "'${mkfs_cmd}' failed."
+			cat temp

testcases/commands/mkfs/mkfs01.sh line 158

Quoted 10 lines
testcases/commands/mkfs/mkfs01.sh new file +10 -0
+			return 1
+		fi
+	fi
+
+	if [ -n "$device" ]; then
+		mkfs_verify "$fs_type" "$device"
+		if [ $? -ne 0 ]; then
+			tst_resm TFAIL "'${mkfs_cmd}' failed, not expected."
+			return 1
+		fi

We should name the function better, mkfs_verify_type() comes to mind.

testcases/commands/mkfs/mkfs01.sh line 167

Quoted 9 lines
testcases/commands/mkfs/mkfs01.sh new file +9 -0
+	fi
+
+	if [ -n "$size" ]; then
+		mkfs_check "$device" "$size"
+		if [ $? -ne 0 ]; then
+			tst_resm TFAIL "'${mkfs_cmd}' failed, not expected."
+			return 1
+		fi
+	fi

Here as well, mkfs_verify_size would be better.

Quoted 7 lines
testcases/commands/mkfs/mkfs01.sh new file +7 -0
+	tst_resm TPASS "'${mkfs_cmd}' passed."
+}
+
+test1()
+{
+	tst_acquire_device
+

testcases/commands/mkfs/mkfs01.sh line 185

Quoted 10 lines
testcases/commands/mkfs/mkfs01.sh new file +10 -0
+	mkfs_test "$MKFS_OP" "$FS_TYPE" "$FS_OP" "$TST_DEVICE"
+
+	tst_release_device
+}
+
+test2()
+{
+	tst_acquire_device
+
+	mkfs_test "$MKFS_OP" "$FS_TYPE" "$FS_OP" "$TST_DEVICE" "10000"

Can you just pass empty string when it should be empty instead of passing empty global variable?

It's more confusing than it could be this way.

testcases/commands/mkfs/mkfs01.sh line 197

Quoted 11 lines
testcases/commands/mkfs/mkfs01.sh new file +11 -0
+	tst_release_device
+}
+
+test3()
+{
+	tst_acquire_device
+
+	mkfs_test "$MKFS_OP" "$FS_TYPE" "-c" "$TST_DEVICE"
+
+	tst_release_device
+}

Why don't we acquire device once in the setup and release it in the cleanup?

Quoted 20 lines
testcases/commands/mkfs/mkfs01.sh new file +20 -0
+test4()
+{
+	mkfs_test "-V"
+}
+
+test5()
+{
+	mkfs_test "-h"
+}
+
+MKFS_OP=""
+FS_TYPE=""
+FS_OP=""
+
+if [ $# -ne 0 ]; then
+	while getopts f:h OPTION; do
+		case $OPTION in
+		f)
+			FS_TYPE=$OPTARG;;
+		h)

testcases/commands/mkfs/mkfs01.sh line 228

Quoted 10 lines
testcases/commands/mkfs/mkfs01.sh new file +10 -0
+			usage;;
+		?)
+			usage;;
+		esac
+	done
+
+	if [ -z "$FS_TYPE" ]; then
+		usage
+	fi
+fi

Eh, why just not:

while getopts f:h OPTION; do

        case $OPTION in
        f)
                FS_TYPE=$OPTARG;;
        h)
                usage;;
        ?)
                usage;;
        esac

done

Quoted 13 lines
testcases/commands/mkfs/mkfs01.sh new file +7 -0
+setup
+for i in $(seq 1 ${TST_TOTAL})
+do
+	test$i
+done
+
+tst_exit
Signature · 5 lines
1.8.4.2


-- 
Mailing list info: http://lists.linux.it/listinfo/ltp
#3 lore raw

PATCH v2 1/1 commands/mkfs: Added new testcase to test mkfs(8) command.

Test mkfs(8) command with some basic options.

---
 runtest/commands                  |  10 ++
 testcases/commands/mkfs/Makefile  |  24 +++++
 testcases/commands/mkfs/mkfs01.sh | 217 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 251 insertions(+)
 create mode 100644 testcases/commands/mkfs/Makefile
 create mode 100755 testcases/commands/mkfs/mkfs01.sh
runtest/commands +10 -0
index e5260ba..6c0485b 100644
@@ -28,3 +28,13 @@ df01_xfs df01.sh -f xfs
 df01_vfat df01.sh -f vfat
 df01_exfat df01.sh -f exfat
 df01_ntfs df01.sh -f ntfs
+mkfs01 mkfs01.sh
+mkfs01_ext2 mkfs01.sh -f ext2
+mkfs01_ext3 mkfs01.sh -f ext3
+mkfs01_ext4 mkfs01.sh -f ext4
+mkfs01_xfs mkfs01.sh -f xfs
+mkfs01_btrfs mkfs01.sh -f btrfs
+mkfs01_minix mkfs01.sh -f minix
+mkfs01_msdos mkfs01.sh -f msdos
+mkfs01_vfat mkfs01.sh -f vfat
+mkfs01_ntfs mkfs01.sh -f ntfs
testcases/commands/mkfs/Makefile new file +24 -0
new file mode 100644
index 0000000..6099017
@@ -0,0 +1,24 @@
+#
+#    commands/mkfs testcases Makefile.
+#
+#    Copyright (c) 2015 Fujitsu Ltd.
+#    Author:Guangwen Feng <[email protected]>
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+
+top_srcdir		?= ../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_TARGETS		:= mkfs01.sh
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/commands/mkfs/mkfs01.sh new file +217 -0

217 lines not on this page · raw message

Signature · 1 line
1.8.4.2
#4 lore raw

PATCH v2 1/1 commands/mkfs: Added new testcase to test mkfs(8) command.

Quoted 152 lines

Test mkfs(8) command with some basic options.

---
  runtest/commands                  |  10 ++
  testcases/commands/mkfs/Makefile  |  24 +++++
  testcases/commands/mkfs/mkfs01.sh | 217 ++++++++++++++++++++++++++++++++++++++
  3 files changed, 251 insertions(+)

create mode 100644 testcases/commands/mkfs/Makefile create mode 100755 testcases/commands/mkfs/mkfs01.sh

runtest/commands +10 -0
index e5260ba..6c0485b 100644
@@ -28,3 +28,13 @@ df01_xfs df01.sh -f xfs
  df01_vfat df01.sh -f vfat
  df01_exfat df01.sh -f exfat
  df01_ntfs df01.sh -f ntfs
+mkfs01 mkfs01.sh
+mkfs01_ext2 mkfs01.sh -f ext2
+mkfs01_ext3 mkfs01.sh -f ext3
+mkfs01_ext4 mkfs01.sh -f ext4
+mkfs01_xfs mkfs01.sh -f xfs
+mkfs01_btrfs mkfs01.sh -f btrfs
+mkfs01_minix mkfs01.sh -f minix
+mkfs01_msdos mkfs01.sh -f msdos
+mkfs01_vfat mkfs01.sh -f vfat
+mkfs01_ntfs mkfs01.sh -f ntfs
testcases/commands/mkfs/Makefile new file +24 -0
new file mode 100644
index 0000000..6099017
@@ -0,0 +1,24 @@
+#
+#    commands/mkfs testcases Makefile.
+#
+#    Copyright (c) 2015 Fujitsu Ltd.
+#    Author:Guangwen Feng <[email protected]>
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+
+top_srcdir		?= ../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_TARGETS		:= mkfs01.sh
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/commands/mkfs/mkfs01.sh new file +87 -0
new file mode 100755
index 0000000..c1337a6
@@ -0,0 +1,217 @@
+#!/bin/sh
+#
+# Copyright (c) 2015 Fujitsu Ltd.
+# Author: Guangwen Feng <[email protected]>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+# the GNU General Public License for more details.
+#
+# Test mkfs command with some basic options.
+#
+
+TCID=mkfs01
+TST_TOTAL=5
+. test.sh
+
+setup()
+{
+	tst_require_root
+
+	tst_check_cmds blkid df
+
+	if [ -n "$FS_TYPE" ]; then
+		tst_check_cmds mkfs.${FS_TYPE}
+	fi
+
+	tst_tmpdir
+
+	tst_acquire_device
+
+	TST_CLEANUP="cleanup"
+
+	ROD_SILENT mkdir -p mntpoint
+}
+
+cleanup()
+{
+	tst_release_device
+
+	tst_rmdir
+}
+
+mkfs_mount()
+{
+	mount ${TST_DEVICE} mntpoint
+	local ret=$?
+	if [ $ret -eq 32 ]; then
+		tst_brkm TCONF "Cannot mount ${FS_TYPE}, missing driver?"
+	fi
+
+	if [ $ret -ne 0 ]; then
+		tst_brkm TBROK "Failed to mount device: mount exit = $ret"
+	fi
+}
+
+mkfs_umount()
+{
+	grep -q ${TST_DEVICE} /proc/mounts
+	if [ $? -eq 0 ]; then
+		umount ${TST_DEVICE}
+		if [ $? -ne 0 ];then
+			tst_resm TWARN "'umount ${TST_DEVICE}' failed"
+		fi
+	else
+		tst_resm TINFO "${TST_DEVICE} is not mounted"
+	fi
+}
+
+usage()
+{
+	cat << EOF
+	usage: $0 [-f <ext2|ext3|ext4|vfat|...>]
+
+	OPTIONS
+		-f	Specify the type of filesystem to be built. If not
+			specified, the default filesystem type (currently ext2)
+			is used.
+		-h	Display help text and exit.
+
+EOF
+	tst_brkm TWARN "Display help text or unknown options"

testcases/commands/mkfs/mkfs01.sh line 97

Quoted 10 lines
testcases/commands/mkfs/mkfs01.sh new file +10 -0
+}
+
+mkfs_verify_type()
+{
+	if [ -z "$1" ]; then
+		blkid $2 | grep -q "ext2"
+	else
+		blkid $2 | grep -q "$1"
+	fi
+}

Hi, how about:
mkfs_verify_type()

{
	if [ -z "$1" ]; then
		blkid $2 -t TYPE="ext2"
	else
		blkid $2 -t TYPE="$1"
	fi
}
Signature · 1 line
Rock Lee
#5 lore raw

PATCH v2 1/1 commands/mkfs: Added new testcase to test mkfs(8) command.

Hi!

Quoted 11 lines

testcases/commands/mkfs/mkfs01.sh line 97

Quoted 8 lines
testcases/commands/mkfs/mkfs01.sh new file +8 -0
+mkfs_verify_type()
+{
+    if [ -z "$1" ]; then
+        blkid $2 | grep -q "ext2"
+    else
+        blkid $2 | grep -q "$1"
+    fi
+}

Hi, how about:
mkfs_verify_type()

Quoted 8 lines
{
    if [ -z "$1" ]; then
        blkid $2 -t TYPE="ext2"
    else
        blkid $2 -t TYPE="$1"
    fi
}

It looks better since it's more logical? thanks!

#6 lore raw

PATCH 1/1 commands/mkfs: Added new testcase to test mkfs(8) command.

In reply to Cyril Hrubis
Quoted 115 lines · Cyril Hrubis
Quoted 52 lines
testcases/commands/mkfs/mkfs01.sh new file +52 -0
+#!/bin/sh
+#
+# Copyright (c) 2015 Fujitsu Ltd.
+# Author: Guangwen Feng <[email protected]>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+# the GNU General Public License for more details.
+#
+# Test mkfs command with some basic options.
+#
+
+TCID=mkfs01
+TST_TOTAL=5
+. test.sh
+
+setup()
+{
+	tst_require_root
+
+	tst_check_cmds blkid df
+
+	if [ -n "$FS_TYPE" ]; then
+		tst_check_cmds mkfs.${FS_TYPE}
+	fi
+
+	tst_tmpdir
+
+	TST_CLEANUP="cleanup"
+
+	ROD_SILENT mkdir -p mntpoint
+}
+
+cleanup()
+{
+	tst_release_device
+
+	tst_rmdir
+}
+
+mkfs_mount()
+{
+	mount ${TST_DEVICE} mntpoint
+	local ret=$?
+	if [ $ret -eq 32 ]; then
+		tst_brkm TCONF "Cannot mount ${FS_TYPE}, missing driver?"

testcases/commands/mkfs/mkfs01.sh line 62

Quoted 10 lines
testcases/commands/mkfs/mkfs01.sh new file +10 -0
+	fi
+
+	if [ $ret -ne 0 ]; then
+		tst_brkm TBROK "Failed to mount device: mount exit = $ret"
+	fi
+}
+
+mkfs_umount()
+{
+	grep -q ${TST_DEVICE} /proc/self/mounts

^
Why not just /proc/mounts?

Quoted 13 lines
testcases/commands/mkfs/mkfs01.sh new file +13 -0
+	if [ $? -eq 0 ]; then
+		umount ${TST_DEVICE}
+		if [ $? -ne 0 ];then
+			tst_resm TWARN "'umount ${TST_DEVICE}' failed"
+		fi
+	else
+		tst_resm TINFO "${TST_DEVICE} is not mounted"
+	fi
+}
+
+usage()
+{
+	cat << EOF

testcases/commands/mkfs/mkfs01.sh line 85

Quoted 10 lines
testcases/commands/mkfs/mkfs01.sh new file +10 -0
+	usage: $0 [-f <ext2|ext3|ext4|vfat|...>]
+
+	OPTIONS
+		-f	Specify the type of filesystem to be built. If not
+			specified, the default filesystem type (currently ext2)
+			is used.
+		-h	Display help text and exit.
+
+EOF
+	tst_brkm TCONF "Display help text or unknown options"

^
I would rather make this TWARN, because when runtest entries became corrupted somehow the test would start reporting TCONF And that may end up being undetected for quite some time.

testcases/commands/mkfs/mkfs01.sh line 94

Quoted 9 lines
testcases/commands/mkfs/mkfs01.sh new file +9 -0
+}
+
+mkfs_verify()
+{
+	if [ -z "$1" ]; then
+		blkid | grep "$2" | grep -q "ext2"
+	else
+		blkid | grep "$2" | grep -q "$1"
+	fi

You can actually pass the device to blkid as a parameter instead of grepping it in the output.

testcases/commands/mkfs/mkfs01.sh line 100

Quoted 6 lines
testcases/commands/mkfs/mkfs01.sh new file +6 -0
+}
+
+mkfs_check()
+{
+	mkfs_mount
+	local blocknum=`df -aT | grep "$1" | awk '{print $3}'`

You can pass the mount point to the df instead of greping the device.

Quoted 9 lines

testcases/commands/mkfs/mkfs01.sh line 105

Quoted 5 lines
testcases/commands/mkfs/mkfs01.sh new file +5 -0
+	mkfs_umount
+
+	if [ $blocknum -gt "$2" ]; then
+		return 1
+	fi

So the size we get as $2 is in kB and df -T reports 1k blocks shouldn't these be equal, or are there any reserved block in play?

Indeed, "$blocknum" here is equal to struct statfs'f_blocks, which denotes total data blocks in filesystem(df uses statfs(2) to get this info) and does not contain some metadata in filesytem, e.g. ext3's journal space size.

Best Regards,
Guangwen Feng

Quoted 185 lines

testcases/commands/mkfs/mkfs01.sh line 117

Quoted 12 lines
testcases/commands/mkfs/mkfs01.sh new file +12 -0
+}
+
+mkfs_test()
+{
+	local mkfs_op=$1
+	local fs_type=$2
+	local fs_op=$3
+	local device=$4
+	local size=$5
+
+	if [ -n "$fs_type" ]; then
+		mkfs_op="-t"

Why are you adding the flags by the tiniest bits?

Why don't you rather do:

	mkfs_op="-t $fs_type"

Which is far more logical.

testcases/commands/mkfs/mkfs01.sh line 121

Quoted 4 lines
testcases/commands/mkfs/mkfs01.sh new file +4 -0
+	fi
+
+	if [ "$fs_type" = "xfs" ] || [ "$fs_type" = "btrfs" ]; then
+		fs_op+=" -f"

This is bashism. You have to do fs_op="$fs_op -f" instead.

testcases/commands/mkfs/mkfs01.sh line 125

Quoted 4 lines
testcases/commands/mkfs/mkfs01.sh new file +4 -0
+	fi
+
+	local mkfs_cmd="mkfs $mkfs_op $fs_type $fs_op $device $size"
+	mkfs_cmd=`echo "$mkfs_cmd" | sed 's/\s\+/ /g'`

This is just cosmetic, isn't it? I would just omit it.

testcases/commands/mkfs/mkfs01.sh line 130

Quoted 4 lines
testcases/commands/mkfs/mkfs01.sh new file +4 -0
+	echo ${fs_op} | grep -q "\-c"
+	if [ $? -eq 0 ] && [ "$fs_type" = "ntfs" ]; then
+		tst_resm TCONF "'${mkfs_cmd}' not supported."
+		return 32

This is fairly misleading. It would be better to use return 0 in case when you just need to exit the function. Because returning different values and ingoring them later is misleading.

testcases/commands/mkfs/mkfs01.sh line 136

Quoted 6 lines
testcases/commands/mkfs/mkfs01.sh new file +6 -0
+	fi
+
+	if [ -n "$size" ]; then
+		if [ "$fs_type" = "xfs" ] || [ "$fs_type" = "btrfs" ]; then
+			tst_resm TCONF "'${mkfs_cmd}' not supported."
+			return 32

Here as well.

Quoted 12 lines
testcases/commands/mkfs/mkfs01.sh new file +12 -0
+		fi
+	fi
+
+	${mkfs_cmd} >temp 2>&1
+	if [ $? -ne 0 ]; then
+		grep -q -E "unknown option | invalid option" temp
+		if [ $? -eq 0 ]; then
+			tst_resm TCONF "'${mkfs_cmd}' not supported."
+			return 32
+		else
+			tst_resm TFAIL "'${mkfs_cmd}' failed."
+			cat temp

testcases/commands/mkfs/mkfs01.sh line 158

Quoted 10 lines
testcases/commands/mkfs/mkfs01.sh new file +10 -0
+			return 1
+		fi
+	fi
+
+	if [ -n "$device" ]; then
+		mkfs_verify "$fs_type" "$device"
+		if [ $? -ne 0 ]; then
+			tst_resm TFAIL "'${mkfs_cmd}' failed, not expected."
+			return 1
+		fi

We should name the function better, mkfs_verify_type() comes to mind.

testcases/commands/mkfs/mkfs01.sh line 167

Quoted 9 lines
testcases/commands/mkfs/mkfs01.sh new file +9 -0
+	fi
+
+	if [ -n "$size" ]; then
+		mkfs_check "$device" "$size"
+		if [ $? -ne 0 ]; then
+			tst_resm TFAIL "'${mkfs_cmd}' failed, not expected."
+			return 1
+		fi
+	fi

Here as well, mkfs_verify_size would be better.

Quoted 7 lines
testcases/commands/mkfs/mkfs01.sh new file +7 -0
+	tst_resm TPASS "'${mkfs_cmd}' passed."
+}
+
+test1()
+{
+	tst_acquire_device
+

testcases/commands/mkfs/mkfs01.sh line 185

Quoted 10 lines
testcases/commands/mkfs/mkfs01.sh new file +10 -0
+	mkfs_test "$MKFS_OP" "$FS_TYPE" "$FS_OP" "$TST_DEVICE"
+
+	tst_release_device
+}
+
+test2()
+{
+	tst_acquire_device
+
+	mkfs_test "$MKFS_OP" "$FS_TYPE" "$FS_OP" "$TST_DEVICE" "10000"

Can you just pass empty string when it should be empty instead of passing empty global variable?

It's more confusing than it could be this way.

testcases/commands/mkfs/mkfs01.sh line 197

Quoted 11 lines
testcases/commands/mkfs/mkfs01.sh new file +11 -0
+	tst_release_device
+}
+
+test3()
+{
+	tst_acquire_device
+
+	mkfs_test "$MKFS_OP" "$FS_TYPE" "-c" "$TST_DEVICE"
+
+	tst_release_device
+}

Why don't we acquire device once in the setup and release it in the cleanup?

Quoted 20 lines
testcases/commands/mkfs/mkfs01.sh new file +20 -0
+test4()
+{
+	mkfs_test "-V"
+}
+
+test5()
+{
+	mkfs_test "-h"
+}
+
+MKFS_OP=""
+FS_TYPE=""
+FS_OP=""
+
+if [ $# -ne 0 ]; then
+	while getopts f:h OPTION; do
+		case $OPTION in
+		f)
+			FS_TYPE=$OPTARG;;
+		h)

testcases/commands/mkfs/mkfs01.sh line 228

Quoted 10 lines
testcases/commands/mkfs/mkfs01.sh new file +10 -0
+			usage;;
+		?)
+			usage;;
+		esac
+	done
+
+	if [ -z "$FS_TYPE" ]; then
+		usage
+	fi
+fi

Eh, why just not:

while getopts f:h OPTION; do

        case $OPTION in
        f)
                FS_TYPE=$OPTARG;;
        h)
                usage;;
        ?)
                usage;;
        esac

done

Quoted 13 lines
testcases/commands/mkfs/mkfs01.sh new file +7 -0
+setup
+for i in $(seq 1 ${TST_TOTAL})
+do
+	test$i
+done
+
+tst_exit
Signature · 5 lines
1.8.4.2


-- 
Mailing list info: http://lists.linux.it/listinfo/ltp
#7 lore raw

PATCH 1/1 commands/mkfs: Added new testcase to test mkfs(8) command.

Hi!

Quoted 10 lines
Quoted 9 lines

testcases/commands/mkfs/mkfs01.sh line 105

Quoted 5 lines
testcases/commands/mkfs/mkfs01.sh new file +5 -0
+	mkfs_umount
+
+	if [ $blocknum -gt "$2" ]; then
+		return 1
+	fi

So the size we get as $2 is in kB and df -T reports 1k blocks shouldn't these be equal, or are there any reserved block in play?

Quoted 3 lines

Indeed, "$blocknum" here is equal to struct statfs'f_blocks, which denotes total data blocks in filesystem(df uses statfs(2) to get this info) and does not contain some metadata in filesytem, e.g. ext3's journal space size.

Ok, then we should check for lower bound as well. Something as blocknum is greater than 90% of size or similar.

Signature · 2 lines
Cyril Hrubis
[email protected]
#8 lore raw

PATCH 1/1 commands/mkfs: Added new testcase to test mkfs(8) command.

Quoted 11 lines · Cyril Hrubis

Hi!

Quoted 10 lines
Quoted 9 lines

testcases/commands/mkfs/mkfs01.sh line 105

Quoted 5 lines
testcases/commands/mkfs/mkfs01.sh new file +5 -0
+	mkfs_umount
+
+	if [ $blocknum -gt "$2" ]; then
+		return 1
+	fi

So the size we get as $2 is in kB and df -T reports 1k blocks shouldn't these be equal, or are there any reserved block in play?

Quoted 7 lines
Quoted 3 lines

Indeed, "$blocknum" here is equal to struct statfs'f_blocks, which denotes total data blocks in filesystem(df uses statfs(2) to get this info) and does not contain some metadata in filesytem, e.g. ext3's journal space size.

Ok, then we should check for lower bound as well. Something as blocknum is greater than 90% of size or similar.

OK, I see, thanks!
Please ignore the v2 I just sent, I will email a v3 with lower bound check.

Best Regards,
Guangwen Feng

#9 lore raw

PATCH v3 1/1 commands/mkfs: Added new testcase to test mkfs(8) command.

Test mkfs(8) command with some basic options.

---
 runtest/commands                  |  10 ++
 testcases/commands/mkfs/Makefile  |  24 ++++
 testcases/commands/mkfs/mkfs01.sh | 234 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 268 insertions(+)
 create mode 100644 testcases/commands/mkfs/Makefile
 create mode 100755 testcases/commands/mkfs/mkfs01.sh
runtest/commands +10 -0
index e5260ba..6c0485b 100644
@@ -28,3 +28,13 @@ df01_xfs df01.sh -f xfs
 df01_vfat df01.sh -f vfat
 df01_exfat df01.sh -f exfat
 df01_ntfs df01.sh -f ntfs
+mkfs01 mkfs01.sh
+mkfs01_ext2 mkfs01.sh -f ext2
+mkfs01_ext3 mkfs01.sh -f ext3
+mkfs01_ext4 mkfs01.sh -f ext4
+mkfs01_xfs mkfs01.sh -f xfs
+mkfs01_btrfs mkfs01.sh -f btrfs
+mkfs01_minix mkfs01.sh -f minix
+mkfs01_msdos mkfs01.sh -f msdos
+mkfs01_vfat mkfs01.sh -f vfat
+mkfs01_ntfs mkfs01.sh -f ntfs
testcases/commands/mkfs/Makefile new file +24 -0
new file mode 100644
index 0000000..6099017
@@ -0,0 +1,24 @@
+#
+#    commands/mkfs testcases Makefile.
+#
+#    Copyright (c) 2015 Fujitsu Ltd.
+#    Author:Guangwen Feng <[email protected]>
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+
+top_srcdir		?= ../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_TARGETS		:= mkfs01.sh
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/commands/mkfs/mkfs01.sh new file +234 -0

234 lines not on this page · raw message

Signature · 1 line
1.8.4.2
#10 lore raw

PATCH v3 1/1 commands/mkfs: Added new testcase to test mkfs(8) command.

Hi!

Quoted 12 lines
testcases/commands/mkfs/mkfs01.sh new file +12 -0
+mkfs_verify_size()
+{
+	mkfs_mount
+	local blocknum=`df -B 1k mntpoint | tail -n1 | awk '{print $2}'`
+	mkfs_umount
+
+	if [ $blocknum -gt "$2" ]; then
+		return 1
+	fi
+
+	# Size argument in mkfs.ntfs denotes number-of-sectors which is 512bytes,
+	# 1k-block size should be devided by this argument for ntfs verification.

testcases/commands/mkfs/mkfs01.sh line 124

Quoted 10 lines
testcases/commands/mkfs/mkfs01.sh new file +10 -0
+	if [ "$1" = "ntfs" ]; then
+		local rate=1024/512
+		if [ $blocknum -lt "$(($2/rate*9/10))" ]; then
+			return 1
+		fi
+	else
+		if [ $blocknum -lt "$(($2*9/10))" ]; then
+			return 1
+		fi
+	fi

I've added explicit return 0 here, since otherwise the retul value would be set by the last executed command (which would be the either umount or mount above...).

And pushed, thanks.

Signature · 2 lines
Cyril Hrubis
[email protected]
#11 lore raw

PATCH v3 1/1 commands/mkfs: Added new testcase to test mkfs(8) command.

Quoted 19 lines · Cyril Hrubis

Hi!

Quoted 18 lines
testcases/commands/mkfs/mkfs01.sh new file +18 -0
+mkfs_verify_size()
+{
+	mkfs_mount
+	local blocknum=`df -B 1k mntpoint | tail -n1 | awk '{print $2}'`
+	mkfs_umount
+
+	if [ $blocknum -gt "$2" ]; then
+		return 1
+	fi
+
+	# Size argument in mkfs.ntfs denotes number-of-sectors which is 512bytes,
+	# 1k-block size should be devided by this argument for ntfs verification.
+	if [ "$1" = "ntfs" ]; then
+		local rate=1024/512
+		if [ $blocknum -lt "$(($2/rate*9/10))" ]; then
+			return 1
+		fi
+	else
Quoted 9 lines

testcases/commands/mkfs/mkfs01.sh line 124

Quoted 4 lines
testcases/commands/mkfs/mkfs01.sh new file +4 -0
+		if [ $blocknum -lt "$(($2*9/10))" ]; then
+			return 1
+		fi
+	fi

I've added explicit return 0 here, since otherwise the retul value would be set by the last executed command (which would be the either umount or mount above...).

Indeed, got it.
Many thanks!

Best Regards,
Guangwen Feng

Quoted 3 lines

And pushed, thanks.