1# $FreeBSD$ 2 3PIDFILE=ggated.pid 4PLAINFILES=plainfiles 5PORT=33080 6CONF=gg.exports 7RETRIES=16 8 9atf_test_case ggated cleanup 10ggated_head() 11{ 12 atf_set "descr" "ggated can proxy geoms" 13 atf_set "require.progs" "ggatec ggated" 14 atf_set "require.user" "root" 15 atf_set "timeout" 60 16} 17 18ggated_body() 19{ 20 us=$(alloc_ggate_dev) 21 work=$(alloc_md) 22 src=$(alloc_md) 23 24 dd if=/dev/random of=/dev/$work bs=1m count=1 conv=notrunc 25 dd if=/dev/random of=/dev/$src bs=1m count=1 conv=notrunc 26 27 echo $CONF >> $PLAINFILES 28 echo "127.0.0.1 RW /dev/$work" > $CONF 29 30 atf_check ggated -p $PORT -F $PIDFILE $CONF 31 for try in `jot $RETRIES`; do 32 ggatec create -p $PORT -u $us 127.0.0.1 /dev/$work && break 33 # wait for ggated to be ready 34 sleep 0.25 35 done 36 if [ "$try" -eq "$RETRIES" ]; then 37 atf_fail "ggatec create failed" 38 fi 39 40 for try in `jot $RETRIES`; do 41 dd if=/dev/${src} of=/dev/ggate${us} bs=1m count=1 conv=notrunc\ 42 && break 43 # Wait for /dev/ggate${us} to be ready 44 sleep 0.25 45 done 46 if [ "$try" -eq "$RETRIES" ]; then 47 atf_fail "dd failed; /dev/ggate${us} isn't working" 48 fi 49 50 checksum /dev/$src /dev/$work 51} 52 53ggated_cleanup() 54{ 55 common_cleanup 56} 57 58atf_test_case ggatel_file cleanup 59ggatel_file_head() 60{ 61 atf_set "descr" "ggatel can proxy files" 62 atf_set "require.progs" "ggatel" 63 atf_set "require.user" "root" 64 atf_set "timeout" 15 65} 66 67ggatel_file_body() 68{ 69 us=$(alloc_ggate_dev) 70 71 echo src work >> ${PLAINFILES} 72 dd if=/dev/random of=work bs=1m count=1 73 dd if=/dev/random of=src bs=1m count=1 74 75 atf_check ggatel create -u $us work 76 77 dd if=src of=/dev/ggate${us} bs=1m count=1 conv=notrunc 78 79 checksum src work 80} 81 82ggatel_file_cleanup() 83{ 84 common_cleanup 85} 86 87atf_test_case ggatel_md cleanup 88ggatel_md_head() 89{ 90 atf_set "descr" "ggatel can proxy files" 91 atf_set "require.progs" "ggatel" 92 atf_set "require.user" "root" 93 atf_set "timeout" 15 94} 95 96ggatel_md_body() 97{ 98 us=$(alloc_ggate_dev) 99 work=$(alloc_md) 100 src=$(alloc_md) 101 102 dd if=/dev/random of=$work bs=1m count=1 conv=notrunc 103 dd if=/dev/random of=$src bs=1m count=1 conv=notrunc 104 105 atf_check ggatel create -u $us /dev/$work 106 107 dd if=/dev/$src of=/dev/ggate${us} bs=1m count=1 conv=notrunc 108 109 checksum /dev/$src /dev/$work 110} 111 112ggatel_md_cleanup() 113{ 114 common_cleanup 115} 116 117atf_init_test_cases() 118{ 119 atf_add_test_case ggated 120 atf_add_test_case ggatel_file 121 atf_add_test_case ggatel_md 122} 123 124alloc_ggate_dev() 125{ 126 local us 127 128 us=0 129 while [ -c /dev/ggate${us} ]; do 130 : $(( us += 1 )) 131 done 132 echo ${us} > ggate.devs 133 echo ${us} 134} 135 136alloc_md() 137{ 138 local md 139 140 md=$(mdconfig -a -t malloc -s 1M) || \ 141 atf_fail "failed to allocate md device" 142 echo ${md} >> md.devs 143 echo ${md} 144} 145 146checksum() 147{ 148 local src work 149 src=$1 150 work=$2 151 152 src_checksum=$(md5 -q $src) 153 work_checksum=$(md5 -q $work) 154 155 if [ "$work_checksum" != "$src_checksum" ]; then 156 atf_fail "work md5 checksum didn't match" 157 fi 158 159 ggate_checksum=$(md5 -q /dev/ggate${us}) 160 if [ "$ggate_checksum" != "$src_checksum" ]; then 161 atf_fail "ggate md5 checksum didn't match" 162 fi 163} 164 165common_cleanup() 166{ 167 if [ -f "ggate.devs" ]; then 168 while read test_ggate; do 169 ggatec destroy -f -u $test_ggate >/dev/null 170 done < ggate.devs 171 rm ggate.devs 172 fi 173 174 if [ -f "$PIDFILE" ]; then 175 pkill -F "$PIDFILE" 176 rm $PIDFILE 177 fi 178 179 if [ -f "PLAINFILES" ]; then 180 while read f; do 181 rm -f ${f} 182 done < ${PLAINFILES} 183 rm ${PLAINFILES} 184 fi 185 186 if [ -f "md.devs" ]; then 187 while read test_md; do 188 mdconfig -d -u $test_md 2>/dev/null 189 done < md.devs 190 rm md.devs 191 fi 192 true 193} 194