xref: /freebsd/tests/sys/geom/class/eli/misc_test.sh (revision 4d846d26)
1# SPDX-License-Identifier: BSD-2-Clause
2#
3# Copyright (c) 2018 Alan Somers
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8# 1. Redistributions of source code must retain the above copyright
9#    notice, this list of conditions and the following disclaimer.
10# 2. Redistributions in binary form must reproduce the above copyright
11#    notice, this list of conditions and the following disclaimer in the
12#    documentation and/or other materials provided with the distribution.
13#
14# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24# SUCH DAMAGE.
25#
26# $FreeBSD$
27
28. $(atf_get_srcdir)/conf.sh
29
30atf_test_case preserve_props cleanup
31preserve_props_head()
32{
33	atf_set "descr" "geli should preserve basic GEOM properties"
34	atf_set "require.user" "root"
35	atf_set "timeout" 15
36}
37preserve_props_body()
38{
39	geli_test_setup
40
41	md=$(attach_md -s1m)
42	atf_check geli onetime /dev/${md}
43	md_secsize=$(diskinfo ${md} | cut -wf 2)
44	md_stripesize=$(diskinfo ${md} | cut -wf 5)
45	eli_secsize=$(diskinfo ${md}.eli | cut -wf 2)
46	eli_stripesize=$(diskinfo ${md}.eli | cut -wf 5)
47	atf_check_equal "$md_secsize" "$eli_secsize"
48	atf_check_equal "$md_stripesize" "$eli_stripesize"
49}
50preserve_props_cleanup()
51{
52	geli_test_cleanup
53}
54
55atf_test_case preserve_disk_props cleanup
56preserve_disk_props_head()
57{
58	atf_set "descr" "geli should preserve properties for disks"
59	atf_set "require.user" "root"
60	atf_set "require.config" "disks"
61	atf_set "timeout" 15
62}
63preserve_disk_props_body()
64{
65	geli_test_setup
66
67	disks=`atf_config_get disks`
68	disk=${disks%% *}
69	if [ -z "$disk" ]; then
70		atf_skip "Must define disks (see tests(7))"
71	fi
72	atf_check geli onetime ${disk}
73
74	disk_ident=$(diskinfo -s ${disk})
75	disk_descr=$(diskinfo -v ${disk} | awk '/Disk descr/ {print $1}')
76	disk_rotrate=$(diskinfo -v ${disk} | awk '/Rotation rate/ {print $1}')
77	disk_zonemode=$(diskinfo -v ${disk} | awk '/Zone Mode/ {print $1}')
78	eli_ident=$(diskinfo -s ${disk}.eli)
79	eli_descr=$(diskinfo -v ${disk}.eli | awk '/Disk descr/ {print $1}')
80	eli_rotrate=$(diskinfo -v ${disk}.eli | awk '/Rotation/ {print $1}')
81	eli_zonemode=$(diskinfo -v ${disk}.eli | awk '/Zone Mode/ {print $1}')
82	atf_check_equal "$disk_ident" "$eli_ident"
83	atf_check_equal "$disk_descr" "$eli_descr"
84	atf_check_equal "$disk_rotrate" "$eli_rotrate"
85	atf_check_equal "$disk_zonemode" "$eli_zonemode"
86}
87preserve_disk_props_cleanup()
88{
89	disk_cleanup
90	geli_test_cleanup
91}
92
93atf_test_case physpath cleanup
94physpath_head()
95{
96	atf_set "descr" "geli should append /eli to the underlying device's physical path"
97	atf_set "require.user" "root"
98	atf_set "timeout" 15
99}
100physpath_body()
101{
102	geli_test_setup
103	if ! error_message=$(geom_load_class_if_needed nop); then
104		atf_skip "$error_message"
105	fi
106
107	md=$(attach_md -s1m)
108	# If the underlying device has no physical path, then geli should not
109	# create one.
110	atf_check -o empty -e ignore diskinfo -p $md
111	atf_check -s exit:0 geli onetime $md
112	atf_check -o empty -e ignore diskinfo -p $md.eli
113	atf_check -s exit:0 geli kill $md
114
115	# If the underlying device does have a physical path, then geli should
116	# append "/eli"
117	physpath="some/physical/path"
118	atf_check gnop create -z $physpath ${md}
119	atf_check -s exit:0 geli onetime $md.nop
120	atf_check -o match:"^${physpath}/eli$" diskinfo -p $md.nop.eli
121}
122physpath_cleanup()
123{
124	if [ -f "$TEST_MDS_FILE" ]; then
125		while read md; do
126			[ -c /dev/${md}.nop.eli ] && \
127				geli detach $md.nop.eli 2>/dev/null
128			[ -c /dev/${md}.nop ] && \
129				gnop destroy -f $md.nop 2>/dev/null
130			[ -c /dev/${md}.eli ] && \
131				geli detach $md.eli 2>/dev/null
132			mdconfig -d -u $md 2>/dev/null
133		done < $TEST_MDS_FILE
134	fi
135	true
136}
137
138atf_init_test_cases()
139{
140	atf_add_test_case physpath
141	atf_add_test_case preserve_props
142	atf_add_test_case preserve_disk_props
143}
144
145
146common_cleanup()
147{
148
149	if [ -f "$MD_DEVS" ]; then
150		while read test_md; do
151			gnop destroy -f ${test_md}.nop 2>/dev/null
152			mdconfig -d -u $test_md 2>/dev/null
153		done < $MD_DEVS
154		rm $MD_DEVS
155	fi
156
157	if [ -f "$PLAINFILES" ]; then
158		while read f; do
159			rm -f ${f}
160		done < ${PLAINFILES}
161		rm ${PLAINFILES}
162	fi
163	true
164}
165
166disk_cleanup()
167{
168	disks=`atf_config_get disks`
169	disk=${disks%% *}
170	if [ -n "$disk" ]; then
171		geli kill ${disk} 2>/dev/null
172	fi
173}
174