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