Test df(1) command with some basic options. Signed-off-by: Zeng Linggang <zenglg...@cn.fujitsu.com> --- runtest/commands | 1 + testcases/commands/df/Makefile | 28 ++++++ testcases/commands/df/df01.sh | 215 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 244 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..a6208b3 100644 --- a/runtest/commands +++ b/runtest/commands @@ -21,3 +21,4 @@ sssd01 sssd01 sssd02 sssd02 sssd03 sssd03 du01 du01.sh +df01 df01.sh 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..8f3fc86 --- /dev/null +++ b/testcases/commands/df/df01.sh @@ -0,0 +1,215 @@ +#!/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.ext2 + + tst_tmpdir + + tst_acquire_device + + ROD_SILENT mkfs.ext2 -b 1024 -I 128 ${TST_DEVICE} + + ROD_SILENT mkdir -p mntpoint + + ROD_SILENT mount ${TST_DEVICE} mntpoint +} + +cleanup() +{ + grep -q mntpoint /proc/self/mounts + if [ $? -eq 0 ]; then + umount mntpoint + if [ $? -ne 0 ];then + tst_resm TWARN "'umount mntpoint' failed" + fi + else + tst_resm TINFO "mntpoint is not mounted" + fi + + tst_release_device + + tst_rmdir +} + +df_test() +{ + df_verify $1 + if [ $? -ne 0 ]; then + return + fi + + local old_used=$(get_used_value) + + ROD_SILENT dd if=/dev/zero of=mntpoint/testimg bs=1024 count=10240 + + df_verify $1 + + local new_used=$(get_used_value) + + local diff_used=$(sub $new_used $old_used) + # Some file system maybe calculate ACL block, so we need take away it. + if [ ${diff_used} == $2 -o $((diff_used - 1)) == $2 ]; then + tst_resm TPASS "'$1' passed." + else + tst_resm TFAIL "'$1' failed." + fi + + ROD_SILENT rm -rf mntpoint/testimg +} + +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 +} + +get_used_value() +{ + # 'df -T' will output 7 field while others output 6. + grep mntpoint output | awk 'NF==6{print $3} NF==7{print $4}' +} + +sub() +{ + minuend=$(echo $1 | sed -r 's/([[:digit:]]{1,}).*/\1/') + if echo $1 | grep -q -E "m|M"; then + minuend=$((minuend*1024*1024)) + flag=m + elif echo $1 | grep -q -E "k|K"; then + minuend=$((minuend*1024)) + flag=k + else + flag=0 + fi + + subtrahend=$(echo $2 | sed -r 's/([[:digit:]]{1,}).*/\1/') + if echo $2 | grep -q -E "m|M"; then + subtrahend=$((subtrahend*1024*1024)) + elif echo $2 | grep -q -E "k|K"; then + subtrahend=$((subtrahend*1024)) + fi + + rest=$((minuend - subtrahend)) + if [ $flag == m ]; then + echo $((rest/1024/1024)) + elif [ $flag == k ]; then + echo $((rest/1024)) + else + echo $rest + fi +} + +test1() +{ + df_test "df" "10281" +} + +test2() +{ + df_test "df -a" "10281" +} + +test3() +{ + df_test "df -h" "10" +} + +test4() +{ + df_test "df -H" "10" +} + +test5() +{ + df_test "df -i" "1" +} + +test6() +{ + df_test "df -k" "10281" +} + +test7() +{ + df_test "df -m" "10" +} + +test8() +{ + df_test "df -t ext2" "10281" +} + +test9() +{ + df_test "df -T" "10281" +} + +test10() +{ + df_test "df -v mntpoint" "10281" +} + +test11() +{ + df_verify "df -x ext2" + if [ $? -ne 0 ]; then + return + fi + + grep ${TST_DEVICE} output | grep -q mntpoint + if [ $? -ne 0 ]; then + tst_resm TPASS "'df -x ext2' passed." + else + tst_resm TFAIL "'df -x ext2' failed." + fi +} + +test12() +{ + df_verify "df --version" + if [ $? -eq 0 ]; then + tst_resm TPASS "'df --version' passed." + fi +} + +TST_CLEANUP="cleanup" +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