xref: /freebsd/usr.sbin/makefs/tests/makefs_ffs_tests.sh (revision ecdc04d006de93eb343ce3b77208abd937d4f8ac)
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
30MAKEFS="makefs -t ffs"
31MOUNT="mount"
32
33. "$(dirname "$0")/makefs_tests_common.sh"
34
35TEST_TUNEFS_OUTPUT=$TMPDIR/tunefs.output
36
37common_cleanup()
38{
39	if ! test_md_device=$(cat $TEST_MD_DEVICE_FILE); then
40		echo "$TEST_MD_DEVICE_FILE could not be opened; has an md(4) device been attached?"
41		return
42	fi
43
44	umount -f /dev/$test_md_device || :
45	mdconfig -d -u $test_md_device || :
46}
47
48check_ffs_image_contents()
49{
50	atf_check -e save:$TEST_TUNEFS_OUTPUT -o empty -s exit:0 \
51	    tunefs -p /dev/$(cat $TEST_MD_DEVICE_FILE)
52
53	check_image_contents "$@"
54}
55
56# With no -M, -m, or -s options, makefs should autocalculate the image size
57atf_test_case autocalculate_image_size cleanup
58autocalculate_image_size_body()
59{
60	create_test_inputs
61
62	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
63	    mtree -c -k "$DEFAULT_MTREE_KEYWORDS" -p $TEST_INPUTS_DIR
64
65	cd $TEST_INPUTS_DIR
66	atf_check -e empty -o not-empty -s exit:0 \
67	    $MAKEFS $TEST_IMAGE $TEST_SPEC_FILE
68	cd -
69
70	mount_image
71	check_ffs_image_contents
72}
73autocalculate_image_size_cleanup()
74{
75	common_cleanup
76}
77
78atf_test_case D_flag cleanup
79D_flag_body()
80{
81	atf_skip "makefs crashes with SIGBUS with dupe mtree entries; see FreeBSD bug # 192839"
82
83	create_test_inputs
84
85	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
86	    mtree -cp $TEST_INPUTS_DIR
87	atf_check -e empty -o not-empty -s exit:0 \
88	    $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
89
90	atf_check -e empty -o empty -s exit:0 \
91	    cp $TEST_SPEC_FILE spec2.mtree
92	atf_check -e empty -o save:dupe_$TEST_SPEC_FILE -s exit:0 \
93	    cat $TEST_SPEC_FILE spec2.mtree
94
95	atf_check -e empty -o not-empty -s not-exit:0 \
96	    $MAKEFS -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
97	atf_check -e empty -o not-empty -s exit:0 \
98	    $MAKEFS -D -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
99}
100D_flag_cleanup()
101{
102	common_cleanup
103}
104
105atf_test_case F_flag cleanup
106F_flag_body()
107{
108	create_test_inputs
109
110	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
111	    mtree -cp $TEST_INPUTS_DIR
112
113	atf_check -e empty -o not-empty -s exit:0 \
114	    $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
115
116	mount_image
117	check_ffs_image_contents
118}
119F_flag_cleanup()
120{
121	common_cleanup
122}
123
124atf_test_case from_mtree_spec_file cleanup
125from_mtree_spec_file_body()
126{
127	create_test_inputs
128
129	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
130	    mtree -c -k "$DEFAULT_MTREE_KEYWORDS" -p $TEST_INPUTS_DIR
131
132	cd $TEST_INPUTS_DIR
133	atf_check -e empty -o not-empty -s exit:0 \
134	    $MAKEFS -M 1m $TEST_IMAGE $TEST_SPEC_FILE
135	cd -
136
137	mount_image
138	check_ffs_image_contents
139}
140from_mtree_spec_file_cleanup()
141{
142	common_cleanup
143}
144
145atf_test_case from_multiple_dirs cleanup
146from_multiple_dirs_body()
147{
148	test_inputs_dir2=$TMPDIR/inputs2
149
150	create_test_inputs
151
152	atf_check -e empty -o empty -s exit:0 mkdir -p $test_inputs_dir2
153	atf_check -e empty -o empty -s exit:0 \
154	    touch $test_inputs_dir2/multiple_dirs_test_file
155
156	atf_check -e empty -o not-empty -s exit:0 \
157	    $MAKEFS -M 1m $TEST_IMAGE $TEST_INPUTS_DIR $test_inputs_dir2
158
159	mount_image
160	check_image_contents -d $test_inputs_dir2
161}
162from_multiple_dirs_cleanup()
163{
164	common_cleanup
165}
166
167atf_test_case from_single_dir cleanup
168from_single_dir_body()
169{
170	create_test_inputs
171
172	atf_check -e empty -o not-empty -s exit:0 \
173	    $MAKEFS -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
174
175	mount_image
176	check_ffs_image_contents
177}
178from_single_dir_cleanup()
179{
180	common_cleanup
181}
182
183atf_test_case o_flag_version_1 cleanup
184o_flag_version_1_body()
185{
186	ffs_version=1
187
188	platform=$(uname)
189	case "$platform" in
190	FreeBSD)
191		ffs_label=UFS${ffs_version}
192		;;
193	NetBSD)
194		ffs_label=FFSv${ffs_version}
195		;;
196	*)
197		atf_skip "Unsupported platform"
198		;;
199	esac
200
201	create_test_inputs
202
203	atf_check -e empty -o not-empty -s exit:0 \
204	    $MAKEFS -M 1m -o version=$ffs_version $TEST_IMAGE $TEST_INPUTS_DIR
205
206	mount_image
207	atf_check -e ignore -o match:"$ffs_label" dumpfs $TEST_MOUNT_DIR
208	check_ffs_image_contents
209}
210o_flag_version_1_cleanup()
211{
212	common_cleanup
213}
214
215atf_test_case o_flag_version_2 cleanup
216o_flag_version_2_body()
217{
218	ffs_version=2
219
220	platform=$(uname)
221	case "$platform" in
222	FreeBSD)
223		ffs_label=UFS${ffs_version}
224		;;
225	NetBSD)
226		ffs_label=FFSv${ffs_version}
227		;;
228	*)
229		atf_skip "Unsupported platform"
230		;;
231	esac
232
233	create_test_inputs
234
235	atf_check -e empty -o not-empty -s exit:0 \
236	    $MAKEFS -M 1m -o version=$ffs_version $TEST_IMAGE $TEST_INPUTS_DIR
237
238	mount_image
239	atf_check -e ignore -o match:"$ffs_label" dumpfs $TEST_MOUNT_DIR
240	check_ffs_image_contents
241}
242o_flag_version_2_cleanup()
243{
244	common_cleanup
245}
246
247atf_init_test_cases()
248{
249
250	atf_add_test_case autocalculate_image_size
251
252	atf_add_test_case D_flag
253	atf_add_test_case F_flag
254
255	atf_add_test_case from_mtree_spec_file
256	atf_add_test_case from_multiple_dirs
257	atf_add_test_case from_single_dir
258
259	atf_add_test_case o_flag_version_1
260	atf_add_test_case o_flag_version_2
261}
262