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: stable/11/tests/sys/geom/class/eli/misc_test.sh 345394 2019-03-21 22:23:52Z asomers $ 26329273Sasomers 27345394Sasomers. $(atf_get_srcdir)/conf.sh 28345394Sasomers 29329273Sasomersatf_test_case preserve_props cleanup 30329273Sasomerspreserve_props_head() 31329273Sasomers{ 32329273Sasomers atf_set "descr" "geli should preserve basic GEOM properties" 33329273Sasomers atf_set "require.user" "root" 34329273Sasomers atf_set "timeout" 15 35329273Sasomers} 36329273Sasomerspreserve_props_body() 37329273Sasomers{ 38345394Sasomers geli_test_setup 39345394Sasomers 40329273Sasomers md=$(attach_md -s1m) 41329273Sasomers atf_check geli onetime /dev/${md} 42329273Sasomers md_secsize=$(diskinfo ${md} | cut -wf 2) 43329273Sasomers md_stripesize=$(diskinfo ${md} | cut -wf 5) 44329273Sasomers eli_secsize=$(diskinfo ${md}.eli | cut -wf 2) 45329273Sasomers eli_stripesize=$(diskinfo ${md}.eli | cut -wf 5) 46329273Sasomers atf_check_equal "$md_secsize" "$eli_secsize" 47329273Sasomers atf_check_equal "$md_stripesize" "$eli_stripesize" 48329273Sasomers} 49329273Sasomerspreserve_props_cleanup() 50329273Sasomers{ 51329273Sasomers geli_test_cleanup 52329273Sasomers} 53329273Sasomers 54329273Sasomersatf_test_case preserve_disk_props cleanup 55329273Sasomerspreserve_disk_props_head() 56329273Sasomers{ 57329273Sasomers atf_set "descr" "geli should preserve properties for disks" 58329273Sasomers atf_set "require.user" "root" 59329273Sasomers atf_set "require.config" "disks" 60329273Sasomers atf_set "timeout" 15 61329273Sasomers} 62329273Sasomerspreserve_disk_props_body() 63329273Sasomers{ 64345394Sasomers geli_test_setup 65345394Sasomers 66329273Sasomers disks=`atf_config_get disks` 67329273Sasomers disk=${disks%% *} 68329273Sasomers if [ -z "$disk" ]; then 69329273Sasomers atf_skip "Must define disks (see tests(7))" 70329273Sasomers fi 71329273Sasomers atf_check geli onetime ${disk} 72329273Sasomers 73329273Sasomers disk_ident=$(diskinfo -s ${disk}) 74329273Sasomers disk_descr=$(diskinfo -v ${disk} | awk '/Disk descr/ {print $1}') 75329273Sasomers disk_rotrate=$(diskinfo -v ${disk} | awk '/Rotation rate/ {print $1}') 76329273Sasomers disk_zonemode=$(diskinfo -v ${disk} | awk '/Zone Mode/ {print $1}') 77329273Sasomers eli_ident=$(diskinfo -s ${disk}.eli) 78329273Sasomers eli_descr=$(diskinfo -v ${disk}.eli | awk '/Disk descr/ {print $1}') 79329273Sasomers eli_rotrate=$(diskinfo -v ${disk}.eli | awk '/Rotation/ {print $1}') 80329273Sasomers eli_zonemode=$(diskinfo -v ${disk}.eli | awk '/Zone Mode/ {print $1}') 81329273Sasomers atf_check_equal "$disk_ident" "$eli_ident" 82329273Sasomers atf_check_equal "$disk_descr" "$eli_descr" 83329273Sasomers atf_check_equal "$disk_rotrate" "$eli_rotrate" 84329273Sasomers atf_check_equal "$disk_zonemode" "$eli_zonemode" 85329273Sasomers} 86329273Sasomerspreserve_disk_props_cleanup() 87329273Sasomers{ 88329273Sasomers disk_cleanup 89329273Sasomers geli_test_cleanup 90329273Sasomers} 91329273Sasomers 92329273Sasomersatf_test_case physpath cleanup 93329273Sasomersphyspath_head() 94329273Sasomers{ 95329273Sasomers atf_set "descr" "geli should append /eli to the underlying device's physical path" 96329273Sasomers atf_set "require.user" "root" 97329273Sasomers atf_set "timeout" 15 98329273Sasomers} 99329273Sasomersphyspath_body() 100329273Sasomers{ 101345394Sasomers geli_test_setup 102345394Sasomers if ! error_message=$(geom_load_class_if_needed nop); then 103345394Sasomers atf_skip "$error_message" 104345394Sasomers fi 105329273Sasomers 106329273Sasomers md=$(attach_md -s1m) 107329273Sasomers # If the underlying device has no physical path, then geli should not 108329273Sasomers # create one. 109329273Sasomers atf_check -o empty -e ignore diskinfo -p $md 110329273Sasomers atf_check -s exit:0 geli onetime $md 111329273Sasomers atf_check -o empty -e ignore diskinfo -p $md.eli 112329273Sasomers atf_check -s exit:0 geli kill $md 113329273Sasomers 114329273Sasomers # If the underlying device does have a physical path, then geli should 115329273Sasomers # append "/eli" 116329273Sasomers physpath="some/physical/path" 117329273Sasomers atf_check gnop create -z $physpath ${md} 118329273Sasomers atf_check -s exit:0 geli onetime $md.nop 119329273Sasomers atf_check -o match:"^${physpath}/eli$" diskinfo -p $md.nop.eli 120329273Sasomers} 121329273Sasomersphyspath_cleanup() 122329273Sasomers{ 123329273Sasomers if [ -f "$TEST_MDS_FILE" ]; then 124329273Sasomers while read md; do 125329273Sasomers [ -c /dev/${md}.nop.eli ] && \ 126329273Sasomers geli detach $md.nop.eli 2>/dev/null 127329273Sasomers [ -c /dev/${md}.nop ] && \ 128329273Sasomers gnop destroy -f $md.nop 2>/dev/null 129329273Sasomers [ -c /dev/${md}.eli ] && \ 130329273Sasomers geli detach $md.eli 2>/dev/null 131329273Sasomers mdconfig -d -u $md 2>/dev/null 132329273Sasomers done < $TEST_MDS_FILE 133329273Sasomers fi 134329273Sasomers true 135329273Sasomers} 136329273Sasomers 137329273Sasomersatf_init_test_cases() 138329273Sasomers{ 139329273Sasomers atf_add_test_case physpath 140329273Sasomers atf_add_test_case preserve_props 141329273Sasomers atf_add_test_case preserve_disk_props 142329273Sasomers} 143329273Sasomers 144329273Sasomers 145329273Sasomerscommon_cleanup() 146329273Sasomers{ 147329273Sasomers 148329273Sasomers if [ -f "$MD_DEVS" ]; then 149329273Sasomers while read test_md; do 150329273Sasomers gnop destroy -f ${test_md}.nop 2>/dev/null 151329273Sasomers mdconfig -d -u $test_md 2>/dev/null 152329273Sasomers done < $MD_DEVS 153329273Sasomers rm $MD_DEVS 154329273Sasomers fi 155329273Sasomers 156329273Sasomers if [ -f "$PLAINFILES" ]; then 157329273Sasomers while read f; do 158329273Sasomers rm -f ${f} 159329273Sasomers done < ${PLAINFILES} 160329273Sasomers rm ${PLAINFILES} 161329273Sasomers fi 162329273Sasomers true 163329273Sasomers} 164329273Sasomers 165329273Sasomersdisk_cleanup() 166329273Sasomers{ 167329273Sasomers disks=`atf_config_get disks` 168329273Sasomers disk=${disks%% *} 169329273Sasomers if [ -n "$disk" ]; then 170329273Sasomers geli kill ${disk} 2>/dev/null 171329273Sasomers fi 172329273Sasomers} 173