t_mtree.sh revision 1.1 1 1.1 jruoho # $NetBSD: t_mtree.sh,v 1.1 2012/03/17 16:33:16 jruoho Exp $
2 1.1 jruoho #
3 1.1 jruoho # Copyright (c) 2009 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.1 jruoho h_postprocess()
31 1.1 jruoho {
32 1.1 jruoho sed -e '
33 1.1 jruoho /^# user: /s/:.*/: x/
34 1.1 jruoho /^# machine: /s/:.*/: x/
35 1.1 jruoho /^# tree: /s/:.*/: x/
36 1.1 jruoho /^# date: /s/:.*/: x/
37 1.1 jruoho '
38 1.1 jruoho }
39 1.1 jruoho
40 1.1 jruoho h_check()
41 1.1 jruoho {
42 1.1 jruoho diff -Nru "$1" "$2" || atf_fail "files $1 and $2 differ"
43 1.1 jruoho }
44 1.1 jruoho
45 1.1 jruoho atf_test_case create
46 1.1 jruoho create_head()
47 1.1 jruoho {
48 1.1 jruoho atf_set "descr" "Create a specfile describing a directory tree"
49 1.1 jruoho }
50 1.1 jruoho create_setup()
51 1.1 jruoho {
52 1.1 jruoho # create some directories
53 1.1 jruoho mkdir -p create/a/1 create/a/2 create/b
54 1.1 jruoho # create some files
55 1.1 jruoho for file in create/top.file.1 \
56 1.1 jruoho create/a/a.file.1 \
57 1.1 jruoho create/a/a.file.2 \
58 1.1 jruoho create/a/1/a1.file.1 \
59 1.1 jruoho create/b/b.file.1 \
60 1.1 jruoho create/b/b.file.2
61 1.1 jruoho do
62 1.1 jruoho echo "$file" >$file
63 1.1 jruoho done
64 1.1 jruoho # hard link to file in same dir
65 1.1 jruoho ln create/b/b.file.1 create/b/b.hardlink.1
66 1.1 jruoho # hard link to file in another dir
67 1.1 jruoho ln create/b/b.file.2 create/a/a.hardlink.b2
68 1.1 jruoho # symlink to file
69 1.1 jruoho ln -s a.file.1 create/a.symlink.1
70 1.1 jruoho # symlink to dir
71 1.1 jruoho ln -s b create/top.symlink.b
72 1.1 jruoho # dangling symlink
73 1.1 jruoho ln -s nonexistent create/top.dangling
74 1.1 jruoho }
75 1.1 jruoho create_body()
76 1.1 jruoho {
77 1.1 jruoho create_setup
78 1.1 jruoho
79 1.1 jruoho # run mtree and check output
80 1.1 jruoho ( cd create && mtree -c -k type,nlink,link,size,sha256 ) >output.raw \
81 1.1 jruoho || atf_fail "mtree exit status $?"
82 1.1 jruoho h_postprocess <output.raw >output
83 1.1 jruoho h_check "$(atf_get_srcdir)/d_create.out" output
84 1.1 jruoho }
85 1.1 jruoho
86 1.1 jruoho atf_test_case check
87 1.1 jruoho check_head()
88 1.1 jruoho {
89 1.1 jruoho atf_set "descr" "Check a directory tree against a specfile"
90 1.1 jruoho }
91 1.1 jruoho check_body()
92 1.1 jruoho {
93 1.1 jruoho # we use the same directory tree and specfile as in the "create" test
94 1.1 jruoho create_setup
95 1.1 jruoho
96 1.1 jruoho # run mtree and check output
97 1.1 jruoho ( cd create && mtree ) <"$(atf_get_srcdir)/d_create.out" >output \
98 1.1 jruoho || atf_fail "mtree exit status $?"
99 1.1 jruoho h_check /dev/null output
100 1.1 jruoho }
101 1.1 jruoho
102 1.1 jruoho atf_test_case convert_C
103 1.1 jruoho convert_C_head()
104 1.1 jruoho {
105 1.1 jruoho atf_set "descr" "Convert a specfile to mtree -C format, unsorted"
106 1.1 jruoho }
107 1.1 jruoho convert_C_body()
108 1.1 jruoho {
109 1.1 jruoho mtree -C -K all <"$(atf_get_srcdir)/d_convert.in" >output
110 1.1 jruoho h_check "$(atf_get_srcdir)/d_convert_C.out" output
111 1.1 jruoho }
112 1.1 jruoho
113 1.1 jruoho atf_test_case convert_C_S
114 1.1 jruoho convert_C_S_head()
115 1.1 jruoho {
116 1.1 jruoho atf_set "descr" "Convert a specfile to mtree -C format, sorted"
117 1.1 jruoho }
118 1.1 jruoho convert_C_S_body()
119 1.1 jruoho {
120 1.1 jruoho mtree -C -S -K all <"$(atf_get_srcdir)/d_convert.in" >output
121 1.1 jruoho h_check "$(atf_get_srcdir)/d_convert_C_S.out" output
122 1.1 jruoho }
123 1.1 jruoho
124 1.1 jruoho atf_test_case convert_D
125 1.1 jruoho convert_D_head()
126 1.1 jruoho {
127 1.1 jruoho atf_set "descr" "Convert a specfile to mtree -D format, unsorted"
128 1.1 jruoho }
129 1.1 jruoho convert_D_body()
130 1.1 jruoho {
131 1.1 jruoho mtree -D -K all <"$(atf_get_srcdir)/d_convert.in" >output
132 1.1 jruoho h_check "$(atf_get_srcdir)/d_convert_D.out" output
133 1.1 jruoho }
134 1.1 jruoho
135 1.1 jruoho atf_test_case convert_D_S
136 1.1 jruoho convert_D_S_head()
137 1.1 jruoho {
138 1.1 jruoho atf_set "descr" "Convert a specfile to mtree -D format, sorted"
139 1.1 jruoho }
140 1.1 jruoho convert_D_S_body()
141 1.1 jruoho {
142 1.1 jruoho mtree -D -S -K all <"$(atf_get_srcdir)/d_convert.in" >output
143 1.1 jruoho h_check "$(atf_get_srcdir)/d_convert_D_S.out" output
144 1.1 jruoho }
145 1.1 jruoho
146 1.1 jruoho atf_test_case merge
147 1.1 jruoho merge_head()
148 1.1 jruoho {
149 1.1 jruoho atf_set "descr" "Merge records of different type"
150 1.1 jruoho }
151 1.1 jruoho merge_body()
152 1.1 jruoho {
153 1.1 jruoho mtree -C -M -K all <"$(atf_get_srcdir)/d_merge.in" >output
154 1.1 jruoho h_check "$(atf_get_srcdir)/d_merge_C_M.out" output
155 1.1 jruoho # same again, with sorting
156 1.1 jruoho mtree -C -M -S -K all <"$(atf_get_srcdir)/d_merge.in" >output
157 1.1 jruoho h_check "$(atf_get_srcdir)/d_merge_C_M_S.out" output
158 1.1 jruoho }
159 1.1 jruoho
160 1.1 jruoho atf_init_test_cases()
161 1.1 jruoho {
162 1.1 jruoho atf_add_test_case create
163 1.1 jruoho atf_add_test_case check
164 1.1 jruoho atf_add_test_case convert_C
165 1.1 jruoho atf_add_test_case convert_C_S
166 1.1 jruoho atf_add_test_case convert_D
167 1.1 jruoho atf_add_test_case convert_D_S
168 1.1 jruoho atf_add_test_case merge
169 1.1 jruoho }
170