xref: /freebsd/tests/sys/geom/class/part/misc.sh (revision 834063202a16592e1ef5c3a9fbd04ca5f1df3ed0)
1*83406320SAlan Somers# Copyright (c) 2018 Alan Somers
2*83406320SAlan Somers# All rights reserved.
3*83406320SAlan Somers#
4*83406320SAlan Somers# Redistribution and use in source and binary forms, with or without
5*83406320SAlan Somers# modification, are permitted provided that the following conditions
6*83406320SAlan Somers# are met:
7*83406320SAlan Somers# 1. Redistributions of source code must retain the above copyright
8*83406320SAlan Somers#    notice, this list of conditions and the following disclaimer.
9*83406320SAlan Somers# 2. Redistributions in binary form must reproduce the above copyright
10*83406320SAlan Somers#    notice, this list of conditions and the following disclaimer in the
11*83406320SAlan Somers#    documentation and/or other materials provided with the distribution.
12*83406320SAlan Somers#
13*83406320SAlan Somers# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14*83406320SAlan Somers# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15*83406320SAlan Somers# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16*83406320SAlan Somers# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17*83406320SAlan Somers# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18*83406320SAlan Somers# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19*83406320SAlan Somers# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20*83406320SAlan Somers# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21*83406320SAlan Somers# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22*83406320SAlan Somers# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23*83406320SAlan Somers# SUCH DAMAGE.
24*83406320SAlan Somers#
25*83406320SAlan Somers# $FreeBSD$
26*83406320SAlan Somers
27*83406320SAlan SomersMD_DEVS="md.devs"
28*83406320SAlan Somers
29*83406320SAlan Somersatf_test_case blank_physpath cleanup
30*83406320SAlan Somersblank_physpath_head()
31*83406320SAlan Somers{
32*83406320SAlan Somers	atf_set "descr" "gpart shouldn't add physical paths to underlying providers that have none"
33*83406320SAlan Somers	atf_set "require.user" "root"
34*83406320SAlan Somers}
35*83406320SAlan Somersblank_physpath_body()
36*83406320SAlan Somers{
37*83406320SAlan Somers	load_gnop
38*83406320SAlan Somers	load_gpart
39*83406320SAlan Somers	md=$(alloc_md)
40*83406320SAlan Somers	atf_check -o empty -e ignore diskinfo -p ${md}
41*83406320SAlan Somers	atf_check -s exit:0 -o ignore gpart create -s bsd ${md}
42*83406320SAlan Somers	atf_check -s exit:0 -o ignore gpart add -t freebsd-ufs ${md}
43*83406320SAlan Somers	atf_check -o empty -e ignore diskinfo -p ${md}a
44*83406320SAlan Somers}
45*83406320SAlan Somersblank_physpath_cleanup()
46*83406320SAlan Somers{
47*83406320SAlan Somers	common_cleanup
48*83406320SAlan Somers}
49*83406320SAlan Somers
50*83406320SAlan Somers
51*83406320SAlan Somersatf_test_case bsd_physpath cleanup
52*83406320SAlan Somersbsd_physpath_head()
53*83406320SAlan Somers{
54*83406320SAlan Somers	atf_set "descr" "BSD partitions should append /X to the underlying device's physical path"
55*83406320SAlan Somers	atf_set "require.user" "root"
56*83406320SAlan Somers}
57*83406320SAlan Somersbsd_physpath_body()
58*83406320SAlan Somers{
59*83406320SAlan Somers	load_gnop
60*83406320SAlan Somers	load_gpart
61*83406320SAlan Somers	md=$(alloc_md)
62*83406320SAlan Somers	physpath="some/physical/path"
63*83406320SAlan Somers	atf_check gnop create -z $physpath /dev/${md}
64*83406320SAlan Somers	atf_check -s exit:0 -o ignore gpart create -s bsd ${md}.nop
65*83406320SAlan Somers	atf_check -s exit:0 -o ignore gpart add -t freebsd-ufs ${md}.nop
66*83406320SAlan Somers	gpart_physpath=$(diskinfo -p ${md}.nopa)
67*83406320SAlan Somers	atf_check_equal "${physpath}/a" "$gpart_physpath"
68*83406320SAlan Somers}
69*83406320SAlan Somersbsd_physpath_cleanup()
70*83406320SAlan Somers{
71*83406320SAlan Somers	common_cleanup
72*83406320SAlan Somers}
73*83406320SAlan Somers
74*83406320SAlan Somersatf_test_case gpt_physpath cleanup
75*83406320SAlan Somersgpt_physpath_head()
76*83406320SAlan Somers{
77*83406320SAlan Somers	atf_set "descr" "GPT partitions should append /pX to the underlying device's physical path"
78*83406320SAlan Somers	atf_set "require.user" "root"
79*83406320SAlan Somers}
80*83406320SAlan Somersgpt_physpath_body()
81*83406320SAlan Somers{
82*83406320SAlan Somers	load_gnop
83*83406320SAlan Somers	load_gpart
84*83406320SAlan Somers	md=$(alloc_md)
85*83406320SAlan Somers	physpath="some/physical/path"
86*83406320SAlan Somers	atf_check gnop create -z $physpath /dev/${md}
87*83406320SAlan Somers	atf_check -s exit:0 -o ignore gpart create -s gpt ${md}.nop
88*83406320SAlan Somers	atf_check -s exit:0 -o ignore gpart add -t efi ${md}.nop
89*83406320SAlan Somers	gpart_physpath=$(diskinfo -p ${md}.nopp1)
90*83406320SAlan Somers	atf_check_equal "${physpath}/p1" "$gpart_physpath"
91*83406320SAlan Somers}
92*83406320SAlan Somersgpt_physpath_cleanup()
93*83406320SAlan Somers{
94*83406320SAlan Somers	common_cleanup
95*83406320SAlan Somers}
96*83406320SAlan Somers
97*83406320SAlan Somersatf_test_case mbr_physpath cleanup
98*83406320SAlan Somersmbr_physpath_head()
99*83406320SAlan Somers{
100*83406320SAlan Somers	atf_set "descr" "MBR partitions should append /sX to the underlying device's physical path"
101*83406320SAlan Somers	atf_set "require.user" "root"
102*83406320SAlan Somers}
103*83406320SAlan Somersmbr_physpath_body()
104*83406320SAlan Somers{
105*83406320SAlan Somers	load_gnop
106*83406320SAlan Somers	load_gpart
107*83406320SAlan Somers	md=$(alloc_md)
108*83406320SAlan Somers	physpath="some/physical/path"
109*83406320SAlan Somers	atf_check gnop create -z $physpath /dev/${md}
110*83406320SAlan Somers	atf_check -s exit:0 -o ignore gpart create -s mbr ${md}.nop
111*83406320SAlan Somers	atf_check -s exit:0 -o ignore gpart add -t freebsd ${md}.nop
112*83406320SAlan Somers	gpart_physpath=$(diskinfo -p ${md}.nops1)
113*83406320SAlan Somers	atf_check_equal "${physpath}/s1" "$gpart_physpath"
114*83406320SAlan Somers}
115*83406320SAlan Somersmbr_physpath_cleanup()
116*83406320SAlan Somers{
117*83406320SAlan Somers	common_cleanup
118*83406320SAlan Somers}
119*83406320SAlan Somers
120*83406320SAlan Somersatf_test_case mbr_bsd_physpath cleanup
121*83406320SAlan Somersmbr_bsd_physpath_head()
122*83406320SAlan Somers{
123*83406320SAlan Somers	atf_set "descr" "BSD partitions nested within MBR partitions should append /sX/Y to the underlying device's physical path"
124*83406320SAlan Somers	atf_set "require.user" "root"
125*83406320SAlan Somers}
126*83406320SAlan Somersmbr_bsd_physpath_body()
127*83406320SAlan Somers{
128*83406320SAlan Somers	load_gnop
129*83406320SAlan Somers	load_gpart
130*83406320SAlan Somers	md=$(alloc_md)
131*83406320SAlan Somers	physpath="some/physical/path"
132*83406320SAlan Somers	atf_check gnop create -z $physpath /dev/${md}
133*83406320SAlan Somers	atf_check -s exit:0 -o ignore gpart create -s mbr ${md}.nop
134*83406320SAlan Somers	atf_check -s exit:0 -o ignore gpart add -t freebsd ${md}.nop
135*83406320SAlan Somers	atf_check -s exit:0 -o ignore gpart create -s bsd ${md}.nops1
136*83406320SAlan Somers	atf_check -s exit:0 -o ignore gpart add -t freebsd-ufs ${md}.nops1
137*83406320SAlan Somers	gpart_physpath=$(diskinfo -p ${md}.nops1a)
138*83406320SAlan Somers	atf_check_equal "${physpath}/s1/a" "$gpart_physpath"
139*83406320SAlan Somers}
140*83406320SAlan Somersmbr_bsd_physpath_cleanup()
141*83406320SAlan Somers{
142*83406320SAlan Somers	common_cleanup
143*83406320SAlan Somers}
144*83406320SAlan Somers
145*83406320SAlan Somersatf_init_test_cases()
146*83406320SAlan Somers{
147*83406320SAlan Somers	atf_add_test_case blank_physpath
148*83406320SAlan Somers	atf_add_test_case bsd_physpath
149*83406320SAlan Somers	atf_add_test_case gpt_physpath
150*83406320SAlan Somers	atf_add_test_case mbr_physpath
151*83406320SAlan Somers	atf_add_test_case mbr_bsd_physpath
152*83406320SAlan Somers}
153*83406320SAlan Somers
154*83406320SAlan Somersalloc_md()
155*83406320SAlan Somers{
156*83406320SAlan Somers	local md
157*83406320SAlan Somers
158*83406320SAlan Somers	md=$(mdconfig -a -t swap -s 1M) || atf_fail "mdconfig -a failed"
159*83406320SAlan Somers	echo ${md} >> $MD_DEVS
160*83406320SAlan Somers	echo ${md}
161*83406320SAlan Somers}
162*83406320SAlan Somers
163*83406320SAlan Somerscommon_cleanup()
164*83406320SAlan Somers{
165*83406320SAlan Somers	if [ -f "$MD_DEVS" ]; then
166*83406320SAlan Somers		while read test_md; do
167*83406320SAlan Somers			gnop destroy -f ${test_md}.nop 2>/dev/null
168*83406320SAlan Somers			mdconfig -d -u $test_md 2>/dev/null
169*83406320SAlan Somers		done < $MD_DEVS
170*83406320SAlan Somers		rm $MD_DEVS
171*83406320SAlan Somers	fi
172*83406320SAlan Somers	true
173*83406320SAlan Somers}
174*83406320SAlan Somers
175*83406320SAlan Somersload_gpart()
176*83406320SAlan Somers{
177*83406320SAlan Somers	if ! kldstat -q -m g_part; then
178*83406320SAlan Somers		geom part load || atf_skip "could not load module for geom part"
179*83406320SAlan Somers	fi
180*83406320SAlan Somers}
181*83406320SAlan Somers
182*83406320SAlan Somersload_gnop()
183*83406320SAlan Somers{
184*83406320SAlan Somers	if ! kldstat -q -m g_nop; then
185*83406320SAlan Somers		geom nop load || atf_skip "could not load module for geom nop"
186*83406320SAlan Somers	fi
187*83406320SAlan Somers}
188