aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/makefs/tests/makefs_cd9660_tests.sh
blob: 01c99f730ec6e2a0243eef1f318aee15ae649fa1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
#
# Copyright 2015 EMC Corp.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
#   notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
#   notice, this list of conditions and the following disclaimer in the
#   documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# $FreeBSD$
#

# A note on specs:
# - A copy of the ISO-9660 spec can be found here:
#   https://www.ecma-international.org/publications/files/ECMA-ST/Ecma-119.pdf
# - Any references to `rockridge` are referring to the `Rock Ridge` extensions
#   of the ISO-9660 spec. A copy of the draft `IEEE-P1282` spec can be found
#   here:
#   http://www.ymi.com/ymi/sites/default/files/pdf/Rockridge.pdf

MAKEFS="makefs -t cd9660"
MOUNT="mount_cd9660"

. "$(dirname "$0")/makefs_tests_common.sh"

common_cleanup()
{
	if ! test_md_device=$(cat $TEST_MD_DEVICE_FILE); then
		echo "$TEST_MD_DEVICE_FILE could not be opened; has an md(4) device been attached?"
		return
	fi

	umount -f /dev/$test_md_device || :
	mdconfig -d -u $test_md_device || :
}

check_base_iso9660_image_contents()
{
	# Symlinks are treated like files when rockridge support isn't
	# specified
	check_image_contents "$@" -X c

	atf_check -e empty -o empty -s exit:0 test -L $TEST_INPUTS_DIR/c
	atf_check -e empty -o empty -s exit:0 test -f $TEST_MOUNT_DIR/c
}

check_cd9660_support() {
	kldstat -m cd9660 || \
		atf_skip "Requires cd9660 filesystem support to be present in the kernel"
}

atf_test_case D_flag cleanup
D_flag_body()
{
	atf_skip "makefs crashes with SIGBUS with dupe mtree entries; see FreeBSD bug # 192839"

	create_test_inputs

	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
	    mtree -cp $TEST_INPUTS_DIR
	atf_check -e empty -o not-empty -s exit:0 \
	    $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR

	atf_check -e empty -o empty -s exit:0 \
	    cp $TEST_SPEC_FILE spec2.mtree
	atf_check -e empty -o save:dupe_$TEST_SPEC_FILE -s exit:0 \
	    cat $TEST_SPEC_FILE spec2.mtree

	atf_check -e empty -o not-empty -s not-exit:0 \
	    $MAKEFS -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
	atf_check -e empty -o not-empty -s exit:0 \
	    $MAKEFS -D -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
}
D_flag_cleanup()
{
	common_cleanup
}

atf_test_case F_flag cleanup
F_flag_body()
{
	check_cd9660_support

	create_test_inputs

	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
	    mtree -cp $TEST_INPUTS_DIR

	atf_check -e empty -o empty -s exit:0 \
	    $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR

	mount_image
	check_base_iso9660_image_contents
}
F_flag_cleanup()
{
	common_cleanup
}

atf_test_case from_mtree_spec_file cleanup
from_mtree_spec_file_body()
{
	check_cd9660_support

	create_test_inputs

	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
	    mtree -c -k "$DEFAULT_MTREE_KEYWORDS" -p $TEST_INPUTS_DIR
	cd $TEST_INPUTS_DIR
	atf_check -e empty -o empty -s exit:0 \
	    $MAKEFS $TEST_IMAGE $TEST_SPEC_FILE
	cd -

	mount_image
	check_base_iso9660_image_contents
}
from_mtree_spec_file_cleanup()
{
	common_cleanup
}

atf_test_case from_multiple_dirs cleanup
from_multiple_dirs_body()
{
	check_cd9660_support

	test_inputs_dir2=$TMPDIR/inputs2

	create_test_inputs

	atf_check -e empty -o empty -s exit:0 mkdir -p $test_inputs_dir2
	atf_check -e empty -o empty -s exit:0 \
	    touch $test_inputs_dir2/multiple_dirs_test_file

	atf_check -e empty -o empty -s exit:0 \
	    $MAKEFS $TEST_IMAGE $TEST_INPUTS_DIR $test_inputs_dir2

	mount_image
	check_base_iso9660_image_contents -d $test_inputs_dir2
}
from_multiple_dirs_cleanup()
{
	common_cleanup
}

