geom_gate userland utility improvements
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

152 行
2.6 KiB

  1. # $FreeBSD$
  2. PIDFILE=ggated.pid
  3. TESTURL="$GGATEHTTP_URL"
  4. TEMPFILE="random.data"
  5. atf_test_case ggatehttp cleanup
  6. ggatehttp_head()
  7. {
  8. atf_set "descr" "ggatehttp can proxy to http"
  9. atf_set "require.progs" "ggatehttp"
  10. atf_set "require.user" "root"
  11. atf_set "timeout" 10
  12. }
  13. ggatehttp_body()
  14. {
  15. load_ggate
  16. us=$(alloc_ggate_dev)
  17. src=$(alloc_md)
  18. n1mchunks=10
  19. atf_check -e ignore -o ignore \
  20. dd if=/dev/random of="$TEMPFILE" bs=1m count=$n1mchunks conv=notrunc
  21. atf_check ggatehttp create -u $us "$TESTURL"
  22. ggate_dev=/dev/ggate${us}
  23. wait_for_ggate_device ${ggate_dev}
  24. # Test writing
  25. atf_check -e ignore -o ignore \
  26. dd if="$TEMPFILE" of=${ggate_dev} bs=1m count=$n1mchunks conv=notrunc
  27. # Test reading
  28. atf_check -e ignore -o ignore \
  29. dd of="$TEMPFILE"2 if=${ggate_dev} bs=1m count=$n1mchunks conv=notrunc
  30. ls -l "$TEMPFILE" "$TEMPFILE"2
  31. # Verify that we read what we wrote
  32. atf_check cmp "$TEMPFILE" "$TEMPFILE"2
  33. rm "$TEMPFILE" "$TEMPFILE"2
  34. }
  35. ggatehttp_cleanup()
  36. {
  37. common_cleanup
  38. }
  39. atf_init_test_cases()
  40. {
  41. atf_add_test_case ggatehttp
  42. }
  43. alloc_ggate_dev()
  44. {
  45. local us
  46. us=0
  47. while [ -c /dev/ggate${us} ]; do
  48. : $(( us += 1 ))
  49. done
  50. echo ${us} > ggate.devs
  51. echo ${us}
  52. }
  53. alloc_md()
  54. {
  55. local md
  56. md=$(mdconfig -a -t malloc -s 1M) || \
  57. atf_fail "failed to allocate md device"
  58. echo ${md} >> md.devs
  59. echo ${md}
  60. }
  61. checksum()
  62. {
  63. local src work
  64. src=$1
  65. work=$2
  66. src_checksum=$(md5 -q $src)
  67. work_checksum=$(md5 -q $work)
  68. if [ "$work_checksum" != "$src_checksum" ]; then
  69. atf_fail "work md5 checksum didn't match"
  70. fi
  71. ggate_checksum=$(md5 -q /dev/ggate${us})
  72. if [ "$ggate_checksum" != "$src_checksum" ]; then
  73. atf_fail "ggate md5 checksum didn't match"
  74. fi
  75. }
  76. common_cleanup()
  77. {
  78. if [ -f "ggate.devs" ]; then
  79. while read test_ggate; do
  80. ggatec destroy -f -u $test_ggate >/dev/null
  81. done < ggate.devs
  82. rm ggate.devs
  83. fi
  84. if [ -f "$PIDFILE" ]; then
  85. pkill -F "$PIDFILE"
  86. rm $PIDFILE
  87. fi
  88. if [ -f "PLAINFILES" ]; then
  89. while read f; do
  90. rm -f ${f}
  91. done < ${PLAINFILES}
  92. rm ${PLAINFILES}
  93. fi
  94. if [ -f "md.devs" ]; then
  95. while read test_md; do
  96. mdconfig -d -u $test_md 2>/dev/null
  97. done < md.devs
  98. rm md.devs
  99. fi
  100. true
  101. }
  102. load_ggate()
  103. {
  104. local class=gate
  105. # If the geom class isn't already loaded, try loading it.
  106. if ! kldstat -q -m g_${class}; then
  107. if ! geom ${class} load; then
  108. atf_skip "could not load module for geom class=${class}"
  109. fi
  110. fi
  111. }
  112. # Bug 204616: ggatel(8) creates /dev/ggate* asynchronously if `ggatel create`
  113. # isn't called with `-v`.
  114. wait_for_ggate_device()
  115. {
  116. ggate_device=$1
  117. while [ ! -c $ggate_device ]; do
  118. sleep 0.5
  119. done
  120. }