xref: /freebsd/usr.sbin/makefs/tests/makefs_cd9660_tests.sh (revision 39ee7a7a6bdd1557b1c3532abf60d139798ac88b)
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 type,link,size -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_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