atf_test_case from_single_dir cleanup
from_single_dir_body()
{
	check_cd9660_support

	create_test_inputs

	atf_check -e empty -o empty -s exit:0 \
	    $MAKEFS $TEST_IMAGE $TEST_INPUTS_DIR

	mount_image
	check_base_iso9660_image_contents
}
from_single_dir_cleanup()
{
	common_cleanup
}

atf_test_case o_flag_allow_deep_trees cleanup
o_flag_allow_deep_trees_body()
{
	create_test_inputs

	# Make sure the "more than 8 levels deep" requirement is met.
	atf_check -e empty -o empty -s exit:0 \
	    mkdir -p $TEST_INPUTS_DIR/a/b/c/d/e/f/g/h/i/j

	atf_check -e empty -o empty -s exit:0 \
	    $MAKEFS -o allow-deep-trees $TEST_IMAGE $TEST_INPUTS_DIR

	mount_image
	check_base_iso9660_image_contents
}
o_flag_allow_deep_trees_cleanup()
{
	common_cleanup
}

atf_test_case o_flag_allow_max_name cleanup
o_flag_allow_max_name_body()
{
	atf_expect_fail "-o allow-max-name doesn't appear to be implemented on FreeBSD's copy of makefs [yet]"

	create_test_inputs

	long_path=$TEST_INPUTS_DIR/$(jot -s '' -b 0 37)

	# Make sure the "37 char name" limit requirement is met.
	atf_check -e empty -o empty -s exit:0 touch $long_path

	atf_check -e empty -o empty -s exit:0 \
	    $MAKEFS -o allow-max-name $TEST_IMAGE $TEST_INPUTS_DIR

	mount_image
	check_base_iso9660_image_contents
}
o_flag_allow_max_name_cleanup()
{
	common_cleanup
}

atf_test_case o_flag_isolevel_1 cleanup
o_flag_isolevel_1_body()
{
	atf_expect_fail "this testcase needs work; the filenames generated seem incorrect/corrupt"

	create_test_inputs

	atf_check -e empty -o empty -s exit:0 \
	    $MAKEFS -o isolevel=1 $TEST_IMAGE $TEST_INPUTS_DIR

	mount_image
	check_base_iso9660_image_contents
}
o_flag_isolevel_1_cleanup()
{
	common_cleanup
}

atf_test_case o_flag_isolevel_2 cleanup
o_flag_isolevel_2_body()
{
	create_test_inputs

	atf_check -e empty -o empty -s exit:0 \
	    $MAKEFS -o isolevel=2 $TEST_IMAGE $TEST_INPUTS_DIR

	mount_image
	check_base_iso9660_image_contents
}
o_flag_isolevel_2_cleanup()
{
	common_cleanup
}

atf_test_case o_flag_isolevel_3 cleanup
o_flag_isolevel_3_body()
{
	create_test_inputs

	# XXX: isolevel=3 isn't implemented yet. See FreeBSD bug # 203645
	if true; then
	atf_check -e match:'makefs: ISO Level 3 is greater than 2\.' -o empty -s not-exit:0 \
	    $MAKEFS -o isolevel=3 $TEST_IMAGE $TEST_INPUTS_DIR
	else
	atf_check -e empty -o empty -s exit:0 \
	    $MAKEFS -o isolevel=3 $TEST_IMAGE $TEST_INPUTS_DIR
	mount_image
	check_base_iso9660_image_contents
	fi
}
o_flag_isolevel_3_cleanup()
{
	common_cleanup
}

