• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3# Copyright (c) 2015 Fujitsu Ltd.
4# Author: Zeng Linggang <zenglg.jy@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
23TST_CNT=23
24TST_SETUP=setup
25TST_TESTFUNC=do_test
26TST_NEEDS_TMPDIR=1
27TST_NEEDS_CMDS="dd du stat"
28. tst_test.sh
29
30setup()
31{
32	ROD_SILENT mkdir basedir
33	ROD_SILENT cd basedir
34
35	ROD_SILENT dd if=/dev/zero of=testfile bs=1M count=10
36
37	ROD_SILENT mkdir -p testdir
38
39	ROD_SILENT ln -s ../testfile testdir/testsymlink
40
41	# Display values are in units of the first available SIZE
42	# from --block-size, and the DU_BLOCK_SIZE, BLOCK_SIZE and
43	# BLOCKSIZE environment variables. Here we need to
44	# set DU_BLOCK_SIZE to 1024 to ensure the result is expected.
45	export DU_BLOCK_SIZE=1024
46}
47
48du_test()
49{
50	local test_return
51
52	$1 > ../temp 2>&1
53	test_return=$?
54
55	if [ ${test_return} -ne 0 ]; then
56		grep -q -E "unrecognized option|invalid option" ../temp
57		if [ $? -eq 0 ]; then
58			tst_res TCONF "'$1' not supported"
59		else
60			tst_res TFAIL "'$1' failed"
61		fi
62		return
63	fi
64
65	grep -q $2 ../temp
66	if [ $? -eq 0 ]; then
67		tst_res TPASS "'$1' passed"
68	else
69		tst_res TFAIL "'$1' failed"
70		tst_res TINFO "Looking for '$2' in:"
71		cat ../temp
72	fi
73}
74
75block_size=512
76page_size=$(tst_getconf PAGESIZE)
77if [ "$page_size" -lt 1024 ]; then
78	tst_brk TBROK "Page size < 1024"
79fi
80page_size=$((page_size / 1024))
81
82# The output could be different in some systems, if we use du to
83# estimate file space usage with the same filesystem and the same size.
84# So we use the approximate value to check.
85check1="^10[2-3][0-9][0-9][[:space:]]\."
86check2="^10[2-3][0-9][0-9][[:space:]]testfile"
87check3="^\(0\|${page_size}\)[[:space:]]\.\/testdir\/testsymlink"
88check5="^20[4-6][0-9][0-9][[:space:]]\."
89check7="^10[4-5][0-9][0-9]\{4\}[[:space:]]\."
90check9="^10[2-3][0-9][0-9][[:space:]]total"
91check11="^10[2-3][0-9][0-9][[:space:]]testdir\/testsymlink"
92check14="^1[0,1]M[[:space:]]\."
93check16="^10[2-3][0-9][0-9][[:space:]]testdir\/"
94check20="^11M[[:space:]]\."
95check23="^[0-9]\{1,2\}[[:space:]]\."
96
97do_test()
98{
99	case $1 in
100	1) du_test "du" ${check1};;
101	2) du_test "du testfile" ${check2};;
102	3) du_test "du -a" ${check3};;
103	4) du_test "du --all" ${check3};;
104	5) du_test "du -B ${block_size}" ${check5};;
105	6) du_test "du --block-size=${block_size}" ${check5};;
106	7) du_test "du -b" ${check7};;
107	8) du_test "du --bytes" ${check7};;
108	9) du_test "du -c" ${check9};;
109	10) du_test "du --total" ${check9};;
110	11) du_test "du -D testdir/testsymlink" ${check11};;
111	12) du_test "du --dereference-args testdir/testsymlink" ${check11};;
112	13) du_test "du --max-depth=1" ${check1};;
113	14) du_test "du --human-readable" ${check14};;
114	15) du_test "du -k" ${check1};;
115	16) du_test "du -L testdir/" ${check16};;
116	17) du_test "du --dereference testdir/" ${check16};;
117	18) du_test "du -P" ${check1};;
118	19) du_test "du --no-dereference" ${check1};;
119	20) du_test "du --si" ${check20};;
120	21) du_test "du -s" ${check1};;
121	22) du_test "du --summarize" ${check1};;
122	23) du_test "du --exclude=testfile" ${check23};;
123	esac
124}
125
126tst_run
127