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