1 #!/bin/sh 2 # 3 # Copyright (c) 2015 Fujitsu Ltd. 4 # Author: Zeng Linggang <zenglg.jy (at] cn.fujitsu.com> 5 # 6 # This program is free software; you can redistribute it and/or modify 7 # it under the terms of the GNU General Public License as published by 8 # the Free Software Foundation; either version 2 of the License, or 9 # (at your option) any later version. 10 # 11 # This program is distributed in the hope that it will be useful, 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 # GNU General Public License for more details. 15 # 16 # You should have received a copy of the GNU General Public License 17 # along with this program; if not, write to the Free Software 18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 # 20 # Test du command with some basic options. 21 # 22 23 TST_ID="du01" 24 TST_CNT=23 25 TST_SETUP=setup 26 TST_TESTFUNC=do_test 27 TST_NEEDS_TMPDIR=1 28 TST_NEEDS_CMDS="dd du stat" 29 . tst_test.sh 30 31 setup() 32 { 33 ROD_SILENT mkdir basedir 34 ROD_SILENT cd basedir 35 36 ROD_SILENT dd if=/dev/zero of=testfile bs=1M count=10 37 38 ROD_SILENT mkdir -p testdir 39 40 ROD_SILENT ln -s ../testfile testdir/testsymlink 41 42 # Display values are in units of the first available SIZE 43 # from --block-size, and the DU_BLOCK_SIZE, BLOCK_SIZE and 44 # BLOCKSIZE environment variables. Here we need to 45 # set DU_BLOCK_SIZE to 1024 to ensure the result is expected. 46 export DU_BLOCK_SIZE=1024 47 } 48 49 du_test() 50 { 51 local test_return 52 53 $1 > ../temp 2>&1 54 test_return=$? 55 56 if [ ${test_return} -ne 0 ]; then 57 grep -q -E "unrecognized option|invalid option" ../temp 58 if [ $? -eq 0 ]; then 59 tst_res TCONF "'$1' not supported" 60 else 61 tst_res TFAIL "'$1' failed" 62 fi 63 return 64 fi 65 66 grep -q $2 ../temp 67 if [ $? -eq 0 ]; then 68 tst_res TPASS "'$1' passed" 69 else 70 tst_res TFAIL "'$1' failed" 71 tst_res TINFO "Looking for '$2' in:" 72 cat ../temp 73 fi 74 } 75 76 block_size=512 77 page_size=$(getconf PAGESIZE) 78 if [ "$page_size" -lt 1024 ]; then 79 tst_brk TBROK "Page size < 1024" 80 fi 81 page_size=$((page_size / 1024)) 82 83 # The output could be different in some systems, if we use du to 84 # estimate file space usage with the same filesystem and the same size. 85 # So we use the approximate value to check. 86 check1="^10[2-3][0-9][0-9][[:space:]]\." 87 check2="^10[2-3][0-9][0-9][[:space:]]testfile" 88 check3="^\(0\|${page_size}\)[[:space:]]\.\/testdir\/testsymlink" 89 check5="^20[4-6][0-9][0-9][[:space:]]\." 90 check7="^10[4-5][0-9][0-9]\{4\}[[:space:]]\." 91 check9="^10[2-3][0-9][0-9][[:space:]]total" 92 check11="^10[2-3][0-9][0-9][[:space:]]testdir\/testsymlink" 93 check14="^1[0,1]M[[:space:]]\." 94 check16="^10[2-3][0-9][0-9][[:space:]]testdir\/" 95 check20="^11M[[:space:]]\." 96 check23="^[0-9]\{1,2\}[[:space:]]\." 97 98 do_test() 99 { 100 case $1 in 101 1) du_test "du" ${check1};; 102 2) du_test "du testfile" ${check2};; 103 3) du_test "du -a" ${check3};; 104 4) du_test "du --all" ${check3};; 105 5) du_test "du -B ${block_size}" ${check5};; 106 6) du_test "du --block-size=${block_size}" ${check5};; 107 7) du_test "du -b" ${check7};; 108 8) du_test "du --bytes" ${check7};; 109 9) du_test "du -c" ${check9};; 110 10) du_test "du --total" ${check9};; 111 11) du_test "du -D testdir/testsymlink" ${check11};; 112 12) du_test "du --dereference-args testdir/testsymlink" ${check11};; 113 13) du_test "du --max-depth=1" ${check1};; 114 14) du_test "du --human-readable" ${check14};; 115 15) du_test "du -k" ${check1};; 116 16) du_test "du -L testdir/" ${check16};; 117 17) du_test "du --dereference testdir/" ${check16};; 118 18) du_test "du -P" ${check1};; 119 19) du_test "du --no-dereference" ${check1};; 120 20) du_test "du --si" ${check20};; 121 21) du_test "du -s" ${check1};; 122 22) du_test "du --summarize" ${check1};; 123 23) du_test "du --exclude=testfile" ${check23};; 124 esac 125 } 126 127 tst_run 128