1# Copyright (c) 2018 Alan Somers 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions 6# are met: 7# 1. Redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer. 9# 2. Redistributions in binary form must reproduce the above copyright 10# notice, this list of conditions and the following disclaimer in the 11# documentation and/or other materials provided with the distribution. 12# 13# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23# SUCH DAMAGE. 24# 25# $FreeBSD$ 26 27. $(atf_get_srcdir)/conf.sh 28 29atf_test_case preserve_props cleanup 30preserve_props_head() 31{ 32 atf_set "descr" "geli should preserve basic GEOM properties" 33 atf_set "require.user" "root" 34 atf_set "timeout" 15 35} 36preserve_props_body() 37{ 38 geli_test_setup 39 40 md=$(attach_md -s1m) 41 atf_check geli onetime /dev/${md} 42 md_secsize=$(diskinfo ${md} | cut -wf 2) 43 md_stripesize=$(diskinfo ${md} | cut -wf 5) 44 eli_secsize=$(diskinfo ${md}.eli | cut -wf 2) 45 eli_stripesize=$(diskinfo ${md}.eli | cut -wf 5) 46 atf_check_equal "$md_secsize" "$eli_secsize" 47 atf_check_equal "$md_stripesize" "$eli_stripesize" 48} 49preserve_props_cleanup() 50{ 51 geli_test_cleanup 52} 53 54atf_test_case preserve_disk_props cleanup 55preserve_disk_props_head() 56{ 57 atf_set "descr" "geli should preserve properties for disks" 58 atf_set "require.user" "root" 59 atf_set "require.config" "disks" 60 atf_set "timeout" 15 61} 62preserve_disk_props_body() 63{ 64 geli_test_setup 65 66 disks=`atf_config_get disks` 67 disk=${disks%% *} 68 if [ -z "$disk" ]; then 69 atf_skip "Must define disks (see tests(7))" 70 fi 71 atf_check geli onetime ${disk} 72 73 disk_ident=$(diskinfo -s ${disk}) 74 disk_descr=$(diskinfo -v ${disk} | awk '/Disk descr/ {print $1}') 75 disk_rotrate=$(diskinfo -v ${disk} | awk '/Rotation rate/ {print $1}') 76 disk_zonemode=$(diskinfo -v ${disk} | awk '/Zone Mode/ {print $1}') 77 eli_ident=$(diskinfo -s ${disk}.eli) 78 eli_descr=$(diskinfo -v ${disk}.eli | awk '/Disk descr/ {print $1}') 79 eli_rotrate=$(diskinfo -v ${disk}.eli | awk '/Rotation/ {print $1}') 80 eli_zonemode=$(diskinfo -v ${disk}.eli | awk '/Zone Mode/ {print $1}') 81 atf_check_equal "$disk_ident" "$eli_ident" 82 atf_check_equal "$disk_descr" "$eli_descr" 83 atf_check_equal "$disk_rotrate" "$eli_rotrate" 84 atf_check_equal "$disk_zonemode" "$eli_zonemode" 85} 86preserve_disk_props_cleanup() 87{ 88 disk_cleanup 89 geli_test_cleanup 90} 91 92atf_test_case physpath cleanup 93physpath_head() 94{ 95 atf_set "descr" "geli should append /eli to the underlying device's physical path" 96 atf_set "require.user" "root" 97 atf_set "timeout" 15 98} 99physpath_body() 100{ 101 geli_test_setup 102 if ! error_message=$(geom_load_class_if_needed nop); then 103 atf_skip "$error_message" 104 fi 105 106 md=$(attach_md -s1m) 107 # If the underlying device has no physical path, then geli should not 108 # create one. 109 atf_check -o empty -e ignore diskinfo -p $md 110 atf_check -s exit:0 geli onetime $md 111 atf_check -o empty -e ignore diskinfo -p $md.eli 112 atf_check -s exit:0 geli kill $md 113 114 # If the underlying device does have a physical path, then geli should 115 # append "/eli" 116 physpath="some/physical/path" 117 atf_check gnop create -z $physpath ${md} 118 atf_check -s exit:0 geli onetime $md.nop 119 atf_check -o match:"^${physpath}/eli$" diskinfo -p $md.nop.eli 120} 121physpath_cleanup() 122{ 123 if [ -f "$TEST_MDS_FILE" ]; then 124 while read md; do 125 [ -c /dev/${md}.nop.eli ] && \ 126 geli detach $md.nop.eli 2>/dev/null 127 [ -c /dev/${md}.nop ] && \ 128 gnop destroy -f $md.nop 2>/dev/null 129 [ -c /dev/${md}.eli ] && \ 130 geli detach $md.eli 2>/dev/null 131 mdconfig -d -u $md 2>/dev/null 132 done < $TEST_MDS_FILE 133 fi 134 true 135} 136 137atf_init_test_cases() 138{ 139 atf_add_test_case physpath 140 atf_add_test_case preserve_props 141 atf_add_test_case preserve_disk_props 142} 143 144 145common_cleanup() 146{ 147 148 if [ -f "$MD_DEVS" ]; then 149 while read test_md; do 150 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