test-network.sh 7.2 KB

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