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