xref: /freebsd/usr.sbin/makefs/tests/makefs_cd9660_tests.sh (revision d9f0ce31900a48d1a2bfc1c8c86f79d1e831451a)
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
64atf_test_case D_flag cleanup
65D_flag_body()
66{
67	atf_skip "makefs crashes with SIGBUS with dupe mtree entries; see FreeBSD bug # 192839"
68
69	create_test_inputs
70
71	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
72	    mtree -cp $TEST_INPUTS_DIR
73	atf_check -e empty -o not-empty -s exit:0 \
74	    $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
75
76	atf_check -e empty -o empty -s exit:0 \
77	    cp $TEST_SPEC_FILE spec2.mtree
78	atf_check -e empty -o save:dupe_$TEST_SPEC_FILE -s exit:0 \
79	    cat $TEST_SPEC_FILE spec2.mtree
80
81	atf_check -e empty -o not-empty -s not-exit:0 \
82	    $MAKEFS -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
83	atf_check -e empty -o not-empty -s exit:0 \
84	    $MAKEFS -D -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
85}
86D_flag_cleanup()
87{
88	common_cleanup
89}
90
91atf_test_case F_flag cleanup
92F_flag_body()
93{
94	create_test_inputs
95
96	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
97	    mtree -cp $TEST_INPUTS_DIR
98
99	atf_check -e empty -o empty -s exit:0 \
100	    $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
101
102	mount_image
103	check_base_iso9660_image_contents
104}
105F_flag_cleanup()
106{
107	common_cleanup
108}
109
110atf_test_case from_mtree_spec_file cleanup
111from_mtree_spec_file_body()
112{
113	create_test_inputs
114
115	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
116	    mtree -c -k "$DEFAULT_MTREE_KEYWORDS" -p $TEST_INPUTS_DIR
117	cd $TEST_INPUTS_DIR
118	atf_check -e empty -o empty -s exit:0 \
119	    $MAKEFS $TEST_IMAGE $TEST_SPEC_FILE
120	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_isolevel_1 cleanup
212o_flag_isolevel_1_body()
213{
214	atf_expect_fail "this testcase needs work; the filenames generated seem incorrect/corrupt"
215
216	create_test_inputs
217
218	atf_check -e empty -o empty -s exit:0 \
219	    $MAKEFS -o isolevel=1 $TEST_IMAGE $TEST_INPUTS_DIR
220
221	mount_image
222	check_base_iso9660_image_contents
223}
224o_flag_isolevel_1_cleanup()
225{
226	common_cleanup
227}
228
229atf_test_case o_flag_isolevel_2 cleanup
230o_flag_isolevel_2_body()
231{
232	create_test_inputs
233
234	atf_check -e empty -o empty -s exit:0 \
235	    $MAKEFS -o isolevel=2 $TEST_IMAGE $TEST_INPUTS_DIR
236
237	mount_image
238	check_base_iso9660_image_contents
239}
240o_flag_isolevel_2_cleanup()
241{
242	common_cleanup
243}
244
245atf_test_case o_flag_isolevel_3 cleanup
246o_flag_isolevel_3_body()
247{
248	create_test_inputs
249
250	# XXX: isolevel=3 isn't implemented yet. See FreeBSD bug # 203645
251	if true; then
252	atf_check -e match:'makefs: ISO Level 3 is greater than 2\.' -o empty -s not-exit:0 \
253	    $MAKEFS -o isolevel=3 $TEST_IMAGE $TEST_INPUTS_DIR
254	else
255	atf_check -e empty -o empty -s exit:0 \
256	    $MAKEFS -o isolevel=3 $TEST_IMAGE $TEST_INPUTS_DIR
257	mount_image
258	check_base_iso9660_image_contents
259	fi
260}
261o_flag_isolevel_3_cleanup()
262{
263	common_cleanup
264}
265
266atf_test_case o_flag_preparer
267o_flag_preparer_body()
268{
269	create_test_dirs
270
271	preparer='My Very First ISO'
272	preparer_uppercase="$(echo $preparer | tr '[[:lower:]]' '[[:upper:]]')"
273
274	atf_check -e empty -o empty -s exit:0 touch $TEST_INPUTS_DIR/dummy_file
275	atf_check -e empty -o empty -s exit:0 \
276	    $MAKEFS -o preparer="$preparer" $TEST_IMAGE $TEST_INPUTS_DIR
277	atf_check -e empty -o match:"$preparer_uppercase" -s exit:0 \
278	    strings $TEST_IMAGE
279}
280
281atf_test_case o_flag_publisher
282o_flag_publisher_body()
283{
284	create_test_dirs
285
286	publisher='My Super Awesome Publishing Company LTD'
287	publisher_uppercase="$(echo $publisher | tr '[[:lower:]]' '[[:upper:]]')"
288
289	atf_check -e empty -o empty -s exit:0 touch $TEST_INPUTS_DIR/dummy_file
290	atf_check -e empty -o empty -s exit:0 \
291	    $MAKEFS -o publisher="$publisher" $TEST_IMAGE $TEST_INPUTS_DIR
292	atf_check -e empty -o match:"$publisher_uppercase" -s exit:0 \
293	    strings $TEST_IMAGE
294}
295
296atf_test_case o_flag_rockridge cleanup
297o_flag_rockridge_body()
298{
299	create_test_dirs
300
301	# Make sure the "more than 8 levels deep" requirement is met.
302	atf_check -e empty -o empty -s exit:0 \
303	    mkdir -p $TEST_INPUTS_DIR/a/b/c/d/e/f/g/h/i/j
304
305	# Make sure the "pathname larger than 255 chars" requirement is met.
306	#
307	# $long_path's needs to be nested in a directory, as creating it
308	# outright as a 256 char filename via touch will fail with ENAMETOOLONG
309	long_path=$TEST_INPUTS_DIR/$(jot -s '/' -b "$(jot -s '' -b 0 64)" 4)
310	atf_check -e empty -o empty -s exit:0 mkdir -p "$(dirname $long_path)"
311	atf_check -e empty -o empty -s exit:0 touch "$long_path"
312
313	atf_check -e empty -o empty -s exit:0 \
314	    $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR
315
316	mount_image
317	check_image_contents -X .rr_moved
318
319	# .rr_moved is a special directory created when you have deep directory
320	# trees with rock ridge extensions on
321	atf_check -e empty -o empty -s exit:0 \
322	    test -d $TEST_MOUNT_DIR/.rr_moved
323}
324o_flag_rockridge_cleanup()
325{
326	common_cleanup
327}
328
329atf_test_case o_flag_rockridge_dev_nodes cleanup
330o_flag_rockridge_dev_nodes_head()
331{
332	atf_set "descr" "Functional tests to ensure that dev nodes are handled properly with rockridge extensions (NetBSD kern/48852; FreeBSD bug 203648)"
333}
334o_flag_rockridge_dev_nodes_body()
335{
336	create_test_dirs
337
338	(tar -cvf - -C /dev null && touch .tar_ok) | \
339	atf_check -e not-empty -o empty -s exit:0 tar -xvf - -C "$TEST_INPUTS_DIR"
340
341	atf_check -e empty -o empty -s exit:0 test -c $TEST_INPUTS_DIR/null
342	atf_check -e empty -o empty -s exit:0 test -f .tar_ok
343
344	atf_check -e empty -o empty -s exit:0 \
345	    $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR
346
347	mount_image
348	check_image_contents
349}
350o_flag_rockridge_dev_nodes_cleanup()
351{
352	common_cleanup
353}
354
355atf_init_test_cases()
356{
357	atf_add_test_case D_flag
358	atf_add_test_case F_flag
359
360	atf_add_test_case from_mtree_spec_file
361	atf_add_test_case from_multiple_dirs
362	atf_add_test_case from_single_dir
363
364	atf_add_test_case o_flag_allow_deep_trees
365	atf_add_test_case o_flag_allow_max_name
366	atf_add_test_case o_flag_isolevel_1
367	atf_add_test_case o_flag_isolevel_2
368	atf_add_test_case o_flag_isolevel_3
369	atf_add_test_case o_flag_preparer
370	atf_add_test_case o_flag_publisher
371	atf_add_test_case o_flag_rockridge
372	atf_add_test_case o_flag_rockridge_dev_nodes
373}
374