atf_test_case o_flag_preparer
o_flag_preparer_head()
{
	atf_set "require.progs" "strings"
}
o_flag_preparer_body()
{
	create_test_dirs

	preparer='My Very First ISO'
	preparer_uppercase="$(echo $preparer | tr '[[:lower:]]' '[[:upper:]]')"

	atf_check -e empty -o empty -s exit:0 touch $TEST_INPUTS_DIR/dummy_file
	atf_check -e empty -o empty -s exit:0 \
	    $MAKEFS -o preparer="$preparer" $TEST_IMAGE $TEST_INPUTS_DIR
	atf_check -e empty -o match:"$preparer_uppercase" -s exit:0 \
	    strings $TEST_IMAGE
}

atf_test_case o_flag_publisher
o_flag_publisher_head()
{
	atf_set "require.progs" "strings"
}
o_flag_publisher_body()
{
	create_test_dirs

	publisher='My Super Awesome Publishing Company LTD'
	publisher_uppercase="$(echo $publisher | tr '[[:lower:]]' '[[:upper:]]')"

	atf_check -e empty -o empty -s exit:0 touch $TEST_INPUTS_DIR/dummy_file
	atf_check -e empty -o empty -s exit:0 \
	    $MAKEFS -o publisher="$publisher" $TEST_IMAGE $TEST_INPUTS_DIR
	atf_check -e empty -o match:"$publisher_uppercase" -s exit:0 \
	    strings $TEST_IMAGE
}

atf_test_case o_flag_rockridge cleanup
o_flag_rockridge_body()
{
	create_test_dirs

	# Make sure the "more than 8 levels deep" requirement is met.
	atf_check -e empty -o empty -s exit:0 \
	    mkdir -p $TEST_INPUTS_DIR/a/b/c/d/e/f/g/h/i/j

	# Make sure the "pathname larger than 255 chars" requirement is met.
	#
	# $long_path's needs to be nested in a directory, as creating it
	# outright as a 256 char filename via touch will fail with ENAMETOOLONG
	long_path=$TEST_INPUTS_DIR/$(jot -s '/' -b "$(jot -s '' -b 0 64)" 4)
	atf_check -e empty -o empty -s exit:0 mkdir -p "$(dirname $long_path)"
	atf_check -e empty -o empty -s exit:0 touch "$long_path"

	atf_check -e empty -o empty -s exit:0 \
	    $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR

	mount_image
	check_image_contents -X .rr_moved

	# .rr_moved is a special directory created when you have deep directory
	# trees with rock ridge extensions on
	atf_check -e empty -o empty -s exit:0 \
	    test -d $TEST_MOUNT_DIR/.rr_moved
}
o_flag_rockridge_cleanup()
{
	common_cleanup
}

atf_test_case o_flag_rockridge_dev_nodes cleanup
o_flag_rockridge_dev_nodes_head()
{
	atf_set "descr" "Functional tests to ensure that dev nodes are handled properly with rockridge extensions (NetBSD kern/48852; FreeBSD bug 203648)"
}
o_flag_rockridge_dev_nodes_body()
{
	create_test_dirs

	(tar -cvf - -C /dev null && touch .tar_ok) | \
	atf_check -e not-empty -o empty -s exit:0 tar -xvf - -C "$TEST_INPUTS_DIR"

	atf_check -e empty -o empty -s exit:0 test -c $TEST_INPUTS_DIR/null
	atf_check -e empty -o empty -s exit:0 test -f .tar_ok

	atf_check -e empty -o empty -s exit:0 \
	    $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR

	mount_image
	check_image_contents
}
o_flag_rockridge_dev_nodes_cleanup()
{
	common_cleanup
}

atf_init_test_cases()
{
	atf_add_test_case D_flag
	atf_add_test_case F_flag

	atf_add_test_case from_mtree_spec_file
	atf_add_test_case from_multiple_dirs
	atf_add_test_case from_single_dir

	atf_add_test_case o_flag_allow_deep_trees
	atf_add_test_case o_flag_allow_max_name
	atf_add_test_case o_flag_isolevel_1
	atf_add_test_case o_flag_isolevel_2
	atf_add_test_case o_flag_isolevel_3
	atf_add_test_case o_flag_preparer
	atf_add_test_case o_flag_publisher
	atf_add_test_case o_flag_rockridge
	atf_add_test_case o_flag_rockridge_dev_nodes
}