xref: /freebsd/tests/sys/geom/class/nop/nop_test.sh (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1*4d846d26SWarner Losh# SPDX-License-Identifier: BSD-2-Clause
2809a8352SAlan Somers#
3162ea6dcSAlan Somers# Copyright (c) 2016 Alan Somers
4162ea6dcSAlan Somers#
5162ea6dcSAlan Somers# Redistribution and use in source and binary forms, with or without
6162ea6dcSAlan Somers# modification, are permitted provided that the following conditions
7162ea6dcSAlan Somers# are met:
8162ea6dcSAlan Somers# 1. Redistributions of source code must retain the above copyright
9162ea6dcSAlan Somers#    notice, this list of conditions and the following disclaimer.
10162ea6dcSAlan Somers# 2. Redistributions in binary form must reproduce the above copyright
11162ea6dcSAlan Somers#    notice, this list of conditions and the following disclaimer in the
12162ea6dcSAlan Somers#    documentation and/or other materials provided with the distribution.
13162ea6dcSAlan Somers#
14162ea6dcSAlan Somers# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15162ea6dcSAlan Somers# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16162ea6dcSAlan Somers# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17162ea6dcSAlan Somers# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18162ea6dcSAlan Somers# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19162ea6dcSAlan Somers# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20162ea6dcSAlan Somers# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21162ea6dcSAlan Somers# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22162ea6dcSAlan Somers# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23162ea6dcSAlan Somers# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24162ea6dcSAlan Somers# SUCH DAMAGE.
25162ea6dcSAlan Somers#
26162ea6dcSAlan Somers
27162ea6dcSAlan SomersMD_DEVS="md.devs"
28162ea6dcSAlan SomersPLAINFILES=plainfiles
29162ea6dcSAlan Somers
306f7f85e0SAlan Somersatf_test_case preserve_props cleanup
316f7f85e0SAlan Somerspreserve_props_head()
32162ea6dcSAlan Somers{
336f7f85e0SAlan Somers	atf_set "descr" "gnop should preserve basic GEOM properties"
34162ea6dcSAlan Somers	atf_set "require.user" "root"
35162ea6dcSAlan Somers	atf_set "timeout" 15
36162ea6dcSAlan Somers}
376f7f85e0SAlan Somerspreserve_props_body()
38162ea6dcSAlan Somers{
3937a13f57SMark Johnston	load_gnop
40162ea6dcSAlan Somers	us=$(alloc_md)
41162ea6dcSAlan Somers	atf_check gnop create /dev/${us}
42162ea6dcSAlan Somers	md_secsize=$(diskinfo ${us} | cut -wf 2)
43162ea6dcSAlan Somers	md_mediasize=$(diskinfo ${us} | cut -wf 3)
44162ea6dcSAlan Somers	md_stripesize=$(diskinfo ${us} | cut -wf 5)
45162ea6dcSAlan Somers	nop_secsize=$(diskinfo ${us}.nop | cut -wf 2)
46162ea6dcSAlan Somers	nop_mediasize=$(diskinfo ${us}.nop | cut -wf 3)
47162ea6dcSAlan Somers	nop_stripesize=$(diskinfo ${us}.nop | cut -wf 5)
48162ea6dcSAlan Somers	atf_check_equal "$md_secsize" "$nop_secsize"
49162ea6dcSAlan Somers	atf_check_equal "$md_mediasize" "$nop_mediasize"
50162ea6dcSAlan Somers	atf_check_equal "$md_stripesize" "$nop_stripesize"
51162ea6dcSAlan Somers}
526f7f85e0SAlan Somerspreserve_props_cleanup()
53162ea6dcSAlan Somers{
54162ea6dcSAlan Somers	common_cleanup
55162ea6dcSAlan Somers}
56162ea6dcSAlan Somers
576f7f85e0SAlan Somersatf_test_case preserve_disk_props cleanup
586f7f85e0SAlan Somerspreserve_disk_props_head()
596f7f85e0SAlan Somers{
606f7f85e0SAlan Somers	atf_set "descr" "gnop should preserve properties for disks"
616f7f85e0SAlan Somers	atf_set "require.user" "root"
626f7f85e0SAlan Somers	atf_set "require.config" "disks"
636f7f85e0SAlan Somers	atf_set "timeout" 15
646f7f85e0SAlan Somers}
656f7f85e0SAlan Somerspreserve_disk_props_body()
666f7f85e0SAlan Somers{
676f7f85e0SAlan Somers	load_gnop
686f7f85e0SAlan Somers	disks=`atf_config_get disks`
696f7f85e0SAlan Somers	disk=${disks%% *}
706f7f85e0SAlan Somers	if [ -z "$disk" ]; then
716f7f85e0SAlan Somers		atf_skip "Must define disks (see tests(7))"
726f7f85e0SAlan Somers	fi
736f7f85e0SAlan Somers	atf_check gnop create ${disk}
746f7f85e0SAlan Somers
756f7f85e0SAlan Somers	disk_ident=$(diskinfo -s ${disk})
766f7f85e0SAlan Somers	disk_physpath=$(diskinfo -p ${disk})
776f7f85e0SAlan Somers	disk_descr=$(diskinfo -v ${disk} | awk '/Disk descr/ {print $1}')
786f7f85e0SAlan Somers	disk_trim=$(diskinfo -v ${disk} | awk '/TRIM.UNMAP/ {print $1}')
796f7f85e0SAlan Somers	disk_rotrate=$(diskinfo -v ${disk} | awk '/Rotation rate/ {print $1}')
806f7f85e0SAlan Somers	disk_zonemode=$(diskinfo -v ${disk} | awk '/Zone Mode/ {print $1}')
816f7f85e0SAlan Somers	nop_ident=$(diskinfo -s ${disk}.nop)
826f7f85e0SAlan Somers	nop_physpath=$(diskinfo -p ${disk}.nop)
836f7f85e0SAlan Somers	nop_descr=$(diskinfo -v ${disk}.nop | awk '/Disk descr/ {print $1}')
846f7f85e0SAlan Somers	nop_trim=$(diskinfo -v ${disk}.nop | awk '/TRIM.UNMAP/ {print $1}')
856f7f85e0SAlan Somers	nop_rotrate=$(diskinfo -v ${disk}.nop | awk '/Rotation/ {print $1}')
866f7f85e0SAlan Somers	nop_zonemode=$(diskinfo -v ${disk}.nop | awk '/Zone Mode/ {print $1}')
876f7f85e0SAlan Somers	atf_check_equal "$disk_ident" "$nop_ident"
886f7f85e0SAlan Somers	atf_check_equal "$disk_physpath" "$nop_physpath"
896f7f85e0SAlan Somers	atf_check_equal "$disk_descr" "$nop_descr"
906f7f85e0SAlan Somers	atf_check_equal "$disk_trim" "$nop_trim"
916f7f85e0SAlan Somers	atf_check_equal "$disk_rotrate" "$nop_rotrate"
926f7f85e0SAlan Somers	atf_check_equal "$disk_zonemode" "$nop_zonemode"
936f7f85e0SAlan Somers}
946f7f85e0SAlan Somerspreserve_disk_props_cleanup()
956f7f85e0SAlan Somers{
966f7f85e0SAlan Somers	disk_cleanup
976f7f85e0SAlan Somers	common_cleanup
986f7f85e0SAlan Somers}
996f7f85e0SAlan Somers
100162ea6dcSAlan Somersatf_test_case io cleanup
101162ea6dcSAlan Somersio_head()
102162ea6dcSAlan Somers{
103162ea6dcSAlan Somers	atf_set "descr" "I/O works on gnop devices"
104162ea6dcSAlan Somers	atf_set "require.user" "root"
105162ea6dcSAlan Somers	atf_set "timeout" 15
106162ea6dcSAlan Somers}
107162ea6dcSAlan Somersio_body()
108162ea6dcSAlan Somers{
10937a13f57SMark Johnston	load_gnop
110162ea6dcSAlan Somers	us=$(alloc_md)
111162ea6dcSAlan Somers	atf_check gnop create /dev/${us}
112162ea6dcSAlan Somers
113162ea6dcSAlan Somers	echo src >> $PLAINFILES
114162ea6dcSAlan Somers	echo dst >> $PLAINFILES
115162ea6dcSAlan Somers	dd if=/dev/random of=src bs=1m count=1 >/dev/null 2>&1
116162ea6dcSAlan Somers	dd if=src of=/dev/${us}.nop bs=1m count=1 > /dev/null 2>&1
117162ea6dcSAlan Somers	dd if=/dev/${us}.nop of=dst bs=1m count=1 > /dev/null 2>&1
118162ea6dcSAlan Somers
119162ea6dcSAlan Somers	atf_check_equal `md5 -q src` `md5 -q dst`
120162ea6dcSAlan Somers}
121162ea6dcSAlan Somersio_cleanup()
122162ea6dcSAlan Somers{
123162ea6dcSAlan Somers	common_cleanup
124162ea6dcSAlan Somers}
125162ea6dcSAlan Somers
1266f7f85e0SAlan Somersatf_test_case physpath cleanup
1276f7f85e0SAlan Somersphyspath_head()
1286f7f85e0SAlan Somers{
1296f7f85e0SAlan Somers	atf_set "descr" "Test gnop's -z option"
1306f7f85e0SAlan Somers	atf_set "require.user" "root"
1316f7f85e0SAlan Somers	atf_set "timeout" 15
1326f7f85e0SAlan Somers}
1336f7f85e0SAlan Somersphyspath_body()
1346f7f85e0SAlan Somers{
1356f7f85e0SAlan Somers	load_gnop
1366f7f85e0SAlan Somers	us=$(alloc_md)
1376f7f85e0SAlan Somers	physpath="some/physical/path"
1386f7f85e0SAlan Somers	atf_check gnop create -z $physpath /dev/${us}
1396f7f85e0SAlan Somers	gnop_physpath=$(diskinfo -p ${us}.nop)
1406f7f85e0SAlan Somers	atf_check_equal "$physpath" "$gnop_physpath"
1416f7f85e0SAlan Somers}
1426f7f85e0SAlan Somersphyspath_cleanup()
1436f7f85e0SAlan Somers{
1446f7f85e0SAlan Somers	common_cleanup
1456f7f85e0SAlan Somers}
1466f7f85e0SAlan Somers
1476f7f85e0SAlan Somersatf_test_case physpath_blank cleanup
1486f7f85e0SAlan Somersphyspath_blank_head()
1496f7f85e0SAlan Somers{
1506f7f85e0SAlan Somers	atf_set "descr" "gnop can set physical path to the empty string"
1516f7f85e0SAlan Somers	atf_set "require.user" "root"
1526f7f85e0SAlan Somers	atf_set "require.config" "disks"
1536f7f85e0SAlan Somers	atf_set "timeout" 15
1546f7f85e0SAlan Somers}
1556f7f85e0SAlan Somersphyspath_blank_body()
1566f7f85e0SAlan Somers{
1576f7f85e0SAlan Somers	load_gnop
1586f7f85e0SAlan Somers	disks=`atf_config_get disks`
1596f7f85e0SAlan Somers	disk=${disks%% *}
1606f7f85e0SAlan Somers	if [ -z "$disk" ]; then
1616f7f85e0SAlan Somers		atf_skip "Must define disks (see tests(7))"
1626f7f85e0SAlan Somers	fi
1636f7f85e0SAlan Somers
1646f7f85e0SAlan Somers	atf_check gnop create -z "" ${disk}
1656f7f85e0SAlan Somers	gnop_physpath=$(diskinfo -p ${disk}.nop)
1666f7f85e0SAlan Somers	atf_check_equal "" "$gnop_physpath"
1676f7f85e0SAlan Somers}
1686f7f85e0SAlan Somersphyspath_blank_cleanup()
1696f7f85e0SAlan Somers{
1706f7f85e0SAlan Somers	disk_cleanup
1716f7f85e0SAlan Somers	common_cleanup
1726f7f85e0SAlan Somers}
1736f7f85e0SAlan Somers
174162ea6dcSAlan Somersatf_test_case size cleanup
175162ea6dcSAlan Somerssize_head()
176162ea6dcSAlan Somers{
177162ea6dcSAlan Somers	atf_set "descr" "Test gnop's -s option"
178162ea6dcSAlan Somers	atf_set "require.user" "root"
179162ea6dcSAlan Somers	atf_set "timeout" 15
180162ea6dcSAlan Somers}
181162ea6dcSAlan Somerssize_body()
182162ea6dcSAlan Somers{
18337a13f57SMark Johnston	load_gnop
184162ea6dcSAlan Somers	us=$(alloc_md)
185162ea6dcSAlan Somers	for mediasize in 65536 524288 1048576; do
186162ea6dcSAlan Somers		atf_check gnop create -s ${mediasize} /dev/${us}
187162ea6dcSAlan Somers		gnop_mediasize=`diskinfo /dev/${us}.nop | cut -wf 3`
188162ea6dcSAlan Somers		atf_check_equal "${mediasize}" "${gnop_mediasize}"
189162ea6dcSAlan Somers		atf_check gnop destroy /dev/${us}.nop
190162ea6dcSAlan Somers	done
191162ea6dcSAlan Somers	# We shouldn't be able to extend the provider's size
192162ea6dcSAlan Somers	atf_check -s not-exit:0 -e ignore gnop create -s 2097152 /dev/${us}
193162ea6dcSAlan Somers}
194162ea6dcSAlan Somerssize_cleanup()
195162ea6dcSAlan Somers{
196162ea6dcSAlan Somers	common_cleanup
197162ea6dcSAlan Somers}
198162ea6dcSAlan Somers
199162ea6dcSAlan Somersatf_test_case stripesize cleanup
200162ea6dcSAlan Somersstripesize_head()
201162ea6dcSAlan Somers{
202162ea6dcSAlan Somers	atf_set "descr" "Test gnop's -p and -P options"
203162ea6dcSAlan Somers	atf_set "require.user" "root"
2047db4981bSRuslan Bukin	atf_set "timeout" 120
205162ea6dcSAlan Somers}
206162ea6dcSAlan Somersstripesize_body()
207162ea6dcSAlan Somers{
20837a13f57SMark Johnston	load_gnop
209162ea6dcSAlan Somers	us=$(alloc_md)
210162ea6dcSAlan Somers	for ss in 512 1024 2048 4096 8192; do
211162ea6dcSAlan Somers		for sofs in `seq 0 512 ${ss}`; do
212162ea6dcSAlan Somers			[ "$sofs" -eq "$ss" ] && continue
213162ea6dcSAlan Somers			atf_check gnop create -p ${ss} -P ${sofs} /dev/${us}
214162ea6dcSAlan Somers			gnop_ss=`diskinfo /dev/${us}.nop | cut -wf 5`
215162ea6dcSAlan Somers			gnop_sofs=`diskinfo /dev/${us}.nop | cut -wf 6`
216162ea6dcSAlan Somers			atf_check_equal "${ss}" "${gnop_ss}"
217162ea6dcSAlan Somers			atf_check_equal "${sofs}" "${gnop_sofs}"
218162ea6dcSAlan Somers			atf_check gnop destroy /dev/${us}.nop
219162ea6dcSAlan Somers		done
220162ea6dcSAlan Somers	done
221162ea6dcSAlan Somers}
222162ea6dcSAlan Somersstripesize_cleanup()
223162ea6dcSAlan Somers{
224162ea6dcSAlan Somers	common_cleanup
225162ea6dcSAlan Somers}
226162ea6dcSAlan Somers
227162ea6dcSAlan Somersatf_init_test_cases()
228162ea6dcSAlan Somers{
229162ea6dcSAlan Somers	atf_add_test_case io
2306f7f85e0SAlan Somers	atf_add_test_case physpath
2316f7f85e0SAlan Somers	atf_add_test_case physpath_blank
2326f7f85e0SAlan Somers	atf_add_test_case preserve_props
2336f7f85e0SAlan Somers	atf_add_test_case preserve_disk_props
234162ea6dcSAlan Somers	atf_add_test_case stripesize
235162ea6dcSAlan Somers	atf_add_test_case size
236162ea6dcSAlan Somers}
237162ea6dcSAlan Somers
238162ea6dcSAlan Somersalloc_md()
239162ea6dcSAlan Somers{
240162ea6dcSAlan Somers	local md
241162ea6dcSAlan Somers
242162ea6dcSAlan Somers	md=$(mdconfig -a -t swap -s 1M) || atf_fail "mdconfig -a failed"
243162ea6dcSAlan Somers	echo ${md} >> $MD_DEVS
244162ea6dcSAlan Somers	echo ${md}
245162ea6dcSAlan Somers}
246162ea6dcSAlan Somers
247162ea6dcSAlan Somerscommon_cleanup()
248162ea6dcSAlan Somers{
249162ea6dcSAlan Somers	if [ -f "$MD_DEVS" ]; then
250162ea6dcSAlan Somers		while read test_md; do
251162ea6dcSAlan Somers			gnop destroy -f ${test_md}.nop 2>/dev/null
252162ea6dcSAlan Somers			mdconfig -d -u $test_md 2>/dev/null
253162ea6dcSAlan Somers		done < $MD_DEVS
254162ea6dcSAlan Somers		rm $MD_DEVS
255162ea6dcSAlan Somers	fi
256162ea6dcSAlan Somers
257162ea6dcSAlan Somers	if [ -f "$PLAINFILES" ]; then
258162ea6dcSAlan Somers		while read f; do
259162ea6dcSAlan Somers			rm -f ${f}
260162ea6dcSAlan Somers		done < ${PLAINFILES}
261162ea6dcSAlan Somers		rm ${PLAINFILES}
262162ea6dcSAlan Somers	fi
263162ea6dcSAlan Somers	true
264162ea6dcSAlan Somers}
26537a13f57SMark Johnston
2666f7f85e0SAlan Somersdisk_cleanup()
2676f7f85e0SAlan Somers{
2686f7f85e0SAlan Somers	disks=`atf_config_get disks`
2696f7f85e0SAlan Somers	disk=${disks%% *}
2706f7f85e0SAlan Somers	if [ -n "$disk" ]; then
2716f7f85e0SAlan Somers		gnop destroy -f ${disk}.nop 2>/dev/null
2726f7f85e0SAlan Somers	fi
2736f7f85e0SAlan Somers}
2746f7f85e0SAlan Somers
27537a13f57SMark Johnstonload_gnop()
27637a13f57SMark Johnston{
27737a13f57SMark Johnston	if ! kldstat -q -m g_nop; then
27837a13f57SMark Johnston		geom nop load || atf_skip "could not load module for geom nop"
27937a13f57SMark Johnston	fi
28037a13f57SMark Johnston}
281