misc_test.sh revision 345394
155682Smarkm# Copyright (c) 2018 Alan Somers 2102644Snectar# All rights reserved. 355682Smarkm# 455682Smarkm# Redistribution and use in source and binary forms, with or without 555682Smarkm# modification, are permitted provided that the following conditions 655682Smarkm# are met: 755682Smarkm# 1. Redistributions of source code must retain the above copyright 855682Smarkm# notice, this list of conditions and the following disclaimer. 955682Smarkm# 2. Redistributions in binary form must reproduce the above copyright 1055682Smarkm# notice, this list of conditions and the following disclaimer in the 1155682Smarkm# documentation and/or other materials provided with the distribution. 1255682Smarkm# 1355682Smarkm# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1455682Smarkm# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1555682Smarkm# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1655682Smarkm# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1755682Smarkm# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1855682Smarkm# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 1955682Smarkm# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2055682Smarkm# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2155682Smarkm# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2255682Smarkm# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2355682Smarkm# SUCH DAMAGE. 2455682Smarkm# 2555682Smarkm# $FreeBSD: stable/11/tests/sys/geom/class/eli/misc_test.sh 345394 2019-03-21 22:23:52Z asomers $ 2655682Smarkm 2755682Smarkm. $(atf_get_srcdir)/conf.sh 2855682Smarkm 2955682Smarkmatf_test_case preserve_props cleanup 3055682Smarkmpreserve_props_head() 3155682Smarkm{ 3255682Smarkm atf_set "descr" "geli should preserve basic GEOM properties" 3355682Smarkm atf_set "require.user" "root" 3455682Smarkm atf_set "timeout" 15 35102644Snectar} 3655682Smarkmpreserve_props_body() 37178825Sdfr{ 3855682Smarkm geli_test_setup 3955682Smarkm 4055682Smarkm md=$(attach_md -s1m) 4155682Smarkm atf_check geli onetime /dev/${md} 4255682Smarkm md_secsize=$(diskinfo ${md} | cut -wf 2) 4355682Smarkm md_stripesize=$(diskinfo ${md} | cut -wf 5) 4455682Smarkm eli_secsize=$(diskinfo ${md}.eli | cut -wf 2) 4555682Smarkm eli_stripesize=$(diskinfo ${md}.eli | cut -wf 5) 4655682Smarkm atf_check_equal "$md_secsize" "$eli_secsize" 4755682Smarkm atf_check_equal "$md_stripesize" "$eli_stripesize" 4855682Smarkm} 4955682Smarkmpreserve_props_cleanup() 5055682Smarkm{ 5155682Smarkm geli_test_cleanup 5255682Smarkm} 5355682Smarkm 5455682Smarkmatf_test_case preserve_disk_props cleanup 5555682Smarkmpreserve_disk_props_head() 5655682Smarkm{ 5772445Sassar atf_set "descr" "geli should preserve properties for disks" 5855682Smarkm atf_set "require.user" "root" 5955682Smarkm atf_set "require.config" "disks" 6055682Smarkm atf_set "timeout" 15 6155682Smarkm} 6255682Smarkmpreserve_disk_props_body() 6355682Smarkm{ 6455682Smarkm geli_test_setup 6555682Smarkm 6655682Smarkm disks=`atf_config_get disks` 67178825Sdfr disk=${disks%% *} 68178825Sdfr if [ -z "$disk" ]; then 69178825Sdfr atf_skip "Must define disks (see tests(7))" 70178825Sdfr fi 71178825Sdfr atf_check geli onetime ${disk} 72178825Sdfr 7355682Smarkm disk_ident=$(diskinfo -s ${disk}) 7455682Smarkm disk_descr=$(diskinfo -v ${disk} | awk '/Disk descr/ {print $1}') 7555682Smarkm disk_rotrate=$(diskinfo -v ${disk} | awk '/Rotation rate/ {print $1}') 7655682Smarkm disk_zonemode=$(diskinfo -v ${disk} | awk '/Zone Mode/ {print $1}') 7755682Smarkm eli_ident=$(diskinfo -s ${disk}.eli) 7855682Smarkm eli_descr=$(diskinfo -v ${disk}.eli | awk '/Disk descr/ {print $1}') 7955682Smarkm eli_rotrate=$(diskinfo -v ${disk}.eli | awk '/Rotation/ {print $1}') 8055682Smarkm eli_zonemode=$(diskinfo -v ${disk}.eli | awk '/Zone Mode/ {print $1}') 8155682Smarkm atf_check_equal "$disk_ident" "$eli_ident" 8255682Smarkm atf_check_equal "$disk_descr" "$eli_descr" 8355682Smarkm atf_check_equal "$disk_rotrate" "$eli_rotrate" 8455682Smarkm atf_check_equal "$disk_zonemode" "$eli_zonemode" 8555682Smarkm} 8655682Smarkmpreserve_disk_props_cleanup() 8755682Smarkm{ 8855682Smarkm disk_cleanup 8955682Smarkm geli_test_cleanup 9055682Smarkm} 9155682Smarkm 9255682Smarkmatf_test_case physpath cleanup 9355682Smarkmphyspath_head() 9455682Smarkm{ 9555682Smarkm atf_set "descr" "geli should append /eli to the underlying device's physical path" 96178825Sdfr atf_set "require.user" "root" 9755682Smarkm atf_set "timeout" 15 9855682Smarkm} 9955682Smarkmphyspath_body() 10055682Smarkm{ 10155682Smarkm geli_test_setup 10255682Smarkm if ! error_message=$(geom_load_class_if_needed nop); then 10355682Smarkm atf_skip "$error_message" 10455682Smarkm fi 10555682Smarkm 10655682Smarkm md=$(attach_md -s1m) 10755682Smarkm # If the underlying device has no physical path, then geli should not 10855682Smarkm # create one. 10955682Smarkm atf_check -o empty -e ignore diskinfo -p $md 110102644Snectar atf_check -s exit:0 geli onetime $md 11155682Smarkm atf_check -o empty -e ignore diskinfo -p $md.eli 11255682Smarkm atf_check -s exit:0 geli kill $md 11355682Smarkm 11455682Smarkm # If the underlying device does have a physical path, then geli should 11555682Smarkm # append "/eli" 11655682Smarkm physpath="some/physical/path" 11755682Smarkm atf_check gnop create -z $physpath ${md} 11855682Smarkm atf_check -s exit:0 geli onetime $md.nop 11955682Smarkm atf_check -o match:"^${physpath}/eli$" diskinfo -p $md.nop.eli 12055682Smarkm} 121178825Sdfrphyspath_cleanup() 12255682Smarkm{ 12355682Smarkm if [ -f "$TEST_MDS_FILE" ]; then 124178825Sdfr while read md; do 12555682Smarkm [ -c /dev/${md}.nop.eli ] && \ 126178825Sdfr geli detach $md.nop.eli 2>/dev/null 127178825Sdfr [ -c /dev/${md}.nop ] && \ 128178825Sdfr gnop destroy -f $md.nop 2>/dev/null 129178825Sdfr [ -c /dev/${md}.eli ] && \ 130178825Sdfr geli detach $md.eli 2>/dev/null 131178825Sdfr mdconfig -d -u $md 2>/dev/null 132178825Sdfr done < $TEST_MDS_FILE 133178825Sdfr fi 134178825Sdfr true 135178825Sdfr} 136178825Sdfr 137178825Sdfratf_init_test_cases() 138178825Sdfr{ 139178825Sdfr atf_add_test_case physpath 140178825Sdfr atf_add_test_case preserve_props 141178825Sdfr atf_add_test_case preserve_disk_props 142178825Sdfr} 143178825Sdfr 144178825Sdfr 145178825Sdfrcommon_cleanup() 146178825Sdfr{ 147178825Sdfr 148178825Sdfr if [ -f "$MD_DEVS" ]; then 149178825Sdfr while read test_md; do 150178825Sdfr gnop destroy -f ${test_md}.nop 2>/dev/null 151 mdconfig -d -u $test_md 2>/dev/null 152 done < $MD_DEVS 153 rm $MD_DEVS 154 fi 155 156 if [ -f "$PLAINFILES" ]; then 157 while read f; do 158 rm -f ${f} 159 done < ${PLAINFILES} 160 rm ${PLAINFILES} 161 fi 162 true 163} 164 165disk_cleanup() 166{ 167 disks=`atf_config_get disks` 168 disk=${disks%% *} 169 if [ -n "$disk" ]; then 170 geli kill ${disk} 2>/dev/null 171 fi 172} 173