t_mtree.sh revision 1.3 1 1.3 jruoho # $NetBSD: t_mtree.sh,v 1.3 2012/03/19 06:39:22 jruoho Exp $
2 1.1 jruoho #
3 1.3 jruoho # Copyright (c) 2009, 2012 The NetBSD Foundation, Inc.
4 1.1 jruoho # All rights reserved.
5 1.1 jruoho #
6 1.1 jruoho # Redistribution and use in source and binary forms, with or without
7 1.1 jruoho # modification, are permitted provided that the following conditions
8 1.1 jruoho # are met:
9 1.1 jruoho # 1. Redistributions of source code must retain the above copyright
10 1.1 jruoho # notice, this list of conditions and the following disclaimer.
11 1.1 jruoho # 2. Redistributions in binary form must reproduce the above copyright
12 1.1 jruoho # notice, this list of conditions and the following disclaimer in the
13 1.1 jruoho # documentation and/or other materials provided with the distribution.
14 1.1 jruoho #
15 1.1 jruoho # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 1.1 jruoho # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 1.1 jruoho # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 1.1 jruoho # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 1.1 jruoho # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 1.1 jruoho # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 1.1 jruoho # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 1.1 jruoho # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.1 jruoho # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 1.1 jruoho # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.1 jruoho # POSSIBILITY OF SUCH DAMAGE.
26 1.1 jruoho #
27 1.1 jruoho
28 1.1 jruoho # Postprocess mtree output, canonicalising portions that
29 1.1 jruoho # are expected to differ from one run to another.
30 1.2 jruoho #
31 1.1 jruoho h_postprocess()
32 1.1 jruoho {
33 1.1 jruoho sed -e '
34 1.1 jruoho /^# user: /s/:.*/: x/
35 1.1 jruoho /^# machine: /s/:.*/: x/
36 1.1 jruoho /^# tree: /s/:.*/: x/
37 1.1 jruoho /^# date: /s/:.*/: x/
38 1.1 jruoho '
39 1.1 jruoho }
40 1.1 jruoho
41 1.1 jruoho h_check()
42 1.1 jruoho {
43 1.1 jruoho diff -Nru "$1" "$2" || atf_fail "files $1 and $2 differ"
44 1.1 jruoho }
45 1.1 jruoho
46 1.1 jruoho atf_test_case create
47 1.1 jruoho create_head()
48 1.1 jruoho {
49 1.1 jruoho atf_set "descr" "Create a specfile describing a directory tree"
50 1.1 jruoho }
51 1.3 jruoho
52 1.1 jruoho create_setup()
53 1.1 jruoho {
54 1.1 jruoho # create some directories
55 1.1 jruoho mkdir -p create/a/1 create/a/2 create/b
56 1.1 jruoho # create some files
57 1.1 jruoho for file in create/top.file.1 \
58 1.1 jruoho create/a/a.file.1 \
59 1.1 jruoho create/a/a.file.2 \
60 1.1 jruoho create/a/1/a1.file.1 \
61 1.1 jruoho create/b/b.file.1 \
62 1.1 jruoho create/b/b.file.2
63 1.1 jruoho do
64 1.1 jruoho echo "$file" >$file
65 1.1 jruoho done
66 1.1 jruoho # hard link to file in same dir
67 1.1 jruoho ln create/b/b.file.1 create/b/b.hardlink.1
68 1.1 jruoho # hard link to file in another dir
69 1.1 jruoho ln create/b/b.file.2 create/a/a.hardlink.b2
70 1.1 jruoho # symlink to file
71 1.1 jruoho ln -s a.file.1 create/a.symlink.1
72 1.1 jruoho # symlink to dir
73 1.1 jruoho ln -s b create/top.symlink.b
74 1.1 jruoho # dangling symlink
75 1.1 jruoho ln -s nonexistent create/top.dangling
76 1.1 jruoho }
77 1.3 jruoho
78 1.1 jruoho create_body()
79 1.1 jruoho {
80 1.1 jruoho create_setup
81 1.1 jruoho
82 1.1 jruoho # run mtree and check output
83 1.1 jruoho ( cd create && mtree -c -k type,nlink,link,size,sha256 ) >output.raw \
84 1.1 jruoho || atf_fail "mtree exit status $?"
85 1.1 jruoho h_postprocess <output.raw >output
86 1.1 jruoho h_check "$(atf_get_srcdir)/d_create.out" output
87 1.1 jruoho }
88 1.1 jruoho
89 1.1 jruoho atf_test_case check
90 1.1 jruoho check_head()
91 1.1 jruoho {
92 1.1 jruoho atf_set "descr" "Check a directory tree against a specfile"
93 1.1 jruoho }
94 1.3 jruoho
95 1.1 jruoho check_body()
96 1.1 jruoho {
97 1.1 jruoho # we use the same directory tree and specfile as in the "create" test
98 1.1 jruoho create_setup
99 1.1 jruoho
100 1.1 jruoho # run mtree and check output
101 1.1 jruoho ( cd create && mtree ) <"$(atf_get_srcdir)/d_create.out" >output \
102 1.1 jruoho || atf_fail "mtree exit status $?"
103 1.1 jruoho h_check /dev/null output
104 1.1 jruoho }
105 1.1 jruoho
106 1.1 jruoho atf_test_case convert_C
107 1.1 jruoho convert_C_head()
108 1.1 jruoho {
109 1.1 jruoho atf_set "descr" "Convert a specfile to mtree -C format, unsorted"
110 1.1 jruoho }
111 1.3 jruoho
112 1.1 jruoho convert_C_body()
113 1.1 jruoho {
114 1.1 jruoho mtree -C -K all <"$(atf_get_srcdir)/d_convert.in" >output
115 1.1 jruoho h_check "$(atf_get_srcdir)/d_convert_C.out" output
116 1.1 jruoho }
117 1.1 jruoho
118 1.1 jruoho atf_test_case convert_C_S
119 1.1 jruoho convert_C_S_head()
120 1.1 jruoho {
121 1.1 jruoho atf_set "descr" "Convert a specfile to mtree -C format, sorted"
122 1.1 jruoho }
123 1.3 jruoho
124 1.1 jruoho convert_C_S_body()
125 1.1 jruoho {
126 1.1 jruoho mtree -C -S -K all <"$(atf_get_srcdir)/d_convert.in" >output
127 1.1 jruoho h_check "$(atf_get_srcdir)/d_convert_C_S.out" output
128 1.1 jruoho }
129 1.1 jruoho
130 1.1 jruoho atf_test_case convert_D
131 1.1 jruoho convert_D_head()
132 1.1 jruoho {
133 1.1 jruoho atf_set "descr" "Convert a specfile to mtree -D format, unsorted"
134 1.1 jruoho }
135 1.3 jruoho
136 1.1 jruoho convert_D_body()
137 1.1 jruoho {
138 1.1 jruoho mtree -D -K all <"$(atf_get_srcdir)/d_convert.in" >output
139 1.1 jruoho h_check "$(atf_get_srcdir)/d_convert_D.out" output
140 1.1 jruoho }
141 1.1 jruoho
142 1.1 jruoho atf_test_case convert_D_S
143 1.1 jruoho convert_D_S_head()
144 1.1 jruoho {
145 1.1 jruoho atf_set "descr" "Convert a specfile to mtree -D format, sorted"
146 1.1 jruoho }
147 1.3 jruoho
148 1.1 jruoho convert_D_S_body()
149 1.1 jruoho {
150 1.1 jruoho mtree -D -S -K all <"$(atf_get_srcdir)/d_convert.in" >output
151 1.1 jruoho h_check "$(atf_get_srcdir)/d_convert_D_S.out" output
152 1.1 jruoho }
153 1.1 jruoho
154 1.3 jruoho atf_test_case ignore
155 1.3 jruoho ignore_head()
156 1.3 jruoho {
157 1.3 jruoho atf_set "descr" "Test that -d ignores symlinks (PR bin/41061)"
158 1.3 jruoho }
159 1.3 jruoho
160 1.3 jruoho ignore_body()
161 1.3 jruoho {
162 1.3 jruoho mkdir newdir
163 1.3 jruoho mtree -c | mtree -Ck uid,gid,mode > mtree.spec
164 1.3 jruoho ln -s newdir otherdir
165 1.3 jruoho
166 1.3 jruoho # This yields "extra: otherdir" even with -d.
167 1.3 jruoho #
168 1.3 jruoho atf_expect_fail "PR bin/41061"
169 1.3 jruoho atf_check -s ignore -o empty -e empty -x "mtree -d < mtree.spec"
170 1.3 jruoho
171 1.3 jruoho # Delete the symlink and re-verify.
172 1.3 jruoho #
173 1.3 jruoho rm otherdir
174 1.3 jruoho atf_check -s ignore -o empty -e empty -x "mtree -d < mtree.spec"
175 1.3 jruoho }
176 1.3 jruoho
177 1.1 jruoho atf_test_case merge
178 1.1 jruoho merge_head()
179 1.1 jruoho {
180 1.1 jruoho atf_set "descr" "Merge records of different type"
181 1.1 jruoho }
182 1.3 jruoho
183 1.1 jruoho merge_body()
184 1.1 jruoho {
185 1.1 jruoho mtree -C -M -K all <"$(atf_get_srcdir)/d_merge.in" >output
186 1.1 jruoho h_check "$(atf_get_srcdir)/d_merge_C_M.out" output
187 1.1 jruoho # same again, with sorting
188 1.1 jruoho mtree -C -M -S -K all <"$(atf_get_srcdir)/d_merge.in" >output
189 1.1 jruoho h_check "$(atf_get_srcdir)/d_merge_C_M_S.out" output
190 1.1 jruoho }
191 1.1 jruoho
192 1.2 jruoho atf_test_case nonemptydir
193 1.3 jruoho nonemptydir_head()
194 1.3 jruoho {
195 1.2 jruoho atf_set "descr" "Test that new non-empty " \
196 1.2 jruoho "directories are recorded (PR bin/25693)"
197 1.2 jruoho }
198 1.2 jruoho
199 1.3 jruoho nonemptydir_body()
200 1.3 jruoho {
201 1.2 jruoho mkdir testdir
202 1.2 jruoho cd testdir
203 1.2 jruoho
204 1.2 jruoho mtree -c > mtree.spec
205 1.2 jruoho
206 1.2 jruoho if [ ! -f mtree.spec ]; then
207 1.2 jruoho atf_fail "mtree failed"
208 1.2 jruoho fi
209 1.2 jruoho
210 1.2 jruoho touch bar
211 1.2 jruoho atf_check -s ignore -o save:output -x "mtree -f mtree.spec"
212 1.2 jruoho
213 1.2 jruoho if [ ! -n "$(egrep "extra: bar" output)" ]; then
214 1.2 jruoho atf_fail "mtree did not record changes (PR bin/25693)"
215 1.2 jruoho fi
216 1.2 jruoho }
217 1.2 jruoho
218 1.1 jruoho atf_init_test_cases()
219 1.1 jruoho {
220 1.1 jruoho atf_add_test_case create
221 1.1 jruoho atf_add_test_case check
222 1.1 jruoho atf_add_test_case convert_C
223 1.1 jruoho atf_add_test_case convert_C_S
224 1.1 jruoho atf_add_test_case convert_D
225 1.1 jruoho atf_add_test_case convert_D_S
226 1.3 jruoho atf_add_test_case ignore
227 1.1 jruoho atf_add_test_case merge
228 1.2 jruoho atf_add_test_case nonemptydir
229 1.1 jruoho }
230