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