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.
 
 
 
 

226 lines
3.9 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_init_test_cases()
  94. {
  95. atf_add_test_case ggated
  96. atf_add_test_case ggatel_file
  97. atf_add_test_case ggatel_md
  98. }
  99. alloc_ggate_dev()
  100. {
  101. local us
  102. us=0
  103. while [ -c /dev/ggate${us} ]; do
  104. : $(( us += 1 ))
  105. done
  106. echo ${us} > ggate.devs
  107. echo ${us}
  108. }
  109. alloc_md()
  110. {
  111. local md
  112. md=$(mdconfig -a -t malloc -s 1M) || \
  113. atf_fail "failed to allocate md device"
  114. echo ${md} >> md.devs
  115. echo ${md}
  116. }
  117. checksum()
  118. {
  119. local src work
  120. src=$1
  121. work=$2
  122. src_checksum=$(md5 -q $src)
  123. work_checksum=$(md5 -q $work)
  124. if [ "$work_checksum" != "$src_checksum" ]; then
  125. atf_fail "work md5 checksum didn't match"
  126. fi
  127. ggate_checksum=$(md5 -q /dev/ggate${us})
  128. if [ "$ggate_checksum" != "$src_checksum" ]; then
  129. atf_fail "ggate md5 checksum didn't match"
  130. fi
  131. }
  132. common_cleanup()
  133. {
  134. if [ -f "ggate.devs" ]; then
  135. while read test_ggate; do
  136. ggatec destroy -f -u $test_ggate >/dev/null
  137. done < ggate.devs
  138. rm ggate.devs
  139. fi
  140. if [ -f "$PIDFILE" ]; then
  141. pkill -F "$PIDFILE"
  142. rm $PIDFILE
  143. fi
  144. if [ -f "PLAINFILES" ]; then
  145. while read f; do
  146. rm -f ${f}
  147. done < ${PLAINFILES}
  148. rm ${PLAINFILES}
  149. fi
  150. if [ -f "md.devs" ]; then
  151. while read test_md; do
  152. mdconfig -d -u $test_md 2>/dev/null
  153. done < md.devs
  154. rm md.devs
  155. fi
  156. true
  157. }
  158. load_ggate()
  159. {
  160. local class=gate
  161. # If the geom class isn't already loaded, try loading it.
  162. if ! kldstat -q -m g_${class}; then
  163. if ! geom ${class} load; then
  164. atf_skip "could not load module for geom class=${class}"
  165. fi
  166. fi
  167. }
  168. # Bug 204616: ggatel(8) creates /dev/ggate* asynchronously if `ggatel create`
  169. # isn't called with `-v`.
  170. wait_for_ggate_device()
  171. {
  172. ggate_device=$1
  173. while [ ! -c $ggate_device ]; do
  174. sleep 0.5
  175. done
  176. }