test-network.sh 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. # the path of a tor build directory
  14. # --tor-path overrides --tor and --tor-gencert
  15. export TOR_DIR="$2"
  16. shift
  17. ;;
  18. --tor)
  19. # the name or path of a tor binary
  20. export CHUTNEY_TOR="$2"
  21. shift
  22. ;;
  23. --tor-gencert)
  24. # the name or path of a tor-gencert binary
  25. export CHUTNEY_TOR_GENCERT="$2"
  26. shift
  27. ;;
  28. --flavor|--flavour|--network-flavor|--network-flavour)
  29. export NETWORK_FLAVOUR="$2"
  30. shift
  31. ;;
  32. # The amount of time chutney will wait before starting to verify
  33. # If negative, chutney exits straight after launching the network
  34. --start-time)
  35. export CHUTNEY_START_TIME="$2"
  36. shift
  37. ;;
  38. # The amount of time chutney will try to verify, before failing
  39. # If negative, chutney exits without verifying
  40. --delay|--sleep|--bootstrap-time|--time|--verify-time)
  41. # This isn't the best name for this variable, but we kept it the same
  42. # for backwards compatibility
  43. export CHUTNEY_BOOTSTRAP_TIME="$2"
  44. shift
  45. ;;
  46. # The amount of time chutney will wait after successfully verifying
  47. # If negative, chutney exits without stopping
  48. --stop-time)
  49. export CHUTNEY_STOP_TIME="$2"
  50. shift
  51. ;;
  52. # Environmental variables used by chutney verify performance tests
  53. # Send this many bytes per client connection (10 KBytes)
  54. --data|--data-bytes|--data-byte|--bytes|--byte)
  55. export CHUTNEY_DATA_BYTES="$2"
  56. shift
  57. ;;
  58. # Make this many connections per client (1)
  59. # Note: If you create 7 or more connections to a hidden service from
  60. # a single Tor 0.2.7 client, you'll likely get a verification failure due
  61. # to #15937. This is fixed in 0.2.8.
  62. --connections|--connection|--connection-count|--count)
  63. export CHUTNEY_CONNECTIONS="$2"
  64. shift
  65. ;;
  66. # Make each client connect to each HS (0)
  67. # 0 means a single client connects to each HS
  68. # 1 means every client connects to every HS
  69. --hs-multi-client|--hs-multi-clients|--hs-client|--hs-clients)
  70. export CHUTNEY_HS_MULTI_CLIENT="$2"
  71. shift
  72. ;;
  73. --coverage)
  74. export USE_COVERAGE_BINARY=true
  75. ;;
  76. --dry-run)
  77. # process arguments, but don't call any other scripts
  78. export NETWORK_DRY_RUN=true
  79. ;;
  80. *)
  81. echo "$myname: Sorry, I don't know what to do with '$1'."
  82. # continue processing arguments during a dry run
  83. if [ "$NETWORK_DRY_RUN" != true ]; then
  84. exit 2
  85. fi
  86. ;;
  87. esac
  88. shift
  89. done
  90. # optional: $TOR_DIR is the tor build directory
  91. # it's used to find the location of tor binaries
  92. # if it's not set:
  93. # - set it ro $BUILDDIR, or
  94. # - if $PWD looks like a tor build directory, set it to $PWD, or
  95. # - unset $TOR_DIR, and let chutney fall back to finding tor binaries in $PATH
  96. if [ ! -d "$TOR_DIR" ]; then
  97. if [ -d "$BUILDDIR/src/or" -a -d "$BUILDDIR/src/tools" ]; then
  98. # Choose the build directory
  99. # But only if it looks like one
  100. echo "$myname: \$TOR_DIR not set, trying \$BUILDDIR"
  101. export TOR_DIR="$BUILDDIR"
  102. elif [ -d "$PWD/src/or" -a -d "$PWD/src/tools" ]; then
  103. # Guess the tor directory is the current directory
  104. # But only if it looks like one
  105. echo "$myname: \$TOR_DIR not set, trying \$PWD"
  106. export TOR_DIR="$PWD"
  107. elif [ -d "$PWD/../tor" -a -d "$PWD/../tor/src/or" -a \
  108. -d "$PWD/../tor/src/tools" ]; then
  109. # Guess the tor directory is next to the current directory
  110. # But only if it looks like one
  111. echo "$myname: \$TOR_DIR not set, trying \$PWD/../tor"
  112. export TOR_DIR="$PWD/../tor"
  113. else
  114. echo "$myname: no \$TOR_DIR, chutney will use \$PATH for tor binaries"
  115. unset TOR_DIR
  116. fi
  117. fi
  118. # mandatory: $CHUTNEY_PATH is the path to the chutney launch script
  119. # if it's not set:
  120. # - if $PWD looks like a chutney directory, set it to $PWD, or
  121. # - set it based on $TOR_DIR, expecting chutney to be next to tor, or
  122. # - fail and tell the user how to clone the chutney repository
  123. if [ ! -d "$CHUTNEY_PATH" -o ! -x "$CHUTNEY_PATH/chutney" ]; then
  124. if [ -x "$PWD/chutney" ]; then
  125. echo "$myname: \$CHUTNEY_PATH not valid, trying \$PWD"
  126. export CHUTNEY_PATH="$PWD"
  127. elif [ -d "`dirname \"$0\"`/.." -a \
  128. -x "`dirname \"$0\"`/../chutney" ]; then
  129. echo "$myname: \$CHUTNEY_PATH not valid, using this script's location"
  130. export CHUTNEY_PATH="`dirname \"$0\"`/.."
  131. elif [ -d "$TOR_DIR" -a -d "$TOR_DIR/../chutney" -a \
  132. -x "$TOR_DIR/../chutney/chutney" ]; then
  133. echo "$myname: \$CHUTNEY_PATH not valid, trying \$TOR_DIR/../chutney"
  134. export CHUTNEY_PATH="$TOR_DIR/../chutney"
  135. else
  136. # TODO: work out how to package and install chutney,
  137. # so users can find it in $PATH
  138. echo "$myname: missing 'chutney' in \$CHUTNEY_PATH ($CHUTNEY_PATH)"
  139. echo "$myname: Get chutney: git clone https://git.torproject.org/\
  140. chutney.git"
  141. echo "$myname: Set \$CHUTNEY_PATH to a non-standard location: export \
  142. CHUTNEY_PATH=\`pwd\`/chutney"
  143. unset CHUTNEY_PATH
  144. exit 1
  145. fi
  146. fi
  147. # For picking up the right tor binaries.
  148. # If $TOR_DIR isn't set, chutney looks for tor binaries by name or path
  149. # using $CHUTNEY_TOR and $CHUTNEY_TOR_GENCERT, and then falls back to
  150. # looking for tor and tor-gencert in $PATH
  151. if [ -d "$TOR_DIR" ]; then
  152. tor_name=tor
  153. tor_gencert_name=tor-gencert
  154. if [ "$USE_COVERAGE_BINARY" = true ]; then
  155. tor_name=tor-cov
  156. fi
  157. export CHUTNEY_TOR="${TOR_DIR}/src/or/${tor_name}"
  158. export CHUTNEY_TOR_GENCERT="${TOR_DIR}/src/tools/${tor_gencert_name}"
  159. fi
  160. # Set the variables for the chutney network flavour
  161. export NETWORK_FLAVOUR=${NETWORK_FLAVOUR:-"bridges+hs"}
  162. export CHUTNEY_NETWORK=networks/$NETWORK_FLAVOUR
  163. # And finish up if we're doing a dry run
  164. if [ "$NETWORK_DRY_RUN" = true ]; then
  165. # we can't exit here, it breaks argument processing
  166. return
  167. fi
  168. cd "$CHUTNEY_PATH"
  169. ./tools/bootstrap-network.sh $NETWORK_FLAVOUR || exit 2
  170. # chutney starts verifying after 15 seconds, keeps on trying for 60 seconds,
  171. # and then stops immediately (by default)
  172. # Even the fastest chutney networks take 5 seconds for their first consensus
  173. # and then 10 seconds after that for relays to bootstrap and upload descriptors
  174. CHUTNEY_START_TIME=${CHUTNEY_START_TIME:-15}
  175. CHUTNEY_BOOTSTRAP_TIME=${CHUTNEY_BOOTSTRAP_TIME:-60}
  176. CHUTNEY_STOP_TIME=${CHUTNEY_STOP_TIME:-0}
  177. if [ "$CHUTNEY_START_TIME" -ge 0 ]; then
  178. echo "Waiting ${CHUTNEY_START_TIME} seconds for a consensus containing relays to be generated..."
  179. sleep "$CHUTNEY_START_TIME"
  180. else
  181. echo "Chutney network launched and running. To stop the network, use:"
  182. echo "$PWD/chutney stop $CHUTNEY_NETWORK"
  183. exit 0
  184. fi
  185. if [ "$CHUTNEY_BOOTSTRAP_TIME" -ge 0 ]; then
  186. # Chutney will try to verify for $CHUTNEY_BOOTSTRAP_TIME seconds
  187. ./chutney verify $CHUTNEY_NETWORK
  188. VERIFY_EXIT_STATUS=$?
  189. else
  190. echo "Chutney network ready and running. To stop the network, use:"
  191. echo "$PWD/chutney stop $CHUTNEY_NETWORK"
  192. exit 0
  193. fi
  194. if [ "$CHUTNEY_STOP_TIME" -ge 0 ]; then
  195. if [ "$CHUTNEY_STOP_TIME" -gt 0 ]; then
  196. echo "Waiting ${CHUTNEY_STOP_TIME} seconds before stopping the network..."
  197. fi
  198. sleep "$CHUTNEY_STOP_TIME"
  199. # work around a bug/feature in make -j2 (or more)
  200. # where make hangs if any child processes are still alive
  201. ./chutney stop $CHUTNEY_NETWORK
  202. exit $VERIFY_EXIT_STATUS
  203. else
  204. echo "Chutney network verified and running. To stop the network, use:"
  205. echo "$PWD/chutney stop $CHUTNEY_NETWORK"
  206. exit 0
  207. fi