1319850Sngie#
2346920Sngie# Copyright (c) 2017 Enji Cooper <ngie@FreeBSD.org>
3319850Sngie#
4319850Sngie# Redistribution and use in source and binary forms, with or without
5319850Sngie# modification, are permitted provided that the following conditions
6319850Sngie# are met:
7319850Sngie# 1. Redistributions of source code must retain the above copyright
8319850Sngie#    notice, this list of conditions and the following disclaimer.
9319850Sngie# 2. Redistributions in binary form must reproduce the above copyright
10319850Sngie#    notice, this list of conditions and the following disclaimer in the
11319850Sngie#    documentation and/or other materials provided with the distribution.
12319850Sngie#
13319850Sngie# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14319850Sngie# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15319850Sngie# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16319850Sngie# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17319850Sngie# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18319850Sngie# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19319850Sngie# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20319850Sngie# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21319850Sngie# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22319850Sngie# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23319850Sngie# SUCH DAMAGE.
24319850Sngie#
25319850Sngie# $FreeBSD: stable/11/usr.bin/du/tests/du_test.sh 346920 2019-04-29 19:36:46Z ngie $
26319850Sngie
27319850Sngieatf_test_case A_flag
28319850SngieA_flag_head()
29319850Sngie{
30319850Sngie	atf_set "descr" "Verify -A behavior"
31319850Sngie}
32319850SngieA_flag_body()
33319850Sngie{
34319850Sngie	# XXX: compressed volumes?
35319850Sngie	atf_check truncate -s 10g sparse.file
36319850Sngie	atf_check -o inline:'1\tsparse.file\n' du -g sparse.file
37319850Sngie	atf_check -o inline:'10\tsparse.file\n' du -A -g sparse.file
38319850Sngie}
39319850Sngie
40319850Sngieatf_test_case H_flag
41319850SngieH_flag_head()
42319850Sngie{
43319850Sngie	atf_set "descr" "Verify -H behavior"
44319850Sngie}
45319850SngieH_flag_body()
46319850Sngie{
47319850Sngie	local paths1='testdir/A/B testdir/A testdir/C testdir'
48319850Sngie	local paths2='testdir/A/B testdir/A testdir/C testdir'
49319850Sngie	local sep='\n[0-9]+\t'
50319850Sngie
51319850Sngie	atf_check mkdir testdir
52319850Sngie	atf_check -x "cd testdir && mkdir A && touch A/B && ln -s A C"
53319850Sngie
54319850Sngie	atf_check -o save:du.out du -aAH testdir
55319850Sngie	atf_check egrep -q "[0-9]+\t$(echo $paths1 | tr ' ' "$sep")\n" du.out
56319850Sngie	atf_check -o save:du_C.out du -aAH testdir/C
57319850Sngie	atf_check egrep -q "[0-9]+\t$(echo $paths2 | tr ' ' "$sep")\n" du_C.out
58319850Sngie}
59319850Sngie
60319850Sngieatf_test_case I_flag
61319850SngieI_flag_head()
62319850Sngie{
63319850Sngie	atf_set "descr" "Verify -I behavior"
64319850Sngie}
65319850SngieI_flag_body()
66319850Sngie{
67319850Sngie	paths_sans_foo_named="a/motley/fool/of/sorts fool/parts/with/their/cache bar baz"
68319850Sngie	paths_foo_named="foo foobar"
69319850Sngie	paths="$paths_sans_foo_named $paths_foo_named"
70319850Sngie
71319850Sngie	# cd'ing to testdir helps ensure that files from atf/kyua don't
72319850Sngie	# pollute the results.
73319850Sngie	atf_check -x "mkdir testdir && cd testdir && mkdir -p $paths"
74319850Sngie	atf_check -o save:du.out -x "cd testdir && du -s $paths_sans_foo_named"
75319850Sngie	atf_check -o save:du_I.out -x "cd testdir && du -I '*foo*' -s $paths"
76319850Sngie
77319850Sngie	atf_check diff -u du.out du_I.out
78319850Sngie}
79319850Sngie
80319850Sngieatf_test_case c_flag
81319850Sngiec_flag_head()
82319850Sngie{
83319850Sngie	atf_set	"descr" "Verify -c output"
84319850Sngie}
85319850Sngiec_flag_body()
86319850Sngie{
87319850Sngie	atf_check truncate -s 0 foo bar
88319850Sngie}
89319850Sngie
90319850Sngieatf_test_case g_flag
91319850Sngieg_flag_head()
92319850Sngie{
93319850Sngie	atf_set "descr" "Verify -g output"
94319850Sngie}
95319850Sngieg_flag_body()
96319850Sngie{
97319850Sngie	atf_check truncate -s 1k A
98319850Sngie	atf_check truncate -s 1m B
99319850Sngie	atf_check truncate -s 1g C
100319850Sngie	atf_check truncate -s 1t D
101319850Sngie	atf_check -o inline:'1\tA\n1\tB\n1\tC\n1024\tD\n' du -Ag A B C D
102319850Sngie}
103319850Sngie
104319850Sngieatf_test_case h_flag
105319850Sngieh_flag_head()
106319850Sngie{
107319850Sngie	atf_set	"descr" "Verify -h output"
108319850Sngie}
109319850Sngieh_flag_body()
110319850Sngie{
111319850Sngie	atf_check truncate -s 1k A
112319850Sngie	atf_check truncate -s 1m B
113319850Sngie	atf_check truncate -s 1g C
114319850Sngie	atf_check truncate -s 1t D
115319850Sngie	atf_check -o inline:'1.0K\tA\n1.0M\tB\n1.0G\tC\n1.0T\tD\n' du -Ah A B C D
116319850Sngie}
117319850Sngie
118319850Sngieatf_test_case k_flag
119319850Sngiek_flag_head()
120319850Sngie{
121319850Sngie	atf_set "descr" "Verify -k output"
122319850Sngie}
123319850Sngiek_flag_body()
124319850Sngie{
125319850Sngie	atf_check truncate -s 1k A
126319850Sngie	atf_check truncate -s 1m B
127319850Sngie	atf_check -o inline:'1\tA\n1024\tB\n' du -Ak A B
128319850Sngie}
129319850Sngie
130319850Sngieatf_test_case m_flag
131319850Sngiem_flag_head()
132319850Sngie{
133319850Sngie	atf_set "descr" "Verify -m output"
134319850Sngie}
135319850Sngiem_flag_body()
136319850Sngie{
137319850Sngie	atf_check truncate -s 1k A
138319850Sngie	atf_check truncate -s 1m B
139319850Sngie	atf_check truncate -s 1g C
140319850Sngie	atf_check -o inline:'1\tA\n1\tB\n1024\tC\n' du -Am A B C
141319850Sngie}
142319850Sngie
143328139Skevansatf_test_case si_flag
144328139Skevanssi_flag_head()
145328139Skevans{
146328139Skevans	atf_set "descr" "Verify --si output"
147328139Skevans}
148328139Skevanssi_flag_body()
149328139Skevans{
150328139Skevans	atf_check truncate -s 1500000 A
151328139Skevans	atf_check truncate -s 1572864 B
152328139Skevans
153328139Skevans	atf_check -o inline:'1.4M\tA\n1.5M\tB\n' du -Ah A B
154328139Skevans	atf_check -o inline:'1.5M\tA\n1.6M\tB\n' du -A --si A B
155328139Skevans}
156328139Skevans
157319850Sngieatf_init_test_cases()
158319850Sngie{
159319850Sngie	atf_add_test_case A_flag
160319850Sngie	atf_add_test_case H_flag
161319850Sngie	atf_add_test_case I_flag
162319850Sngie	atf_add_test_case g_flag
163319850Sngie	atf_add_test_case h_flag
164319850Sngie	atf_add_test_case k_flag
165319850Sngie	atf_add_test_case m_flag
166328139Skevans	atf_add_test_case si_flag
167319850Sngie}
168