misc_test.sh revision 329273
1329273Sasomers# Copyright (c) 2018 Alan Somers 2329273Sasomers# All rights reserved. 3329273Sasomers# 4329273Sasomers# Redistribution and use in source and binary forms, with or without 5329273Sasomers# modification, are permitted provided that the following conditions 6329273Sasomers# are met: 7329273Sasomers# 1. Redistributions of source code must retain the above copyright 8329273Sasomers# notice, this list of conditions and the following disclaimer. 9329273Sasomers# 2. Redistributions in binary form must reproduce the above copyright 10329273Sasomers# notice, this list of conditions and the following disclaimer in the 11329273Sasomers# documentation and/or other materials provided with the distribution. 12329273Sasomers# 13329273Sasomers# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14329273Sasomers# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15329273Sasomers# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16329273Sasomers# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17329273Sasomers# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18329273Sasomers# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19329273Sasomers# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20329273Sasomers# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21329273Sasomers# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22329273Sasomers# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23329273Sasomers# SUCH DAMAGE. 24329273Sasomers# 25329273Sasomers# $FreeBSD: head/tests/sys/geom/class/eli/misc_test.sh 329273 2018-02-14 20:15:32Z asomers $ 26329273Sasomers 27329273Sasomersatf_test_case preserve_props cleanup 28329273Sasomerspreserve_props_head() 29329273Sasomers{ 30329273Sasomers atf_set "descr" "geli should preserve basic GEOM properties" 31329273Sasomers atf_set "require.user" "root" 32329273Sasomers atf_set "timeout" 15 33329273Sasomers} 34329273Sasomerspreserve_props_body() 35329273Sasomers{ 36329273Sasomers . $(atf_get_srcdir)/conf.sh 37329273Sasomers md=$(attach_md -s1m) 38329273Sasomers atf_check geli onetime /dev/${md} 39329273Sasomers md_secsize=$(diskinfo ${md} | cut -wf 2) 40329273Sasomers md_stripesize=$(diskinfo ${md} | cut -wf 5) 41329273Sasomers eli_secsize=$(diskinfo ${md}.eli | cut -wf 2) 42329273Sasomers eli_stripesize=$(diskinfo ${md}.eli | cut -wf 5) 43329273Sasomers atf_check_equal "$md_secsize" "$eli_secsize" 44329273Sasomers atf_check_equal "$md_stripesize" "$eli_stripesize" 45329273Sasomers} 46329273Sasomerspreserve_props_cleanup() 47329273Sasomers{ 48329273Sasomers . $(atf_get_srcdir)/conf.sh 49329273Sasomers geli_test_cleanup 50329273Sasomers} 51329273Sasomers 52329273Sasomersatf_test_case preserve_disk_props cleanup 53329273Sasomerspreserve_disk_props_head() 54329273Sasomers{ 55329273Sasomers atf_set "descr" "geli should preserve properties for disks" 56329273Sasomers atf_set "require.user" "root" 57329273Sasomers atf_set "require.config" "disks" 58329273Sasomers atf_set "timeout" 15 59329273Sasomers} 60329273Sasomerspreserve_disk_props_body() 61329273Sasomers{ 62329273Sasomers . $(atf_get_srcdir)/conf.sh 63329273Sasomers disks=`atf_config_get disks` 64329273Sasomers disk=${disks%% *} 65329273Sasomers if [ -z "$disk" ]; then 66329273Sasomers atf_skip "Must define disks (see tests(7))" 67329273Sasomers fi 68329273Sasomers atf_check geli onetime ${disk} 69329273Sasomers 70329273Sasomers disk_ident=$(diskinfo -s ${disk}) 71329273Sasomers disk_descr=$(diskinfo -v ${disk} | awk '/Disk descr/ {print $1}') 72329273Sasomers disk_rotrate=$(diskinfo -v ${disk} | awk '/Rotation rate/ {print $1}') 73329273Sasomers disk_zonemode=$(diskinfo -v ${disk} | awk '/Zone Mode/ {print $1}') 74329273Sasomers eli_ident=$(diskinfo -s ${disk}.eli) 75329273Sasomers eli_descr=$(diskinfo -v ${disk}.eli | awk '/Disk descr/ {print $1}') 76329273Sasomers eli_rotrate=$(diskinfo -v ${disk}.eli | awk '/Rotation/ {print $1}') 77329273Sasomers eli_zonemode=$(diskinfo -v ${disk}.eli | awk '/Zone Mode/ {print $1}') 78329273Sasomers atf_check_equal "$disk_ident" "$eli_ident" 79329273Sasomers atf_check_equal "$disk_descr" "$eli_descr" 80329273Sasomers atf_check_equal "$disk_rotrate" "$eli_rotrate" 81329273Sasomers atf_check_equal "$disk_zonemode" "$eli_zonemode" 82329273Sasomers} 83329273Sasomerspreserve_disk_props_cleanup() 84329273Sasomers{ 85329273Sasomers . $(atf_get_srcdir)/conf.sh 86329273Sasomers disk_cleanup 87329273Sasomers geli_test_cleanup 88329273Sasomers} 89329273Sasomers 90329273Sasomersatf_test_case physpath cleanup 91329273Sasomersphyspath_head() 92329273Sasomers{ 93329273Sasomers atf_set "descr" "geli should append /eli to the underlying device's physical path" 94329273Sasomers atf_set "require.user" "root" 95329273Sasomers atf_set "timeout" 15 96329273Sasomers} 97329273Sasomersphyspath_body() 98329273Sasomers{ 99329273Sasomers . $(atf_get_srcdir)/conf.sh 100329273Sasomers load_gnop 101329273Sasomers 102329273Sasomers md=$(attach_md -s1m) 103329273Sasomers # If the underlying device has no physical path, then geli should not 104329273Sasomers # create one. 105329273Sasomers atf_check -o empty -e ignore diskinfo -p $md 106329273Sasomers atf_check -s exit:0 geli onetime $md 107329273Sasomers atf_check -o empty -e ignore diskinfo -p $md.eli 108329273Sasomers atf_check -s exit:0 geli kill $md 109329273Sasomers 110329273Sasomers # If the underlying device does have a physical path, then geli should 111329273Sasomers # append "/eli" 112329273Sasomers physpath="some/physical/path" 113329273Sasomers atf_check gnop create -z $physpath ${md} 114329273Sasomers atf_check -s exit:0 geli onetime $md.nop 115329273Sasomers atf_check -o match:"^${physpath}/eli$" diskinfo -p $md.nop.eli 116329273Sasomers} 117329273Sasomersphyspath_cleanup() 118329273Sasomers{ 119329273Sasomers . $(atf_get_srcdir)/conf.sh 120329273Sasomers 121329273Sasomers if [ -f "$TEST_MDS_FILE" ]; then 122329273Sasomers while read md; do 123329273Sasomers [ -c /dev/${md}.nop.eli ] && \ 124329273Sasomers geli detach $md.nop.eli 2>/dev/null 125329273Sasomers [ -c /dev/${md}.nop ] && \ 126329273Sasomers gnop destroy -f $md.nop 2>/dev/null 127329273Sasomers [ -c /dev/${md}.eli ] && \ 128329273Sasomers geli detach $md.eli 2>/dev/null 129329273Sasomers mdconfig -d -u $md 2>/dev/null 130329273Sasomers done < $TEST_MDS_FILE 131329273Sasomers fi 132329273Sasomers true 133329273Sasomers} 134329273Sasomers 135329273Sasomersatf_init_test_cases() 136329273Sasomers{ 137329273Sasomers atf_add_test_case physpath 138329273Sasomers atf_add_test_case preserve_props 139329273Sasomers atf_add_test_case preserve_disk_props 140329273Sasomers} 141329273Sasomers 142329273Sasomers 143329273Sasomerscommon_cleanup() 144329273Sasomers{ 145329273Sasomers 146329273Sasomers if [ -f "$MD_DEVS" ]; then 147329273Sasomers while read test_md; do 148329273Sasomers gnop destroy -f ${test_md}.nop 2>/dev/null 149329273Sasomers mdconfig -d -u $test_md 2>/dev/null 150329273Sasomers done < $MD_DEVS 151329273Sasomers rm $MD_DEVS 152329273Sasomers fi 153329273Sasomers 154329273Sasomers if [ -f "$PLAINFILES" ]; then 155329273Sasomers while read f; do 156329273Sasomers rm -f ${f} 157329273Sasomers done < ${PLAINFILES} 158329273Sasomers rm ${PLAINFILES} 159329273Sasomers fi 160329273Sasomers true 161329273Sasomers} 162329273Sasomers 163329273Sasomersdisk_cleanup() 164329273Sasomers{ 165329273Sasomers disks=`atf_config_get disks` 166329273Sasomers disk=${disks%% *} 167329273Sasomers if [ -n "$disk" ]; then 168329273Sasomers geli kill ${disk} 2>/dev/null 169329273Sasomers fi 170329273Sasomers} 171329273Sasomers 172329273Sasomersload_gnop() 173329273Sasomers{ 174329273Sasomers if ! kldstat -q -m g_nop; then 175329273Sasomers geom nop load || atf_skip "could not load module for geom nop" 176329273Sasomers fi 177329273Sasomers} 178