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