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