test-network.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #! /bin/sh
  2. ECHO_N="/bin/echo -n"
  3. use_coverage_binary=false
  4. until [ -z "$1" ]
  5. do
  6. case "$1" in
  7. --chutney-path)
  8. export CHUTNEY_PATH="$2"
  9. shift
  10. ;;
  11. --tor-path)
  12. export TOR_DIR="$2"
  13. shift
  14. ;;
  15. --flavor|--flavour|--network-flavor|--network-flavour)
  16. export NETWORK_FLAVOUR="$2"
  17. shift
  18. ;;
  19. --delay|--sleep|--bootstrap-time|--time)
  20. export BOOTSTRAP_TIME="$2"
  21. shift
  22. ;;
  23. # Environmental variables used by chutney verify performance tests
  24. # Send this many bytes per client connection (10 KBytes)
  25. --data|--data-bytes|--data-byte|--bytes|--byte)
  26. export CHUTNEY_DATA_BYTES="$2"
  27. shift
  28. ;;
  29. # Make this many connections per client (1)
  30. # Note: If you create 7 or more connections to a hidden service from
  31. # a single client, you'll likely get a verification failure due to
  32. # https://trac.torproject.org/projects/tor/ticket/15937
  33. --connections|--connection|--connection-count|--count)
  34. export CHUTNEY_CONNECTIONS="$2"
  35. shift
  36. ;;
  37. # Make each client connect to each HS (0)
  38. # 0 means a single client connects to each HS
  39. # 1 means every client connects to every HS
  40. --hs-multi-client|--hs-multi-clients|--hs-client|--hs-clients)
  41. export CHUTNEY_HS_MULTI_CLIENT="$2"
  42. shift
  43. ;;
  44. --coverage)
  45. use_coverage_binary=true
  46. ;;
  47. *)
  48. echo "Sorry, I don't know what to do with '$1'."
  49. exit 2
  50. ;;
  51. esac
  52. shift
  53. done
  54. TOR_DIR="${TOR_DIR:-$PWD}"
  55. NETWORK_FLAVOUR=${NETWORK_FLAVOUR:-"bridges+hs"}
  56. CHUTNEY_NETWORK=networks/$NETWORK_FLAVOUR
  57. myname=$(basename $0)
  58. [ -n "$CHUTNEY_PATH" ] || {
  59. echo "$myname: \$CHUTNEY_PATH not set, trying $TOR_DIR/../chutney"
  60. CHUTNEY_PATH="$TOR_DIR/../chutney"
  61. }
  62. [ -d "$CHUTNEY_PATH" ] && [ -x "$CHUTNEY_PATH/chutney" ] || {
  63. echo "$myname: missing 'chutney' in CHUTNEY_PATH ($CHUTNEY_PATH)"
  64. echo "$myname: Get chutney: git clone https://git.torproject.org/\
  65. chutney.git"
  66. echo "$myname: Set \$CHUTNEY_PATH to a non-standard location: export CHUTNEY_PATH=\`pwd\`/chutney"
  67. exit 1
  68. }
  69. cd "$CHUTNEY_PATH"
  70. # For picking up the right tor binaries.
  71. tor_name=tor
  72. tor_gencert_name=tor-gencert
  73. if test "$use_coverage_binary" = true; then
  74. tor_name=tor-cov
  75. fi
  76. export CHUTNEY_TOR="${TOR_DIR}/src/or/${tor_name}"
  77. export CHUTNEY_TOR_GENCERT="${TOR_DIR}/src/tools/${tor_gencert_name}"
  78. ./tools/bootstrap-network.sh $NETWORK_FLAVOUR || exit 2
  79. # Sleep some, waiting for the network to bootstrap.
  80. # TODO: Add chutney command 'bootstrap-status' and use that instead.
  81. BOOTSTRAP_TIME=${BOOTSTRAP_TIME:-35}
  82. $ECHO_N "$myname: sleeping for $BOOTSTRAP_TIME seconds"
  83. n=$BOOTSTRAP_TIME; while [ $n -gt 0 ]; do
  84. sleep 1; n=$(expr $n - 1); $ECHO_N .
  85. done; echo ""
  86. ./chutney verify $CHUTNEY_NETWORK
  87. VERIFY_EXIT_STATUS=$?
  88. # work around a bug/feature in make -j2 (or more)
  89. # where make hangs if any child processes are still alive
  90. ./chutney stop $CHUTNEY_NETWORK
  91. exit $VERIFY_EXIT_STATUS