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.
 
 
 
 

150 lines
2.6 KiB

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