Improve tests

This commit is contained in:
Jeremy Lakeman 2013-12-16 14:54:16 +10:30
parent 4bb3336b33
commit 6d942f8d4f
5 changed files with 121 additions and 121 deletions

View File

@ -259,6 +259,7 @@ setup_servald_so() {
start_servald_server() {
push_instance
set_instance_fromarg "$1" && shift
configure_servald_server
# Start servald server
local -a before_pids
local -a after_pids
@ -699,14 +700,8 @@ add_servald_interface() {
start_servald_instances() {
push_instance
tfw_log "# start servald instances $*"
local I
for I; do
set_instance $I
# These config settings can be overridden in a caller-supplied configure_servald_server().
# They are extremely useful for the majority of fixtures.
configure_servald_server
foreach_instance "$@" \
start_servald_server
done
# Now wait until they see each other.
foreach_instance "$@" \
wait_until --sleep=0.25 has_seen_instances "$@"

View File

@ -45,17 +45,10 @@ set_server_vars() {
set log.console.level debug \
set log.console.show_pid on \
set log.console.show_time on \
set mdp.iftype.wifi.tick_ms 100 \
set rhizome.enable No \
set debug.overlayinterfaces No \
set debug.overlaybuffer No \
set debug.packetformats No \
set debug.overlayframes No \
set debug.overlayrouting No \
set debug.packettx No \
set debug.packetrx No \
set debug.mdprequests Yes \
set debug.keyring Yes
set debug.keyring Yes \
set debug.linkstate Yes
}
doc_LookupWildcard="Lookup by wildcard"

View File

@ -36,7 +36,7 @@ teardown() {
# Called by start_servald_instances for each instance.
configure_servald_server() {
add_servald_interface
add_servald_interface --file
executeOk_servald config \
set log.console.level debug \
set log.console.show_pid on \

View File

@ -27,30 +27,33 @@ interface_up() {
return 0
}
has_link() {
interface_ex=".*"
case "$1" in
dummy*) interface_ex="$1"; shift;;
esac
set_instance $1
executeOk_servald route print
tfw_log "Looking for link from $1 to $2 ($4)"
if ! grep "^${4}:\(BROADCAST\|UNICAST\):${interface_ex}:0*\$" $_tfw_tmp/stdout; then
link_matches() {
local interface_ex=".*"
local link_type="\(BROADCAST\|\UNICAST\)"
local via="0*"
local sid=""
while [ $# -ne 0 ]; do
case "$1" in
--interface) interface_ex="$2"; shift 2;;
--broadcast) link_type="BROADCAST"; shift;;
--unicast) link_type="UNICAST"; shift;;
--via) link_type="INDIRECT"; via="$2"; interface_ex=""; shift 2;;
*) break;;
esac
done
sid="$1"
tfw_log "Looking for link ${sid}, ${link_type}, ${interface_ex}, ${via}"
if ! grep "^${sid}:${link_type}:${interface_ex}:${via}\$" $_tfw_tmp/stdout; then
tfw_log "Link not found"
# tfw_log "^${4}:\(BROADCAST\|UNICAST\):${interface_ex}:0*\$"
# tfw_cat --stdout --stderr
return 1
fi
[ $4 = $5 ] && return 0;
tfw_log "Path from $1 to $3 should be via $2 ($5, $4)"
if ! grep "^${5}:INDIRECT::${4}\$" $_tfw_tmp/stdout; then
tfw_log "No path found"
# tfw_log "^${5}:INDIRECT::${4}\$"
# tfw_cat --stdout --stderr
return 1
fi
}
has_link() {
executeOk_servald route print
link_matches $@
}
path_exists() {
local dest
eval dest=\$$#
@ -61,13 +64,17 @@ path_exists() {
for I; do
local sidvar=SID${I#+}
[ -n "${!sidvar}" ] || break
has_link $next_inst $I $dest ${!sidvar} ${!dest_sidvar} || return 1
set_instance $next_inst
executeOk_servald route print
link_matches ${!sidvar} || return 1
[ $I = $dest ] && return 0
link_matches --via ${!sidvar} ${!dest_sidvar} || return 1
next_inst=$I
done
return 0
}
start_routing_instance() {
configure_servald_server() {
executeOk_servald config \
set debug.mdprequests yes \
set debug.linkstate yes \
@ -77,8 +84,6 @@ start_routing_instance() {
set log.console.show_pid on \
set log.console.show_time on \
set rhizome.enable no
start_servald_server
wait_until interface_up
}
log_routing_table() {
@ -100,7 +105,7 @@ setup_single_link() {
assert_no_servald_processes
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_servald_interface 1
foreach_instance +A +B start_routing_instance
foreach_instance +A +B start_servald_server
}
test_single_link() {
wait_until --timeout=10 path_exists +A +B
@ -116,25 +121,27 @@ setup_multiple_ids() {
assert_no_servald_processes
foreach_instance +A +B create_identities 2
foreach_instance +A +B add_servald_interface 1
foreach_instance +A +B start_routing_instance
foreach_instance +A +B start_servald_server
}
test_multiple_ids() {
wait_until path_exists +A +B
wait_until has_link +A +B +B $SIDB1 $SIDB2
set_instance +A
wait_until has_link --via $SIDB1 $SIDB2
wait_until path_exists +B +A
wait_until has_link +B +A +A $SIDA1 $SIDA2
set_instance +B
wait_until has_link --via $SIDA1 $SIDA2
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDB2 1
tfw_cat --stdout --stderr
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDB1:BROADCAST:dummy.*:0*"
assertStdoutGrep --matches=1 "^$SIDB2:INDIRECT::$SIDB1"
link_matches --broadcast $SIDB1
link_matches --via $SIDB1 $SIDB2
set_instance +B
executeOk_servald mdp ping --timeout=3 $SIDA2 1
tfw_cat --stdout --stderr
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDA1:BROADCAST:dummy.*:0*"
assertStdoutGrep --matches=1 "^$SIDA2:INDIRECT::$SIDA1"
link_matches --broadcast $SIDA1
link_matches --via $SIDA1 $SIDA2
}
doc_unlock_ids="Routes appear and disappear as identities are [un]locked"
@ -146,14 +153,15 @@ setup_unlock_ids() {
set_instance +A
executeOk_servald keyring add 'entry-pin'
extract_stdout_keyvalue SIDX sid "$rexp_sid"
foreach_instance +A +B start_routing_instance
foreach_instance +A +B start_servald_server
}
test_unlock_ids() {
wait_until path_exists +A +B
wait_until path_exists +B +A
set_instance +A
executeOk_servald id enter pin 'entry-pin'
wait_until has_link +B +A +A $SIDA $SIDX
set_instance +B
wait_until has_link --via $SIDA $SIDX
set_instance +A
executeOk_servald id relinquish pin 'entry-pin'
set_instance +B
@ -173,17 +181,19 @@ setup_migrate_id() {
executeOk_servald keyring load sidx '' 'entry-pin'
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_servald_interface 1
foreach_instance +A +B start_routing_instance
foreach_instance +A +B start_servald_server
}
test_migrate_id() {
wait_until path_exists +A +B
wait_until path_exists +B +A
set_instance +A
executeOk_servald id enter pin 'entry-pin'
wait_until has_link +B +A +A $SIDA $SIDX
set_instance +B
wait_until has_link --via $SIDA $SIDX
set_instance +B
executeOk_servald id enter pin 'entry-pin'
wait_until --timeout=30 has_link +A +B +B $SIDB $SIDX
set_instance +A
wait_until --timeout=30 has_link --via $SIDB $SIDX
}
doc_single_mdp="Use single MDP per packet encapsulation"
@ -193,7 +203,7 @@ setup_single_mdp() {
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_servald_interface 1
foreach_instance +A +B executeOk_servald config set interfaces.1.encapsulation single
foreach_instance +A +B start_routing_instance
foreach_instance +A +B start_servald_server
}
test_single_mdp() {
wait_until path_exists +A +B
@ -210,7 +220,7 @@ setup_mismatched_encap() {
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_servald_interface 1
foreach_instance +A executeOk_servald config set interfaces.1.encapsulation single
foreach_instance +A +B start_routing_instance
foreach_instance +A +B start_servald_server
}
test_mismatched_encap() {
wait_until path_exists +A +B
@ -230,7 +240,7 @@ setup_single_p2p() {
executeOk_servald config \
set interfaces.1.encapsulation single \
set interfaces.1.point_to_point on
foreach_instance +A +B start_routing_instance
foreach_instance +A +B start_servald_server
}
test_single_p2p() {
wait_until path_exists +A +B
@ -282,7 +292,7 @@ setup_simulate_extender() {
set interfaces.1.socket_type STREAM \
set interfaces.1.encapsulation SINGLE \
set interfaces.1.point_to_point on
foreach_instance +A +B start_routing_instance
foreach_instance +A +B start_servald_server
}
test_simulate_extender() {
wait_until path_exists +A +B
@ -304,7 +314,7 @@ setup_multiple_nodes() {
assert_no_servald_processes
foreach_instance +A +B +C +D create_single_identity
foreach_instance +A +B +C +D add_servald_interface 1
foreach_instance +A +B +C +D start_routing_instance
foreach_instance +A +B +C +D start_servald_server
}
test_multiple_nodes() {
wait_until path_exists +A +B
@ -331,7 +341,9 @@ setup_scan() {
foreach_instance +A +B +C \
executeOk_servald config \
set interfaces.1.drop_broadcasts on
foreach_instance +A +B +C start_routing_instance
foreach_instance +A +B +C start_servald_server
foreach_instance +A +B +C \
wait_until interface_up
}
test_scan() {
set_instance +A
@ -339,14 +351,14 @@ test_scan() {
wait_until scan_completed
wait_until --timeout=10 has_seen_instances +B +C
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDB:UNICAST:"
assertStdoutGrep --matches=1 "^$SIDC:UNICAST:"
link_matches --unicast $SIDB
link_matches --unicast $SIDC
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
set_instance +B
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDA:UNICAST:"
assertStdoutGrep --matches=1 "^$SIDC:INDIRECT:"
link_matches --unicast $SIDA
link_matches --via $SIDA $SIDC
executeOk_servald mdp ping --timeout=3 $SIDC 1
tfw_cat --stdout --stderr
}
@ -361,7 +373,7 @@ test_scan_one() {
wait_until scan_completed
wait_until --timeout=10 has_seen_instances +B
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDB:UNICAST:"
link_matches --unicast $SIDB
assertStdoutGrep --matches=0 "^$SIDC:"
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
@ -381,19 +393,15 @@ setup_single_filter() {
set_instance +B
executeOk_servald config \
set interfaces.1.drop_broadcasts on
foreach_instance +A +B start_routing_instance
foreach_instance +A +B start_servald_server
}
test_single_filter() {
wait_until --timeout=10 path_exists +A +B
wait_until --timeout=5 path_exists +B +A
set_instance +A
wait_until --timeout=10 has_link --unicast $SIDB
set_instance +B
wait_until --timeout=5 has_link --broadcast $SIDA
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDB:UNICAST:"
set_instance +B
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDA:BROADCAST:"
}
doc_broadcast_only="Broadcast packets only"
@ -404,16 +412,16 @@ setup_broadcast_only() {
foreach_instance +A +B add_servald_interface --file 1
foreach_instance +A +B \
executeOk_servald config set interfaces.1.drop_unicasts 1
foreach_instance +A +B start_routing_instance
foreach_instance +A +B start_servald_server
}
test_broadcast_only() {
wait_until path_exists +A +B
wait_until path_exists +B +A
set_instance +A
wait_until has_link --broadcast $SIDB
set_instance +B
wait_until has_link --broadcast $SIDA
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDB:BROADCAST:"
}
doc_prefer_unicast="Prefer unicast packets"
@ -426,16 +434,18 @@ setup_prefer_unicast() {
executeOk_servald config \
set interfaces.1.prefer_unicast 1 \
set debug.overlayframes 1
foreach_instance +A +B start_routing_instance
foreach_instance +A +B start_servald_server
}
test_prefer_unicast() {
set_instance +A
wait_until has_link --unicast $SIDB
set_instance +B
wait_until has_link --unicast $SIDA
wait_until path_exists +A +B
wait_until path_exists +B +A
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDB:UNICAST:"
}
doc_multihop_linear="Start 4 instances in a linear arrangement"
@ -446,7 +456,7 @@ setup_multihop_linear() {
foreach_instance +A +B add_servald_interface 1
foreach_instance +B +C add_servald_interface 2
foreach_instance +C +D add_servald_interface 3
foreach_instance +A +B +C +D start_routing_instance
foreach_instance +A +B +C +D start_servald_server
}
test_multihop_linear() {
wait_until path_exists +A +B +C +D
@ -479,7 +489,7 @@ setup_unicast_route() {
executeOk_servald config \
set interfaces.2.drop_broadcasts on \
set interfaces.3.drop_broadcasts on
foreach_instance +A +B +C +D start_routing_instance
foreach_instance +A +B +C +D start_servald_server
}
test_unicast_route() {
wait_until --timeout=20 path_exists +A +B +C +D
@ -495,7 +505,7 @@ setup_offline() {
foreach_instance +A +B +C +D create_single_identity
foreach_instance +A +B +C add_servald_interface 1
foreach_instance +A +B +D add_servald_interface 2
foreach_instance +A +B +C +D start_routing_instance
foreach_instance +A +B +C +D start_servald_server
}
sid_offline() {
@ -534,7 +544,7 @@ setup_lose_neighbours() {
foreach_instance +A +B +C create_single_identity
foreach_instance +A +B add_servald_interface 1
foreach_instance +B +C add_servald_interface 2
foreach_instance +A +B +C start_routing_instance
foreach_instance +A +B +C start_servald_server
}
test_lose_neighbours() {
wait_until path_exists +A +B +C
@ -555,25 +565,25 @@ setup_multi_interface() {
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_servald_interface --wifi 1
foreach_instance +A +B add_servald_interface --ethernet 2
foreach_instance +A +B start_routing_instance
foreach_instance +A +B start_servald_server
}
doc_multi_interface="Multiple links of different types to the same neighbour"
test_multi_interface() {
set_instance +A
wait_until has_link "dummy2.*" +A +B +B $SIDB $SIDB
wait_until has_link --interface "dummy2.*" $SIDB
set_instance +B
wait_until has_link "dummy2.*" +B +A +A $SIDA $SIDA
wait_until has_link --interface "dummy2.*" $SIDA
set_instance +A
executeOk_servald config set interfaces.2.exclude 1
wait_until has_link "dummy1.*" +A +B +B $SIDB $SIDB
wait_until has_link --interface "dummy1.*" $SIDB
set_instance +B
wait_until has_link "dummy1.*" +B +A +A $SIDA $SIDA
wait_until has_link --interface "dummy1.*" $SIDA
set_instance +A
executeOk_servald config del interfaces.2.exclude
wait_until has_link "dummy2.*" +A +B +B $SIDB $SIDB
wait_until has_link --interface "dummy2.*" $SIDB
set_instance +B
wait_until has_link "dummy2.*" +B +A +A $SIDA $SIDA
wait_until has_link --interface "dummy2.*" $SIDA
}
# TODO assert that all packets arrive? assert that no duplicates arrive?
@ -586,7 +596,7 @@ setup_ping_unreliable() {
foreach_instance +A +B \
executeOk_servald config \
set interfaces.1.drop_packets 40
foreach_instance +A +B start_routing_instance
foreach_instance +A +B start_servald_server
}
test_ping_unreliable() {
wait_until path_exists +A +B
@ -609,7 +619,7 @@ setup_ping_unreliable2() {
foreach_instance +B +C \
executeOk_servald config \
set interfaces.2.drop_packets 40
foreach_instance +A +B +C start_routing_instance
foreach_instance +A +B +C start_servald_server
}
test_ping_unreliable2() {
wait_until path_exists +A +B +C
@ -628,7 +638,7 @@ setup_brping_unreliable() {
foreach_instance +A +B \
executeOk_servald config \
set interfaces.1.drop_packets 20
foreach_instance +A +B start_routing_instance
foreach_instance +A +B start_servald_server
}
test_brping_unreliable() {
wait_until path_exists +A +B
@ -658,7 +668,7 @@ setup_unreliable_links() {
executeOk_servald config \
set interfaces.2.drop_packets 5 \
set interfaces.3.drop_packets 70
foreach_instance +A +B +C start_routing_instance
foreach_instance +A +B +C start_servald_server
}
test_unreliable_links() {
wait_until path_exists +A +B +C
@ -701,7 +711,7 @@ setup_unreliable_links2() {
set interfaces.3.drop_packets 90 \
set interfaces.5.drop_packets 40 \
set interfaces.6.drop_packets 5
foreach_instance +A +B +C +D start_routing_instance
foreach_instance +A +B +C +D start_servald_server
}
test_unreliable_links2() {
wait_until path_exists +A +B +C +D
@ -723,7 +733,7 @@ setup_circle() {
foreach_instance +F +G add_servald_interface 6
foreach_instance +G +H add_servald_interface 7
foreach_instance +H +A add_servald_interface 8
foreach_instance +A +B +C +D +E +F +G +H start_routing_instance
foreach_instance +A +B +C +D +E +F +G +H start_servald_server
}
doc_circle="Circle of nodes with one going offline"
@ -735,8 +745,6 @@ test_circle() {
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDC 1
tfw_cat --stdout --stderr
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDC:INDIRECT:"
stop_servald_server +B
foreach_instance +A +C \
wait_until --timeout=10 instance_offline +B
@ -745,8 +753,6 @@ test_circle() {
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDC 1
tfw_cat --stdout --stderr
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDC:INDIRECT:"
}
setup_crowded_mess() {
@ -764,16 +770,15 @@ setup_crowded_mess() {
foreach_instance +A +B +C +D +E +F +G +H \
executeOk_servald config \
set mdp.iftype.wifi.reachable_timeout_ms 60000
foreach_instance +A +B +C +D +E +F +G +H start_routing_instance
foreach_instance +A +B +C +D +E +F +G +H start_servald_server
}
doc_crowded_mess="Multiple possible paths"
test_crowded_mess() {
foreach_instance +A +H \
wait_until has_seen_instances +A +H
set_instance +H
wait_until has_link --via "[0-9A-F]*" $SIDA
set_instance +A
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDH:INDIRECT:"
wait_until has_link --via "[0-9A-F]*" $SIDH
executeOk_servald mdp ping --timeout=3 $SIDH 1
tfw_cat --stdout --stderr
}

View File

@ -26,17 +26,17 @@ setup() {
assert_no_servald_processes
}
setup_interfaces() {
>$TFWTMP/dummy
executeOk_servald config set interfaces "+>$TFWTMP/dummy"
}
teardown() {
get_servald_server_pidfile && stop_servald_server
kill_all_servald_processes
assert_no_servald_processes
}
# make sure servald config is blank
configure_servald_server() {
:
}
doc_StartCreateInstanceDir="Starting server creates instance directory"
setup_StartCreateInstanceDir() {
setup
@ -53,10 +53,8 @@ setup_StartLogfile() {
executeOk_servald config set log.file.directory_path "$PWD/log"
}
test_StartLogfile() {
executeOk_servald start
sleep 0.1
assert [ -s log/*.log ]
tfw_cat log/*.log
start_servald_server
assert_servald_server_no_errors
}
doc_StartNoInterfaces="Starting server with no configured interfaces gives warning"
@ -70,14 +68,26 @@ test_StartNoInterfaces() {
tfw_cat "$instance_servald_log"
}
doc_StartNoErrors="Starting server on dummy interface gives no errors"
doc_StartNoErrors="Starting server on dummy file interface gives no errors"
setup_StartNoErrors() {
setup
setup_interfaces
add_servald_interface --file
}
test_StartNoErrors() {
start_servald_server
sleep 0.1
wait_until grep "Interface .* is up" $instance_servald_log
assert_servald_server_no_errors
tfw_cat "$instance_servald_log"
}
doc_StartLocalNoErrors="Starting server on local interface gives no errors"
setup_StartLocalNoErrors() {
setup
add_servald_interface
}
test_StartLocalNoErrors() {
start_servald_server
wait_until grep "Interface .* is up" $instance_servald_log
assert_servald_server_no_errors
tfw_cat "$instance_servald_log"
}
@ -85,7 +95,6 @@ test_StartNoErrors() {
doc_StartStart="Start server while already running"
setup_StartStart() {
setup
setup_interfaces
start_servald_server
}
test_StartStart() {
@ -99,7 +108,6 @@ test_StartStart() {
doc_StartStopFast="Stop server before it finishes starting"
setup_StartStopFast() {
setup
setup_interfaces
export SERVALD_SERVER_START_DELAY=250
}
test_StartStopFast() {
@ -110,7 +118,6 @@ test_StartStopFast() {
doc_NoZombie="Server process does not become a zombie"
setup_NoZombie() {
setup
setup_interfaces
export SERVALD_START_POST_SLEEP=1000
servald_start &
start_pid=$!