aboutsummaryrefslogtreecommitdiff
path: root/src/test/test-network.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/test-network.sh')
-rwxr-xr-xsrc/test/test-network.sh163
1 files changed, 86 insertions, 77 deletions
diff --git a/src/test/test-network.sh b/src/test/test-network.sh
index 05080e0c52..6e0f286573 100755
--- a/src/test/test-network.sh
+++ b/src/test/test-network.sh
@@ -1,99 +1,108 @@
-#! /bin/sh
+#!/bin/sh
-ECHO_N="/bin/echo -n"
-use_coverage_binary=false
+# This script calls the equivalent script in chutney/tools
+# If we already know CHUTNEY_PATH, don't bother with argument parsing
+TEST_NETWORK="$CHUTNEY_PATH/tools/test-network.sh"
+# Call the chutney version of this script, if it exists, and we can find it
+if [ -d "$CHUTNEY_PATH" -a -x "$TEST_NETWORK" ]; then
+ # we can't produce any output, because we might be --quiet
+ # this preserves arguments with spaces correctly
+ exec "$TEST_NETWORK" "$@"
+fi
+
+# We need to go looking for CHUTNEY_PATH
+
+# Do we output anything at all?
+ECHO="${ECHO:-echo}"
+# Output is prefixed with the name of the script
+myname=$(basename $0)
+
+# Save the arguments before we destroy them
+# This might not preserve arguments with spaces in them
+ORIGINAL_ARGS="$@"
+
+# We need to find CHUTNEY_PATH, so that we can call the version of this script
+# in chutney/tools with the same arguments. We also need to respect --quiet.
until [ -z "$1" ]
do
case "$1" in
--chutney-path)
- export CHUTNEY_PATH="$2"
+ CHUTNEY_PATH="$2"
shift
;;
--tor-path)
- export TOR_DIR="$2"
- shift
- ;;
- --flavor|--flavour|--network-flavor|--network-flavour)
- export NETWORK_FLAVOUR="$2"
- shift
- ;;
- --delay|--sleep|--bootstrap-time|--time)
- export BOOTSTRAP_TIME="$2"
- shift
- ;;
- # Environmental variables used by chutney verify performance tests
- # Send this many bytes per client connection (10 KBytes)
- --data|--data-bytes|--data-byte|--bytes|--byte)
- export CHUTNEY_DATA_BYTES="$2"
+ TOR_DIR="$2"
shift
;;
- # Make this many connections per client (1)
- # Note: If you create 7 or more connections to a hidden service from
- # a single client, you'll likely get a verification failure due to
- # https://trac.torproject.org/projects/tor/ticket/15937
- --connections|--connection|--connection-count|--count)
- export CHUTNEY_CONNECTIONS="$2"
- shift
+ --quiet)
+ ECHO=true
;;
- # Make each client connect to each HS (0)
- # 0 means a single client connects to each HS
- # 1 means every client connects to every HS
- --hs-multi-client|--hs-multi-clients|--hs-client|--hs-clients)
- export CHUTNEY_HS_MULTI_CLIENT="$2"
- shift
- ;;
- --coverage)
- use_coverage_binary=true
- ;;
*)
- echo "Sorry, I don't know what to do with '$1'."
- exit 2
+ # maybe chutney's test-network.sh can handle it
;;
esac
shift
done
-TOR_DIR="${TOR_DIR:-$PWD}"
-NETWORK_FLAVOUR=${NETWORK_FLAVOUR:-"bridges+hs"}
-CHUTNEY_NETWORK=networks/$NETWORK_FLAVOUR
-myname=$(basename $0)
-
-[ -n "$CHUTNEY_PATH" ] || {
- echo "$myname: \$CHUTNEY_PATH not set, trying $TOR_DIR/../chutney"
- CHUTNEY_PATH="$TOR_DIR/../chutney"
-}
+# optional: $TOR_DIR is the tor build directory
+# it's used to find the location of tor binaries
+# if it's not set:
+# - set it to $BUILDDIR, or
+# - if $PWD looks like a tor build directory, set it to $PWD, or
+# - unset $TOR_DIR, and let chutney fall back to finding tor binaries in $PATH
+if [ ! -d "$TOR_DIR" ]; then
+ if [ -d "$BUILDDIR/src/or" -a -d "$BUILDDIR/src/tools" ]; then
+ # Choose the build directory
+ # But only if it looks like one
+ $ECHO "$myname: \$TOR_DIR not set, trying \$BUILDDIR"
+ TOR_DIR="$BUILDDIR"
+ elif [ -d "$PWD/src/or" -a -d "$PWD/src/tools" ]; then
+ # Guess the tor directory is the current directory
+ # But only if it looks like one
+ $ECHO "$myname: \$TOR_DIR not set, trying \$PWD"
+ TOR_DIR="$PWD"
+ else
+ $ECHO "$myname: no \$TOR_DIR, chutney will use \$PATH for tor binaries"
+ unset TOR_DIR
+ fi
+fi
-[ -d "$CHUTNEY_PATH" ] && [ -x "$CHUTNEY_PATH/chutney" ] || {
- echo "$myname: missing 'chutney' in CHUTNEY_PATH ($CHUTNEY_PATH)"
- echo "$myname: Get chutney: git clone https://git.torproject.org/\
+# mandatory: $CHUTNEY_PATH is the path to the chutney launch script
+# if it's not set:
+# - if $PWD looks like a chutney directory, set it to $PWD, or
+# - set it based on $TOR_DIR, expecting chutney to be next to tor, or
+# - fail and tell the user how to clone the chutney repository
+if [ ! -d "$CHUTNEY_PATH" -o ! -x "$CHUTNEY_PATH/chutney" ]; then
+ if [ -x "$PWD/chutney" ]; then
+ $ECHO "$myname: \$CHUTNEY_PATH not valid, trying \$PWD"
+ CHUTNEY_PATH="$PWD"
+ elif [ -d "$TOR_DIR" -a -d "$TOR_DIR/../chutney" -a \
+ -x "$TOR_DIR/../chutney/chutney" ]; then
+ $ECHO "$myname: \$CHUTNEY_PATH not valid, trying \$TOR_DIR/../chutney"
+ CHUTNEY_PATH="$TOR_DIR/../chutney"
+ else
+ $ECHO "$myname: missing 'chutney' in \$CHUTNEY_PATH ($CHUTNEY_PATH)"
+ $ECHO "$myname: Get chutney: git clone https://git.torproject.org/\
chutney.git"
- echo "$myname: Set \$CHUTNEY_PATH to a non-standard location: export CHUTNEY_PATH=\`pwd\`/chutney"
- exit 1
-}
-
-cd "$CHUTNEY_PATH"
-# For picking up the right tor binaries.
-tor_name=tor
-tor_gencert_name=tor-gencert
-if test "$use_coverage_binary" = true; then
- tor_name=tor-cov
+ $ECHO "$myname: Set \$CHUTNEY_PATH to a non-standard location: export \
+CHUTNEY_PATH=\`pwd\`/chutney"
+ unset CHUTNEY_PATH
+ exit 1
+ fi
fi
-export CHUTNEY_TOR="${TOR_DIR}/src/or/${tor_name}"
-export CHUTNEY_TOR_GENCERT="${TOR_DIR}/src/tools/${tor_gencert_name}"
-
-./tools/bootstrap-network.sh $NETWORK_FLAVOUR || exit 2
-# Sleep some, waiting for the network to bootstrap.
-# TODO: Add chutney command 'bootstrap-status' and use that instead.
-BOOTSTRAP_TIME=${BOOTSTRAP_TIME:-35}
-$ECHO_N "$myname: sleeping for $BOOTSTRAP_TIME seconds"
-n=$BOOTSTRAP_TIME; while [ $n -gt 0 ]; do
- sleep 1; n=$(expr $n - 1); $ECHO_N .
-done; echo ""
-./chutney verify $CHUTNEY_NETWORK
-VERIFY_EXIT_STATUS=$?
-# work around a bug/feature in make -j2 (or more)
-# where make hangs if any child processes are still alive
-./chutney stop $CHUTNEY_NETWORK
-exit $VERIFY_EXIT_STATUS
+TEST_NETWORK="$CHUTNEY_PATH/tools/test-network.sh"
+# Call the chutney version of this script, if it exists, and we can find it
+if [ -d "$CHUTNEY_PATH" -a -x "$TEST_NETWORK" ]; then
+ $ECHO "$myname: Calling newer chutney script $TEST_NETWORK"
+ # this may fail if some arguments have spaces in them
+ # if so, set CHUTNEY_PATH before calling test-network.sh, and spaces
+ # will be handled correctly
+ exec "$TEST_NETWORK" $ORIGINAL_ARGS
+else
+ $ECHO "$myname: Could not find tools/test-network.sh in CHUTNEY_PATH."
+ $ECHO "$myname: Please update your chutney using 'git pull'."
+ # We have failed to do what the user asked
+ exit 1
+fi