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