-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commands/du: Added new testcase to test du(1) command.
Test du(1) command with some basic options. Signed-off-by: Zeng Linggang <[email protected]>
- Loading branch information
Showing
3 changed files
with
247 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ size01 size01 | |
sssd01 sssd01 | ||
sssd02 sssd02 | ||
sssd03 sssd03 | ||
du01 du01.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# | ||
# commands/du testcases Makefile. | ||
# | ||
# Copyright (c) 2015 Fujitsu Ltd. | ||
# Author: Zeng Linggang <[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. | ||
# | ||
# 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 := du01.sh | ||
|
||
include $(top_srcdir)/include/mk/generic_leaf_target.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
#!/bin/sh | ||
# | ||
# Copyright (c) 2015 Fujitsu Ltd. | ||
# Author: Zeng Linggang <[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. | ||
# | ||
# 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 St, Fifth Floor, Boston, MA 02110-1301 USA | ||
# | ||
# Test du command with some basic options. | ||
# | ||
|
||
TCID=du01 | ||
TST_TOTAL=23 | ||
. test.sh | ||
|
||
setup() | ||
{ | ||
tst_require_root | ||
|
||
tst_check_cmds dd du stat | ||
|
||
tst_tmpdir | ||
|
||
ROD_SILENT dd if=/dev/zero of=testfile bs=1M count=10 | ||
|
||
ROD_SILENT mkdir -p testdir | ||
|
||
ROD_SILENT ln -s ../testfile testdir/testfile | ||
|
||
# Display values are in units of the first available SIZE | ||
# from --block-size, and the DU_BLOCK_SIZE, BLOCK_SIZE and | ||
# BLOCKSIZE environment variables. Here we need to | ||
# set DU_BLOCK_SIZE to 1024 to ensure the result is expected. | ||
export DU_BLOCK_SIZE=1024 | ||
} | ||
|
||
cleanup() | ||
{ | ||
tst_rmdir | ||
} | ||
|
||
du_test() | ||
{ | ||
local test_return | ||
|
||
$1 > ${TCID}.temp 2>&1 | ||
test_return=$? | ||
|
||
if [ ${test_return} -ne 0 ]; then | ||
grep -q -E "unrecognized option|invalid option" ${TCID}.temp | ||
if [ $? -eq 0 ]; then | ||
tst_resm TCONF "'$1'" "not supported." | ||
return | ||
else | ||
tst_resm TFAIL "'$1'" "failed." | ||
return | ||
fi | ||
fi | ||
|
||
grep -q $2 ${TCID}.temp | ||
if [ $? -eq 0 ]; then | ||
tst_resm TPASS "'$1'" "passed." | ||
else | ||
tst_resm TFAIL "'$1'" "failed." | ||
fi | ||
} | ||
|
||
test1() | ||
{ | ||
du_test "du" ${check1} | ||
} | ||
|
||
test2() | ||
{ | ||
du_test "du testfile" ${check2} | ||
} | ||
|
||
test3() | ||
{ | ||
du_test "du -a" ${check3} | ||
} | ||
|
||
test4() | ||
{ | ||
du_test "du --all" ${check3} | ||
} | ||
|
||
test5() | ||
{ | ||
du_test "du -B ${block_size}" ${check5} | ||
} | ||
|
||
test6() | ||
{ | ||
du_test "du --block-size=${block_size}" ${check5} | ||
} | ||
|
||
test7() | ||
{ | ||
du_test "du -b" ${check7} | ||
} | ||
|
||
test8() | ||
{ | ||
du_test "du --bytes" ${check7} | ||
} | ||
|
||
test9() | ||
{ | ||
du_test "du -c" ${check9} | ||
} | ||
|
||
test10() | ||
{ | ||
du_test "du --total" ${check9} | ||
} | ||
|
||
test11() | ||
{ | ||
du_test "du -D testdir/testfile" ${check11} | ||
} | ||
|
||
test12() | ||
{ | ||
du_test "du --dereference-args testdir/testfile" ${check11} | ||
} | ||
|
||
test13() | ||
{ | ||
du_test "du --max-depth=1" ${check1} | ||
} | ||
|
||
test14() | ||
{ | ||
du_test "du --human-readable" ${check14} | ||
} | ||
|
||
test15() | ||
{ | ||
du_test "du -k" ${check1} | ||
} | ||
|
||
test16() | ||
{ | ||
du_test "du -L testdir/" ${check16} | ||
} | ||
|
||
test17() | ||
{ | ||
du_test "du --dereference testdir/" ${check16} | ||
} | ||
|
||
test18() | ||
{ | ||
du_test "du -P" ${check1} | ||
} | ||
|
||
test19() | ||
{ | ||
du_test "du --no-dereference" ${check1} | ||
} | ||
|
||
test20() | ||
{ | ||
du_test "du --si" ${check20} | ||
} | ||
|
||
test21() | ||
{ | ||
du_test "du -s" ${check1} | ||
} | ||
|
||
test22() | ||
{ | ||
du_test "du --summarize" ${check1} | ||
} | ||
|
||
test23() | ||
{ | ||
du_test "du --exclude=testfile" ${check23} | ||
} | ||
|
||
setup | ||
TST_CLEANUP=cleanup | ||
|
||
block_size=512 | ||
|
||
# The output could be different in some systems, if we use du to | ||
# estimate file space usage with the same filesystem and the same size. | ||
# So we use the approximate value to check. | ||
check1="10[2-3][0-9][0-9][[:space:]]\." | ||
check2="10[2-3][0-9][0-9][[:space:]]testfile" | ||
check3="0[[:space:]]\.\/testdir\/testfile" | ||
check5="20[4-5][0-9][0-9][[:space:]]\." | ||
check7="10[4-5][0-9][0-9]\{4\}[[:space:]]\." | ||
check9="10[2-3][0-9][0-9][[:space:]]total" | ||
check11="10[2-3][0-9][0-9][[:space:]]testdir\/testfile" | ||
check14="1[0,1]M[[:space:]]\." | ||
check16="10[2-3][0-9][0-9][[:space:]]testdir\/" | ||
check20="11M[[:space:]]\." | ||
check23="[0-9]\{1,2\}[[:space:]]\." | ||
|
||
for i in $(seq 1 ${TST_TOTAL}) | ||
do | ||
test$i | ||
done | ||
|
||
tst_exit |