xref: /freebsd/usr.sbin/makefs/tests/makefs_ffs_tests.sh (revision 865c7b713cff763cb75520d002dbae51fa55a985)
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	atf_expect_fail "PR 229929 makefs(8) can underestimate image size"
61	create_test_inputs
62
63	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
64	    mtree -c -k "$DEFAULT_MTREE_KEYWORDS" -p $TEST_INPUTS_DIR
65
66	cd $TEST_INPUTS_DIR
67	atf_check -e empty -o not-empty -s exit:0 \
68	    $MAKEFS $TEST_IMAGE $TEST_SPEC_FILE
69	cd -
70
71	mount_image
72	check_ffs_image_contents
73}
74autocalculate_image_size_cleanup()
75{
76	common_cleanup
77}
78
79atf_test_case D_flag cleanup
80D_flag_body()
81{
82	atf_skip "makefs crashes with SIGBUS with dupe mtree entries; see FreeBSD bug # 192839"
83
84	create_test_inputs
85
86	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
87	    mtree -cp $TEST_INPUTS_DIR
88	atf_check -e empty -o not-empty -s exit:0 \
89	    $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
90
91	atf_check -e empty -o empty -s exit:0 \
92	    cp $TEST_SPEC_FILE spec2.mtree
93	atf_check -e empty -o save:dupe_$TEST_SPEC_FILE -s exit:0 \
94	    cat $TEST_SPEC_FILE spec2.mtree
95
96	atf_check -e empty -o not-empty -s not-exit:0 \
97	    $MAKEFS -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
98	atf_check -e empty -o not-empty -s exit:0 \
99	    $MAKEFS -D -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
100}
101D_flag_cleanup()
102{
103	common_cleanup
104}
105
106atf_test_case F_flag cleanup
107F_flag_body()
108{
109	if [ "$(atf_config_get ci false)" = "true" ]; then
110		atf_skip "https://bugs.freebsd.org/247425"
111	fi
112
113	create_test_inputs
114
115	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
116	    mtree -cp $TEST_INPUTS_DIR
117
118	atf_check -e empty -o not-empty -s exit:0 \
119	    $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
120
121	mount_image
122	check_ffs_image_contents
123}
124F_flag_cleanup()
125{
126	common_cleanup
127}
128
129atf_test_case from_mtree_spec_file cleanup
130from_mtree_spec_file_body()
131{
132	if [ "$(atf_config_get ci false)" = "true" ]; then
133		atf_skip "https://bugs.freebsd.org/247425"
134	fi
135
136	create_test_inputs
137
138	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
139	    mtree -c -k "$DEFAULT_MTREE_KEYWORDS" -p $TEST_INPUTS_DIR
140
141	cd $TEST_INPUTS_DIR
142	atf_check -e empty -o not-empty -s exit:0 \
143	    $MAKEFS -M 1m $TEST_IMAGE $TEST_SPEC_FILE
144	cd -
145
146	mount_image
147	check_ffs_image_contents
148}
149from_mtree_spec_file_cleanup()
150{
151	common_cleanup
152}
153
154atf_test_case from_multiple_dirs cleanup
155from_multiple_dirs_body()
156{
157	if [ "$(atf_config_get ci false)" = "true" ]; then
158		atf_skip "https://bugs.freebsd.org/247425"
159	fi
160
161	test_inputs_dir2=$TMPDIR/inputs2
162
163	create_test_inputs
164
165	atf_check -e empty -o empty -s exit:0 mkdir -p $test_inputs_dir2
166	atf_check -e empty -o empty -s exit:0 \
167	    touch $test_inputs_dir2/multiple_dirs_test_file
168
169	atf_check -e empty -o not-empty -s exit:0 \
170	    $MAKEFS -M 1m $TEST_IMAGE $TEST_INPUTS_DIR $test_inputs_dir2
171
172	mount_image
173	check_image_contents -d $test_inputs_dir2
174}
175from_multiple_dirs_cleanup()
176{
177	common_cleanup
178}
179
180atf_test_case from_single_dir cleanup
181from_single_dir_body()
182{
183	if [ "$(atf_config_get ci false)" = "true" ]; then
184		atf_skip "https://bugs.freebsd.org/247425"
185	fi
186
187	create_test_inputs
188
189	atf_check -e empty -o not-empty -s exit:0 \
190	    $MAKEFS -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
191
192	mount_image
193	check_ffs_image_contents
194}
195from_single_dir_cleanup()
196{
197	common_cleanup
198}
199
200atf_test_case o_flag_version_1 cleanup
201o_flag_version_1_body()
202{
203	if [ "$(atf_config_get ci false)" = "true" ]; then
204		atf_skip "https://bugs.freebsd.org/247425"
205	fi
206
207	ffs_version=1
208
209	platform=$(uname)
210	case "$platform" in
211	FreeBSD)
212		ffs_label=UFS${ffs_version}
213		;;
214	NetBSD)
215		ffs_label=FFSv${ffs_version}
216		;;
217	*)
218		atf_skip "Unsupported platform"
219		;;
220	esac
221
222	create_test_inputs
223
224	atf_check -e empty -o not-empty -s exit:0 \
225	    $MAKEFS -M 1m -o version=$ffs_version $TEST_IMAGE $TEST_INPUTS_DIR
226
227	mount_image
228	atf_check -e ignore -o match:"$ffs_label" dumpfs $TEST_MOUNT_DIR
229	check_ffs_image_contents
230}
231o_flag_version_1_cleanup()
232{
233	common_cleanup
234}
235
236atf_test_case o_flag_version_2 cleanup
237o_flag_version_2_body()
238{
239	if [ "$(atf_config_get ci false)" = "true" ]; then
240		atf_skip "https://bugs.freebsd.org/247425"
241	fi
242
243	ffs_version=2
244
245	platform=$(uname)
246	case "$platform" in
247	FreeBSD)
248		ffs_label=UFS${ffs_version}
249		;;
250	NetBSD)
251		ffs_label=FFSv${ffs_version}
252		;;
253	*)
254		atf_skip "Unsupported platform"
255		;;
256	esac
257
258	create_test_inputs
259
260	atf_check -e empty -o not-empty -s exit:0 \
261	    $MAKEFS -M 1m -o version=$ffs_version $TEST_IMAGE $TEST_INPUTS_DIR
262
263	mount_image
264	atf_check -e ignore -o match:"$ffs_label" dumpfs $TEST_MOUNT_DIR
265	check_ffs_image_contents
266}
267o_flag_version_2_cleanup()
268{
269	common_cleanup
270}
271
272atf_init_test_cases()
273{
274
275	atf_add_test_case autocalculate_image_size
276
277	atf_add_test_case D_flag
278	atf_add_test_case F_flag
279
280	atf_add_test_case from_mtree_spec_file
281	atf_add_test_case from_multiple_dirs
282	atf_add_test_case from_single_dir
283
284	atf_add_test_case o_flag_version_1
285	atf_add_test_case o_flag_version_2
286}
287