test-network.sh 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #! /bin/sh
  2. # Please do not modify this script, it has been moved to chutney/tools
  3. ECHO_N="/bin/echo -n"
  4. # Output is prefixed with the name of the script
  5. myname=$(basename $0)
  6. # We need to find CHUTNEY_PATH, so that we can call the version of this script
  7. # in chutney/tools. And we want to pass any arguments to that script as well.
  8. # So we source this script, which processes its arguments to find CHUTNEY_PATH.
  9. # Avoid recursively sourcing this script, and don't call the chutney version
  10. # while recursing, either
  11. if [ "$TEST_NETWORK_RECURSING" != true ]; then
  12. # Process the arguments into environmental variables with this script
  13. # to make sure $CHUTNEY_PATH is set
  14. # When we switch to using test-network.sh in chutney/tools, --dry-run
  15. # can be removed, because this script will find chutney, then pass all
  16. # arguments to chutney's test-network.sh
  17. echo "$myname: Parsing command-line arguments to find \$CHUTNEY_PATH"
  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 client, you'll likely get a verification failure due to
  66. # https://trac.torproject.org/projects/tor/ticket/15937
  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. *)
  86. echo "$myname: Sorry, I don't know what to do with '$1'."
  87. echo "$myname: Maybe chutney's test-network.sh understands '$1'."
  88. echo "$myname: Please update your chutney using 'git pull', and set \
  89. \$CHUTNEY_PATH"
  90. # continue processing arguments during a dry run
  91. if [ "$NETWORK_DRY_RUN" != true ]; then
  92. exit 2
  93. fi
  94. ;;
  95. esac
  96. shift
  97. done
  98. # optional: $TOR_DIR is the tor build directory
  99. # it's used to find the location of tor binaries
  100. # if it's not set:
  101. # - set it ro $BUILDDIR, or
  102. # - if $PWD looks like a tor build directory, set it to $PWD, or
  103. # - unset $TOR_DIR, and let chutney fall back to finding tor binaries in $PATH
  104. if [ ! -d "$TOR_DIR" ]; then
  105. if [ -d "$BUILDDIR/src/or" -a -d "$BUILDDIR/src/tools" ]; then
  106. # Choose the build directory
  107. # But only if it looks like one
  108. echo "$myname: \$TOR_DIR not set, trying \$BUILDDIR"
  109. export TOR_DIR="$BUILDDIR"
  110. elif [ -d "$PWD/src/or" -a -d "$PWD/src/tools" ]; then
  111. # Guess the tor directory is the current directory
  112. # But only if it looks like one
  113. echo "$myname: \$TOR_DIR not set, trying \$PWD"
  114. export TOR_DIR="$PWD"
  115. else
  116. echo "$myname: no \$TOR_DIR, chutney will use \$PATH for tor binaries"
  117. unset TOR_DIR
  118. fi
  119. fi
  120. # mandatory: $CHUTNEY_PATH is the path to the chutney launch script
  121. # if it's not set:
  122. # - if $PWD looks like a chutney directory, set it to $PWD, or
  123. # - set it based on $TOR_DIR, expecting chutney to be next to tor, or
  124. # - fail and tell the user how to clone the chutney repository
  125. if [ ! -d "$CHUTNEY_PATH" -o ! -x "$CHUTNEY_PATH/chutney" ]; then
  126. if [ -x "$PWD/chutney" ]; then
  127. echo "$myname: \$CHUTNEY_PATH not valid, trying \$PWD"
  128. export CHUTNEY_PATH="$PWD"
  129. elif [ -d "$TOR_DIR" -a -d "$TOR_DIR/../chutney" -a \
  130. -x "$TOR_DIR/../chutney/chutney" ]; then
  131. echo "$myname: \$CHUTNEY_PATH not valid, trying \$TOR_DIR/../chutney"
  132. export CHUTNEY_PATH="$TOR_DIR/../chutney"
  133. else
  134. # TODO: work out how to package and install chutney,
  135. # so users can find it in $PATH
  136. echo "$myname: missing 'chutney' in \$CHUTNEY_PATH ($CHUTNEY_PATH)"
  137. echo "$myname: Get chutney: git clone https://git.torproject.org/\
  138. chutney.git"
  139. echo "$myname: Set \$CHUTNEY_PATH to a non-standard location: export \
  140. CHUTNEY_PATH=\`pwd\`/chutney"
  141. unset CHUTNEY_PATH
  142. exit 1
  143. fi
  144. fi
  145. # When we switch to using test-network.sh in chutney/tools, this comment and
  146. # everything below it can be removed
  147. # For picking up the right tor binaries.
  148. # If these varibles aren't set, chutney looks for tor binaries in $PATH
  149. if [ -d "$TOR_DIR" ]; then
  150. tor_name=tor
  151. tor_gencert_name=tor-gencert
  152. if [ "$USE_COVERAGE_BINARY" = true ]; then
  153. tor_name=tor-cov
  154. fi
  155. export CHUTNEY_TOR="${TOR_DIR}/src/or/${tor_name}"
  156. export CHUTNEY_TOR_GENCERT="${TOR_DIR}/src/tools/${tor_gencert_name}"
  157. fi
  158. # Set the variables for the chutney network flavour
  159. export NETWORK_FLAVOUR=${NETWORK_FLAVOUR:-"bridges+hs"}
  160. export CHUTNEY_NETWORK=networks/$NETWORK_FLAVOUR
  161. # And finish up if we're doing a dry run
  162. if [ "$NETWORK_DRY_RUN" = true ]; then
  163. # we can't exit here, it breaks argument processing
  164. return
  165. fi
  166. cd "$CHUTNEY_PATH"
  167. ./tools/bootstrap-network.sh $NETWORK_FLAVOUR || exit 2
  168. # Sleep some, waiting for the network to bootstrap.
  169. # TODO: Add chutney command 'bootstrap-status' and use that instead.
  170. BOOTSTRAP_TIME=${BOOTSTRAP_TIME:-35}
  171. $ECHO_N "$myname: sleeping for $BOOTSTRAP_TIME seconds"
  172. n=$BOOTSTRAP_TIME; while [ $n -gt 0 ]; do
  173. sleep 1; n=$(expr $n - 1); $ECHO_N .
  174. done; echo ""
  175. ./chutney verify $CHUTNEY_NETWORK
  176. VERIFY_EXIT_STATUS=$?
  177. # work around a bug/feature in make -j2 (or more)
  178. # where make hangs if any child processes are still alive
  179. ./chutney stop $CHUTNEY_NETWORK
  180. exit $VERIFY_EXIT_STATUS