xref: /freebsd/usr.sbin/makefs/tests/makefs_cd9660_tests.sh (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1#
2# Copyright 2015 EMC Corp.
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met:
8#
9# * Redistributions of source code must retain the above copyright
10#   notice, this list of conditions and the following disclaimer.
11# * 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 COPYRIGHT HOLDERS AND CONTRIBUTORS
16# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26#
27#
28
29# A note on specs:
30# - A copy of the ISO-9660 spec can be found here:
31#   https://www.ecma-international.org/publications/files/ECMA-ST/Ecma-119.pdf
32# - Any references to `rockridge` are referring to the `Rock Ridge` extensions
33#   of the ISO-9660 spec. A copy of the draft `IEEE-P1282` spec can be found
34#   here:
35#   http://www.ymi.com/ymi/sites/default/files/pdf/Rockridge.pdf
36
37MAKEFS="makefs -t cd9660"
38MOUNT="mount_cd9660"
39
40. "$(dirname "$0")/makefs_tests_common.sh"
41
42common_cleanup()
43{
44	if ! test_md_device=$(cat $TEST_MD_DEVICE_FILE); then
45		echo "$TEST_MD_DEVICE_FILE could not be opened; has an md(4) device been attached?"
46		return
47	fi
48
49	umount -f /dev/$test_md_device || :
50	mdconfig -d -u $test_md_device || :
51}
52
53check_base_iso9660_image_contents()
54{
55	# Symlinks are treated like files when rockridge support isn't
56	# specified
57	check_image_contents "$@" -X c
58
59	atf_check -e empty -o empty -s exit:0 test -L $TEST_INPUTS_DIR/c
60	atf_check -e empty -o empty -s exit:0 test -f $TEST_MOUNT_DIR/c
61}
62
63check_cd9660_support() {
64	kldstat -m cd9660 || \
65		atf_skip "Requires cd9660 filesystem support to be present in the kernel"
66}
67
68atf_test_case D_flag cleanup
69D_flag_body()
70{
71	atf_skip "makefs crashes with SIGBUS with dupe mtree entries; see FreeBSD bug # 192839"
72
73	create_test_inputs
74
75	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
76	    mtree -cp $TEST_INPUTS_DIR
77	atf_check -e empty -o not-empty -s exit:0 \
78	    $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
79
80	atf_check -e empty -o empty -s exit:0 \
81	    cp $TEST_SPEC_FILE spec2.mtree
82	atf_check -e empty -o save:dupe_$TEST_SPEC_FILE -s exit:0 \
83	    cat $TEST_SPEC_FILE spec2.mtree
84
85	atf_check -e empty -o not-empty -s not-exit:0 \
86	    $MAKEFS -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
87	atf_check -e empty -o not-empty -s exit:0 \
88	    $MAKEFS -D -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
89}
90D_flag_cleanup()
91{
92	common_cleanup
93}
94
95atf_test_case F_flag cleanup
96F_flag_body()
97{
98	create_test_inputs
99
100	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
101	    mtree -cp $TEST_INPUTS_DIR
102
103	atf_check -e empty -o empty -s exit:0 \
104	    $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
105
106	check_cd9660_support
107	mount_image
108	check_base_iso9660_image_contents
109}
110F_flag_cleanup()
111{
112	common_cleanup
113}
114
115atf_test_case from_mtree_spec_file cleanup
116from_mtree_spec_file_body()
117{
118	create_test_inputs
119
120	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
121	    mtree -c -k "$DEFAULT_MTREE_KEYWORDS" -p $TEST_INPUTS_DIR
122	cd $TEST_INPUTS_DIR
123	atf_check -e empty -o empty -s exit:0 \
124	    $MAKEFS $TEST_IMAGE $TEST_SPEC_FILE
125	cd -
126
127	check_cd9660_support
128	mount_image
129	check_base_iso9660_image_contents
130}
131from_mtree_spec_file_cleanup()
132{
133	common_cleanup
134}
135
136atf_test_case from_multiple_dirs cleanup
137from_multiple_dirs_body()
138{
139	test_inputs_dir2=$TMPDIR/inputs2
140
141	create_test_inputs
142
143	atf_check -e empty -o empty -s exit:0 mkdir -p $test_inputs_dir2
144	atf_check -e empty -o empty -s exit:0 \
145	    touch $test_inputs_dir2/multiple_dirs_test_file
146
147	atf_check -e empty -o empty -s exit:0 \
148	    $MAKEFS $TEST_IMAGE $TEST_INPUTS_DIR $test_inputs_dir2
149
150	check_cd9660_support
151	mount_image
152	check_base_iso9660_image_contents -d $test_inputs_dir2
153}
154from_multiple_dirs_cleanup()
155{
156	common_cleanup
157}
158
159atf_test_case from_single_dir cleanup
160from_single_dir_body()
161{
162	create_test_inputs
163
164	atf_check -e empty -o empty -s exit:0 \
165	    $MAKEFS $TEST_IMAGE $TEST_INPUTS_DIR
166
167	check_cd9660_support
168	mount_image
169	check_base_iso9660_image_contents
170}
171from_single_dir_cleanup()
172{
173	common_cleanup
174}
175
176atf_test_case o_flag_allow_deep_trees cleanup
177o_flag_allow_deep_trees_body()
178{
179	create_test_inputs
180
181	# Make sure the "more than 8 levels deep" requirement is met.
182	atf_check -e empty -o empty -s exit:0 \
183	    mkdir -p $TEST_INPUTS_DIR/a/b/c/d/e/f/g/h/i/j
184
185	atf_check -e empty -o empty -s exit:0 \
186	    $MAKEFS -o allow-deep-trees $TEST_IMAGE $TEST_INPUTS_DIR
187
188	check_cd9660_support
189	mount_image
190	check_base_iso9660_image_contents
191}
192o_flag_allow_deep_trees_cleanup()
193{
194	common_cleanup
195}
196
197atf_test_case o_flag_allow_max_name cleanup
198o_flag_allow_max_name_body()
199{
200	atf_expect_fail "-o allow-max-name doesn't appear to be implemented on FreeBSD's copy of makefs [yet]"
201
202	create_test_inputs
203
204	long_path=$TEST_INPUTS_DIR/$(jot -s '' -b 0 37)
205
206	# Make sure the "37 char name" limit requirement is met.
207	atf_check -e empty -o empty -s exit:0 touch $long_path
208
209	atf_check -e empty -o empty -s exit:0 \
210	    $MAKEFS -o allow-max-name $TEST_IMAGE $TEST_INPUTS_DIR
211
212	check_cd9660_support
213	mount_image
214	check_base_iso9660_image_contents
215}
216o_flag_allow_max_name_cleanup()
217{
218	common_cleanup
219}
220
221atf_test_case o_flag_isolevel_1 cleanup
222o_flag_isolevel_1_body()
223{
224	atf_expect_fail "this testcase needs work; the filenames generated seem incorrect/corrupt"
225
226	create_test_inputs
227
228	atf_check -e empty -o empty -s exit:0 \
229	    $MAKEFS -o isolevel=1 $TEST_IMAGE $TEST_INPUTS_DIR
230
231	check_cd9660_support
232	mount_image
233	check_base_iso9660_image_contents
234}
235o_flag_isolevel_1_cleanup()
236{
237	common_cleanup
238}
239
240atf_test_case o_flag_isolevel_2 cleanup
241o_flag_isolevel_2_body()
242{
243	create_test_inputs
244
245	atf_check -e empty -o empty -s exit:0 \
246	    $MAKEFS -o isolevel=2 $TEST_IMAGE $TEST_INPUTS_DIR
247
248	check_cd9660_support
249	mount_image
250	check_base_iso9660_image_contents
251}
252o_flag_isolevel_2_cleanup()
253{
254	common_cleanup
255}
256
257atf_test_case o_flag_isolevel_3 cleanup
258o_flag_isolevel_3_body()
259{
260	create_test_inputs
261
262	# XXX: isolevel=3 isn't implemented yet. See FreeBSD bug # 203645
263	if true; then
264	atf_check -e match:'makefs: ISO Level 3 is greater than 2\.' -o empty -s not-exit:0 \
265	    $MAKEFS -o isolevel=3 $TEST_IMAGE $TEST_INPUTS_DIR
266	else
267	atf_check -e empty -o empty -s exit:0 \
268	    $MAKEFS -o isolevel=3 $TEST_IMAGE $TEST_INPUTS_DIR
269
270	check_cd9660_support
271	mount_image
272	check_base_iso9660_image_contents
273	fi
274}
275o_flag_isolevel_3_cleanup()
276{
277	common_cleanup
278}
279
280atf_test_case o_flag_preparer
281o_flag_preparer_head()
282{
283	atf_set "require.progs" "strings"
284}
285o_flag_preparer_body()
286{
287	create_test_dirs
288
289	preparer='My Very First ISO'
290	preparer_uppercase="$(echo $preparer | tr '[[:lower:]]' '[[:upper:]]')"
291
292	atf_check -e empty -o empty -s exit:0 touch $TEST_INPUTS_DIR/dummy_file
293	atf_check -e empty -o empty -s exit:0 \
294	    $MAKEFS -o preparer="$preparer" $TEST_IMAGE $TEST_INPUTS_DIR
295	atf_check -e empty -o match:"$preparer_uppercase" -s exit:0 \
296	    strings $TEST_IMAGE
297}
298
299atf_test_case o_flag_publisher
300o_flag_publisher_head()
301{
302	atf_set "require.progs" "strings"
303}
304o_flag_publisher_body()
305{
306	create_test_dirs
307
308	publisher='My Super Awesome Publishing Company LTD'
309	publisher_uppercase="$(echo $publisher | tr '[[:lower:]]' '[[:upper:]]')"
310
311	atf_check -e empty -o empty -s exit:0 touch $TEST_INPUTS_DIR/dummy_file
312	atf_check -e empty -o empty -s exit:0 \
313	    $MAKEFS -o publisher="$publisher" $TEST_IMAGE $TEST_INPUTS_DIR
314	atf_check -e empty -o match:"$publisher_uppercase" -s exit:0 \
315	    strings $TEST_IMAGE
316}
317
318atf_test_case o_flag_rockridge cleanup
319o_flag_rockridge_body()
320{
321	create_test_dirs
322
323	# Make sure the "more than 8 levels deep" requirement is met.
324	atf_check -e empty -o empty -s exit:0 \
325	    mkdir -p $TEST_INPUTS_DIR/a/b/c/d/e/f/g/h/i/j
326
327	# Make sure the "pathname larger than 255 chars" requirement is met.
328	#
329	# $long_path's needs to be nested in a directory, as creating it
330	# outright as a 256 char filename via touch will fail with ENAMETOOLONG
331	long_path=$TEST_INPUTS_DIR/$(jot -s '/' -b "$(jot -s '' -b 0 64)" 4)
332	atf_check -e empty -o empty -s exit:0 mkdir -p "$(dirname $long_path)"
333	atf_check -e empty -o empty -s exit:0 touch "$long_path"
334
335	atf_check -e empty -o empty -s exit:0 \
336	    $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR
337
338	check_cd9660_support
339	mount_image
340	check_image_contents -X .rr_moved
341
342	# .rr_moved is a special directory created when you have deep directory
343	# trees with rock ridge extensions on
344	atf_check -e empty -o empty -s exit:0 \
345	    test -d $TEST_MOUNT_DIR/.rr_moved
346}
347o_flag_rockridge_cleanup()
348{
349	common_cleanup
350}
351
352atf_test_case o_flag_rockridge_dev_nodes cleanup
353o_flag_rockridge_dev_nodes_head()
354{
355	atf_set "descr" "Functional tests to ensure that dev nodes are handled properly with rockridge extensions (NetBSD kern/48852; FreeBSD bug 203648)"
356}
357o_flag_rockridge_dev_nodes_body()
358{
359	create_test_dirs
360
361	(tar -cvf - -C /dev null && touch .tar_ok) | \
362	atf_check -e not-empty -o empty -s exit:0 tar -xvf - -C "$TEST_INPUTS_DIR"
363
364	atf_check -e empty -o empty -s exit:0 test -c $TEST_INPUTS_DIR/null
365	atf_check -e empty -o empty -s exit:0 test -f .tar_ok
366
367	atf_check -e empty -o empty -s exit:0 \
368	    $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR
369
370	check_cd9660_support
371	mount_image
372	check_image_contents
373}
374o_flag_rockridge_dev_nodes_cleanup()
375{
376	common_cleanup
377}
378
379atf_init_test_cases()
380{
381	atf_add_test_case D_flag
382	atf_add_test_case F_flag
383
384	atf_add_test_case from_mtree_spec_file
385	atf_add_test_case from_multiple_dirs
386	atf_add_test_case from_single_dir
387
388	atf_add_test_case o_flag_allow_deep_trees
389	atf_add_test_case o_flag_allow_max_name
390	atf_add_test_case o_flag_isolevel_1
391	atf_add_test_case o_flag_isolevel_2
392	atf_add_test_case o_flag_isolevel_3
393	atf_add_test_case o_flag_preparer
394	atf_add_test_case o_flag_publisher
395	atf_add_test_case o_flag_rockridge
396	atf_add_test_case o_flag_rockridge_dev_nodes
397}
398