1 2PIDFILE=ggated.pid 3PLAINFILES=plainfiles 4PORT=33080 5CONF=gg.exports 6 7atf_test_case ggatec_trim cleanup 8ggatec_trim_head() 9{ 10 atf_set "descr" "ggatec survives a trim" 11 atf_set "require.progs" "ggatec" 12 atf_set "require.user" "root" 13 atf_set "timeout" 60 14} 15 16ggatec_trim_body() 17{ 18 load_ggate 19 20 us=$(alloc_ggate_dev) 21 work=$(alloc_md) 22 atf_check -e ignore -o ignore dd if=/dev/random of=/dev/$work bs=1m count=1 conv=notrunc 23 echo $CONF >> $PLAINFILES 24 echo "localhost RW /dev/$work" > $CONF 25 atf_check ggated -p $PORT -F $PIDFILE $CONF 26 atf_check ggatec create -p $PORT -u $us localhost /dev/$work 27 ggate_dev=/dev/ggate${us} 28 wait_for_ggate_device ${ggate_dev} 29 30 # ggatec only supports read or write. 31 atf_check -s not-exit:0 -e ignore -o ignore trim -q -f ${ggate_dev} 32} 33 34ggatec_trim_cleanup() 35{ 36 common_cleanup 37} 38 39 40atf_test_case ggated cleanup 41ggated_head() 42{ 43 atf_set "descr" "ggated can proxy geoms" 44 atf_set "require.progs" "ggatec ggated" 45 atf_set "require.user" "root" 46 atf_set "timeout" 60 47} 48 49ggated_body() 50{ 51 if [ "$(atf_config_get ci false)" = "true" ] && \ 52 [ "$(uname -p)" = "i386" ]; then 53 atf_skip "https://bugs.freebsd.org/244737" 54 fi 55 56 load_ggate 57 58 us=$(alloc_ggate_dev) 59 work=$(alloc_md) 60 src=$(alloc_md) 61 62 atf_check -e ignore -o ignore \ 63 dd if=/dev/random of=/dev/$work bs=1m count=1 conv=notrunc 64 atf_check -e ignore -o ignore \ 65 dd if=/dev/random of=/dev/$src bs=1m count=1 conv=notrunc 66 67 echo $CONF >> $PLAINFILES 68 echo "127.0.0.1 RW /dev/$work" > $CONF 69 70 atf_check ggated -p $PORT -F $PIDFILE $CONF 71 atf_check ggatec create -p $PORT -u $us 127.0.0.1 /dev/$work 72 73 ggate_dev=/dev/ggate${us} 74 75 wait_for_ggate_device ${ggate_dev} 76 77 atf_check -e ignore -o ignore \ 78 dd if=/dev/${src} of=${ggate_dev} bs=1m count=1 conv=notrunc 79 80 checksum /dev/$src /dev/$work 81} 82 83ggated_cleanup() 84{ 85 common_cleanup 86} 87 88atf_test_case ggatel_file cleanup 89ggatel_file_head() 90{ 91 atf_set "descr" "ggatel can proxy files" 92 atf_set "require.progs" "ggatel" 93 atf_set "require.user" "root" 94 atf_set "timeout" 15 95} 96 97ggatel_file_body() 98{ 99 load_ggate 100 101 us=$(alloc_ggate_dev) 102 103 echo src work >> ${PLAINFILES} 104 dd if=/dev/random of=work bs=1m count=1 105 dd if=/dev/random of=src bs=1m count=1 106 107 atf_check ggatel create -u $us work 108 109 ggate_dev=/dev/ggate${us} 110 111 wait_for_ggate_device ${ggate_dev} 112 113 atf_check -e ignore -o ignore \ 114 dd if=src of=${ggate_dev} bs=1m count=1 conv=notrunc 115 116 checksum src work 117} 118 119ggatel_file_cleanup() 120{ 121 common_cleanup 122} 123 124atf_test_case ggatel_md cleanup 125ggatel_md_head() 126{ 127 atf_set "descr" "ggatel can proxy files" 128 atf_set "require.progs" "ggatel" 129 atf_set "require.user" "root" 130 atf_set "timeout" 15 131} 132 133ggatel_md_body() 134{ 135 load_ggate 136 137 us=$(alloc_ggate_dev) 138 work=$(alloc_md) 139 src=$(alloc_md) 140 141 atf_check -e ignore -o ignore \ 142 dd if=/dev/random of=$work bs=1m count=1 conv=notrunc 143 atf_check -e ignore -o ignore \ 144 dd if=/dev/random of=$src bs=1m count=1 conv=notrunc 145 146 atf_check ggatel create -u $us /dev/$work 147 148 ggate_dev=/dev/ggate${us} 149 150 wait_for_ggate_device ${ggate_dev} 151 152 atf_check -e ignore -o ignore \ 153 dd if=/dev/$src of=${ggate_dev} bs=1m count=1 conv=notrunc 154 155 checksum /dev/$src /dev/$work 156} 157 158ggatel_md_cleanup() 159{ 160 common_cleanup 161} 162 163atf_init_test_cases() 164{ 165 atf_add_test_case ggated 166 atf_add_test_case ggatel_file 167 atf_add_test_case ggatel_md 168 atf_add_test_case ggatec_trim 169} 170 171alloc_ggate_dev() 172{ 173 local us 174 175 us=0 176 while [ -c /dev/ggate${us} ]; do 177 : $(( us += 1 )) 178 done 179 echo ${us} > ggate.devs 180 echo ${us} 181} 182 183alloc_md() 184{ 185 local md 186 187 md=$(mdconfig -a -t malloc -s 1M) || \ 188 atf_fail "failed to allocate md device" 189 echo ${md} >> md.devs 190 echo ${md} 191} 192 193checksum() 194{ 195 local src work 196 src=$1 197 work=$2 198 199 src_checksum=$(md5 -q $src) 200 work_checksum=$(md5 -q $work) 201 202 if [ "$work_checksum" != "$src_checksum" ]; then 203 atf_fail "work md5 checksum didn't match" 204 fi 205 206 ggate_checksum=$(md5 -q /dev/ggate${us}) 207 if [ "$ggate_checksum" != "$src_checksum" ]; then 208 atf_fail "ggate md5 checksum didn't match" 209 fi 210} 211 212common_cleanup() 213{ 214 if [ -f "ggate.devs" ]; then 215 while read test_ggate; do 216 ggatec destroy -f -u $test_ggate >/dev/null 217 done < ggate.devs 218 rm ggate.devs 219 fi 220 221 if [ -f "$PIDFILE" ]; then 222 pkill -F "$PIDFILE" 223 rm $PIDFILE 224 fi 225 226 if [ -f "PLAINFILES" ]; then 227 while read f; do 228 rm -f ${f} 229 done < ${PLAINFILES} 230 rm ${PLAINFILES} 231 fi 232 233 if [ -f "md.devs" ]; then 234 while read test_md; do 235 # ggatec destroy doesn't release the provider 236 # synchronously, so we may need to retry destroying it. 237 while ! mdconfig -d -u $test_md; do 238 sleep 0.1 239 done 240 done < md.devs 241 rm md.devs 242 fi 243 true 244} 245 246load_ggate() 247{ 248 local class=gate 249 250 # If the geom class isn't already loaded, try loading it. 251 if ! kldstat -q -m g_${class}; then 252 if ! geom ${class} load; then 253 atf_skip "could not load module for geom class=${class}" 254 fi 255 fi 256} 257 258# Bug 204616: ggatel(8) creates /dev/ggate* asynchronously if `ggatel create` 259# isn't called with `-v`. 260wait_for_ggate_device() 261{ 262 ggate_device=$1 263 264 while [ ! -c $ggate_device ]; do 265 sleep 0.5 266 done 267} 268