1 # $NetBSD: t_mtree.sh,v 1.7 2017/01/14 20:45:16 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.
36 /^# machine: /s/:.*/: x/
40 -e '/type=dir/s/ size=[0-9]*//'
45 diff -Nru "$1" "$2" || atf_fail "files $1 and $2 differ"
49 atf_test_case mtree_create
50 atf_test_case netbsd6_create
53 atf_set "descr" "Create a specfile describing a directory tree"
58 # create some directories
60 mkdir -p create/a/1 create/a/2 create/b
62 for file in create/top.file.1 \
65 create/a/1/a1.file.1 \
71 # hard link to file in same dir
72 ln create/b/b.file.1 create/b/b.hardlink.1
73 # hard link to file in another dir
74 ln create/b/b.file.2 create/a/a.hardlink.b2
76 ln -s a.file.1 create/a.symlink.1
78 ln -s b create/top.symlink.b
80 ln -s nonexistent create/top.dangling
87 # run mtree and check output
88 ( cd create && mtree -F ${FLAVOR} -c -k type,nlink,link,size,sha256 ) >output.raw \
89 || atf_fail "mtree exit status $?"
90 h_postprocess <output.raw >output
91 h_check "$(atf_get_srcdir)/${FLAVOR}_d_create.out" output
96 FLAVOR=mtree create_head
100 FLAVOR=netbsd6 create_head
105 FLAVOR=mtree create_body
107 netbsd6_create_body()
109 FLAVOR=netbsd6 create_body
113 atf_test_case mtree_check
114 atf_test_case netbsd6_check
117 atf_set "descr" "Check a directory tree against a specfile"
122 # we use the same directory tree and specfile as in the "create" test
125 # run mtree and check output
126 ( cd create && mtree -F ${FLAVOR} ) <"$(atf_get_srcdir)/${FLAVOR}_d_create.out" >output \
127 || atf_fail "mtree exit status $?"
128 h_check /dev/null output
133 FLAVOR=mtree check_head
137 FLAVOR=netbsd6 check_head
142 FLAVOR=mtree check_body
146 FLAVOR=netbsd6 check_body
150 atf_test_case mtree_convert_C
151 atf_test_case netbsd6_convert_C
154 atf_set "descr" "Convert a specfile to mtree -C format, unsorted"
159 mtree -F ${FLAVOR} -C -K all <"$(atf_get_srcdir)/d_convert.in" >output
160 h_check "$(atf_get_srcdir)/d_convert_C.out" output
163 mtree_convert_C_head()
165 FLAVOR=mtree convert_C_head
167 netbsd6_convert_C_head()
169 FLAVOR=netbsd6 convert_C_head
172 mtree_convert_C_body()
174 FLAVOR=mtree convert_C_body
176 netbsd6_convert_C_body()
178 FLAVOR=netbsd6 convert_C_body
182 atf_test_case mtree_convert_C_S
183 atf_test_case netbsd6_convert_C_S
186 atf_set "descr" "Convert a specfile to mtree -C format, sorted"
191 mtree -F ${FLAVOR} -C -S -K all <"$(atf_get_srcdir)/d_convert.in" >output
192 h_check "$(atf_get_srcdir)/d_convert_C_S.out" output
195 mtree_convert_C_S_head()
197 FLAVOR=mtree convert_C_S_head
199 netbsd6_convert_C_S_head()
201 FLAVOR=netbsd6 convert_C_S_head
204 mtree_convert_C_S_body()
206 FLAVOR=mtree convert_C_S_body
208 netbsd6_convert_C_S_body()
210 FLAVOR=netbsd6 convert_C_S_body
214 atf_test_case mtree_convert_D
215 atf_test_case netbsd6_convert_D
218 atf_set "descr" "Convert a specfile to mtree -D format, unsorted"
223 mtree -F ${FLAVOR} -D -K all <"$(atf_get_srcdir)/d_convert.in" >output
224 h_check "$(atf_get_srcdir)/d_convert_D.out" output
227 mtree_convert_D_head()
229 FLAVOR=mtree convert_D_head
231 netbsd6_convert_D_head()
233 FLAVOR=netbsd6 convert_D_head
236 mtree_convert_D_body()
238 FLAVOR=mtree convert_D_body
240 netbsd6_convert_D_body()
242 FLAVOR=netbsd6 convert_D_body
246 atf_test_case mtree_convert_D_S
247 atf_test_case netbsd6_convert_D_S
250 atf_set "descr" "Convert a specfile to mtree -D format, sorted"
255 mtree -F ${FLAVOR} -D -S -K all <"$(atf_get_srcdir)/d_convert.in" >output
256 h_check "$(atf_get_srcdir)/d_convert_D_S.out" output
259 mtree_convert_D_S_head()
261 FLAVOR=mtree convert_D_S_head
263 netbsd6_convert_D_S_head()
265 FLAVOR=netbsd6 convert_D_S_head
268 mtree_convert_D_S_body()
270 FLAVOR=mtree convert_D_S_body
272 netbsd6_convert_D_S_body()
274 FLAVOR=netbsd6 convert_D_S_body
278 atf_test_case mtree_ignore
279 atf_test_case netbs6_ignore
282 atf_set "descr" "Test that -d ignores symlinks (PR bin/41061)"
287 # Kyua 0.11 and above point TMPDIR to our work directory and atf-check
288 # generates a temporary file, which confuses mtree. Put the mtree files
289 # into a subdirectory.
291 # See https://github.com/jmmv/kyua/issues/133 for details.
292 mkdir root && cd root
295 mtree -F ${FLAVOR} -c | mtree -F ${FLAVOR} -Ck uid,gid,mode > mtree.spec
296 ln -s newdir otherdir
298 # This yields "extra: otherdir" even with -d.
300 atf_check -s ignore -o empty -e empty -x "mtree -F ${FLAVOR} -d < mtree.spec"
302 # Delete the symlink and re-verify.
305 atf_check -s ignore -o empty -e empty -x "mtree -F ${FLAVOR} -d < mtree.spec"
310 FLAVOR=mtree ignore_head
312 netbsd6_ignore_head()
314 FLAVOR=netbsd6 ignore_head
319 FLAVOR=mtree ignore_body
321 netbsd6_ignore_body()
323 # Kyua 0.11 and above point TMPDIR to our work directory and atf-check
324 # generates a temporary file, which confuses mtree. Put the mtree files
325 # into a subdirectory.
327 # See https://github.com/jmmv/kyua/issues/133 for details.
328 mkdir root && cd root
330 FLAVOR=netbsd6 ignore_body
334 atf_test_case mtree_merge
335 atf_test_case netbsd6_merge
338 atf_set "descr" "Merge records of different type"
343 mtree -F ${FLAVOR} -C -M -K all <"$(atf_get_srcdir)/d_merge.in" >output
344 h_check "$(atf_get_srcdir)/d_merge_C_M.out" output
345 # same again, with sorting
346 mtree -F ${FLAVOR} -C -M -S -K all <"$(atf_get_srcdir)/d_merge.in" >output
347 h_check "$(atf_get_srcdir)/d_merge_C_M_S.out" output
352 FLAVOR=mtree merge_head
356 FLAVOR=netbsd6 merge_head
361 FLAVOR=mtree merge_body
365 FLAVOR=netbsd6 merge_body
369 atf_test_case mtree_nonemptydir
370 atf_test_case netbsd6_nonemptydir
373 atf_set "descr" "Test that new non-empty " \
374 "directories are recorded (PR bin/25693)"
382 mtree -F ${FLAVOR} -c > mtree.spec
384 if [ ! -f mtree.spec ]; then
385 atf_fail "mtree failed"
389 atf_check -s ignore -o save:output -x "mtree -F ${FLAVOR} -f mtree.spec"
391 if [ ! -n "$(egrep "extra: bar" output)" ]; then
392 atf_fail "mtree did not record changes (PR bin/25693)"
396 mtree_nonemptydir_head()
398 FLAVOR=mtree nonemptydir_head
400 netbsd6_nonemptydir_head()
402 FLAVOR=netbsd6 nonemptydir_head
405 mtree_nonemptydir_body()
407 FLAVOR=mtree nonemptydir_body
409 netbsd6_nonemptydir_body()
411 FLAVOR=netbsd6 nonemptydir_body
415 atf_init_test_cases()
417 atf_add_test_case mtree_create
418 atf_add_test_case mtree_check
419 atf_add_test_case mtree_convert_C
420 atf_add_test_case mtree_convert_C_S
421 atf_add_test_case mtree_convert_D
422 atf_add_test_case mtree_convert_D_S
423 atf_add_test_case mtree_ignore
424 atf_add_test_case mtree_merge
425 atf_add_test_case mtree_nonemptydir
427 atf_add_test_case netbsd6_create
428 atf_add_test_case netbsd6_check
429 atf_add_test_case netbsd6_convert_C
430 atf_add_test_case netbsd6_convert_C_S
431 atf_add_test_case netbsd6_convert_D
432 atf_add_test_case netbsd6_convert_D_S
433 atf_add_test_case netbsd6_ignore
434 atf_add_test_case netbsd6_merge
435 atf_add_test_case netbsd6_nonemptydir