Test df(1) command with some basic options. Signed-off-by: Zeng Linggang <zenglg...@cn.fujitsu.com> --- runtest/commands | 3 + testcases/commands/df/Makefile | 28 +++++ testcases/commands/df/df01.sh | 248 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 279 insertions(+) create mode 100644 testcases/commands/df/Makefile create mode 100755 testcases/commands/df/df01.sh
diff --git a/runtest/commands b/runtest/commands index 06291f0..2930f63 100644 --- a/runtest/commands +++ b/runtest/commands @@ -21,3 +21,6 @@ sssd01 sssd01 sssd02 sssd02 sssd03 sssd03 du01 du01.sh +df01 df01.sh +df01 df01.sh -f ext3 +df01 df01.sh -f ext4 diff --git a/testcases/commands/df/Makefile b/testcases/commands/df/Makefile new file mode 100644 index 0000000..e1a38c8 --- /dev/null +++ b/testcases/commands/df/Makefile @@ -0,0 +1,28 @@ +# +# commands/df testcases Makefile. +# +# Copyright (c) 2015 Fujitsu Ltd. +# Author:Zhang Jin <jy_zhang...@cn.fujitsu.com> +# +# 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. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +top_srcdir ?= ../../.. + +include $(top_srcdir)/include/mk/env_pre.mk + +INSTALL_TARGETS := df01.sh + +include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/commands/df/df01.sh b/testcases/commands/df/df01.sh new file mode 100755 index 0000000..4b2113a --- /dev/null +++ b/testcases/commands/df/df01.sh @@ -0,0 +1,248 @@ +#!/bin/sh +# +# Copyright (c) 2015 Fujitsu Ltd. +# Author: Zhang Jin <jy_zhang...@cn.fujitsu.com> +# +# 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 df command with some basic options. +# + +TCID=df01 +TST_TOTAL=12 +. test.sh + +setup() +{ + tst_require_root + + tst_check_cmds df mkfs.${FS_TYPE} stat + + tst_tmpdir + + TST_CLEANUP="cleanup" + + tst_acquire_device + + ROD_SILENT mkfs.${FS_TYPE} ${TST_DEVICE} + + ROD_SILENT mkdir -p mntpoint + + ROD_SILENT mount ${TST_DEVICE} mntpoint +} + +cleanup() +{ + grep -q ${TST_DEVICE} /proc/self/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 + + tst_release_device + + tst_rmdir +} + +usage() +{ + cat << EOF + usage: $0 [-f <ext2|ext3|ext4>] + + 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" +} + +df_test() +{ + df_verify $1 + if [ $? -ne 0 ]; then + return + fi + + df_check $1 + if [ $? -ne 0 ]; then + tst_resm TFAIL "'$1' failed, not ecpected." + return + fi + + ROD_SILENT dd if=/dev/zero of=mntpoint/testimg bs=1024 count=10240 + + df_verify $1 + + df_check $1 + if [ $? -eq 0 ]; then + tst_resm TPASS "'$1' passed." + else + tst_resm TFAIL "'$1' failed." + fi + + ROD_SILENT rm -rf mntpoint/testimg + + # flush file system buffers, then we can get the actual sizes. + sync +} + +df_verify() +{ + $@ >output 2>&1 + if [ $? -ne 0 ]; then + grep -q -E "unrecognized option | invalid option" output + if [ $? -eq 0 ]; then + tst_resm TCONF "'$1' not supported." + return 32 + else + tst_resm TFAIL "'$1' failed." + return 1 + fi + fi +} + +df_check() +{ + if [ "$(echo $@)" = "df -i" ]; then + local total=$(stat -f mntpoint --printf=%c) + local free=$(stat -f mntpoint --printf=%d) + local used=$((total-free)) + else + local total=$(stat -f mntpoint --printf=%b) + local free=$(stat -f mntpoint --printf=%f) + local used=$((total-free)) + local bsize=$(stat -f mntpoint --printf=%s) + total=$(($total * $bsize / 1024)) + used=$(($used * $bsize / 1024)) + fi + + grep ${TST_DEVICE} output | grep -q "${total}.*${used}" + if [ $? -ne 0 ]; then + return 1 + fi +} + +test1() +{ + df_test "df" +} + +test2() +{ + df_test "df -a" +} + +test3() +{ + df_test "df -i" +} + +test4() +{ + df_test "df -k" +} + +test5() +{ + df_test "df -t ${FS_TYPE}" +} + +test6() +{ + df_test "df -T" +} + +test7() +{ + df_test "df -v ${TST_DEVICE}" +} + +test8() +{ + df_verify "df -h" + if [ $? -eq 0 ]; then + tst_resm TPASS "'df -h' passed." + fi +} + +test9() +{ + df_verify "df -H" + if [ $? -eq 0 ]; then + tst_resm TPASS "'df -H' passed." + fi +} + +test10() +{ + df_verify "df -m" + if [ $? -eq 0 ]; then + tst_resm TPASS "'df -m' passed." + fi +} + +test11() +{ + df_verify "df --version" + if [ $? -eq 0 ]; then + tst_resm TPASS "'df --version' passed." + fi +} + +test12() +{ + df_verify "df -x ${FS_TYPE}" + if [ $? -ne 0 ]; then + return + fi + + grep ${TST_DEVICE} output | grep -q mntpoint + if [ $? -ne 0 ]; then + tst_resm TPASS "'df -x ${FS_TYPE}' passed." + else + tst_resm TFAIL "'df -x ${FS_TYPE}' failed." + fi +} + +FS_TYPE=ext2 +while getopts f:h: OPTION; do + case $OPTION in + f) + FS_TYPE=$OPTARG;; + h) + usage;; + ?) + usage;; + esac +done + +case "${FS_TYPE}" in +ext2) ;; +ext3) ;; +ext4) ;; +*) tst_brkm TCONF "${FS_TYPE} is not supported temporarily";; +esac + +setup + +for i in $(seq 1 ${TST_TOTAL}) +do + test$i +done + +tst_exit -- 1.9.3 ------------------------------------------------------------------------------ _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list