t_mtree.sh revision 1.4.2.3 1 1.4.2.3 yamt # $NetBSD: t_mtree.sh,v 1.4.2.3 2013/01/23 00:06:36 yamt Exp $
2 1.4.2.2 yamt #
3 1.4.2.2 yamt # Copyright (c) 2009, 2012 The NetBSD Foundation, Inc.
4 1.4.2.2 yamt # All rights reserved.
5 1.4.2.2 yamt #
6 1.4.2.2 yamt # Redistribution and use in source and binary forms, with or without
7 1.4.2.2 yamt # modification, are permitted provided that the following conditions
8 1.4.2.2 yamt # are met:
9 1.4.2.2 yamt # 1. Redistributions of source code must retain the above copyright
10 1.4.2.2 yamt # notice, this list of conditions and the following disclaimer.
11 1.4.2.2 yamt # 2. Redistributions in binary form must reproduce the above copyright
12 1.4.2.2 yamt # notice, this list of conditions and the following disclaimer in the
13 1.4.2.2 yamt # documentation and/or other materials provided with the distribution.
14 1.4.2.2 yamt #
15 1.4.2.2 yamt # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 1.4.2.2 yamt # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 1.4.2.2 yamt # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 1.4.2.2 yamt # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 1.4.2.2 yamt # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 1.4.2.2 yamt # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 1.4.2.2 yamt # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 1.4.2.2 yamt # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.4.2.2 yamt # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 1.4.2.2 yamt # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.4.2.2 yamt # POSSIBILITY OF SUCH DAMAGE.
26 1.4.2.2 yamt #
27 1.4.2.2 yamt
28 1.4.2.2 yamt # Postprocess mtree output, canonicalising portions that
29 1.4.2.2 yamt # are expected to differ from one run to another.
30 1.4.2.2 yamt #
31 1.4.2.3 yamt
32 1.4.2.2 yamt h_postprocess()
33 1.4.2.2 yamt {
34 1.4.2.2 yamt sed -e '
35 1.4.2.2 yamt /^# user: /s/:.*/: x/
36 1.4.2.2 yamt /^# machine: /s/:.*/: x/
37 1.4.2.2 yamt /^# tree: /s/:.*/: x/
38 1.4.2.2 yamt /^# date: /s/:.*/: x/
39 1.4.2.2 yamt '
40 1.4.2.2 yamt }
41 1.4.2.2 yamt
42 1.4.2.2 yamt h_check()
43 1.4.2.2 yamt {
44 1.4.2.2 yamt diff -Nru "$1" "$2" || atf_fail "files $1 and $2 differ"
45 1.4.2.2 yamt }
46 1.4.2.2 yamt
47 1.4.2.3 yamt
48 1.4.2.3 yamt atf_test_case mtree_create
49 1.4.2.3 yamt atf_test_case netbsd6_create
50 1.4.2.2 yamt create_head()
51 1.4.2.2 yamt {
52 1.4.2.2 yamt atf_set "descr" "Create a specfile describing a directory tree"
53 1.4.2.2 yamt }
54 1.4.2.2 yamt
55 1.4.2.2 yamt create_setup()
56 1.4.2.2 yamt {
57 1.4.2.2 yamt # create some directories
58 1.4.2.3 yamt rm -fr create
59 1.4.2.2 yamt mkdir -p create/a/1 create/a/2 create/b
60 1.4.2.2 yamt # create some files
61 1.4.2.2 yamt for file in create/top.file.1 \
62 1.4.2.2 yamt create/a/a.file.1 \
63 1.4.2.2 yamt create/a/a.file.2 \
64 1.4.2.2 yamt create/a/1/a1.file.1 \
65 1.4.2.2 yamt create/b/b.file.1 \
66 1.4.2.2 yamt create/b/b.file.2
67 1.4.2.2 yamt do
68 1.4.2.2 yamt echo "$file" >$file
69 1.4.2.2 yamt done
70 1.4.2.2 yamt # hard link to file in same dir
71 1.4.2.2 yamt ln create/b/b.file.1 create/b/b.hardlink.1
72 1.4.2.2 yamt # hard link to file in another dir
73 1.4.2.2 yamt ln create/b/b.file.2 create/a/a.hardlink.b2
74 1.4.2.2 yamt # symlink to file
75 1.4.2.2 yamt ln -s a.file.1 create/a.symlink.1
76 1.4.2.2 yamt # symlink to dir
77 1.4.2.2 yamt ln -s b create/top.symlink.b
78 1.4.2.2 yamt # dangling symlink
79 1.4.2.2 yamt ln -s nonexistent create/top.dangling
80 1.4.2.2 yamt }
81 1.4.2.2 yamt
82 1.4.2.2 yamt create_body()
83 1.4.2.2 yamt {
84 1.4.2.2 yamt create_setup
85 1.4.2.2 yamt
86 1.4.2.2 yamt # run mtree and check output
87 1.4.2.3 yamt ( cd create && mtree -F ${FLAVOR} -c -k type,nlink,link,size,sha256 ) >output.raw \
88 1.4.2.2 yamt || atf_fail "mtree exit status $?"
89 1.4.2.2 yamt h_postprocess <output.raw >output
90 1.4.2.3 yamt h_check "$(atf_get_srcdir)/${FLAVOR}_d_create.out" output
91 1.4.2.3 yamt }
92 1.4.2.3 yamt
93 1.4.2.3 yamt mtree_create_head()
94 1.4.2.3 yamt {
95 1.4.2.3 yamt FLAVOR=mtree create_head
96 1.4.2.3 yamt }
97 1.4.2.3 yamt netbsd6_create_head()
98 1.4.2.3 yamt {
99 1.4.2.3 yamt FLAVOR=netbsd6 create_head
100 1.4.2.2 yamt }
101 1.4.2.2 yamt
102 1.4.2.3 yamt mtree_create_body()
103 1.4.2.3 yamt {
104 1.4.2.3 yamt FLAVOR=mtree create_body
105 1.4.2.3 yamt }
106 1.4.2.3 yamt netbsd6_create_body()
107 1.4.2.3 yamt {
108 1.4.2.3 yamt FLAVOR=netbsd6 create_body
109 1.4.2.3 yamt }
110 1.4.2.3 yamt
111 1.4.2.3 yamt
112 1.4.2.3 yamt atf_test_case mtree_check
113 1.4.2.3 yamt atf_test_case netbsd6_check
114 1.4.2.2 yamt check_head()
115 1.4.2.2 yamt {
116 1.4.2.2 yamt atf_set "descr" "Check a directory tree against a specfile"
117 1.4.2.2 yamt }
118 1.4.2.2 yamt
119 1.4.2.2 yamt check_body()
120 1.4.2.2 yamt {
121 1.4.2.2 yamt # we use the same directory tree and specfile as in the "create" test
122 1.4.2.2 yamt create_setup
123 1.4.2.2 yamt
124 1.4.2.2 yamt # run mtree and check output
125 1.4.2.3 yamt ( cd create && mtree -F ${FLAVOR} ) <"$(atf_get_srcdir)/${FLAVOR}_d_create.out" >output \
126 1.4.2.2 yamt || atf_fail "mtree exit status $?"
127 1.4.2.2 yamt h_check /dev/null output
128 1.4.2.2 yamt }
129 1.4.2.2 yamt
130 1.4.2.3 yamt mtree_check_head()
131 1.4.2.3 yamt {
132 1.4.2.3 yamt FLAVOR=mtree check_head
133 1.4.2.3 yamt }
134 1.4.2.3 yamt netbsd6_check_head()
135 1.4.2.3 yamt {
136 1.4.2.3 yamt FLAVOR=netbsd6 check_head
137 1.4.2.3 yamt }
138 1.4.2.3 yamt
139 1.4.2.3 yamt mtree_check_body()
140 1.4.2.3 yamt {
141 1.4.2.3 yamt FLAVOR=mtree check_body
142 1.4.2.3 yamt }
143 1.4.2.3 yamt netbsd6_check_body()
144 1.4.2.3 yamt {
145 1.4.2.3 yamt FLAVOR=netbsd6 check_body
146 1.4.2.3 yamt }
147 1.4.2.3 yamt
148 1.4.2.3 yamt
149 1.4.2.3 yamt atf_test_case mtree_convert_C
150 1.4.2.3 yamt atf_test_case netbsd6_convert_C
151 1.4.2.2 yamt convert_C_head()
152 1.4.2.2 yamt {
153 1.4.2.2 yamt atf_set "descr" "Convert a specfile to mtree -C format, unsorted"
154 1.4.2.2 yamt }
155 1.4.2.2 yamt
156 1.4.2.2 yamt convert_C_body()
157 1.4.2.2 yamt {
158 1.4.2.3 yamt mtree -F ${FLAVOR} -C -K all <"$(atf_get_srcdir)/d_convert.in" >output
159 1.4.2.2 yamt h_check "$(atf_get_srcdir)/d_convert_C.out" output
160 1.4.2.2 yamt }
161 1.4.2.2 yamt
162 1.4.2.3 yamt mtree_convert_C_head()
163 1.4.2.3 yamt {
164 1.4.2.3 yamt FLAVOR=mtree convert_C_head
165 1.4.2.3 yamt }
166 1.4.2.3 yamt netbsd6_convert_C_head()
167 1.4.2.3 yamt {
168 1.4.2.3 yamt FLAVOR=netbsd6 convert_C_head
169 1.4.2.3 yamt }
170 1.4.2.3 yamt
171 1.4.2.3 yamt mtree_convert_C_body()
172 1.4.2.3 yamt {
173 1.4.2.3 yamt FLAVOR=mtree convert_C_body
174 1.4.2.3 yamt }
175 1.4.2.3 yamt netbsd6_convert_C_body()
176 1.4.2.3 yamt {
177 1.4.2.3 yamt FLAVOR=netbsd6 convert_C_body
178 1.4.2.3 yamt }
179 1.4.2.3 yamt
180 1.4.2.3 yamt
181 1.4.2.3 yamt atf_test_case mtree_convert_C_S
182 1.4.2.3 yamt atf_test_case netbsd6_convert_C_S
183 1.4.2.2 yamt convert_C_S_head()
184 1.4.2.2 yamt {
185 1.4.2.2 yamt atf_set "descr" "Convert a specfile to mtree -C format, sorted"
186 1.4.2.2 yamt }
187 1.4.2.2 yamt
188 1.4.2.2 yamt convert_C_S_body()
189 1.4.2.2 yamt {
190 1.4.2.3 yamt mtree -F ${FLAVOR} -C -S -K all <"$(atf_get_srcdir)/d_convert.in" >output
191 1.4.2.2 yamt h_check "$(atf_get_srcdir)/d_convert_C_S.out" output
192 1.4.2.2 yamt }
193 1.4.2.2 yamt
194 1.4.2.3 yamt mtree_convert_C_S_head()
195 1.4.2.3 yamt {
196 1.4.2.3 yamt FLAVOR=mtree convert_C_S_head
197 1.4.2.3 yamt }
198 1.4.2.3 yamt netbsd6_convert_C_S_head()
199 1.4.2.3 yamt {
200 1.4.2.3 yamt FLAVOR=netbsd6 convert_C_S_head
201 1.4.2.3 yamt }
202 1.4.2.3 yamt
203 1.4.2.3 yamt mtree_convert_C_S_body()
204 1.4.2.3 yamt {
205 1.4.2.3 yamt FLAVOR=mtree convert_C_S_body
206 1.4.2.3 yamt }
207 1.4.2.3 yamt netbsd6_convert_C_S_body()
208 1.4.2.3 yamt {
209 1.4.2.3 yamt FLAVOR=netbsd6 convert_C_S_body
210 1.4.2.3 yamt }
211 1.4.2.3 yamt
212 1.4.2.3 yamt
213 1.4.2.3 yamt atf_test_case mtree_convert_D
214 1.4.2.3 yamt atf_test_case netbsd6_convert_D
215 1.4.2.2 yamt convert_D_head()
216 1.4.2.2 yamt {
217 1.4.2.2 yamt atf_set "descr" "Convert a specfile to mtree -D format, unsorted"
218 1.4.2.2 yamt }
219 1.4.2.2 yamt
220 1.4.2.2 yamt convert_D_body()
221 1.4.2.2 yamt {
222 1.4.2.3 yamt mtree -F ${FLAVOR} -D -K all <"$(atf_get_srcdir)/d_convert.in" >output
223 1.4.2.2 yamt h_check "$(atf_get_srcdir)/d_convert_D.out" output
224 1.4.2.2 yamt }
225 1.4.2.2 yamt
226 1.4.2.3 yamt mtree_convert_D_head()
227 1.4.2.3 yamt {
228 1.4.2.3 yamt FLAVOR=mtree convert_D_head
229 1.4.2.3 yamt }
230 1.4.2.3 yamt netbsd6_convert_D_head()
231 1.4.2.3 yamt {
232 1.4.2.3 yamt FLAVOR=netbsd6 convert_D_head
233 1.4.2.3 yamt }
234 1.4.2.3 yamt
235 1.4.2.3 yamt mtree_convert_D_body()
236 1.4.2.3 yamt {
237 1.4.2.3 yamt FLAVOR=mtree convert_D_body
238 1.4.2.3 yamt }
239 1.4.2.3 yamt netbsd6_convert_D_body()
240 1.4.2.3 yamt {
241 1.4.2.3 yamt FLAVOR=netbsd6 convert_D_body
242 1.4.2.3 yamt }
243 1.4.2.3 yamt
244 1.4.2.3 yamt
245 1.4.2.3 yamt atf_test_case mtree_convert_D_S
246 1.4.2.3 yamt atf_test_case netbsd6_convert_D_S
247 1.4.2.2 yamt convert_D_S_head()
248 1.4.2.2 yamt {
249 1.4.2.2 yamt atf_set "descr" "Convert a specfile to mtree -D format, sorted"
250 1.4.2.2 yamt }
251 1.4.2.2 yamt
252 1.4.2.2 yamt convert_D_S_body()
253 1.4.2.2 yamt {
254 1.4.2.3 yamt mtree -F ${FLAVOR} -D -S -K all <"$(atf_get_srcdir)/d_convert.in" >output
255 1.4.2.2 yamt h_check "$(atf_get_srcdir)/d_convert_D_S.out" output
256 1.4.2.2 yamt }
257 1.4.2.2 yamt
258 1.4.2.3 yamt mtree_convert_D_S_head()
259 1.4.2.3 yamt {
260 1.4.2.3 yamt FLAVOR=mtree convert_D_S_head
261 1.4.2.3 yamt }
262 1.4.2.3 yamt netbsd6_convert_D_S_head()
263 1.4.2.3 yamt {
264 1.4.2.3 yamt FLAVOR=netbsd6 convert_D_S_head
265 1.4.2.3 yamt }
266 1.4.2.3 yamt
267 1.4.2.3 yamt mtree_convert_D_S_body()
268 1.4.2.3 yamt {
269 1.4.2.3 yamt FLAVOR=mtree convert_D_S_body
270 1.4.2.3 yamt }
271 1.4.2.3 yamt netbsd6_convert_D_S_body()
272 1.4.2.3 yamt {
273 1.4.2.3 yamt FLAVOR=netbsd6 convert_D_S_body
274 1.4.2.3 yamt }
275 1.4.2.3 yamt
276 1.4.2.3 yamt
277 1.4.2.3 yamt atf_test_case mtree_ignore
278 1.4.2.3 yamt atf_test_case netbs6_ignore
279 1.4.2.2 yamt ignore_head()
280 1.4.2.2 yamt {
281 1.4.2.2 yamt atf_set "descr" "Test that -d ignores symlinks (PR bin/41061)"
282 1.4.2.2 yamt }
283 1.4.2.2 yamt
284 1.4.2.2 yamt ignore_body()
285 1.4.2.2 yamt {
286 1.4.2.2 yamt mkdir newdir
287 1.4.2.3 yamt mtree -F ${FLAVOR} -c | mtree -F ${FLAVOR} -Ck uid,gid,mode > mtree.spec
288 1.4.2.2 yamt ln -s newdir otherdir
289 1.4.2.2 yamt
290 1.4.2.2 yamt # This yields "extra: otherdir" even with -d.
291 1.4.2.2 yamt # (PR bin/41061)
292 1.4.2.3 yamt atf_check -s ignore -o empty -e empty -x "mtree -F ${FLAVOR} -d < mtree.spec"
293 1.4.2.2 yamt
294 1.4.2.2 yamt # Delete the symlink and re-verify.
295 1.4.2.2 yamt #
296 1.4.2.2 yamt rm otherdir
297 1.4.2.3 yamt atf_check -s ignore -o empty -e empty -x "mtree -F ${FLAVOR} -d < mtree.spec"
298 1.4.2.3 yamt }
299 1.4.2.3 yamt
300 1.4.2.3 yamt mtree_ignore_head()
301 1.4.2.3 yamt {
302 1.4.2.3 yamt FLAVOR=mtree ignore_head
303 1.4.2.3 yamt }
304 1.4.2.3 yamt netbsd6_ignore_head()
305 1.4.2.3 yamt {
306 1.4.2.3 yamt FLAVOR=netbsd6 ignore_head
307 1.4.2.3 yamt }
308 1.4.2.3 yamt
309 1.4.2.3 yamt mtree_ignore_body()
310 1.4.2.3 yamt {
311 1.4.2.3 yamt FLAVOR=mtree ignore_body
312 1.4.2.3 yamt }
313 1.4.2.3 yamt netbsd6_ignore_body()
314 1.4.2.3 yamt {
315 1.4.2.3 yamt FLAVOR=netbsd6 ignore_body
316 1.4.2.2 yamt }
317 1.4.2.2 yamt
318 1.4.2.3 yamt
319 1.4.2.3 yamt atf_test_case mtree_merge
320 1.4.2.3 yamt atf_test_case netbsd6_merge
321 1.4.2.2 yamt merge_head()
322 1.4.2.2 yamt {
323 1.4.2.2 yamt atf_set "descr" "Merge records of different type"
324 1.4.2.2 yamt }
325 1.4.2.2 yamt
326 1.4.2.2 yamt merge_body()
327 1.4.2.2 yamt {
328 1.4.2.3 yamt mtree -F ${FLAVOR} -C -M -K all <"$(atf_get_srcdir)/d_merge.in" >output
329 1.4.2.2 yamt h_check "$(atf_get_srcdir)/d_merge_C_M.out" output
330 1.4.2.2 yamt # same again, with sorting
331 1.4.2.3 yamt mtree -F ${FLAVOR} -C -M -S -K all <"$(atf_get_srcdir)/d_merge.in" >output
332 1.4.2.2 yamt h_check "$(atf_get_srcdir)/d_merge_C_M_S.out" output
333 1.4.2.2 yamt }
334 1.4.2.2 yamt
335 1.4.2.3 yamt mtree_merge_head()
336 1.4.2.3 yamt {
337 1.4.2.3 yamt FLAVOR=mtree merge_head
338 1.4.2.3 yamt }
339 1.4.2.3 yamt netbsd6_merge_head()
340 1.4.2.3 yamt {
341 1.4.2.3 yamt FLAVOR=netbsd6 merge_head
342 1.4.2.3 yamt }
343 1.4.2.3 yamt
344 1.4.2.3 yamt mtree_merge_body()
345 1.4.2.3 yamt {
346 1.4.2.3 yamt FLAVOR=mtree merge_body
347 1.4.2.3 yamt }
348 1.4.2.3 yamt netbsd6_merge_body()
349 1.4.2.3 yamt {
350 1.4.2.3 yamt FLAVOR=netbsd6 merge_body
351 1.4.2.3 yamt }
352 1.4.2.3 yamt
353 1.4.2.3 yamt
354 1.4.2.3 yamt atf_test_case mtree_nonemptydir
355 1.4.2.3 yamt atf_test_case netbsd6_nonemptydir
356 1.4.2.2 yamt nonemptydir_head()
357 1.4.2.2 yamt {
358 1.4.2.2 yamt atf_set "descr" "Test that new non-empty " \
359 1.4.2.2 yamt "directories are recorded (PR bin/25693)"
360 1.4.2.2 yamt }
361 1.4.2.2 yamt
362 1.4.2.2 yamt nonemptydir_body()
363 1.4.2.2 yamt {
364 1.4.2.2 yamt mkdir testdir
365 1.4.2.2 yamt cd testdir
366 1.4.2.2 yamt
367 1.4.2.3 yamt mtree -F ${FLAVOR} -c > mtree.spec
368 1.4.2.2 yamt
369 1.4.2.2 yamt if [ ! -f mtree.spec ]; then
370 1.4.2.2 yamt atf_fail "mtree failed"
371 1.4.2.2 yamt fi
372 1.4.2.2 yamt
373 1.4.2.2 yamt touch bar
374 1.4.2.3 yamt atf_check -s ignore -o save:output -x "mtree -F ${FLAVOR} -f mtree.spec"
375 1.4.2.2 yamt
376 1.4.2.2 yamt if [ ! -n "$(egrep "extra: bar" output)" ]; then
377 1.4.2.2 yamt atf_fail "mtree did not record changes (PR bin/25693)"
378 1.4.2.2 yamt fi
379 1.4.2.2 yamt }
380 1.4.2.2 yamt
381 1.4.2.3 yamt mtree_nonemptydir_head()
382 1.4.2.3 yamt {
383 1.4.2.3 yamt FLAVOR=mtree nonemptydir_head
384 1.4.2.3 yamt }
385 1.4.2.3 yamt netbsd6_nonemptydir_head()
386 1.4.2.3 yamt {
387 1.4.2.3 yamt FLAVOR=netbsd6 nonemptydir_head
388 1.4.2.3 yamt }
389 1.4.2.3 yamt
390 1.4.2.3 yamt mtree_nonemptydir_body()
391 1.4.2.3 yamt {
392 1.4.2.3 yamt FLAVOR=mtree nonemptydir_body
393 1.4.2.3 yamt }
394 1.4.2.3 yamt netbsd6_nonemptydir_body()
395 1.4.2.3 yamt {
396 1.4.2.3 yamt FLAVOR=netbsd6 nonemptydir_body
397 1.4.2.3 yamt }
398 1.4.2.3 yamt
399 1.4.2.3 yamt
400 1.4.2.2 yamt atf_init_test_cases()
401 1.4.2.2 yamt {
402 1.4.2.3 yamt atf_add_test_case mtree_create
403 1.4.2.3 yamt atf_add_test_case mtree_check
404 1.4.2.3 yamt atf_add_test_case mtree_convert_C
405 1.4.2.3 yamt atf_add_test_case mtree_convert_C_S
406 1.4.2.3 yamt atf_add_test_case mtree_convert_D
407 1.4.2.3 yamt atf_add_test_case mtree_convert_D_S
408 1.4.2.3 yamt atf_add_test_case mtree_ignore
409 1.4.2.3 yamt atf_add_test_case mtree_merge
410 1.4.2.3 yamt atf_add_test_case mtree_nonemptydir
411 1.4.2.3 yamt
412 1.4.2.3 yamt atf_add_test_case netbsd6_create
413 1.4.2.3 yamt atf_add_test_case netbsd6_check
414 1.4.2.3 yamt atf_add_test_case netbsd6_convert_C
415 1.4.2.3 yamt atf_add_test_case netbsd6_convert_C_S
416 1.4.2.3 yamt atf_add_test_case netbsd6_convert_D
417 1.4.2.3 yamt atf_add_test_case netbsd6_convert_D_S
418 1.4.2.3 yamt atf_add_test_case netbsd6_ignore
419 1.4.2.3 yamt atf_add_test_case netbsd6_merge
420 1.4.2.3 yamt atf_add_test_case netbsd6_nonemptydir
421 1.4.2.2 yamt }
422