test-network.sh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. --delay|--sleep|--bootstrap-time|--time)
  33. export CHUTNEY_BOOTSTRAP_TIME="$2"
  34. shift
  35. ;;
  36. # Environmental variables used by chutney verify performance tests
  37. # Send this many bytes per client connection (10 KBytes)
  38. --data|--data-bytes|--data-byte|--bytes|--byte)
  39. export CHUTNEY_DATA_BYTES="$2"
  40. shift
  41. ;;
  42. # Make this many connections per client (1)
  43. # Note: If you create 7 or more connections to a hidden service from
  44. # a single Tor 0.2.7 client, you'll likely get a verification failure due
  45. # to #15937. This is fixed in 0.2.8.
  46. --connections|--connection|--connection-count|--count)
  47. export CHUTNEY_CONNECTIONS="$2"
  48. shift
  49. ;;
  50. # Make each client connect to each HS (0)
  51. # 0 means a single client connects to each HS
  52. # 1 means every client connects to every HS
  53. --hs-multi-client|--hs-multi-clients|--hs-client|--hs-clients)
  54. export CHUTNEY_HS_MULTI_CLIENT="$2"
  55. shift
  56. ;;
  57. --coverage)
  58. export USE_COVERAGE_BINARY=true
  59. ;;
  60. --dry-run)
  61. # process arguments, but don't call any other scripts
  62. export NETWORK_DRY_RUN=true
  63. ;;
  64. *)
  65. echo "$myname: Sorry, I don't know what to do with '$1'."
  66. # continue processing arguments during a dry run
  67. if [ "$NETWORK_DRY_RUN" != true ]; then
  68. exit 2
  69. fi
  70. ;;
  71. esac
  72. shift
  73. done
  74. # optional: $TOR_DIR is the tor build directory
  75. # it's used to find the location of tor binaries
  76. # if it's not set:
  77. # - set it ro $BUILDDIR, or
  78. # - if $PWD looks like a tor build directory, set it to $PWD, or
  79. # - unset $TOR_DIR, and let chutney fall back to finding tor binaries in $PATH
  80. if [ ! -d "$TOR_DIR" ]; then
  81. if [ -d "$BUILDDIR/src/or" -a -d "$BUILDDIR/src/tools" ]; then
  82. # Choose the build directory
  83. # But only if it looks like one
  84. echo "$myname: \$TOR_DIR not set, trying \$BUILDDIR"
  85. export TOR_DIR="$BUILDDIR"
  86. elif [ -d "$PWD/src/or" -a -d "$PWD/src/tools" ]; then
  87. # Guess the tor directory is the current directory
  88. # But only if it looks like one
  89. echo "$myname: \$TOR_DIR not set, trying \$PWD"
  90. export TOR_DIR="$PWD"
  91. else
  92. echo "$myname: no \$TOR_DIR, chutney will use \$PATH for tor binaries"
  93. unset TOR_DIR
  94. fi
  95. fi
  96. # mandatory: $CHUTNEY_PATH is the path to the chutney launch script
  97. # if it's not set:
  98. # - if $PWD looks like a chutney directory, set it to $PWD, or
  99. # - set it based on $TOR_DIR, expecting chutney to be next to tor, or
  100. # - fail and tell the user how to clone the chutney repository
  101. if [ ! -d "$CHUTNEY_PATH" -o ! -x "$CHUTNEY_PATH/chutney" ]; then
  102. if [ -x "$PWD/chutney" ]; then
  103. echo "$myname: \$CHUTNEY_PATH not valid, trying \$PWD"
  104. export CHUTNEY_PATH="$PWD"
  105. elif [ -d "$TOR_DIR" -a -d "$TOR_DIR/../chutney" -a \
  106. -x "$TOR_DIR/../chutney/chutney" ]; then
  107. echo "$myname: \$CHUTNEY_PATH not valid, trying \$TOR_DIR/../chutney"
  108. export CHUTNEY_PATH="$TOR_DIR/../chutney"
  109. else
  110. # TODO: work out how to package and install chutney,
  111. # so users can find it in $PATH
  112. echo "$myname: missing 'chutney' in \$CHUTNEY_PATH ($CHUTNEY_PATH)"
  113. echo "$myname: Get chutney: git clone https://git.torproject.org/\
  114. chutney.git"
  115. echo "$myname: Set \$CHUTNEY_PATH to a non-standard location: export \
  116. CHUTNEY_PATH=\`pwd\`/chutney"
  117. unset CHUTNEY_PATH
  118. exit 1
  119. fi
  120. fi
  121. # For picking up the right tor binaries.
  122. # If $TOR_DIR isn't set, chutney looks for tor binaries by name or path
  123. # using $CHUTNEY_TOR and $CHUTNEY_TOR_GENCERT, and then falls back to
  124. # looking for tor and tor-gencert in $PATH
  125. if [ -d "$TOR_DIR" ]; then
  126. tor_name=tor
  127. tor_gencert_name=tor-gencert
  128. if [ "$USE_COVERAGE_BINARY" = true ]; then
  129. tor_name=tor-cov
  130. fi
  131. export CHUTNEY_TOR="${TOR_DIR}/src/or/${tor_name}"
  132. export CHUTNEY_TOR_GENCERT="${TOR_DIR}/src/tools/${tor_gencert_name}"
  133. fi
  134. # Set the variables for the chutney network flavour
  135. export NETWORK_FLAVOUR=${NETWORK_FLAVOUR:-"bridges+hs"}
  136. export CHUTNEY_NETWORK=networks/$NETWORK_FLAVOUR
  137. # And finish up if we're doing a dry run
  138. if [ "$NETWORK_DRY_RUN" = true ]; then
  139. # we can't exit here, it breaks argument processing
  140. return
  141. fi
  142. cd "$CHUTNEY_PATH"
  143. ./tools/bootstrap-network.sh $NETWORK_FLAVOUR || exit 2
  144. # chutney verify starts immediately, and keeps on trying for 60 seconds
  145. CHUTNEY_BOOTSTRAP_TIME=${CHUTNEY_BOOTSTRAP_TIME:-60}
  146. # but even the fastest tor networks take 5 seconds for their first consensus
  147. # and then 10 seconds after that for relays to bootstrap and upload descriptors
  148. echo "Waiting 15 seconds for a consensus containing relays to be generated..."
  149. sleep 15
  150. ./chutney verify $CHUTNEY_NETWORK
  151. VERIFY_EXIT_STATUS=$?
  152. # work around a bug/feature in make -j2 (or more)
  153. # where make hangs if any child processes are still alive
  154. ./chutney stop $CHUTNEY_NETWORK
  155. exit $VERIFY_EXIT_STATUS