Prop210: Refactor connection_get_* to produce lists and counts
[tor.git] / src / test / test-network.sh
blob05080e0c52bdc5ba9cd945a99e02ec284d55d28b
1 #! /bin/sh
3 ECHO_N="/bin/echo -n"
4 use_coverage_binary=false
6 until [ -z "$1" ]
7 do
8 case "$1" in
9 --chutney-path)
10 export CHUTNEY_PATH="$2"
11 shift
13 --tor-path)
14 export TOR_DIR="$2"
15 shift
17 --flavor|--flavour|--network-flavor|--network-flavour)
18 export NETWORK_FLAVOUR="$2"
19 shift
21 --delay|--sleep|--bootstrap-time|--time)
22 export BOOTSTRAP_TIME="$2"
23 shift
25 # Environmental variables used by chutney verify performance tests
26 # Send this many bytes per client connection (10 KBytes)
27 --data|--data-bytes|--data-byte|--bytes|--byte)
28 export CHUTNEY_DATA_BYTES="$2"
29 shift
31 # Make this many connections per client (1)
32 # Note: If you create 7 or more connections to a hidden service from
33 # a single client, you'll likely get a verification failure due to
34 # https://trac.torproject.org/projects/tor/ticket/15937
35 --connections|--connection|--connection-count|--count)
36 export CHUTNEY_CONNECTIONS="$2"
37 shift
39 # Make each client connect to each HS (0)
40 # 0 means a single client connects to each HS
41 # 1 means every client connects to every HS
42 --hs-multi-client|--hs-multi-clients|--hs-client|--hs-clients)
43 export CHUTNEY_HS_MULTI_CLIENT="$2"
44 shift
46 --coverage)
47 use_coverage_binary=true
50 echo "Sorry, I don't know what to do with '$1'."
51 exit 2
53 esac
54 shift
55 done
57 TOR_DIR="${TOR_DIR:-$PWD}"
58 NETWORK_FLAVOUR=${NETWORK_FLAVOUR:-"bridges+hs"}
59 CHUTNEY_NETWORK=networks/$NETWORK_FLAVOUR
60 myname=$(basename $0)
62 [ -n "$CHUTNEY_PATH" ] || {
63 echo "$myname: \$CHUTNEY_PATH not set, trying $TOR_DIR/../chutney"
64 CHUTNEY_PATH="$TOR_DIR/../chutney"
67 [ -d "$CHUTNEY_PATH" ] && [ -x "$CHUTNEY_PATH/chutney" ] || {
68 echo "$myname: missing 'chutney' in CHUTNEY_PATH ($CHUTNEY_PATH)"
69 echo "$myname: Get chutney: git clone https://git.torproject.org/\
70 chutney.git"
71 echo "$myname: Set \$CHUTNEY_PATH to a non-standard location: export CHUTNEY_PATH=\`pwd\`/chutney"
72 exit 1
75 cd "$CHUTNEY_PATH"
76 # For picking up the right tor binaries.
77 tor_name=tor
78 tor_gencert_name=tor-gencert
79 if test "$use_coverage_binary" = true; then
80 tor_name=tor-cov
82 export CHUTNEY_TOR="${TOR_DIR}/src/or/${tor_name}"
83 export CHUTNEY_TOR_GENCERT="${TOR_DIR}/src/tools/${tor_gencert_name}"
85 ./tools/bootstrap-network.sh $NETWORK_FLAVOUR || exit 2
87 # Sleep some, waiting for the network to bootstrap.
88 # TODO: Add chutney command 'bootstrap-status' and use that instead.
89 BOOTSTRAP_TIME=${BOOTSTRAP_TIME:-35}
90 $ECHO_N "$myname: sleeping for $BOOTSTRAP_TIME seconds"
91 n=$BOOTSTRAP_TIME; while [ $n -gt 0 ]; do
92 sleep 1; n=$(expr $n - 1); $ECHO_N .
93 done; echo ""
94 ./chutney verify $CHUTNEY_NETWORK
95 VERIFY_EXIT_STATUS=$?
96 # work around a bug/feature in make -j2 (or more)
97 # where make hangs if any child processes are still alive
98 ./chutney stop $CHUTNEY_NETWORK
99 exit $VERIFY_EXIT_STATUS