test-network.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #! /bin/sh
  2. ECHO_N="/bin/echo -n"
  3. # Output is prefixed with the name of the script
  4. myname=$(basename $0)
  5. until [ -z "$1" ]
  6. do
  7. case "$1" in
  8. --chutney-path)
  9. export CHUTNEY_PATH="$2"
  10. shift
  11. ;;
  12. --tor-path)
  13. export TOR_DIR="$2"
  14. shift
  15. ;;
  16. --flavor|--flavour|--network-flavor|--network-flavour)
  17. export NETWORK_FLAVOUR="$2"
  18. shift
  19. ;;
  20. --delay|--sleep|--bootstrap-time|--time)
  21. export BOOTSTRAP_TIME="$2"
  22. shift
  23. ;;
  24. # Environmental variables used by chutney verify performance tests
  25. # Send this many bytes per client connection (10 KBytes)
  26. --data|--data-bytes|--data-byte|--bytes|--byte)
  27. export CHUTNEY_DATA_BYTES="$2"
  28. shift
  29. ;;
  30. # Make this many connections per client (1)
  31. # Note: If you create 7 or more connections to a hidden service from
  32. # a single client, you'll likely get a verification failure due to
  33. # https://trac.torproject.org/projects/tor/ticket/15937
  34. --connections|--connection|--connection-count|--count)
  35. export CHUTNEY_CONNECTIONS="$2"
  36. shift
  37. ;;
  38. # Make each client connect to each HS (0)
  39. # 0 means a single client connects to each HS
  40. # 1 means every client connects to every HS
  41. --hs-multi-client|--hs-multi-clients|--hs-client|--hs-clients)
  42. export CHUTNEY_HS_MULTI_CLIENT="$2"
  43. shift
  44. ;;
  45. --coverage)
  46. export USE_COVERAGE_BINARY=true
  47. ;;
  48. *)
  49. echo "$myname: Sorry, I don't know what to do with '$1'."
  50. exit 2
  51. ;;
  52. esac
  53. shift
  54. done
  55. # optional: $TOR_DIR is the tor build directory
  56. # it's used to find the location of tor binaries
  57. # if it's not set:
  58. # - set it ro $BUILDDIR, or
  59. # - if $PWD looks like a tor build directory, set it to $PWD, or
  60. # - unset $TOR_DIR, and let chutney fall back to finding tor binaries in $PATH
  61. if [ ! -d "$TOR_DIR" ]; then
  62. if [ -d "$BUILDDIR/src/or" -a -d "$BUILDDIR/src/tools" ]; then
  63. # Choose the build directory
  64. # But only if it looks like one
  65. echo "$myname: \$TOR_DIR not set, trying \$BUILDDIR"
  66. export TOR_DIR="$BUILDDIR"
  67. elif [ -d "$PWD/src/or" -a -d "$PWD/src/tools" ]; then
  68. # Guess the tor directory is the current directory
  69. # But only if it looks like one
  70. echo "$myname: \$TOR_DIR not set, trying \$PWD"
  71. export TOR_DIR="$PWD"
  72. else
  73. echo "$myname: no \$TOR_DIR, chutney will use \$PATH for tor binaries"
  74. unset TOR_DIR
  75. fi
  76. fi
  77. # mandatory: $CHUTNEY_PATH is the path to the chutney launch script
  78. # if it's not set:
  79. # - if $PWD looks like a chutney directory, set it to $PWD, or
  80. # - set it based on $TOR_DIR, expecting chutney to be next to tor, or
  81. # - fail and tell the user how to clone the chutney repository
  82. if [ ! -d "$CHUTNEY_PATH" -o ! -x "$CHUTNEY_PATH/chutney" ]; then
  83. if [ -x "$PWD/chutney" ]; then
  84. echo "$myname: \$CHUTNEY_PATH not valid, trying \$PWD"
  85. export CHUTNEY_PATH="$PWD"
  86. elif [ -d "$TOR_DIR" -a -d "$TOR_DIR/../chutney" -a \
  87. -x "$TOR_DIR/../chutney/chutney" ]; then
  88. echo "$myname: \$CHUTNEY_PATH not valid, trying \$TOR_DIR/../chutney"
  89. export CHUTNEY_PATH="$TOR_DIR/../chutney"
  90. else
  91. # TODO: work out how to package and install chutney,
  92. # so users can find it in $PATH
  93. echo "$myname: missing 'chutney' in \$CHUTNEY_PATH ($CHUTNEY_PATH)"
  94. echo "$myname: Get chutney: git clone https://git.torproject.org/\
  95. chutney.git"
  96. echo "$myname: Set \$CHUTNEY_PATH to a non-standard location: export \
  97. CHUTNEY_PATH=\`pwd\`/chutney"
  98. unset CHUTNEY_PATH
  99. exit 1
  100. fi
  101. fi
  102. # For picking up the right tor binaries.
  103. # If these varibles aren't set, chutney looks for tor binaries in $PATH
  104. if [ -d "$TOR_DIR" ]; then
  105. tor_name=tor
  106. tor_gencert_name=tor-gencert
  107. if [ "$USE_COVERAGE_BINARY" = true ]; then
  108. tor_name=tor-cov
  109. fi
  110. export CHUTNEY_TOR="${TOR_DIR}/src/or/${tor_name}"
  111. export CHUTNEY_TOR_GENCERT="${TOR_DIR}/src/tools/${tor_gencert_name}"
  112. fi
  113. # Set the variables for the chutney network flavour
  114. export NETWORK_FLAVOUR=${NETWORK_FLAVOUR:-"bridges+hs"}
  115. export CHUTNEY_NETWORK=networks/$NETWORK_FLAVOUR
  116. cd "$CHUTNEY_PATH"
  117. ./tools/bootstrap-network.sh $NETWORK_FLAVOUR || exit 2
  118. # Sleep some, waiting for the network to bootstrap.
  119. # TODO: Add chutney command 'bootstrap-status' and use that instead.
  120. BOOTSTRAP_TIME=${BOOTSTRAP_TIME:-35}
  121. $ECHO_N "$myname: sleeping for $BOOTSTRAP_TIME seconds"
  122. n=$BOOTSTRAP_TIME; while [ $n -gt 0 ]; do
  123. sleep 1; n=$(expr $n - 1); $ECHO_N .
  124. done; echo ""
  125. ./chutney verify $CHUTNEY_NETWORK
  126. VERIFY_EXIT_STATUS=$?
  127. # work around a bug/feature in make -j2 (or more)
  128. # where make hangs if any child processes are still alive
  129. ./chutney stop $CHUTNEY_NETWORK
  130. exit $VERIFY_EXIT_STATUS