geom_gate userland utility improvements
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

270 lines
4.8 KiB

  1. # $FreeBSD$
  2. PIDFILE=ggated.pid
  3. PLAINFILES=plainfiles
  4. PORT=33080
  5. CONF=gg.exports
  6. atf_test_case ggated cleanup
  7. ggated_head()
  8. {
  9. atf_set "descr" "ggated can proxy geoms"
  10. atf_set "require.progs" "ggatec ggated"
  11. atf_set "require.user" "root"
  12. atf_set "timeout" 60
  13. }
  14. ggated_body()
  15. {
  16. load_ggate
  17. us=$(alloc_ggate_dev)
  18. work=$(alloc_md)
  19. src=$(alloc_md)
  20. atf_check -e ignore -o ignore \
  21. dd if=/dev/random of=/dev/$work bs=1m count=1 conv=notrunc
  22. atf_check -e ignore -o ignore \
  23. dd if=/dev/random of=/dev/$src bs=1m count=1 conv=notrunc
  24. echo $CONF >> $PLAINFILES
  25. echo "127.0.0.1 RW /dev/$work" > $CONF
  26. atf_check ggated -p $PORT -F $PIDFILE $CONF
  27. atf_check ggatec create -p $PORT -u $us 127.0.0.1 /dev/$work
  28. ggate_dev=/dev/ggate${us}
  29. wait_for_ggate_device ${ggate_dev}
  30. atf_check -e ignore -o ignore \
  31. dd if=/dev/${src} of=${ggate_dev} bs=1m count=1 conv=notrunc
  32. checksum /dev/$src /dev/$work
  33. }
  34. ggated_cleanup()
  35. {
  36. common_cleanup
  37. }
  38. atf_test_case ggatel_file cleanup
  39. ggatel_file_head()
  40. {
  41. atf_set "descr" "ggatel can proxy files"
  42. atf_set "require.progs" "ggatel"
  43. atf_set "require.user" "root"
  44. atf_set "timeout" 15
  45. }
  46. ggatel_file_body()
  47. {
  48. load_ggate
  49. us=$(alloc_ggate_dev)
  50. echo src work >> ${PLAINFILES}
  51. dd if=/dev/random of=work bs=1m count=1
  52. dd if=/dev/random of=src bs=1m count=1
  53. atf_check ggatel create -u $us work
  54. ggate_dev=/dev/ggate${us}
  55. wait_for_ggate_device ${ggate_dev}
  56. atf_check -e ignore -o ignore \
  57. dd if=src of=${ggate_dev} bs=1m count=1 conv=notrunc
  58. checksum src work
  59. }
  60. ggatel_file_cleanup()
  61. {
  62. common_cleanup
  63. }
  64. atf_test_case ggatel_md cleanup
  65. ggatel_md_head()
  66. {
  67. atf_set "descr" "ggatel can proxy files"
  68. atf_set "require.progs" "ggatel"
  69. atf_set "require.user" "root"
  70. atf_set "timeout" 15
  71. }
  72. ggatel_md_body()
  73. {
  74. load_ggate
  75. us=$(alloc_ggate_dev)
  76. work=$(alloc_md)
  77. src=$(alloc_md)
  78. atf_check -e ignore -o ignore \
  79. dd if=/dev/random of=$work bs=1m count=1 conv=notrunc
  80. atf_check -e ignore -o ignore \
  81. dd if=/dev/random of=$src bs=1m count=1 conv=notrunc
  82. atf_check ggatel create -u $us /dev/$work
  83. ggate_dev=/dev/ggate${us}
  84. wait_for_ggate_device ${ggate_dev}
  85. atf_check -e ignore -o ignore \
  86. dd if=/dev/$src of=${ggate_dev} bs=1m count=1 conv=notrunc
  87. checksum /dev/$src /dev/$work
  88. }
  89. ggatel_md_cleanup()
  90. {
  91. common_cleanup
  92. }
  93. atf_test_case ggate_sock cleanup
  94. ggate_sock_head()
  95. {
  96. atf_set "descr" "ggatec can connect to ggated over unix domain socket"
  97. atf_set "require.progs" "ggatec ggated"
  98. atf_set "require.user" "root"
  99. atf_set "timeout" 5
  100. }
  101. ggate_sock_body()
  102. {
  103. load_ggate
  104. us=$(alloc_ggate_dev)
  105. work=$(alloc_md)
  106. src=$(alloc_md)
  107. atf_check -e ignore -o ignore \
  108. dd if=/dev/random of=/dev/$work bs=1m count=1 conv=notrunc
  109. atf_check -e ignore -o ignore \
  110. dd if=/dev/random of=/dev/$src bs=1m count=1 conv=notrunc
  111. echo $CONF >> $PLAINFILES
  112. echo "0.0.0.0 RW /dev/$work" > $CONF
  113. atf_check ggated -s local.sock -F $PIDFILE $CONF
  114. atf_check ggatec create -u $us sock:"$(pwd)/local.sock" /dev/$work
  115. ggate_dev=/dev/ggate${us}
  116. wait_for_ggate_device ${ggate_dev}
  117. atf_check -e ignore -o ignore \
  118. dd if=/dev/${src} of=${ggate_dev} bs=1m count=1 conv=notrunc
  119. checksum /dev/$src /dev/$work
  120. }
  121. ggate_sock_cleanup()
  122. {
  123. common_cleanup
  124. }
  125. atf_init_test_cases()
  126. {
  127. atf_add_test_case ggated
  128. atf_add_test_case ggatel_file
  129. atf_add_test_case ggatel_md
  130. atf_add_test_case ggate_sock
  131. }
  132. alloc_ggate_dev()
  133. {
  134. local us
  135. us=0
  136. while [ -c /dev/ggate${us} ]; do
  137. : $(( us += 1 ))
  138. done
  139. echo ${us} > ggate.devs
  140. echo ${us}
  141. }
  142. alloc_md()
  143. {
  144. local md
  145. md=$(mdconfig -a -t malloc -s 1M) || \
  146. atf_fail "failed to allocate md device"
  147. echo ${md} >> md.devs
  148. echo ${md}
  149. }
  150. checksum()
  151. {
  152. local src work
  153. src=$1
  154. work=$2
  155. src_checksum=$(md5 -q $src)
  156. work_checksum=$(md5 -q $work)
  157. if [ "$work_checksum" != "$src_checksum" ]; then
  158. atf_fail "work md5 checksum didn't match"
  159. fi
  160. ggate_checksum=$(md5 -q /dev/ggate${us})
  161. if [ "$ggate_checksum" != "$src_checksum" ]; then
  162. atf_fail "ggate md5 checksum didn't match"
  163. fi
  164. }
  165. common_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. if [ -f "$PIDFILE" ]; then
  174. pkill -F "$PIDFILE"
  175. rm $PIDFILE
  176. fi
  177. if [ -f "PLAINFILES" ]; then
  178. while read f; do
  179. rm -f ${f}
  180. done < ${PLAINFILES}
  181. rm ${PLAINFILES}
  182. fi
  183. if [ -f "md.devs" ]; then
  184. while read test_md; do
  185. mdconfig -d -u $test_md 2>/dev/null
  186. done < md.devs
  187. rm md.devs
  188. fi
  189. true
  190. }
  191. load_ggate()
  192. {
  193. local class=gate
  194. # If the geom class isn't already loaded, try loading it.
  195. if ! kldstat -q -m g_${class}; then
  196. if ! geom ${class} load; then
  197. atf_skip "could not load module for geom class=${class}"
  198. fi
  199. fi
  200. }
  201. # Bug 204616: ggatel(8) creates /dev/ggate* asynchronously if `ggatel create`
  202. # isn't called with `-v`.
  203. wait_for_ggate_device()
  204. {
  205. ggate_device=$1
  206. while [ ! -c $ggate_device ]; do
  207. sleep 0.5
  208. done
  209. }