test-network.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 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 client, you'll likely get a verification failure due to
  33. # https://trac.torproject.org/projects/tor/ticket/15937
  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. echo "$myname: Maybe chutney's test-network.sh understands '$1'."
  55. echo "$myname: Please update your chutney using 'git pull', and set \
  56. \$CHUTNEY_PATH"
  57. # continue processing arguments during a dry run
  58. if [ "$NETWORK_DRY_RUN" != true ]; then
  59. exit 2
  60. fi
  61. ;;
  62. esac
  63. shift
  64. done
  65. # optional: $TOR_DIR is the tor build directory
  66. # it's used to find the location of tor binaries
  67. # if it's not set:
  68. # - set it ro $BUILDDIR, or
  69. # - if $PWD looks like a tor build directory, set it to $PWD, or
  70. # - unset $TOR_DIR, and let chutney fall back to finding tor binaries in $PATH
  71. if [ ! -d "$TOR_DIR" ]; then
  72. if [ -d "$BUILDDIR/src/or" -a -d "$BUILDDIR/src/tools" ]; then
  73. # Choose the build directory
  74. # But only if it looks like one
  75. echo "$myname: \$TOR_DIR not set, trying \$BUILDDIR"
  76. export TOR_DIR="$BUILDDIR"
  77. elif [ -d "$PWD/src/or" -a -d "$PWD/src/tools" ]; then
  78. # Guess the tor directory is the current directory
  79. # But only if it looks like one
  80. echo "$myname: \$TOR_DIR not set, trying \$PWD"
  81. export TOR_DIR="$PWD"
  82. else
  83. echo "$myname: no \$TOR_DIR, chutney will use \$PATH for tor binaries"
  84. unset TOR_DIR
  85. fi
  86. fi
  87. # mandatory: $CHUTNEY_PATH is the path to the chutney launch script
  88. # if it's not set:
  89. # - if $PWD looks like a chutney directory, set it to $PWD, or
  90. # - set it based on $TOR_DIR, expecting chutney to be next to tor, or
  91. # - fail and tell the user how to clone the chutney repository
  92. if [ ! -d "$CHUTNEY_PATH" -o ! -x "$CHUTNEY_PATH/chutney" ]; then
  93. if [ -x "$PWD/chutney" ]; then
  94. echo "$myname: \$CHUTNEY_PATH not valid, trying \$PWD"
  95. export CHUTNEY_PATH="$PWD"
  96. elif [ -d "$TOR_DIR" -a -d "$TOR_DIR/../chutney" -a \
  97. -x "$TOR_DIR/../chutney/chutney" ]; then
  98. echo "$myname: \$CHUTNEY_PATH not valid, trying \$TOR_DIR/../chutney"
  99. export CHUTNEY_PATH="$TOR_DIR/../chutney"
  100. else
  101. # TODO: work out how to package and install chutney,
  102. # so users can find it in $PATH
  103. echo "$myname: missing 'chutney' in \$CHUTNEY_PATH ($CHUTNEY_PATH)"
  104. echo "$myname: Get chutney: git clone https://git.torproject.org/\
  105. chutney.git"
  106. echo "$myname: Set \$CHUTNEY_PATH to a non-standard location: export \
  107. CHUTNEY_PATH=\`pwd\`/chutney"
  108. unset CHUTNEY_PATH
  109. exit 1
  110. fi
  111. fi
  112. # For picking up the right tor binaries.
  113. # If these varibles aren't set, chutney looks for tor binaries in $PATH
  114. if [ -d "$TOR_DIR" ]; then
  115. tor_name=tor
  116. tor_gencert_name=tor-gencert
  117. if [ "$USE_COVERAGE_BINARY" = true ]; then
  118. tor_name=tor-cov
  119. fi
  120. export CHUTNEY_TOR="${TOR_DIR}/src/or/${tor_name}"
  121. export CHUTNEY_TOR_GENCERT="${TOR_DIR}/src/tools/${tor_gencert_name}"
  122. fi
  123. # Set the variables for the chutney network flavour
  124. export NETWORK_FLAVOUR=${NETWORK_FLAVOUR:-"bridges+hs"}
  125. export CHUTNEY_NETWORK=networks/$NETWORK_FLAVOUR
  126. # And finish up if we're doing a dry run
  127. if [ "$NETWORK_DRY_RUN" = true]; then
  128. exit 0
  129. fi
  130. cd "$CHUTNEY_PATH"
  131. ./tools/bootstrap-network.sh $NETWORK_FLAVOUR || exit 2
  132. # Sleep some, waiting for the network to bootstrap.
  133. # TODO: Add chutney command 'bootstrap-status' and use that instead.
  134. BOOTSTRAP_TIME=${BOOTSTRAP_TIME:-35}
  135. $ECHO_N "$myname: sleeping for $BOOTSTRAP_TIME seconds"
  136. n=$BOOTSTRAP_TIME; while [ $n -gt 0 ]; do
  137. sleep 1; n=$(expr $n - 1); $ECHO_N .
  138. done; echo ""
  139. ./chutney verify $CHUTNEY_NETWORK
  140. VERIFY_EXIT_STATUS=$?
  141. # work around a bug/feature in make -j2 (or more)
  142. # where make hangs if any child processes are still alive
  143. ./chutney stop $CHUTNEY_NETWORK
  144. exit $VERIFY_EXIT_STATUS