test-network.sh 5.1 KB

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