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: stable/11/usr.sbin/makefs/tests/makefs_cd9660_tests.sh 322690 2017-08-19 01:45:02Z ngie $
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_head()
268{
269	atf_set "require.progs" "strings"
270}
271o_flag_preparer_body()
272{
273	create_test_dirs
274
275	preparer='My Very First ISO'
276	preparer_uppercase="$(echo $preparer | tr '[[:lower:]]' '[[:upper:]]')"
277
278	atf_check -e empty -o empty -s exit:0 touch $TEST_INPUTS_DIR/dummy_file
279	atf_check -e empty -o empty -s exit:0 \
280	    $MAKEFS -o preparer="$preparer" $TEST_IMAGE $TEST_INPUTS_DIR
281	atf_check -e empty -o match:"$preparer_uppercase" -s exit:0 \
282	    strings $TEST_IMAGE
283}
284
285atf_test_case o_flag_publisher
286o_flag_publisher_head()
287{
288	atf_set "require.progs" "strings"
289}
290o_flag_publisher_body()
291{
292	create_test_dirs
293
294	publisher='My Super Awesome Publishing Company LTD'
295	publisher_uppercase="$(echo $publisher | tr '[[:lower:]]' '[[:upper:]]')"
296
297	atf_check -e empty -o empty -s exit:0 touch $TEST_INPUTS_DIR/dummy_file
298	atf_check -e empty -o empty -s exit:0 \
299	    $MAKEFS -o publisher="$publisher" $TEST_IMAGE $TEST_INPUTS_DIR
300	atf_check -e empty -o match:"$publisher_uppercase" -s exit:0 \
301	    strings $TEST_IMAGE
302}
303
304atf_test_case o_flag_rockridge cleanup
305o_flag_rockridge_body()
306{
307	create_test_dirs
308
309	# Make sure the "more than 8 levels deep" requirement is met.
310	atf_check -e empty -o empty -s exit:0 \
311	    mkdir -p $TEST_INPUTS_DIR/a/b/c/d/e/f/g/h/i/j
312
313	# Make sure the "pathname larger than 255 chars" requirement is met.
314	#
315	# $long_path's needs to be nested in a directory, as creating it
316	# outright as a 256 char filename via touch will fail with ENAMETOOLONG
317	long_path=$TEST_INPUTS_DIR/$(jot -s '/' -b "$(jot -s '' -b 0 64)" 4)
318	atf_check -e empty -o empty -s exit:0 mkdir -p "$(dirname $long_path)"
319	atf_check -e empty -o empty -s exit:0 touch "$long_path"
320
321	atf_check -e empty -o empty -s exit:0 \
322	    $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR
323
324	mount_image
325	check_image_contents -X .rr_moved
326
327	# .rr_moved is a special directory created when you have deep directory
328	# trees with rock ridge extensions on
329	atf_check -e empty -o empty -s exit:0 \
330	    test -d $TEST_MOUNT_DIR/.rr_moved
331}
332o_flag_rockridge_cleanup()
333{
334	common_cleanup
335}
336
337atf_test_case o_flag_rockridge_dev_nodes cleanup
338o_flag_rockridge_dev_nodes_head()
339{
340	atf_set "descr" "Functional tests to ensure that dev nodes are handled properly with rockridge extensions (NetBSD kern/48852; FreeBSD bug 203648)"
341}
342o_flag_rockridge_dev_nodes_body()
343{
344	create_test_dirs
345
346	(tar -cvf - -C /dev null && touch .tar_ok) | \
347	atf_check -e not-empty -o empty -s exit:0 tar -xvf - -C "$TEST_INPUTS_DIR"
348
349	atf_check -e empty -o empty -s exit:0 test -c $TEST_INPUTS_DIR/null
350	atf_check -e empty -o empty -s exit:0 test -f .tar_ok
351
352	atf_check -e empty -o empty -s exit:0 \
353	    $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR
354
355	mount_image
356	check_image_contents
357}
358o_flag_rockridge_dev_nodes_cleanup()
359{
360	common_cleanup
361}
362
363atf_init_test_cases()
364{
365	atf_add_test_case D_flag
366	atf_add_test_case F_flag
367
368	atf_add_test_case from_mtree_spec_file
369	atf_add_test_case from_multiple_dirs
370	atf_add_test_case from_single_dir
371
372	atf_add_test_case o_flag_allow_deep_trees
373	atf_add_test_case o_flag_allow_max_name
374	atf_add_test_case o_flag_isolevel_1
375	atf_add_test_case o_flag_isolevel_2
376	atf_add_test_case o_flag_isolevel_3
377	atf_add_test_case o_flag_preparer
378	atf_add_test_case o_flag_publisher
379	atf_add_test_case o_flag_rockridge
380	atf_add_test_case o_flag_rockridge_dev_nodes
381}
382