1 # $NetBSD: t_mtree.sh,v 1.6 2013/02/05 16:49:42 christos Exp $
3 # Copyright (c) 2009, 2012 The NetBSD Foundation, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
28 # Postprocess mtree output, canonicalising portions that
29 # are expected to differ from one run to another.
32 # mtree is not in the default user PATH on MINIX
33 export PATH
=$PATH:/usr
/sbin
39 /^# machine: /s/:.*/: x/
43 -e '/type=dir/s/ size=[0-9]*//'
48 diff -Nru "$1" "$2" || atf_fail
"files $1 and $2 differ"
52 atf_test_case mtree_create
53 atf_test_case netbsd6_create
56 atf_set
"descr" "Create a specfile describing a directory tree"
61 # create some directories
63 mkdir
-p create
/a
/1 create
/a
/2 create
/b
65 for file in create
/top.
file.1 \
68 create
/a
/1/a1.
file.1 \
74 # hard link to file in same dir
75 ln create
/b
/b.
file.1 create
/b
/b.hardlink
.1
76 # hard link to file in another dir
77 ln create
/b
/b.
file.2 create
/a
/a.hardlink.b2
79 ln -s a.
file.1 create
/a.symlink
.1
81 ln -s b create
/top.symlink.b
83 ln -s nonexistent create
/top.dangling
90 # run mtree and check output
91 ( cd create
&& mtree
-F ${FLAVOR} -c -k type,nlink
,link
,size
,sha256
) >output.raw \
92 || atf_fail
"mtree exit status $?"
93 h_postprocess
<output.raw
>output
94 h_check
"$(atf_get_srcdir)/${FLAVOR}_d_create.out" output
99 FLAVOR
=mtree create_head
101 netbsd6_create_head
()
103 FLAVOR
=netbsd6 create_head
108 FLAVOR
=mtree create_body
110 netbsd6_create_body
()
112 FLAVOR
=netbsd6 create_body
116 atf_test_case mtree_check
117 atf_test_case netbsd6_check
120 atf_set
"descr" "Check a directory tree against a specfile"
125 # we use the same directory tree and specfile as in the "create" test
128 # run mtree and check output
129 ( cd create
&& mtree
-F ${FLAVOR} ) <"$(atf_get_srcdir)/${FLAVOR}_d_create.out" >output \
130 || atf_fail
"mtree exit status $?"
131 h_check
/dev
/null output
136 FLAVOR
=mtree check_head
140 FLAVOR
=netbsd6 check_head
145 FLAVOR
=mtree check_body
149 FLAVOR
=netbsd6 check_body
153 atf_test_case mtree_convert_C
154 atf_test_case netbsd6_convert_C
157 atf_set
"descr" "Convert a specfile to mtree -C format, unsorted"
162 mtree
-F ${FLAVOR} -C -K all
<"$(atf_get_srcdir)/d_convert.in" >output
163 h_check
"$(atf_get_srcdir)/d_convert_C.out" output
166 mtree_convert_C_head
()
168 FLAVOR
=mtree convert_C_head
170 netbsd6_convert_C_head
()
172 FLAVOR
=netbsd6 convert_C_head
175 mtree_convert_C_body
()
177 FLAVOR
=mtree convert_C_body
179 netbsd6_convert_C_body
()
181 FLAVOR
=netbsd6 convert_C_body
185 atf_test_case mtree_convert_C_S
186 atf_test_case netbsd6_convert_C_S
189 atf_set
"descr" "Convert a specfile to mtree -C format, sorted"
194 mtree
-F ${FLAVOR} -C -S -K all
<"$(atf_get_srcdir)/d_convert.in" >output
195 h_check
"$(atf_get_srcdir)/d_convert_C_S.out" output
198 mtree_convert_C_S_head
()
200 FLAVOR
=mtree convert_C_S_head
202 netbsd6_convert_C_S_head
()
204 FLAVOR
=netbsd6 convert_C_S_head
207 mtree_convert_C_S_body
()
209 FLAVOR
=mtree convert_C_S_body
211 netbsd6_convert_C_S_body
()
213 FLAVOR
=netbsd6 convert_C_S_body
217 atf_test_case mtree_convert_D
218 atf_test_case netbsd6_convert_D
221 atf_set
"descr" "Convert a specfile to mtree -D format, unsorted"
226 mtree
-F ${FLAVOR} -D -K all
<"$(atf_get_srcdir)/d_convert.in" >output
227 h_check
"$(atf_get_srcdir)/d_convert_D.out" output
230 mtree_convert_D_head
()
232 FLAVOR
=mtree convert_D_head
234 netbsd6_convert_D_head
()
236 FLAVOR
=netbsd6 convert_D_head
239 mtree_convert_D_body
()
241 FLAVOR
=mtree convert_D_body
243 netbsd6_convert_D_body
()
245 FLAVOR
=netbsd6 convert_D_body
249 atf_test_case mtree_convert_D_S
250 atf_test_case netbsd6_convert_D_S
253 atf_set
"descr" "Convert a specfile to mtree -D format, sorted"
258 mtree
-F ${FLAVOR} -D -S -K all
<"$(atf_get_srcdir)/d_convert.in" >output
259 h_check
"$(atf_get_srcdir)/d_convert_D_S.out" output
262 mtree_convert_D_S_head
()
264 FLAVOR
=mtree convert_D_S_head
266 netbsd6_convert_D_S_head
()
268 FLAVOR
=netbsd6 convert_D_S_head
271 mtree_convert_D_S_body
()
273 FLAVOR
=mtree convert_D_S_body
275 netbsd6_convert_D_S_body
()
277 FLAVOR
=netbsd6 convert_D_S_body
281 atf_test_case mtree_ignore
282 atf_test_case netbs6_ignore
285 atf_set
"descr" "Test that -d ignores symlinks (PR bin/41061)"
291 mtree
-F ${FLAVOR} -c | mtree
-F ${FLAVOR} -Ck uid
,gid
,mode
> mtree.spec
292 ln -s newdir otherdir
294 # This yields "extra: otherdir" even with -d.
296 atf_check
-s ignore
-o empty
-e empty
-x "mtree -F ${FLAVOR} -d < mtree.spec"
298 # Delete the symlink and re-verify.
301 atf_check
-s ignore
-o empty
-e empty
-x "mtree -F ${FLAVOR} -d < mtree.spec"
306 FLAVOR
=mtree ignore_head
308 netbsd6_ignore_head
()
310 FLAVOR
=netbsd6 ignore_head
315 FLAVOR
=mtree ignore_body
317 netbsd6_ignore_body
()
319 FLAVOR
=netbsd6 ignore_body
323 atf_test_case mtree_merge
324 atf_test_case netbsd6_merge
327 atf_set
"descr" "Merge records of different type"
332 mtree
-F ${FLAVOR} -C -M -K all
<"$(atf_get_srcdir)/d_merge.in" >output
333 h_check
"$(atf_get_srcdir)/d_merge_C_M.out" output
334 # same again, with sorting
335 mtree
-F ${FLAVOR} -C -M -S -K all
<"$(atf_get_srcdir)/d_merge.in" >output
336 h_check
"$(atf_get_srcdir)/d_merge_C_M_S.out" output
341 FLAVOR
=mtree merge_head
345 FLAVOR
=netbsd6 merge_head
350 FLAVOR
=mtree merge_body
354 FLAVOR
=netbsd6 merge_body
358 atf_test_case mtree_nonemptydir
359 atf_test_case netbsd6_nonemptydir
362 atf_set
"descr" "Test that new non-empty " \
363 "directories are recorded (PR bin/25693)"
371 mtree
-F ${FLAVOR} -c > mtree.spec
373 if [ ! -f mtree.spec
]; then
374 atf_fail
"mtree failed"
378 atf_check
-s ignore
-o save
:output
-x "mtree -F ${FLAVOR} -f mtree.spec"
380 if [ ! -n "$(egrep "extra
: bar
" output)" ]; then
381 atf_fail
"mtree did not record changes (PR bin/25693)"
385 mtree_nonemptydir_head
()
387 FLAVOR
=mtree nonemptydir_head
389 netbsd6_nonemptydir_head
()
391 FLAVOR
=netbsd6 nonemptydir_head
394 mtree_nonemptydir_body
()
396 FLAVOR
=mtree nonemptydir_body
398 netbsd6_nonemptydir_body
()
400 FLAVOR
=netbsd6 nonemptydir_body
404 atf_init_test_cases
()
406 atf_add_test_case mtree_create
407 atf_add_test_case mtree_check
408 atf_add_test_case mtree_convert_C
409 atf_add_test_case mtree_convert_C_S
410 atf_add_test_case mtree_convert_D
411 atf_add_test_case mtree_convert_D_S
412 atf_add_test_case mtree_ignore
413 atf_add_test_case mtree_merge
414 atf_add_test_case mtree_nonemptydir
416 atf_add_test_case netbsd6_create
417 atf_add_test_case netbsd6_check
418 atf_add_test_case netbsd6_convert_C
419 atf_add_test_case netbsd6_convert_C_S
420 atf_add_test_case netbsd6_convert_D
421 atf_add_test_case netbsd6_convert_D_S
422 atf_add_test_case netbsd6_ignore
423 atf_add_test_case netbsd6_merge
424 atf_add_test_case netbsd6_nonemptydir