test-network.sh 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. #!/bin/sh
  2. # use bash if it is available, as this script doesn't work well in non-bash sh
  3. # this will be fixed in #19699
  4. # there is no simple, portable way of checking the name of the shell, so we
  5. # exec bash even when sh is bash
  6. if [ -x /bin/bash -a "$USING_BASH" != true ]; then
  7. # only do this once
  8. export USING_BASH=true
  9. exec /bin/bash "$0" "$@"
  10. fi
  11. # Please do not modify this script, it has been moved to chutney/tools
  12. export ECHO="${ECHO:-echo}"
  13. export ECHO_N="${ECHO_N:-/bin/echo -n}"
  14. # Output is prefixed with the name of the script
  15. myname=$(basename $0)
  16. # We need to find CHUTNEY_PATH, so that we can call the version of this script
  17. # in chutney/tools. And we want to pass any arguments to that script as well.
  18. # So we source this script, which processes its arguments to find CHUTNEY_PATH.
  19. # Avoid recursively sourcing this script, and don't call the chutney version
  20. # while recursing, either
  21. if [ "$TEST_NETWORK_RECURSING" != true ]; then
  22. # Process the arguments into environmental variables with this script
  23. # to make sure $CHUTNEY_PATH is set
  24. # When we switch to using test-network.sh in chutney/tools, --dry-run
  25. # can be removed, because this script will find chutney, then pass all
  26. # arguments to chutney's test-network.sh
  27. export TEST_NETWORK_RECURSING=true
  28. # passing arguments to a sourced script only works in bash
  29. # this will be fixed in #19699
  30. . "$0" --dry-run "$@"
  31. # Call the chutney version of this script, if it exists, and we can find it
  32. if [ -d "$CHUTNEY_PATH" -a -x "$CHUTNEY_PATH/tools/test-network.sh" ]; then
  33. unset NETWORK_DRY_RUN
  34. $ECHO "$myname: Calling newer chutney script \
  35. $CHUTNEY_PATH/tools/test-network.sh"
  36. "$CHUTNEY_PATH/tools/test-network.sh" "$@"
  37. exit $?
  38. else
  39. $ECHO "$myname: This script has moved to chutney/tools."
  40. $ECHO "$myname: Please update your chutney using 'git pull'."
  41. # When we switch to using test-network.sh in chutney/tools, we should
  42. # exit with a very loud failure here
  43. $ECHO "$myname: Falling back to the old tor version of the script."
  44. fi
  45. fi
  46. until [ -z "$1" ]
  47. do
  48. case "$1" in
  49. --chutney-path)
  50. export CHUTNEY_PATH="$2"
  51. shift
  52. ;;
  53. --tor-path)
  54. export TOR_DIR="$2"
  55. shift
  56. ;;
  57. # When we switch to using test-network.sh in chutney/tools, only the
  58. # --chutney-path and --tor-path arguments need to be processed by this
  59. # script, everything else can be handled by chutney's test-network.sh
  60. --flavor|--flavour|--network-flavor|--network-flavour)
  61. export NETWORK_FLAVOUR="$2"
  62. shift
  63. ;;
  64. --delay|--sleep|--bootstrap-time|--time)
  65. export BOOTSTRAP_TIME="$2"
  66. shift
  67. ;;
  68. # Environmental variables used by chutney verify performance tests
  69. # Send this many bytes per client connection (10 KBytes)
  70. --data|--data-bytes|--data-byte|--bytes|--byte)
  71. export CHUTNEY_DATA_BYTES="$2"
  72. shift
  73. ;;
  74. # Make this many connections per client (1)
  75. # Note: If you create 7 or more connections to a hidden service from
  76. # a single Tor 0.2.7 client, you'll likely get a verification failure due
  77. # to #15937. This is fixed in 0.2.8.
  78. --connections|--connection|--connection-count|--count)
  79. export CHUTNEY_CONNECTIONS="$2"
  80. shift
  81. ;;
  82. # Make each client connect to each HS (0)
  83. # 0 means a single client connects to each HS
  84. # 1 means every client connects to every HS
  85. --hs-multi-client|--hs-multi-clients|--hs-client|--hs-clients)
  86. export CHUTNEY_HS_MULTI_CLIENT="$2"
  87. shift
  88. ;;
  89. --coverage)
  90. export USE_COVERAGE_BINARY=true
  91. ;;
  92. --dry-run)
  93. # process arguments, but don't call any other scripts
  94. export NETWORK_DRY_RUN=true
  95. ;;
  96. --quiet)
  97. export ECHO=true
  98. export ECHO_N=true
  99. ;;
  100. *)
  101. $ECHO "$myname: Sorry, I don't know what to do with '$1'."
  102. $ECHO "$myname: Maybe chutney's test-network.sh understands '$1'."
  103. $ECHO "$myname: Please update your chutney using 'git pull', and set \
  104. \$CHUTNEY_PATH"
  105. # continue processing arguments during a dry run
  106. if [ "$NETWORK_DRY_RUN" != true ]; then
  107. exit 2
  108. fi
  109. ;;
  110. esac
  111. shift
  112. done
  113. # optional: $TOR_DIR is the tor build directory
  114. # it's used to find the location of tor binaries
  115. # if it's not set:
  116. # - set it ro $BUILDDIR, or
  117. # - if $PWD looks like a tor build directory, set it to $PWD, or
  118. # - unset $TOR_DIR, and let chutney fall back to finding tor binaries in $PATH
  119. if [ ! -d "$TOR_DIR" ]; then
  120. if [ -d "$BUILDDIR/src/or" -a -d "$BUILDDIR/src/tools" ]; then
  121. # Choose the build directory
  122. # But only if it looks like one
  123. $ECHO "$myname: \$TOR_DIR not set, trying \$BUILDDIR"
  124. export TOR_DIR="$BUILDDIR"
  125. elif [ -d "$PWD/src/or" -a -d "$PWD/src/tools" ]; then
  126. # Guess the tor directory is the current directory
  127. # But only if it looks like one
  128. $ECHO "$myname: \$TOR_DIR not set, trying \$PWD"
  129. export TOR_DIR="$PWD"
  130. else
  131. $ECHO "$myname: no \$TOR_DIR, chutney will use \$PATH for tor binaries"
  132. unset TOR_DIR
  133. fi
  134. fi
  135. # mandatory: $CHUTNEY_PATH is the path to the chutney launch script
  136. # if it's not set:
  137. # - if $PWD looks like a chutney directory, set it to $PWD, or
  138. # - set it based on $TOR_DIR, expecting chutney to be next to tor, or
  139. # - fail and tell the user how to clone the chutney repository
  140. if [ ! -d "$CHUTNEY_PATH" -o ! -x "$CHUTNEY_PATH/chutney" ]; then
  141. if [ -x "$PWD/chutney" ]; then
  142. $ECHO "$myname: \$CHUTNEY_PATH not valid, trying \$PWD"
  143. export CHUTNEY_PATH="$PWD"
  144. elif [ -d "$TOR_DIR" -a -d "$TOR_DIR/../chutney" -a \
  145. -x "$TOR_DIR/../chutney/chutney" ]; then
  146. $ECHO "$myname: \$CHUTNEY_PATH not valid, trying \$TOR_DIR/../chutney"
  147. export CHUTNEY_PATH="$TOR_DIR/../chutney"
  148. else
  149. # TODO: work out how to package and install chutney,
  150. # so users can find it in $PATH
  151. $ECHO "$myname: missing 'chutney' in \$CHUTNEY_PATH ($CHUTNEY_PATH)"
  152. $ECHO "$myname: Get chutney: git clone https://git.torproject.org/\
  153. chutney.git"
  154. $ECHO "$myname: Set \$CHUTNEY_PATH to a non-standard location: export \
  155. CHUTNEY_PATH=\`pwd\`/chutney"
  156. unset CHUTNEY_PATH
  157. exit 1
  158. fi
  159. fi
  160. # When we switch to using test-network.sh in chutney/tools, this comment and
  161. # everything below it can be removed
  162. # For picking up the right tor binaries.
  163. # If these varibles aren't set, chutney looks for tor binaries in $PATH
  164. if [ -d "$TOR_DIR" ]; then
  165. tor_name=tor
  166. tor_gencert_name=tor-gencert
  167. if [ "$USE_COVERAGE_BINARY" = true ]; then
  168. tor_name=tor-cov
  169. fi
  170. export CHUTNEY_TOR="${TOR_DIR}/src/or/${tor_name}"
  171. export CHUTNEY_TOR_GENCERT="${TOR_DIR}/src/tools/${tor_gencert_name}"
  172. fi
  173. # Set the variables for the chutney network flavour
  174. export NETWORK_FLAVOUR=${NETWORK_FLAVOUR:-"bridges+hs"}
  175. export CHUTNEY_NETWORK=networks/$NETWORK_FLAVOUR
  176. # And finish up if we're doing a dry run
  177. if [ "$NETWORK_DRY_RUN" = true ]; then
  178. # we can't exit here, it breaks argument processing
  179. # this only works in bash: return semantics are shell-specific
  180. # this will be fixed in #19699
  181. return 2>/dev/null || exit
  182. fi
  183. cd "$CHUTNEY_PATH"
  184. ./tools/bootstrap-network.sh $NETWORK_FLAVOUR || exit 3
  185. # Sleep some, waiting for the network to bootstrap.
  186. # TODO: Add chutney command 'bootstrap-status' and use that instead.
  187. BOOTSTRAP_TIME=${BOOTSTRAP_TIME:-35}
  188. $ECHO_N "$myname: sleeping for $BOOTSTRAP_TIME seconds"
  189. n=$BOOTSTRAP_TIME; while [ $n -gt 0 ]; do
  190. sleep 1; n=$(expr $n - 1); $ECHO_N .
  191. done; $ECHO ""
  192. ./chutney verify $CHUTNEY_NETWORK
  193. VERIFY_EXIT_STATUS=$?
  194. # work around a bug/feature in make -j2 (or more)
  195. # where make hangs if any child processes are still alive
  196. ./chutney stop $CHUTNEY_NETWORK
  197. exit $VERIFY_EXIT_STATUS