diff options
author | Zeng Linggang <zenglg.jy@cn.fujitsu.com> | 2015-06-12 15:55:39 +0800 |
---|---|---|
committer | Cyril Hrubis <chrubis@suse.cz> | 2015-06-16 21:25:07 +0200 |
commit | 9e3a07530f460b32fd381b3538d37c9944de83f8 (patch) | |
tree | c3d7e449567f77ee810bcf9ad6e16abe0fc5c10c /testcases/commands | |
parent | 6bece7e4f1224a7c523c82522200087f7e43547a (diff) |
commands/df: Added new testcase to test df(1) command.
Test df(1) command with some basic options.
Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Diffstat (limited to 'testcases/commands')
-rw-r--r-- | testcases/commands/df/Makefile | 28 | ||||
-rwxr-xr-x | testcases/commands/df/df01.sh | 252 |
2 files changed, 280 insertions, 0 deletions
diff --git a/testcases/commands/df/Makefile b/testcases/commands/df/Makefile new file mode 100644 index 000000000..e1a38c891 --- /dev/null +++ b/testcases/commands/df/Makefile @@ -0,0 +1,28 @@ +# +# commands/df testcases Makefile. +# +# Copyright (c) 2015 Fujitsu Ltd. +# Author:Zhang Jin <jy_zhangjin@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 000000000..fe573e5a7 --- /dev/null +++ b/testcases/commands/df/df01.sh @@ -0,0 +1,252 @@ +#!/bin/sh +# +# Copyright (c) 2015 Fujitsu Ltd. +# Author: Zhang Jin <jy_zhangjin@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 + + mount ${TST_DEVICE} mntpoint + 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 + + DF_FS_TYPE=$(mount | grep "$TST_DEVICE" | awk '{print $5}') +} + +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|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" +} + +df_test() +{ + df_verify $1 + if [ $? -ne 0 ]; then + return + fi + + df_check $1 + if [ $? -ne 0 ]; then + tst_resm TFAIL "'$1' failed, not expected." + return + fi + + ROD_SILENT dd if=/dev/zero of=mntpoint/testimg bs=1024 count=1024 + + 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." + cat output + 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 ${DF_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 ${DF_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 + +setup + +for i in $(seq 1 ${TST_TOTAL}) +do + test$i +done + +tst_exit |