makefs_ffs_tests.sh revision 290586
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/10/usr.sbin/makefs/tests/makefs_ffs_tests.sh 290586 2015-11-09 07:56:06Z ngie $
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
56atf_test_case D_flag cleanup
57D_flag_body()
58{
59	atf_skip "makefs crashes with SIGBUS with dupe mtree entries; see FreeBSD bug # 192839"
60
61	create_test_inputs
62
63	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
64	    mtree -cp $TEST_INPUTS_DIR
65	atf_check -e empty -o not-empty -s exit:0 \
66	    $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
67
68	atf_check -e empty -o empty -s exit:0 \
69	    cp $TEST_SPEC_FILE spec2.mtree
70	atf_check -e empty -o save:dupe_$TEST_SPEC_FILE -s exit:0 \
71	    cat $TEST_SPEC_FILE spec2.mtree
72
73	atf_check -e empty -o not-empty -s not-exit:0 \
74	    $MAKEFS -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
75	atf_check -e empty -o not-empty -s exit:0 \
76	    $MAKEFS -D -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
77}
78D_flag_cleanup()
79{
80	common_cleanup
81}
82
83atf_test_case F_flag cleanup
84F_flag_body()
85{
86	create_test_inputs
87
88	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
89	    mtree -cp $TEST_INPUTS_DIR
90
91	atf_check -e empty -o not-empty -s exit:0 \
92	    $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
93
94	mount_image
95	check_ffs_image_contents
96}
97F_flag_cleanup()
98{
99	common_cleanup
100}
101
102atf_test_case from_mtree_spec_file cleanup
103from_mtree_spec_file_body()
104{
105	create_test_inputs
106
107	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
108	    mtree -c -k type,link,size -p $TEST_INPUTS_DIR
109
110	cd $TEST_INPUTS_DIR
111	atf_check -e empty -o not-empty -s exit:0 \
112	    $MAKEFS $TEST_IMAGE $TEST_SPEC_FILE
113	cd -
114
115	mount_image
116	check_ffs_image_contents
117}
118from_mtree_spec_file_cleanup()
119{
120	common_cleanup
121}
122
123atf_test_case from_multiple_dirs cleanup
124from_multiple_dirs_body()
125{
126	test_inputs_dir2=$TMPDIR/inputs2
127
128	create_test_inputs
129
130	atf_check -e empty -o empty -s exit:0 mkdir -p $test_inputs_dir2
131	atf_check -e empty -o empty -s exit:0 \
132	    touch $test_inputs_dir2/multiple_dirs_test_file
133
134	atf_check -e empty -o not-empty -s exit:0 \
135	    $MAKEFS $TEST_IMAGE $TEST_INPUTS_DIR $test_inputs_dir2
136
137	mount_image
138	check_image_contents -d $test_inputs_dir2
139}
140from_multiple_dirs_cleanup()
141{
142	common_cleanup
143}
144
145atf_test_case from_single_dir cleanup
146from_single_dir_body()
147{
148	create_test_inputs
149
150	atf_check -e empty -o not-empty -s exit:0 \
151	    $MAKEFS -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
152
153	mount_image
154	check_ffs_image_contents
155}
156from_single_dir_cleanup()
157{
158	common_cleanup
159}
160
161atf_init_test_cases()
162{
163
164	atf_add_test_case D_flag
165	atf_add_test_case F_flag
166
167	atf_add_test_case from_mtree_spec_file
168	atf_add_test_case from_multiple_dirs
169	atf_add_test_case from_single_dir
170
171
172}
173