makefs_cd9660_tests.sh revision 289902
1116744Ssam#
2185522Ssam# Copyright 2015 EMC Corp.
3116744Ssam# All rights reserved.
4116744Ssam#
5116744Ssam# Redistribution and use in source and binary forms, with or without
6116744Ssam# modification, are permitted provided that the following conditions are
7116744Ssam# met:
8116744Ssam#
9116744Ssam# * Redistributions of source code must retain the above copyright
10116744Ssam#   notice, this list of conditions and the following disclaimer.
11116744Ssam# * Redistributions in binary form must reproduce the above copyright
12116744Ssam#   notice, this list of conditions and the following disclaimer in the
13116744Ssam#   documentation and/or other materials provided with the distribution.
14116744Ssam#
15116744Ssam# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16116744Ssam# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17116744Ssam# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18116744Ssam# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19116744Ssam# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20116744Ssam# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21116744Ssam# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22116744Ssam# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23116744Ssam# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24116744Ssam# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25116744Ssam# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26116744Ssam#
27116744Ssam# $FreeBSD: head/usr.sbin/makefs/tests/makefs_cd9660_tests.sh 289902 2015-10-24 23:21:08Z ngie $
28116744Ssam#
29116744Ssam
30116744Ssam# A note on specs:
31116744Ssam# - A copy of the ISO-9660 spec can be found here:
32186094Ssam#   http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-119.pdf
33116744Ssam# - Any references to `rockridge` are referring to the `Rock Ridge` extensions
34186094Ssam#   of the ISO-9660 spec. A copy of the draft `IEEE-P1282` spec can be found
35186094Ssam#   here:
36186094Ssam#   http://www.ymi.com/ymi/sites/default/files/pdf/Rockridge.pdf
37186094Ssam
38219185SadrianMAKEFS="makefs -t cd9660"
39219185SadrianMOUNT="mount_cd9660"
40186094Ssam
41203286Srpaulo. "$(dirname "$0")/makefs_tests_common.sh"
42190571Ssam
43186094Ssamcommon_cleanup()
44186094Ssam{
45186094Ssam	if ! test_md_device=$(cat $TEST_MD_DEVICE_FILE); then
46186094Ssam		echo "$TEST_MD_DEVICE_FILE could not be opened; has an md(4) device been attached?"
47186094Ssam		return
48186094Ssam	fi
49185522Ssam
50185522Ssam	umount -f /dev/$test_md_device || :
51185522Ssam	mdconfig -d -u $test_md_device || :
52186094Ssam}
53186094Ssam
54186094Ssamcheck_base_iso9660_image_contents()
55186094Ssam{
56186094Ssam	# Symlinks are treated like files when rockridge support isn't
57186094Ssam	# specified
58186094Ssam	check_image_contents "$@" -X c
59185522Ssam
60185522Ssam	atf_check -e empty -o empty -s exit:0 test -L $TEST_INPUTS_DIR/c
61186094Ssam	atf_check -e empty -o empty -s exit:0 test -f $TEST_MOUNT_DIR/c
62186094Ssam}
63186094Ssam
64186094Ssamatf_test_case D_flag cleanup
65186094SsamD_flag_body()
66186094Ssam{
67185522Ssam	atf_skip "makefs crashes with SIGBUS with dupe mtree entries; see FreeBSD bug # 192839"
68185522Ssam
69186094Ssam	create_test_inputs
70186094Ssam
71186094Ssam	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
72186094Ssam	    mtree -cp $TEST_INPUTS_DIR
73186094Ssam	atf_check -e empty -o not-empty -s exit:0 \
74186094Ssam	    $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
75186094Ssam
76186094Ssam	atf_check -e empty -o empty -s exit:0 \
77186094Ssam	    cp $TEST_SPEC_FILE spec2.mtree
78186094Ssam	atf_check -e empty -o save:dupe_$TEST_SPEC_FILE -s exit:0 \
79186094Ssam	    cat $TEST_SPEC_FILE spec2.mtree
80186094Ssam
81186094Ssam	atf_check -e empty -o not-empty -s not-exit:0 \
82186094Ssam	    $MAKEFS -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
83186094Ssam	atf_check -e empty -o not-empty -s exit:0 \
84186094Ssam	    $MAKEFS -D -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
85186094Ssam}
86203286SrpauloD_flag_cleanup()
87185522Ssam{
88185522Ssam	common_cleanup
89185522Ssam}
90185522Ssam
91186094Ssamatf_test_case F_flag cleanup
92217631SadrianF_flag_body()
93217631Sadrian{
94217631Sadrian	create_test_inputs
95217631Sadrian
96217631Sadrian	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
97186094Ssam	    mtree -cp $TEST_INPUTS_DIR
98217631Sadrian
99217631Sadrian	atf_check -e empty -o empty -s exit:0 \
100219393Sadrian	    $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
101204656Srpaulo
102185522Ssam	mount_image
103186094Ssam	check_base_iso9660_image_contents
104186094Ssam}
105186094SsamF_flag_cleanup()
106190571Ssam{
107186094Ssam	common_cleanup
108186094Ssam}
109186094Ssam
110186094Ssamatf_test_case from_mtree_spec_file cleanup
111186094Ssamfrom_mtree_spec_file_body()
112186094Ssam{
113186094Ssam	create_test_inputs
114116744Ssam
115185522Ssam	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
116116744Ssam	    mtree -c -k type,link,size -p $TEST_INPUTS_DIR
117185522Ssam	cd $TEST_INPUTS_DIR
118185522Ssam	atf_check -e empty -o empty -s exit:0 \
119157438Ssam	    $MAKEFS $TEST_IMAGE $TEST_SPEC_FILE
120116744Ssam	cd -
121
122	mount_image
123	check_base_iso9660_image_contents
124}
125from_mtree_spec_file_cleanup()
126{
127	common_cleanup
128}
129
130atf_test_case from_multiple_dirs cleanup
131from_multiple_dirs_body()
132{
133	test_inputs_dir2=$TMPDIR/inputs2
134
135	create_test_inputs
136
137	atf_check -e empty -o empty -s exit:0 mkdir -p $test_inputs_dir2
138	atf_check -e empty -o empty -s exit:0 \
139	    touch $test_inputs_dir2/multiple_dirs_test_file
140
141	atf_check -e empty -o empty -s exit:0 \
142	    $MAKEFS $TEST_IMAGE $TEST_INPUTS_DIR $test_inputs_dir2
143
144	mount_image
145	check_base_iso9660_image_contents -d $test_inputs_dir2
146}
147from_multiple_dirs_cleanup()
148{
149	common_cleanup
150}
151
152atf_test_case from_single_dir cleanup
153from_single_dir_body()
154{
155	create_test_inputs
156
157	atf_check -e empty -o empty -s exit:0 \
158	    $MAKEFS $TEST_IMAGE $TEST_INPUTS_DIR
159
160	mount_image
161	check_base_iso9660_image_contents
162}
163from_single_dir_cleanup()
164{
165	common_cleanup
166}
167
168atf_test_case o_flag_allow_deep_trees cleanup
169o_flag_allow_deep_trees_body()
170{
171	create_test_inputs
172
173	# Make sure the "more than 8 levels deep" requirement is met.
174	atf_check -e empty -o empty -s exit:0 \
175	    mkdir -p $TEST_INPUTS_DIR/a/b/c/d/e/f/g/h/i/j
176
177	atf_check -e empty -o empty -s exit:0 \
178	    $MAKEFS -o allow-deep-trees $TEST_IMAGE $TEST_INPUTS_DIR
179
180	mount_image
181	check_base_iso9660_image_contents
182}
183o_flag_allow_deep_trees_cleanup()
184{
185	common_cleanup
186}
187
188atf_test_case o_flag_allow_max_name cleanup
189o_flag_allow_max_name_body()
190{
191	atf_expect_fail "-o allow-max-name doesn't appear to be implemented on FreeBSD's copy of makefs [yet]"
192
193	create_test_inputs
194
195	long_path=$TEST_INPUTS_DIR/$(jot -s '' -b 0 37)
196
197	# Make sure the "37 char name" limit requirement is met.
198	atf_check -e empty -o empty -s exit:0 touch $long_path
199
200	atf_check -e empty -o empty -s exit:0 \
201	    $MAKEFS -o allow-max-name $TEST_IMAGE $TEST_INPUTS_DIR
202
203	mount_image
204	check_base_iso9660_image_contents
205}
206o_flag_allow_max_name_cleanup()
207{
208	common_cleanup
209}
210
211atf_test_case o_flag_preparer
212o_flag_preparer_body()
213{
214	create_test_dirs
215
216	preparer='My Very First ISO'
217	preparer_uppercase="$(echo $preparer | tr '[[:lower:]]' '[[:upper:]]')"
218
219	atf_check -e empty -o empty -s exit:0 touch $TEST_INPUTS_DIR/dummy_file
220	atf_check -e empty -o empty -s exit:0 \
221	    $MAKEFS -o preparer="$preparer" $TEST_IMAGE $TEST_INPUTS_DIR
222	atf_check -e empty -o match:"$preparer_uppercase" -s exit:0 \
223	    strings $TEST_IMAGE
224}
225
226atf_test_case o_flag_publisher
227o_flag_publisher_body()
228{
229	create_test_dirs
230
231	publisher='My Super Awesome Publishing Company LTD'
232	publisher_uppercase="$(echo $publisher | tr '[[:lower:]]' '[[:upper:]]')"
233
234	atf_check -e empty -o empty -s exit:0 touch $TEST_INPUTS_DIR/dummy_file
235	atf_check -e empty -o empty -s exit:0 \
236	    $MAKEFS -o publisher="$publisher" $TEST_IMAGE $TEST_INPUTS_DIR
237	atf_check -e empty -o match:"$publisher_uppercase" -s exit:0 \
238	    strings $TEST_IMAGE
239}
240
241atf_test_case o_flag_rockridge cleanup
242o_flag_rockridge_body()
243{
244	create_test_dirs
245
246	# Make sure the "more than 8 levels deep" requirement is met.
247	atf_check -e empty -o empty -s exit:0 \
248	    mkdir -p $TEST_INPUTS_DIR/a/b/c/d/e/f/g/h/i/j
249
250	# Make sure the "pathname larger than 255 chars" requirement is met.
251	#
252	# $long_path's needs to be nested in a directory, as creating it
253	# outright as a 256 char filename via touch will fail with ENAMETOOLONG
254	long_path=$TEST_INPUTS_DIR/$(jot -s '/' -b "$(jot -s '' -b 0 64)" 4)
255	atf_check -e empty -o empty -s exit:0 mkdir -p "$(dirname $long_path)"
256	atf_check -e empty -o empty -s exit:0 touch "$long_path"
257
258	atf_check -e empty -o empty -s exit:0 \
259	    $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR
260
261	mount_image
262	check_image_contents -X .rr_moved
263
264	# .rr_moved is a special directory created when you have deep directory
265	# trees with rock ridge extensions on
266	atf_check -e empty -o empty -s exit:0 \
267	    test -d $TEST_MOUNT_DIR/.rr_moved
268}
269o_flag_rockridge_cleanup()
270{
271	common_cleanup
272}
273
274atf_test_case o_flag_rockridge_dev_nodes cleanup
275o_flag_rockridge_dev_nodes_head()
276{
277	atf_set "descr" "Functional tests to ensure that dev nodes are handled properly with rockridge extensions (NetBSD kern/48852; FreeBSD bug 203648)"
278}
279o_flag_rockridge_dev_nodes_body()
280{
281	create_test_dirs
282
283	(tar -cvf - -C /dev null && touch .tar_ok) | \
284	atf_check -e not-empty -o empty -s exit:0 tar -xvf - -C "$TEST_INPUTS_DIR"
285
286	atf_check -e empty -o empty -s exit:0 test -c $TEST_INPUTS_DIR/null
287	atf_check -e empty -o empty -s exit:0 test -f .tar_ok
288
289	atf_check -e empty -o empty -s exit:0 \
290	    $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR
291
292	mount_image
293	check_image_contents
294}
295o_flag_rockridge_dev_nodes_cleanup()
296{
297	common_cleanup
298}
299
300atf_init_test_cases()
301{
302	atf_add_test_case D_flag
303	atf_add_test_case F_flag
304
305	atf_add_test_case from_mtree_spec_file
306	atf_add_test_case from_multiple_dirs
307	atf_add_test_case from_single_dir
308
309	atf_add_test_case o_flag_allow_deep_trees
310	atf_add_test_case o_flag_allow_max_name
311	atf_add_test_case o_flag_preparer
312	atf_add_test_case o_flag_publisher
313	atf_add_test_case o_flag_rockridge
314	atf_add_test_case o_flag_rockridge_dev_nodes
315}
316