integration_test.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/env bash
  2. set -e
  3. set -x
  4. set -o pipefail
  5. BIN_ROOT="${BIN_ROOT:-$(realpath $(dirname $0)/..)}"
  6. PTUNNEL_BIN=${PTUNNEL_BIN:-${BIN_ROOT}/src/ptunnel-ng}
  7. PTUNNEL_ARGS="${PTUNNEL_ARGS:-}"
  8. VALGRIND_BIN=${VALGRIND_BIN:-valgrind}
  9. VALGRIND_ARGS="--error-exitcode=1 --exit-on-first-error=yes"
  10. if [ "x${DISABLE_VALGRIND}" = xy ]; then
  11. VALGRIND_BIN=""
  12. VALGRIND_ARGS=""
  13. fi
  14. test -x "${PTUNNEL_BIN}"
  15. ####################
  16. # Test PERFORMANCE #
  17. ####################
  18. TUNNEL_TIMEOUT=25
  19. DATA_TIMEOUT=22
  20. echo -n >/tmp/ptunnel-server.log
  21. echo -n >/tmp/ptunnel-client.log
  22. timeout --foreground -k1 ${TUNNEL_TIMEOUT} \
  23. ${VALGRIND_BIN} ${VALGRIND_ARGS} \
  24. "${PTUNNEL_BIN}" -v4 -r127.0.0.1 -R3000 -l4000 ${PTUNNEL_ARGS} -o/tmp/ptunnel-server.log &
  25. PTUNNEL_SERVER_PID=$!
  26. timeout --foreground -k1 ${TUNNEL_TIMEOUT} \
  27. ${VALGRIND_BIN} ${VALGRIND_ARGS} \
  28. "${PTUNNEL_BIN}" -v4 -p127.0.0.1 -r127.0.0.1 -R3000 -l4000 ${PTUNNEL_ARGS} -o/tmp/ptunnel-client.log &
  29. PTUNNEL_CLIENT_PID=$!
  30. timeout --foreground -k1 ${DATA_TIMEOUT} \
  31. nc -l -p 3000 >/dev/null || true &
  32. DATA_SERVER_PID=$!
  33. sleep 3
  34. timeout --foreground -k1 ${DATA_TIMEOUT} \
  35. sh -c "dd if=/dev/urandom bs=8192 | nc 127.0.0.1 4000" || true
  36. wait ${PTUNNEL_CLIENT_PID} || true
  37. wait ${PTUNNEL_SERVER_PID} || true
  38. wait ${DATA_SERVER_PID} || true
  39. cat /tmp/ptunnel-client.log
  40. cat /tmp/ptunnel-server.log
  41. cat /tmp/ptunnel-client.log |& grep 'Incoming connection.'
  42. cat /tmp/ptunnel-server.log |& grep 'Starting new session to 127.0.0.1:3000'
  43. # verify results
  44. CLIENT_ACK_SERIES=$(cat /tmp/ptunnel-client.log |& grep 'Received ack-series starting at seq' | wc -l)
  45. SERVER_ACK_SERIES=$(cat /tmp/ptunnel-server.log |& grep 'Received ack-series starting at seq' | \
  46. grep -v 'Received ack-series starting at seq 65535' | wc -l)
  47. test ${CLIENT_ACK_SERIES} -eq ${SERVER_ACK_SERIES}
  48. #######################
  49. # Test DATA INTEGRITY #
  50. #######################
  51. TUNNEL_TIMEOUT=10
  52. DATA_TIMEOUT=7
  53. echo -n >/tmp/ptunnel-server.log
  54. echo -n >/tmp/ptunnel-client.log
  55. timeout --foreground -k1 ${TUNNEL_TIMEOUT} \
  56. ${VALGRIND_BIN} ${VALGRIND_ARGS} \
  57. "${PTUNNEL_BIN}" -v4 -r127.0.0.1 -R3000 -l4000 ${PTUNNEL_ARGS} -o/tmp/ptunnel-server.log &
  58. PTUNNEL_SERVER_PID=$!
  59. timeout --foreground -k1 ${TUNNEL_TIMEOUT} \
  60. ${VALGRIND_BIN} ${VALGRIND_ARGS} \
  61. "${PTUNNEL_BIN}" -v4 -p127.0.0.1 -r127.0.0.1 -R3000 -l4000 ${PTUNNEL_ARGS} -o/tmp/ptunnel-client.log &
  62. PTUNNEL_CLIENT_PID=$!
  63. timeout --foreground -k1 ${DATA_TIMEOUT} \
  64. nc -l -p 3000 >/tmp/ptunnel-data-recv || true &
  65. DATA_SERVER_PID=$!
  66. sleep 3
  67. timeout --foreground -k1 ${DATA_TIMEOUT} \
  68. sh -c "dd if=/dev/urandom bs=8192 count=1 >/tmp/ptunnel-data-send && cat /tmp/ptunnel-data-send | sha256sum | cut -d' ' -f1 >/tmp/ptunnel-data-send.sha256 && cat /tmp/ptunnel-data-send | nc 127.0.0.1 4000" || true
  69. wait ${PTUNNEL_CLIENT_PID} || true
  70. wait ${PTUNNEL_SERVER_PID} || true
  71. wait ${DATA_SERVER_PID} || true
  72. # verify results
  73. test ${CLIENT_ACK_SERIES} -eq ${SERVER_ACK_SERIES}
  74. CLIENT_SHA=$(cat /tmp/ptunnel-data-send.sha256)
  75. SERVER_SHA=$(cat /tmp/ptunnel-data-recv | sha256sum | cut -d' ' -f1)
  76. test ${CLIENT_SHA} = ${SERVER_SHA}
  77. set +x
  78. printf '[+] SUCCESS !!\n'