summaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-10-15 21:02:03 +0200
committert3sserakt <t3ss@posteo.de>2021-10-15 21:02:03 +0200
commit513f23e74650db9408267e82ef8bcb8f770d1015 (patch)
tree312db7072dc444e9d1e6a13000b79482eb14de82 /src/testing
parentd190d23831dae1a77075557f2ff6e0c713d747d5 (diff)
parentd64ac269856744b9bab170964e1d6f36896ecc55 (diff)
Merge branch 'master' into dev/t3ss/tng
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/Makefile.am19
-rwxr-xr-xsrc/testing/netjail_core.sh190
-rwxr-xr-xsrc/testing/netjail_core_v2.sh260
-rwxr-xr-xsrc/testing/netjail_exec.sh6
-rwxr-xr-xsrc/testing/netjail_exec_v2.sh14
-rwxr-xr-xsrc/testing/netjail_start.sh70
-rwxr-xr-xsrc/testing/netjail_start_v2.sh74
-rwxr-xr-xsrc/testing/netjail_stop.sh49
-rwxr-xr-xsrc/testing/netjail_stop_v2.sh59
-rw-r--r--src/testing/test_testing_plugin_testcmd.c19
-rw-r--r--src/testing/testing.c26
-rw-r--r--src/testing/testing.h94
-rw-r--r--src/testing/testing_api_cmd_batch.c86
-rw-r--r--src/testing/testing_api_cmd_block_until_all_peers_started.c66
-rw-r--r--src/testing/testing_api_cmd_block_until_external_trigger.c116
-rw-r--r--src/testing/testing_api_cmd_end.c39
-rw-r--r--src/testing/testing_api_cmd_finish.c198
-rw-r--r--src/testing/testing_api_cmd_hello_world.c65
-rw-r--r--src/testing/testing_api_cmd_hello_world_birth.c10
-rw-r--r--src/testing/testing_api_cmd_local_test_finished.c67
-rw-r--r--src/testing/testing_api_cmd_netjail_start.c148
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem.c319
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem_v2.c809
-rw-r--r--src/testing/testing_api_cmd_netjail_start_v2.c229
-rw-r--r--src/testing/testing_api_cmd_netjail_stop.c116
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_testsystem.c58
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c163
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_v2.c225
-rw-r--r--src/testing/testing_api_cmd_send_peer_ready.c29
-rw-r--r--src/testing/testing_api_cmd_system_create.c4
-rw-r--r--src/testing/testing_api_cmd_system_destroy.c33
-rw-r--r--src/testing/testing_api_loop.c629
-rw-r--r--src/testing/testing_api_trait_cmd.c2
-rw-r--r--src/testing/testing_api_traits.c2
-rw-r--r--src/testing/testing_cmds.h2
35 files changed, 1369 insertions, 2926 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 07caeb44e..3daa29e1e 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -42,20 +42,19 @@ libgnunet_test_testing_plugin_testcmd_la_LIBADD = \
libgnunet_test_testing_plugin_testcmd_la_LDFLAGS = \
$(GN_PLUGIN_LDFLAGS)
+
libgnunettesting_la_SOURCES = \
+ testing_api_cmd_end.c \
+ testing_api_cmd_finish.c \
testing_api_cmd_local_test_finished.c \
testing_api_cmd_local_test_prepared.c \
testing_api_cmd_send_peer_ready.c \
testing_api_cmd_block_until_all_peers_started.c \
testing_api_cmd_block_until_external_trigger.c \
testing_api_cmd_netjail_start.c \
- testing_api_cmd_netjail_start_v2.c \
testing_api_cmd_netjail_start_testsystem.c \
- testing_api_cmd_netjail_start_testsystem_v2.c \
testing_api_cmd_netjail_stop_testsystem.c \
- testing_api_cmd_netjail_stop_testsystem_v2.c \
testing_api_cmd_netjail_stop.c \
- testing_api_cmd_netjail_stop_v2.c \
testing.c testing.h \
testing_api_cmd_system_create.c \
testing_api_cmd_system_destroy.c \
@@ -95,7 +94,6 @@ list_keys_LDADD = \
check_PROGRAMS = \
- test_testing_topology \
test_testing_api_cmd_netjail \
test_testing_hello_world \
test_testing_portreservation \
@@ -107,7 +105,6 @@ check_PROGRAMS = \
if ENABLE_TEST_RUN
AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
TESTS = \
- test_testing_topology \
test_testing_api_cmd_netjail \
test_testing_hello_world \
test_testing_portreservation \
@@ -116,11 +113,11 @@ TESTS = \
test_testing_servicestartup
endif
-test_testing_topology_SOURCES = \
- test_testing_topology.c
-test_testing_topology_LDADD = \
- libgnunettesting.la \
- $(top_builddir)/src/util/libgnunetutil.la
+#test_testing_topology_SOURCES = \
+# test_testing_topology.c
+#test_testing_topology_LDADD = \
+# libgnunettesting.la \
+# $(top_builddir)/src/util/libgnunetutil.la
test_testing_api_cmd_netjail_SOURCES = \
test_testing_api_cmd_netjail.c
diff --git a/src/testing/netjail_core.sh b/src/testing/netjail_core.sh
index cf350d3fa..ef0a54a5e 100755
--- a/src/testing/netjail_core.sh
+++ b/src/testing/netjail_core.sh
@@ -2,6 +2,7 @@
#
+PREFIX=${PPID:?must run from a parent process}
# running with `sudo` is required to be
# able running the actual commands as the
@@ -9,10 +10,61 @@
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
-netjail_check() {
- NODE_COUNT=$1
+export RESULT=
+export NAMESPACE_NUM=0
+export INTERFACE_NUM=0
+
+netjail_next_namespace() {
+ local NUM=$NAMESPACE_NUM
+ NAMESPACE_NUM=$(($NAMESPACE_NUM + 1))
+ RESULT=$NUM
+}
+
+netjail_next_interface() {
+ local NUM=$INTERFACE_NUM
+ INTERFACE_NUM=$(($INTERFACE_NUM + 1))
+ RESULT=$NUM
+}
+
+netjail_opt() {
+ local OPT=$1
+ shift 1
+
+ INDEX=1
+
+ while [ $# -gt 0 ]; do
+ if [ "$1" = "$OPT" ]; then
+ RESULT=$INDEX
+ return
+ fi
+
+ INDEX=$(($INDEX + 1))
+ shift 1
+ done
+
+ RESULT=0
+}
+
+netjail_opts() {
+ local OPT=$1
+ local DEF=$2
+ shift 2
+
+ while [ $# -gt 0 ]; do
+ if [ "$1" = "$OPT" ]; then
+ printf "$2"
+ return
+ fi
+
+ shift 1
+ done
+
+ RESULT="$DEF"
+}
- FD_COUNT=$(($(ls /proc/self/fd | wc -w) - 4))
+netjail_check() {
+ local NODE_COUNT=$1
+ local FD_COUNT=$(($(ls /proc/self/fd | wc -w) - 4))
# quit if `$FD_COUNT < ($LOCAL_M * $GLOBAL_N * 2)`:
# the script also requires `sudo -C ($FD_COUNT + 4)`
@@ -25,43 +77,81 @@ netjail_check() {
fi
}
-netjail_print_name() {
- printf "%s%02x%02x" $1 $2 ${3:-0}
+netjail_check_bin() {
+ local PROGRAM=$1
+ local MATCH=$(ls $(echo $PATH | tr ":" "\n") | grep "^$PROGRAM\$" | tr "\n" " " | awk '{ print $1 }')
+
+ # quit if the required binary $PROGRAM can not be
+ # found in the used $PATH.
+
+ if [ "$MATCH" != "$PROGRAM" ]; then
+ echo "Required binary not found: $PROGRAM" >&2
+ exit 1
+ fi
}
netjail_bridge() {
- BRIDGE=$1
+ netjail_next_interface
+ local NUM=$RESULT
+ local BRIDGE=$(printf "%06x-%08x" $PREFIX $NUM)
ip link add $BRIDGE type bridge
ip link set dev $BRIDGE up
+
+ RESULT=$BRIDGE
+}
+
+netjail_bridge_name() {
+ netjail_next_interface
+ local NUM=$RESULT
+ local BRIDGE=$(printf "%06x-%08x" $PREFIX $NUM)
+
+ RESULT=$BRIDGE
}
netjail_bridge_clear() {
- BRIDGE=$1
+ local BRIDGE=$1
ip link delete $BRIDGE
}
netjail_node() {
- NODE=$1
+ netjail_next_namespace
+ local NUM=$RESULT
+ local NODE=$(printf "%06x-%08x" $PREFIX $NUM)
ip netns add $NODE
+
+ RESULT=$NODE
+}
+
+netjail_node_name() {
+ netjail_next_namespace
+ local NUM=$RESULT
+ local NODE=$(printf "%06x-%08x" $PREFIX $NUM)
+
+ RESULT=$NODE
}
netjail_node_clear() {
- NODE=$1
+ local NODE=$1
ip netns delete $NODE
}
netjail_node_link_bridge() {
- NODE=$1
- BRIDGE=$2
- ADDRESS=$3
- MASK=$4
+ local NODE=$1
+ local BRIDGE=$2
+ local ADDRESS=$3
+ local MASK=$4
- LINK_IF="$NODE-$BRIDGE-0"
- LINK_BR="$NODE-$BRIDGE-1"
+ netjail_next_interface
+ local NUM_IF=$RESULT
+ netjail_next_interface
+ local NUM_BR=$RESULT
+
+ local LINK_IF=$(printf "%06x-%08x" $PREFIX $NUM_IF)
+ local LINK_BR=$(printf "%06x-%08x" $PREFIX $NUM_BR)
ip link add $LINK_IF type veth peer name $LINK_BR
ip link set $LINK_IF netns $NODE
@@ -72,28 +162,47 @@ netjail_node_link_bridge() {
ip -n $NODE link set up dev lo
ip link set $LINK_BR up
+
+ RESULT=$LINK_BR
+}
+
+netjail_node_link_bridge_name() {
+
+ netjail_next_interface
+ netjail_next_interface
+ local NUM_BR=$RESULT
+
+ local LINK_BR=$(printf "%06x-%08x" $PREFIX $NUM_BR)
+
+ RESULT=$LINK_BR
+}
+
+netjail_node_unlink_bridge() {
+ local LINK_BR=$1
+
+ ip link delete $LINK_BR
}
netjail_node_add_nat() {
- NODE=$1
- ADDRESS=$2
- MASK=$3
+ local NODE=$1
+ local ADDRESS=$2
+ local MASK=$3
ip netns exec $NODE iptables -t nat -A POSTROUTING -s "$ADDRESS/$MASK" -j MASQUERADE
}
netjail_node_add_default() {
- NODE=$1
- ADDRESS=$2
+ local NODE=$1
+ local ADDRESS=$2
ip -n $NODE route add default via $ADDRESS
}
netjail_node_exec() {
JAILOR=${SUDO_USER:?must run in sudo}
- NODE=$1
- FD_IN=$2
- FD_OUT=$3
+ local NODE=$1
+ local FD_IN=$2
+ local FD_OUT=$3
shift 3
ip netns exec $NODE sudo -u $JAILOR -- $@ 1>& $FD_OUT 0<& $FD_IN
@@ -114,3 +223,38 @@ netjail_node_exec_without_fds_and_sudo() {
ip netns exec $NODE $@
}
+netjail_kill() {
+ local PID=$1
+ local MATCH=$(ps --pid $PID | awk "{ if ( \$1 == $PID ) { print \$1 } }" | wc -l)
+
+ if [ $MATCH -gt 0 ]; then
+ kill -n 19 $PID
+
+ for CHILD in $(ps -o pid,ppid -ax | awk "{ if ( \$2 == $PID ) { print \$1 } }"); do
+ netjail_kill $CHILD
+ done
+
+ kill $PID
+ fi
+}
+
+netjail_killall() {
+ if [ $# -gt 0 ]; then
+ local PIDS=$1
+
+ for PID in $PIDS; do
+ netjail_kill $PID
+ done
+ fi
+}
+
+netjail_waitall() {
+ if [ $# -gt 0 ]; then
+ local PIDS=$1
+
+ for PID in $PIDS; do
+ wait $PID
+ done
+ fi
+}
+
diff --git a/src/testing/netjail_core_v2.sh b/src/testing/netjail_core_v2.sh
deleted file mode 100755
index ef0a54a5e..000000000
--- a/src/testing/netjail_core_v2.sh
+++ /dev/null
@@ -1,260 +0,0 @@
-#!/bin/sh
-#
-
-
-PREFIX=${PPID:?must run from a parent process}
-
-# running with `sudo` is required to be
-# able running the actual commands as the
-# original user.
-
-export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
-
-export RESULT=
-export NAMESPACE_NUM=0
-export INTERFACE_NUM=0
-
-netjail_next_namespace() {
- local NUM=$NAMESPACE_NUM
- NAMESPACE_NUM=$(($NAMESPACE_NUM + 1))
- RESULT=$NUM
-}
-
-netjail_next_interface() {
- local NUM=$INTERFACE_NUM
- INTERFACE_NUM=$(($INTERFACE_NUM + 1))
- RESULT=$NUM
-}
-
-netjail_opt() {
- local OPT=$1
- shift 1
-
- INDEX=1
-
- while [ $# -gt 0 ]; do
- if [ "$1" = "$OPT" ]; then
- RESULT=$INDEX
- return
- fi
-
- INDEX=$(($INDEX + 1))
- shift 1
- done
-
- RESULT=0
-}
-
-netjail_opts() {
- local OPT=$1
- local DEF=$2
- shift 2
-
- while [ $# -gt 0 ]; do
- if [ "$1" = "$OPT" ]; then
- printf "$2"
- return
- fi
-
- shift 1
- done
-
- RESULT="$DEF"
-}
-
-netjail_check() {
- local NODE_COUNT=$1
- local FD_COUNT=$(($(ls /proc/self/fd | wc -w) - 4))
-
- # quit if `$FD_COUNT < ($LOCAL_M * $GLOBAL_N * 2)`:
- # the script also requires `sudo -C ($FD_COUNT + 4)`
- # so you need 'Defaults closefrom_override' in the
- # sudoers file.
-
- if [ $FD_COUNT -lt $(($NODE_COUNT * 2)) ]; then
- echo "File descriptors do not match requirements!" >&2
- exit 1
- fi
-}
-
-netjail_check_bin() {
- local PROGRAM=$1
- local MATCH=$(ls $(echo $PATH | tr ":" "\n") | grep "^$PROGRAM\$" | tr "\n" " " | awk '{ print $1 }')
-
- # quit if the required binary $PROGRAM can not be
- # found in the used $PATH.
-
- if [ "$MATCH" != "$PROGRAM" ]; then
- echo "Required binary not found: $PROGRAM" >&2
- exit 1
- fi
-}
-
-netjail_bridge() {
- netjail_next_interface
- local NUM=$RESULT
- local BRIDGE=$(printf "%06x-%08x" $PREFIX $NUM)
-
- ip link add $BRIDGE type bridge
- ip link set dev $BRIDGE up
-
- RESULT=$BRIDGE
-}
-
-netjail_bridge_name() {
- netjail_next_interface
- local NUM=$RESULT
- local BRIDGE=$(printf "%06x-%08x" $PREFIX $NUM)
-
- RESULT=$BRIDGE
-}
-
-netjail_bridge_clear() {
- local BRIDGE=$1
-
- ip link delete $BRIDGE
-}
-
-netjail_node() {
- netjail_next_namespace
- local NUM=$RESULT
- local NODE=$(printf "%06x-%08x" $PREFIX $NUM)
-
- ip netns add $NODE
-
- RESULT=$NODE
-}
-
-netjail_node_name() {
- netjail_next_namespace
- local NUM=$RESULT
- local NODE=$(printf "%06x-%08x" $PREFIX $NUM)
-
- RESULT=$NODE
-}
-
-netjail_node_clear() {
- local NODE=$1
-
- ip netns delete $NODE
-}
-
-netjail_node_link_bridge() {
- local NODE=$1
- local BRIDGE=$2
- local ADDRESS=$3
- local MASK=$4
-
- netjail_next_interface
- local NUM_IF=$RESULT
- netjail_next_interface
- local NUM_BR=$RESULT
-
- local LINK_IF=$(printf "%06x-%08x" $PREFIX $NUM_IF)
- local LINK_BR=$(printf "%06x-%08x" $PREFIX $NUM_BR)
-
- ip link add $LINK_IF type veth peer name $LINK_BR
- ip link set $LINK_IF netns $NODE
- ip link set $LINK_BR master $BRIDGE
-
- ip -n $NODE addr add "$ADDRESS/$MASK" dev $LINK_IF
- ip -n $NODE link set $LINK_IF up
- ip -n $NODE link set up dev lo
-
- ip link set $LINK_BR up
-
- RESULT=$LINK_BR
-}
-
-netjail_node_link_bridge_name() {
-
- netjail_next_interface
- netjail_next_interface
- local NUM_BR=$RESULT
-
- local LINK_BR=$(printf "%06x-%08x" $PREFIX $NUM_BR)
-
- RESULT=$LINK_BR
-}
-
-netjail_node_unlink_bridge() {
- local LINK_BR=$1
-
- ip link delete $LINK_BR
-}
-
-netjail_node_add_nat() {
- local NODE=$1
- local ADDRESS=$2
- local MASK=$3
-
- ip netns exec $NODE iptables -t nat -A POSTROUTING -s "$ADDRESS/$MASK" -j MASQUERADE
-}
-
-netjail_node_add_default() {
- local NODE=$1
- local ADDRESS=$2
-
- ip -n $NODE route add default via $ADDRESS
-}
-
-netjail_node_exec() {
- JAILOR=${SUDO_USER:?must run in sudo}
- local NODE=$1
- local FD_IN=$2
- local FD_OUT=$3
- shift 3
-
- ip netns exec $NODE sudo -u $JAILOR -- $@ 1>& $FD_OUT 0<& $FD_IN
-}
-
-netjail_node_exec_without_fds() {
- JAILOR=${SUDO_USER:?must run in sudo}
- NODE=$1
- shift 1
-
- ip netns exec $NODE sudo -u $JAILOR -- $@
-}
-
-netjail_node_exec_without_fds_and_sudo() {
- NODE=$1
- shift 1
-
- ip netns exec $NODE $@
-}
-
-netjail_kill() {
- local PID=$1
- local MATCH=$(ps --pid $PID | awk "{ if ( \$1 == $PID ) { print \$1 } }" | wc -l)
-
- if [ $MATCH -gt 0 ]; then
- kill -n 19 $PID
-
- for CHILD in $(ps -o pid,ppid -ax | awk "{ if ( \$2 == $PID ) { print \$1 } }"); do
- netjail_kill $CHILD
- done
-
- kill $PID
- fi
-}
-
-netjail_killall() {
- if [ $# -gt 0 ]; then
- local PIDS=$1
-
- for PID in $PIDS; do
- netjail_kill $PID
- done
- fi
-}
-
-netjail_waitall() {
- if [ $# -gt 0 ]; then
- local PIDS=$1
-
- for PID in $PIDS; do
- wait $PID
- done
- fi
-}
-
diff --git a/src/testing/netjail_exec.sh b/src/testing/netjail_exec.sh
index 17a7caaac..cd993a39b 100755
--- a/src/testing/netjail_exec.sh
+++ b/src/testing/netjail_exec.sh
@@ -9,8 +9,6 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
M=$1
N=$2
-NODE=$(netjail_print_name "N" $N $M)
+NODE=$6
-
-
-netjail_node_exec_without_fds_and_sudo $NODE $3 $4 $5 $1 $2
+netjail_node_exec_without_fds_and_sudo $NODE $3 $4 $5 $1 $2
diff --git a/src/testing/netjail_exec_v2.sh b/src/testing/netjail_exec_v2.sh
deleted file mode 100755
index 597baad20..000000000
--- a/src/testing/netjail_exec_v2.sh
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/sh
-. "./../testing/netjail_core_v2.sh"
-
-set -eu
-set -x
-
-export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
-
-M=$1
-N=$2
-
-NODE=$6
-
-netjail_node_exec_without_fds_and_sudo $NODE $3 $4 $5 $1 $2
diff --git a/src/testing/netjail_start.sh b/src/testing/netjail_start.sh
index 0984a3c42..1dfe1dfdf 100755
--- a/src/testing/netjail_start.sh
+++ b/src/testing/netjail_start.sh
@@ -1,52 +1,74 @@
-#!/bin/sh
+#!/bin/bash
. "./../testing/netjail_core.sh"
+. "./../testing/topo.sh"
set -eu
set -x
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
-LOCAL_M=$1
-GLOBAL_N=$2
+filename=$1
+PREFIX=$2
-# TODO: stunserver? ..and globally known peer?
+read_topology $filename
shift 2
LOCAL_GROUP="192.168.15"
GLOBAL_GROUP="92.68.150"
+KNOWN_GROUP="92.68.151"
-NETWORK_NET=$(netjail_print_name "n" $GLOBAL_N $LOCAL_M)
-netjail_bridge $NETWORK_NET
+echo "Start [local: $LOCAL_GROUP.0/24, global: $GLOBAL_GROUP.0/16]"
-for N in $(seq $GLOBAL_N); do
- ROUTER=$(netjail_print_name "R" $N)
+netjail_bridge
+NETWORK_NET=$RESULT
- netjail_node $ROUTER
- netjail_node_link_bridge $ROUTER $NETWORK_NET "$GLOBAL_GROUP.$N" 24
+for X in $(seq $KNOWN); do
+ netjail_node
+ KNOWN_NODES[$X]=$RESULT
+ netjail_node_link_bridge ${KNOWN_NODES[$X]} $NETWORK_NET "$KNOWN_GROUP.$X" 16
+ KNOWN_LINKS[$X]=$RESULT
+done
- ROUTER_NET=$(netjail_print_name "r" $N)
+declare -A NODES
+declare -A NODE_LINKS
- netjail_bridge $ROUTER_NET
+for N in $(seq $GLOBAL_N); do
+ netjail_node
+ ROUTERS[$N]=$RESULT
+ netjail_node_link_bridge ${ROUTERS[$N]} $NETWORK_NET "$GLOBAL_GROUP.$N" 16
+ NETWORK_LINKS[$N]=$RESULT
+ netjail_bridge
+ ROUTER_NETS[$N]=$RESULT
for M in $(seq $LOCAL_M); do
- NODE=$(netjail_print_name "N" $N $M)
-
- netjail_node $NODE
- netjail_node_link_bridge $NODE $ROUTER_NET "$LOCAL_GROUP.$M" 24
+ netjail_node
+ NODES[$N,$M]=$RESULT
+ netjail_node_link_bridge ${NODES[$N,$M]} ${ROUTER_NETS[$N]} "$LOCAL_GROUP.$M" 24
+ NODE_LINKS[$N,$M]=$RESULT
done
ROUTER_ADDR="$LOCAL_GROUP.$(($LOCAL_M+1))"
-
- netjail_node_link_bridge $ROUTER $ROUTER_NET $ROUTER_ADDR 24
- netjail_node_add_nat $ROUTER $ROUTER_ADDR 24
+ netjail_node_link_bridge ${ROUTERS[$N]} ${ROUTER_NETS[$N]} $ROUTER_ADDR 24
+ ROUTER_LINKS[$N]=$RESULT
+
+ netjail_node_add_nat ${ROUTERS[$N]} $ROUTER_ADDR 24
for M in $(seq $LOCAL_M); do
- NODE=$(netjail_print_name "N" $N $M)
-
- netjail_node_add_default $NODE $ROUTER_ADDR
+ netjail_node_add_default ${NODES[$N,$M]} $ROUTER_ADDR
done
-done
-
+ # TODO Topology configuration must be enhanced to configure forwarding to more than one subnet node via different ports.
+
+ if [ "1" == "${R_TCP[$N]}" ]
+ then
+ ip netns exec ${ROUTERS[$N]} iptables -t nat -A PREROUTING -p tcp -d $GLOBAL_GROUP.$N --dport 60002 -j DNAT --to $LOCAL_GROUP.1
+ ip netns exec ${ROUTERS[$N]} iptables -A FORWARD -d $LOCAL_GROUP.1 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
+ fi
+ if [ "1" == "${R_UDP[$N]}" ]
+ then
+ ip netns exec ${ROUTERS[$N]} iptables -t nat -A PREROUTING -p udp -d $GLOBAL_GROUP.$N --dport 60002 -j DNAT --to $LOCAL_GROUP.1
+ ip netns exec ${ROUTERS[$N]} iptables -A FORWARD -d $LOCAL_GROUP.1 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
+ fi
+done
diff --git a/src/testing/netjail_start_v2.sh b/src/testing/netjail_start_v2.sh
deleted file mode 100755
index 81196d53d..000000000
--- a/src/testing/netjail_start_v2.sh
+++ /dev/null
@@ -1,74 +0,0 @@
-#!/bin/bash
-. "./../testing/netjail_core_v2.sh"
-. "./../testing/topo.sh"
-
-set -eu
-set -x
-
-export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
-
-filename=$1
-PREFIX=$2
-
-read_topology $filename
-
-shift 2
-
-LOCAL_GROUP="192.168.15"
-GLOBAL_GROUP="92.68.150"
-KNOWN_GROUP="92.68.151"
-
-
-echo "Start [local: $LOCAL_GROUP.0/24, global: $GLOBAL_GROUP.0/16]"
-
-netjail_bridge
-NETWORK_NET=$RESULT
-
-for X in $(seq $KNOWN); do
- netjail_node
- KNOWN_NODES[$X]=$RESULT
- netjail_node_link_bridge ${KNOWN_NODES[$X]} $NETWORK_NET "$KNOWN_GROUP.$X" 16
- KNOWN_LINKS[$X]=$RESULT
-done
-
-declare -A NODES
-declare -A NODE_LINKS
-
-for N in $(seq $GLOBAL_N); do
- netjail_node
- ROUTERS[$N]=$RESULT
- netjail_node_link_bridge ${ROUTERS[$N]} $NETWORK_NET "$GLOBAL_GROUP.$N" 16
- NETWORK_LINKS[$N]=$RESULT
- netjail_bridge
- ROUTER_NETS[$N]=$RESULT
-
- for M in $(seq $LOCAL_M); do
- netjail_node
- NODES[$N,$M]=$RESULT
- netjail_node_link_bridge ${NODES[$N,$M]} ${ROUTER_NETS[$N]} "$LOCAL_GROUP.$M" 24
- NODE_LINKS[$N,$M]=$RESULT
- done
-
- ROUTER_ADDR="$LOCAL_GROUP.$(($LOCAL_M+1))"
- netjail_node_link_bridge ${ROUTERS[$N]} ${ROUTER_NETS[$N]} $ROUTER_ADDR 24
- ROUTER_LINKS[$N]=$RESULT
-
- netjail_node_add_nat ${ROUTERS[$N]} $ROUTER_ADDR 24
-
- for M in $(seq $LOCAL_M); do
- netjail_node_add_default ${NODES[$N,$M]} $ROUTER_ADDR
- done
-
- # TODO Topology configuration must be enhanced to configure forwarding to more than one subnet node via different ports.
-
- if [ -z "${R_TCP[$N]}" -a "1" == "${R_TCP[$N]}" ]
- then
- ip netns exec ${ROUTERS[$N]} iptables -t nat -A PREROUTING -p tcp -d $GLOBAL_GROUP.$N --dport 60002 -j DNAT --to $LOCAL_GROUP.1
- ip netns exec ${ROUTERS[$N]} iptables -A FORWARD -d $LOCAL_GROUP.1 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
- fi
- if [ -z "${R_UDP[$N]}" -a "1" == "${R_UDP[$N]}" ]
- then
- ip netns exec ${ROUTERS[$N]} iptables -t nat -A PREROUTING -p udp -d $GLOBAL_GROUP.$N --dport 60002 -j DNAT --to $LOCAL_GROUP.1
- ip netns exec ${ROUTERS[$N]} iptables -A FORWARD -d $LOCAL_GROUP.1 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
- fi
-done
diff --git a/src/testing/netjail_stop.sh b/src/testing/netjail_stop.sh
index 08f68cf7f..abfaf3acf 100755
--- a/src/testing/netjail_stop.sh
+++ b/src/testing/netjail_stop.sh
@@ -1,24 +1,57 @@
-#!/bin/sh
+#!/bin/bash
. "./../testing/netjail_core.sh"
+. "./../testing/topo.sh"
set -eu
set -x
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
-LOCAL_M=$1
-GLOBAL_N=$2
-NETWORK_NET=$(netjail_print_name "n" $GLOBAL_N $LOCAL_M)
+filename=$1
+PREFIX=$2
-shift 2
+read_topology $filename
+
+declare -A NODES
+declare -A NODE_LINKS
+
+netjail_bridge_name
+NETWORK_NET=$RESULT
+
+for X in $(seq $KNOWN); do
+ netjail_node_name
+ KNOWN_NODES[$X]=$RESULT
+ netjail_node_link_bridge_name
+ KNOWN_LINKS[$X]=$RESULT
+ netjail_node_unlink_bridge ${KNOWN_LINKS[$X]}
+ netjail_node_clear ${KNOWN_NODES[$X]}
+done
for N in $(seq $GLOBAL_N); do
+ netjail_node_name
+ ROUTERS[$N]=$RESULT
+ netjail_node_link_bridge_name
+ NETWORK_LINKS[$N]=$RESULT
+ netjail_bridge_name
+ ROUTER_NETS[$N]=$RESULT
+ netjail_node_link_bridge_name
+ ROUTER_LINKS[$N]=$RESULT
+
+ netjail_node_unlink_bridge ${ROUTER_LINKS[$N]}
+
for M in $(seq $LOCAL_M); do
- netjail_node_clear $(netjail_print_name "N" $N $M)
+ netjail_node_name
+ NODES[$N,$M]=$RESULT
+ netjail_node_link_bridge_name
+ NODE_LINKS[$N,$M]=$RESULT
+ netjail_node_unlink_bridge ${NODE_LINKS[$N,$M]}
+ netjail_node_clear ${NODES[$N,$M]}
done
+
- netjail_bridge_clear $(netjail_print_name "r" $N)
- netjail_node_clear $(netjail_print_name "R" $N)
+ netjail_bridge_clear ${ROUTER_NETS[$N]}
+ netjail_node_unlink_bridge ${NETWORK_LINKS[$N]}
+ netjail_node_clear ${ROUTERS[$N]}
done
netjail_bridge_clear $NETWORK_NET
diff --git a/src/testing/netjail_stop_v2.sh b/src/testing/netjail_stop_v2.sh
deleted file mode 100755
index 6e9fd1ccc..000000000
--- a/src/testing/netjail_stop_v2.sh
+++ /dev/null
@@ -1,59 +0,0 @@
-#!/bin/bash
-. "./../testing/netjail_core_v2.sh"
-. "./../testing/topo.sh"
-
-set -eu
-set -x
-
-export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
-
-filename=$1
-PREFIX=$2
-
-read_topology $filename
-
-declare -A NODES
-declare -A NODE_LINKS
-
-netjail_bridge_name
-NETWORK_NET=$RESULT
-
-for X in $(seq $KNOWN); do
- netjail_node_name
- KNOWN_NODES[$X]=$RESULT
- netjail_node_link_bridge_name
- KNOWN_LINKS[$X]=$RESULT
- netjail_node_unlink_bridge ${KNOWN_LINKS[$X]}
- netjail_node_clear ${KNOWN_NODES[$X]}
-done
-
-for N in $(seq $GLOBAL_N); do
- netjail_node_name
- ROUTERS[$N]=$RESULT
- netjail_node_link_bridge_name
- NETWORK_LINKS[$N]=$RESULT
- netjail_bridge_name
- ROUTER_NETS[$N]=$RESULT
- netjail_node_link_bridge_name
- ROUTER_LINKS[$N]=$RESULT
-
- netjail_node_unlink_bridge ${ROUTER_LINKS[$N]}
-
- for M in $(seq $LOCAL_M); do
- netjail_node_name
- NODES[$N,$M]=$RESULT
- netjail_node_link_bridge_name
- NODE_LINKS[$N,$M]=$RESULT
- netjail_node_unlink_bridge ${NODE_LINKS[$N,$M]}
- netjail_node_clear ${NODES[$N,$M]}
- done
-
-
- netjail_bridge_clear ${ROUTER_NETS[$N]}
- netjail_node_unlink_bridge ${NETWORK_LINKS[$N]}
- netjail_node_clear ${ROUTERS[$N]}
-done
-
-netjail_bridge_clear $NETWORK_NET
-
-echo "Done"
diff --git a/src/testing/test_testing_plugin_testcmd.c b/src/testing/test_testing_plugin_testcmd.c
index 444272fcd..32e2b38a7 100644
--- a/src/testing/test_testing_plugin_testcmd.c
+++ b/src/testing/test_testing_plugin_testcmd.c
@@ -17,11 +17,12 @@
SPDX-License-Identifier: AGPL3.0-or-later
*/
-
/**
* @file testbed/plugin_testcmd.c
* @brief a plugin to provide the API for running test cases.
* @author t3sserakt
+ *
+ * // FIXME: too verbose, no logic to return final status, will segv!
*/
#include "platform.h"
#include "gnunet_testing_ng_lib.h"
@@ -33,8 +34,11 @@
*/
#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
+
+// FIXME: bad global!
unsigned int are_all_peers_started;
+
static void
all_peers_started ()
{
@@ -44,8 +48,10 @@ all_peers_started ()
are_all_peers_started);
}
+
static void
-start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
+start_testcase (TESTING_CMD_HELPER_write_cb write_message,
+ char *router_ip,
char *node_ip,
char *n,
char *m,
@@ -70,9 +76,10 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
write_message)
};
- GNUNET_TESTING_run (NULL,
- commands,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ GNUNET_TESTING_run (commands,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ NULL, /* FIXME: pass continuation! */
+ NULL);
LOG (GNUNET_ERROR_TYPE_ERROR,
"We got here 7!\n");
@@ -113,4 +120,4 @@ libgnunet_plugin_testcmd_done (void *cls)
}
-/* end of plugin_testcmd.c */
+
diff --git a/src/testing/testing.c b/src/testing/testing.c
index d3acd4689..4d9b7c0cb 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -34,6 +34,7 @@
#include "gnunet_arm_service.h"
#include "gnunet_testing_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "testing_cmds.h"
#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
@@ -2259,6 +2260,31 @@ GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection,
/**
+ * Create a GNUNET_CMDS_LOCAL_FINISHED message.
+ *
+ * @param rv The result of the local test as GNUNET_GenericReturnValue.
+ * @return The GNUNET_CMDS_LOCAL_FINISHED message.
+*/
+struct GNUNET_MessageHeader *
+GNUNET_TESTING_send_local_test_finished_msg (enum GNUNET_GenericReturnValue rv)
+{
+ struct GNUNET_CMDS_LOCAL_FINISHED *reply;
+ size_t msg_length;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Local test exits with status %d\n",
+ rv);
+ msg_length = sizeof(struct GNUNET_CMDS_LOCAL_FINISHED);
+ reply = GNUNET_new (struct GNUNET_CMDS_LOCAL_FINISHED);
+ reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED);
+ reply->header.size = htons ((uint16_t) msg_length);
+ reply->result = htons (rv);
+
+ return (struct GNUNET_MessageHeader *) reply;
+}
+
+
+/**
* Getting the topology from file.
*
* @param filename The name of the topology file.
diff --git a/src/testing/testing.h b/src/testing/testing.h
index b12466530..8aba09e4b 100644
--- a/src/testing/testing.h
+++ b/src/testing/testing.h
@@ -21,54 +21,54 @@
/**
* @author t3sserakt
*/
-
+#ifndef TESTING_H
+#define TESTING_H
#include "gnunet_util_lib.h"
+
+/**
+ * Advance internal pointer to next command.
+ *
+ * @param cls batch internal state
+ * @return true if we could advance, false if the batch
+ * has completed and cannot advance anymore
+ */
+bool
+GNUNET_TESTING_cmd_batch_next_ (void *cls);
+
+
+/**
+ * Test if this command is a batch command.
+ *
+ * @return false if not, true if it is a batch command
+ */
+bool
+GNUNET_TESTING_cmd_is_batch_ (const struct GNUNET_TESTING_Command *cmd);
+
+
+/**
+ * Obtain what command the batch is at.
+ *
+ * @return cmd current batch command
+ */
+struct GNUNET_TESTING_Command *
+GNUNET_TESTING_cmd_batch_get_current_ (const struct GNUNET_TESTING_Command *cmd);
+
+
/**
- * Global state of the interpreter, used by a command
- * to access information about other commands.
+ * Set what command the batch should be at. Needed for
+ * loops. We may want to change this to take a label
+ * and/or expose it in the public API in the future.
+ * Not used for now.
+ *
+ * @param cmd current batch command
+ * @param new_ip where to move the IP
*/
-// SUGGESTION: consider making this struct opaque (only known inside of libgnunettesting,
-// say main loop and a few select commands, like next/fail/batch); + helper
-// function to access 'cfg'?
-struct GNUNET_TESTING_Interpreter
-{
-
- /**
- * Commands the interpreter will run.
- */
- struct GNUNET_TESTING_Command *commands;
-
- /**
- * Interpreter task (if one is scheduled).
- */
- struct GNUNET_SCHEDULER_Task *task;
-
- /**
- * Finish task of a blocking call to a commands finish method.
- */
- struct GNUNET_SCHEDULER_Task *finish_task;
-
- /**
- * Our configuration.
- */
- const struct GNUNET_CONFIGURATION_Handle *cfg;
-
- /**
- * Task run on timeout.
- */
- struct GNUNET_SCHEDULER_Task *timeout_task;
-
- /**
- * Instruction pointer. Tells #interpreter_run() which instruction to run
- * next. Need (signed) int because it gets -1 when rewinding the
- * interpreter to the first CMD.
- */
- int ip;
-
- /**
- * Result of the testcases, #GNUNET_OK on success
- */
- int result;
-
-};
+void
+GNUNET_TESTING_cmd_batch_set_current_ (const struct GNUNET_TESTING_Command *cmd,
+ unsigned int new_ip);
+
+
+
+
+#endif
diff --git a/src/testing/testing_api_cmd_batch.c b/src/testing/testing_api_cmd_batch.c
index af260f80d..080a4880d 100644
--- a/src/testing/testing_api_cmd_batch.c
+++ b/src/testing/testing_api_cmd_batch.c
@@ -39,6 +39,11 @@ struct BatchState
struct GNUNET_TESTING_Command *batch;
/**
+ * Our label.
+ */
+ const char *label;
+
+ /**
* Internal command pointer.
*/
unsigned int batch_ip;
@@ -49,12 +54,10 @@ struct BatchState
* Run the command.
*
* @param cls closure.
- * @param cmd the command being executed.
* @param is the interpreter state.
*/
static void
batch_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
struct GNUNET_TESTING_Interpreter *is)
{
struct BatchState *bs = cls;
@@ -69,7 +72,7 @@ batch_run (void *cls,
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Exiting from batch: %s\n",
- cmd->label);
+ bs->label);
return;
}
bs->batch[bs->batch_ip].start_time
@@ -77,7 +80,6 @@ batch_run (void *cls,
= GNUNET_TIME_absolute_get ();
bs->batch[bs->batch_ip].num_tries = 1;
bs->batch[bs->batch_ip].run (bs->batch[bs->batch_ip].cls,
- &bs->batch[bs->batch_ip],
is);
}
@@ -87,20 +89,16 @@ batch_run (void *cls,
* cancel a pending operation thereof.
*
* @param cls closure.
- * @param cmd the command which is being cleaned up.
*/
static void
-batch_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
+batch_cleanup (void *cls)
{
struct BatchState *bs = cls;
- (void) cmd;
for (unsigned int i = 0;
NULL != bs->batch[i].label;
i++)
- bs->batch[i].cleanup (bs->batch[i].cls,
- &bs->batch[i]);
+ bs->batch[i].cleanup (bs->batch[i].cls);
GNUNET_free (bs->batch);
GNUNET_free (bs);
}
@@ -115,22 +113,21 @@ batch_cleanup (void *cls,
* @param index index number of the object to offer.
* @return #GNUNET_OK on success.
*/
-static int
+static enum GNUNET_GenericReturnValue
batch_traits (void *cls,
const void **ret,
const char *trait,
unsigned int index)
{
+ struct BatchState *bs = cls;
+ // FIXME: these constants should be more global!
#define CURRENT_CMD_INDEX 0
#define BATCH_INDEX 1
-
- struct BatchState *bs = cls;
-
struct GNUNET_TESTING_Trait traits[] = {
- GNUNET_TESTING_make_trait_cmd
- (CURRENT_CMD_INDEX, &bs->batch[bs->batch_ip]),
- GNUNET_TESTING_make_trait_cmd
- (BATCH_INDEX, bs->batch),
+ GNUNET_TESTING_make_trait_cmd (CURRENT_CMD_INDEX,
+ &bs->batch[bs->batch_ip]),
+ GNUNET_TESTING_make_trait_cmd (BATCH_INDEX,
+ bs->batch),
GNUNET_TESTING_trait_end ()
};
@@ -162,7 +159,7 @@ GNUNET_TESTING_cmd_batch (const char *label,
unsigned int i;
bs = GNUNET_new (struct BatchState);
-
+ bs->label = label;
/* Get number of commands. */
for (i = 0; NULL != batch[i].label; i++)
/* noop */
@@ -187,68 +184,45 @@ GNUNET_TESTING_cmd_batch (const char *label,
}
-/**
- * Advance internal pointer to next command.
- *
- * @param is interpreter state.
- */
-void
-GNUNET_TESTING_cmd_batch_next (struct GNUNET_TESTING_Interpreter *is)
+bool
+GNUNET_TESTING_cmd_batch_next_ (void *cls)
{
- struct BatchState *bs = is->commands[is->ip].cls;
+ struct BatchState *bs = cls;
if (NULL == bs->batch[bs->batch_ip].label)
- {
- is->commands[is->ip].finish_time = GNUNET_TIME_absolute_get ();
- is->ip++;
- return;
- }
- bs->batch[bs->batch_ip].finish_time = GNUNET_TIME_absolute_get ();
+ return false;
+ bs->batch[bs->batch_ip].finish_time
+ = GNUNET_TIME_absolute_get ();
bs->batch_ip++;
+ return true;
}
-/**
- * Test if this command is a batch command.
- *
- * @return false if not, true if it is a batch command
- */
-int
-GNUNET_TESTING_cmd_is_batch (const struct GNUNET_TESTING_Command *cmd)
+bool
+GNUNET_TESTING_cmd_is_batch_ (const struct GNUNET_TESTING_Command *cmd)
{
return cmd->run == &batch_run;
}
-/**
- * Obtain what command the batch is at.
- *
- * @return cmd current batch command
- */
struct GNUNET_TESTING_Command *
-GNUNET_TESTING_cmd_batch_get_current (const struct GNUNET_TESTING_Command *cmd)
+GNUNET_TESTING_cmd_batch_get_current_ (const struct GNUNET_TESTING_Command *cmd)
{
struct BatchState *bs = cmd->cls;
- GNUNET_assert (cmd->run == &batch_run);
+ GNUNET_assert (GNUNET_TESTING_cmd_is_batch_ (cmd));
return &bs->batch[bs->batch_ip];
}
-/**
- * Set what command the batch should be at.
- *
- * @param cmd current batch command
- * @param new_ip where to move the IP
- */
void
-GNUNET_TESTING_cmd_batch_set_current (const struct GNUNET_TESTING_Command *cmd,
- unsigned int new_ip)
+GNUNET_TESTING_cmd_batch_set_current_ (const struct GNUNET_TESTING_Command *cmd,
+ unsigned int new_ip)
{
struct BatchState *bs = cmd->cls;
/* sanity checks */
- GNUNET_assert (cmd->run == &batch_run);
+ GNUNET_assert (GNUNET_TESTING_cmd_is_batch_ (cmd));
for (unsigned int i = 0; i < new_ip; i++)
GNUNET_assert (NULL != bs->batch[i].label);
/* actual logic */
diff --git a/src/testing/testing_api_cmd_block_until_all_peers_started.c b/src/testing/testing_api_cmd_block_until_all_peers_started.c
index e9d3f0ed3..763713e15 100644
--- a/src/testing/testing_api_cmd_block_until_all_peers_started.c
+++ b/src/testing/testing_api_cmd_block_until_all_peers_started.c
@@ -39,6 +39,11 @@
struct BlockState
{
/**
+ * Context for our asynchronous completion.
+ */
+ struct GNUNET_TESTING_AsyncContext ac;
+
+ /**
* Flag to indicate if all peers have started.
*
*/
@@ -47,26 +52,11 @@ struct BlockState
/**
- * Trait function of this cmd does nothing.
- *
- */
-static int
-block_until_all_peers_started_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- return GNUNET_OK;
-}
-
-
-/**
* The cleanup function of this cmd frees resources the cmd allocated.
*
*/
static void
-block_until_all_peers_started_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
+block_until_all_peers_started_cleanup (void *cls)
{
struct BlockState *bs = cls;
@@ -80,7 +70,6 @@ block_until_all_peers_started_cleanup (void *cls,
*/
static void
block_until_all_peers_started_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
struct GNUNET_TESTING_Interpreter *is)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -89,27 +78,6 @@ block_until_all_peers_started_run (void *cls,
/**
- * Function to check if BlockState#all_peers_started is GNUNET_YES. In that case interpreter_next will be called.
- *
- */
-static int
-block_until_all_peers_started_finish (void *cls,
- GNUNET_SCHEDULER_TaskCallback cont,
- void *cont_cls)
-{
- struct BlockState *bs = cls;
- unsigned int *ret = bs->all_peers_started;
-
- if (GNUNET_YES == *ret)
- {
- cont (cont_cls);
- }
-
- return *ret;
-}
-
-
-/**
* Create command.
*
* @param label name for command.
@@ -125,15 +93,15 @@ GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label,
bs = GNUNET_new (struct BlockState);
bs->all_peers_started = all_peers_started;
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = bs,
- .label = label,
- .run = &block_until_all_peers_started_run,
- .finish = &block_until_all_peers_started_finish,
- .cleanup = &block_until_all_peers_started_cleanup,
- .traits = &block_until_all_peers_started_traits
- };
-
- return cmd;
+ {
+ struct GNUNET_TESTING_Command cmd = {
+ .cls = bs,
+ .label = label,
+ .run = &block_until_all_peers_started_run,
+ .ac = &bs->ac,
+ .cleanup = &block_until_all_peers_started_cleanup
+ };
+
+ return cmd;
+ }
}
diff --git a/src/testing/testing_api_cmd_block_until_external_trigger.c b/src/testing/testing_api_cmd_block_until_external_trigger.c
index 2439afeaf..aeb9ffda3 100644
--- a/src/testing/testing_api_cmd_block_until_external_trigger.c
+++ b/src/testing/testing_api_cmd_block_until_external_trigger.c
@@ -39,25 +39,15 @@
struct BlockState
{
/**
- * Flag to indicate if all peers have started.
- *
+ * Context for our asynchronous completion.
*/
- unsigned int *stop_blocking;
-};
-
+ struct GNUNET_TESTING_AsyncContext ac;
-/**
- * Trait function of this cmd does nothing.
- *
- */
-static int
-block_until_all_peers_started_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- return GNUNET_OK;
-}
+ /**
+ * The label of this command.
+ */
+ const char *label;
+};
/**
@@ -65,47 +55,68 @@ block_until_all_peers_started_traits (void *cls,
*
*/
static void
-block_until_all_peers_started_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
+block_until_all_peers_started_cleanup (void *cls)
{
struct BlockState *bs = cls;
GNUNET_free (bs);
}
+static int
+block_until_external_trigger_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct BlockState *bs = cls;
+ struct GNUNET_TESTING_AsyncContext *ac = &bs->ac;
+ struct GNUNET_TESTING_Trait traits[] = {
+ {
+ .index = 0,
+ .trait_name = "async_context",
+ .ptr = (const void *) ac,
+ },
+ GNUNET_TESTING_trait_end ()
+ };
+
+ return GNUNET_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
/**
- * This function does nothing but to start the cmd.
+ * Function to get the trait with the async context.
*
+ * @param[out] ac GNUNET_TESTING_AsyncContext.
+ * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
*/
-static void
-block_until_all_peers_started_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
- struct GNUNET_TESTING_Interpreter *is)
+int
+GNUNET_TESTING_get_trait_async_context (
+ const struct GNUNET_TESTING_Command *cmd,
+ struct GNUNET_TESTING_AsyncContext **ac)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "block_until_all_peers_started_run!\n");
+ return cmd->traits (cmd->cls,
+ (const void **) ac,
+ "async_context",
+ (unsigned int) 0);
}
/**
- * Function to check if BlockState#all_peers_started is GNUNET_YES. In that case interpreter_next will be called.
+ * This function does nothing but to start the cmd.
*
*/
-static int
-block_until_all_peers_started_finish (void *cls,
- GNUNET_SCHEDULER_TaskCallback cont,
- void *cont_cls)
+static void
+block_until_all_peers_started_run (void *cls,
+ struct GNUNET_TESTING_Interpreter *is)
{
struct BlockState *bs = cls;
- unsigned int *ret = bs->stop_blocking;
- if (GNUNET_YES == *ret)
- {
- cont (cont_cls);
- }
-
- return *ret;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "block %s running!\n",
+ bs->label);
}
@@ -117,23 +128,22 @@ block_until_all_peers_started_finish (void *cls,
* @return command.
*/
struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_block_until_external_trigger (const char *label,
- unsigned int *
- stop_blocking)
+GNUNET_TESTING_cmd_block_until_external_trigger (const char *label)
{
struct BlockState *bs;
bs = GNUNET_new (struct BlockState);
- bs->stop_blocking = stop_blocking;
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = bs,
- .label = label,
- .run = &block_until_all_peers_started_run,
- .finish = &block_until_all_peers_started_finish,
- .cleanup = &block_until_all_peers_started_cleanup,
- .traits = &block_until_all_peers_started_traits
- };
-
- return cmd;
+ bs->label = label;
+ {
+ struct GNUNET_TESTING_Command cmd = {
+ .cls = bs,
+ .label = label,
+ .run = &block_until_all_peers_started_run,
+ .ac = &bs->ac,
+ .cleanup = &block_until_all_peers_started_cleanup,
+ .traits = block_until_external_trigger_traits
+ };
+
+ return cmd;
+ }
}
diff --git a/src/testing/testing_api_cmd_end.c b/src/testing/testing_api_cmd_end.c
new file mode 100644
index 000000000..f0f036429
--- /dev/null
+++ b/src/testing/testing_api_cmd_end.c
@@ -0,0 +1,39 @@
+/*
+ This file is part of GNUnet
+ Copyright (C) 2021 GNUnet e.V.
+
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ SPDX-License-Identifier: AGPL3.0-or-later
+ */
+/**
+ * @file testing/testing_api_cmd_end.c
+ * @brief command to end a command array
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_testing_ng_lib.h"
+
+
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_end (void)
+{
+ static struct GNUNET_TESTING_Command cmd = {
+ .label = NULL
+ };
+
+ return cmd;
+}
+
+
diff --git a/src/testing/testing_api_cmd_finish.c b/src/testing/testing_api_cmd_finish.c
new file mode 100644
index 000000000..3ac0871a5
--- /dev/null
+++ b/src/testing/testing_api_cmd_finish.c
@@ -0,0 +1,198 @@
+/*
+ This file is part of GNUnet
+ Copyright (C) 2021 GNUnet e.V.
+
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ SPDX-License-Identifier: AGPL3.0-or-later
+ */
+/**
+ * @file testing/testing_api_cmd_finish.c
+ * @brief command to wait for completion of async command
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_testing_ng_lib.h"
+
+/**
+ * Struct to use for command-specific context information closure of a command waiting
+ * for another command.
+ */
+struct FinishState
+{
+ /**
+ * Closure for all commands with command-specific context information.
+ */
+ void *cls;
+
+ /**
+ * Label of the asynchronous command the synchronous command of this closure waits for.
+ */
+ const char *async_label;
+
+ /**
+ * Task for running the finish method of the asynchronous task the command is waiting for.
+ */
+ struct GNUNET_SCHEDULER_Task *finish_task;
+
+ /**
+ * Function to call when done.
+ */
+ struct GNUNET_TESTING_AsyncContext ac;
+
+ /**
+ * How long to wait until finish fails hard?
+ */
+ struct GNUNET_TIME_Relative timeout;
+
+};
+
+
+/**
+ * Function called when the command we are waiting on
+ * is finished. Hence we are finished, too.
+ *
+ * @param cls a `struct FinishState` being notified
+ */
+static void
+done_finish (void *cls)
+{
+ struct FinishState *finish_state = cls;
+
+ GNUNET_SCHEDULER_cancel (finish_state->finish_task);
+ finish_state->finish_task = NULL;
+ GNUNET_TESTING_async_finish (&finish_state->ac);
+}
+
+
+/**
+ * Function triggered if the command we are waiting
+ * for did not complete on time.
+ *
+ * @param cls our `struct FinishState`
+ */
+static void
+timeout_finish (void *cls)
+{
+ struct FinishState *finish_state = cls;
+
+ finish_state->finish_task = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Timeout waiting for command `%s' to finish\n",
+ finish_state->async_label);
+ GNUNET_TESTING_async_fail (&finish_state->ac);
+}
+
+
+/**
+ * Run method of the command created by the interpreter to wait for another
+ * command to finish.
+ *
+ */
+static void
+run_finish (void *cls,
+ struct GNUNET_TESTING_Interpreter *is)
+{
+ struct FinishState *finish_state = cls;
+ const struct GNUNET_TESTING_Command *async_cmd;
+ struct GNUNET_TESTING_AsyncContext *aac;
+
+ async_cmd
+ = GNUNET_TESTING_interpreter_lookup_command (is,
+ finish_state->async_label);
+ if (NULL == async_cmd)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Did not find command `%s'\n",
+ finish_state->async_label);
+ GNUNET_TESTING_interpreter_fail (is);
+ return;
+ }
+ if ( (NULL == (aac = async_cmd->ac)) ||
+ (! async_cmd->asynchronous_finish) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Cannot finish `%s': not asynchronous\n",
+ finish_state->async_label);
+ GNUNET_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (GNUNET_NO != aac->finished)
+ {
+ /* Command is already finished, so are we! */
+ GNUNET_TESTING_async_finish (&finish_state->ac);
+ return;
+ }
+ finish_state->finish_task
+ = GNUNET_SCHEDULER_add_delayed (finish_state->timeout,
+ &timeout_finish,
+ finish_state);
+ aac->cont = &done_finish;
+ aac->cont_cls = finish_state;
+}
+
+
+/**
+ * Cleanup state of a finish command.
+ *
+ * @param cls a `struct FinishState` to clean up
+ */
+static void
+cleanup_finish (void *cls)
+{
+ struct FinishState *finish_state = cls;
+
+ if (NULL != finish_state->finish_task)
+ {
+ GNUNET_SCHEDULER_cancel (finish_state->finish_task);
+ finish_state->finish_task = NULL;
+ }
+ GNUNET_free (finish_state);
+}
+
+
+const struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_finish (const char *finish_label,
+ const char *cmd_ref,
+ struct GNUNET_TIME_Relative timeout)
+{
+ struct FinishState *finish_state;
+
+ finish_state = GNUNET_new (struct FinishState);
+ finish_state->async_label = cmd_ref;
+ finish_state->timeout = timeout;
+ {
+ struct GNUNET_TESTING_Command cmd = {
+ .cls = finish_state,
+ .label = finish_label,
+ .run = &run_finish,
+ .ac = &finish_state->ac,
+ .cleanup = &cleanup_finish
+ };
+
+ return cmd;
+ }
+}
+
+
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_make_unblocking (struct GNUNET_TESTING_Command cmd)
+{
+ /* do not permit this function to be used on
+ a finish command! */
+ GNUNET_assert (cmd.run != &run_finish);
+ cmd.asynchronous_finish = true;
+ return cmd;
+}
diff --git a/src/testing/testing_api_cmd_hello_world.c b/src/testing/testing_api_cmd_hello_world.c
index 4347ac818..73dcd6dff 100644
--- a/src/testing/testing_api_cmd_hello_world.c
+++ b/src/testing/testing_api_cmd_hello_world.c
@@ -32,50 +32,51 @@ struct HelloWorldState
const char *birthLabel;
};
+
/**
-*
-*
-* @param cls closure
-* @param cmd current CMD being cleaned up.
-*/
+ *
+ *
+ * @param cls closure
+ */
static void
-hello_world_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
+hello_world_cleanup (void *cls)
{
struct HelloWorldState *hs = cls;
+
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Cleaning up message %s\n",
hs->message);
+ GNUNET_free (hs);
}
+
/**
-*
-*
-* @param cls closure.
-* @param[out] ret result
-* @param trait name of the trait.
-* @param index index number of the object to offer.
-* @return #GNUNET_OK on success.
-*/
-static int
+ *
+ *
+ * @param cls closure.
+ * @param[out] ret result
+ * @param trait name of the trait.
+ * @param index index number of the object to offer.
+ * @return #GNUNET_OK on success.
+ */
+static enum GNUNET_GenericReturnValue
hello_world_traits (void *cls,
const void **ret,
const char *trait,
unsigned int index)
{
- return GNUNET_OK;
+ return GNUNET_NO;
}
+
/**
* Run the "hello world" CMD.
*
* @param cls closure.
-* @param cmd CMD being run.
* @param is interpreter state.
*/
static void
hello_world_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
struct GNUNET_TESTING_Interpreter *is)
{
struct HelloWorldState *hs = cls;
@@ -84,13 +85,16 @@ hello_world_run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"%s\n",
hs->message);
- birth_cmd = GNUNET_TESTING_interpreter_lookup_command (hs->birthLabel);
- GNUNET_TESTING_get_trait_what_am_i (birth_cmd, &hs->message);
+ birth_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
+ hs->birthLabel);
+ GNUNET_TESTING_get_trait_what_am_i (birth_cmd,
+ &hs->message);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Now I am a %s\n",
hs->message);
}
+
/**
* Create command.
*
@@ -108,14 +112,15 @@ GNUNET_TESTING_cmd_hello_world (const char *label,
hs = GNUNET_new (struct HelloWorldState);
hs->message = "Hello World, I was nobody!";
hs->birthLabel = birthLabel;
+ {
+ struct GNUNET_TESTING_Command cmd = {
+ .cls = hs,
+ .label = label,
+ .run = &hello_world_run,
+ .cleanup = &hello_world_cleanup,
+ .traits = &hello_world_traits
+ };
- struct GNUNET_TESTING_Command cmd = {
- .cls = hs,
- .label = label,
- .run = &hello_world_run,
- .cleanup = &hello_world_cleanup,
- .traits = &hello_world_traits
- };
-
- return cmd;
+ return cmd;
+ }
}
diff --git a/src/testing/testing_api_cmd_hello_world_birth.c b/src/testing/testing_api_cmd_hello_world_birth.c
index 9d60059a5..8415b99f0 100644
--- a/src/testing/testing_api_cmd_hello_world_birth.c
+++ b/src/testing/testing_api_cmd_hello_world_birth.c
@@ -40,8 +40,7 @@ struct HelloWorldBirthState
* @param cmd current CMD being cleaned up.
*/
static void
-hello_world_birth_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
+hello_world_birth_cleanup (void *cls)
{
struct HelloWorldBirthState *hbs = cls;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -49,6 +48,7 @@ hello_world_birth_cleanup (void *cls,
hbs->what_am_i);
}
+
/**
*
*
@@ -82,6 +82,7 @@ hello_world_birth_traits (void *cls,
index);
}
+
/**
* Run the "hello world" CMD.
*
@@ -91,14 +92,13 @@ hello_world_birth_traits (void *cls,
*/
static void
hello_world_birth_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
struct GNUNET_TESTING_Interpreter *is)
{
struct HelloWorldBirthState *hbs = cls;
struct GNUNET_TIME_Relative relative;
relative = GNUNET_TIME_absolute_get_difference (*hbs->date,
- GNUNET_TIME_absolute_get ());
+ GNUNET_TIME_absolute_get ());
if (0 == relative.rel_value_us % 10)
{
@@ -114,6 +114,7 @@ hello_world_birth_run (void *cls,
}
}
+
/**
* Offer data from trait
*
@@ -131,6 +132,7 @@ GNUNET_TESTING_get_trait_what_am_i (const struct GNUNET_TESTING_Command *cmd,
(unsigned int) 0);
}
+
/**
* Create command.
*
diff --git a/src/testing/testing_api_cmd_local_test_finished.c b/src/testing/testing_api_cmd_local_test_finished.c
index b50e471e9..0e7e214dc 100644
--- a/src/testing/testing_api_cmd_local_test_finished.c
+++ b/src/testing/testing_api_cmd_local_test_finished.c
@@ -19,7 +19,7 @@
*/
/**
- * @file testing_api_cmd_block_until_all_peers_started.c
+ * @file testing_api_cmd_local_test_finished.c
* @brief cmd to block the interpreter loop until all peers started.
* @author t3sserakt
*/
@@ -40,6 +40,7 @@
*/
struct LocalFinishedState
{
+
/**
* Callback to write messages to the master loop.
*
@@ -55,26 +56,11 @@ struct LocalFinishedState
/**
- * Trait function of this cmd does nothing.
- *
- */
-static int
-local_test_finished_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- return GNUNET_OK;
-}
-
-
-/**
* The cleanup function of this cmd frees resources the cmd allocated.
*
*/
static void
-local_test_finished_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
+local_test_finished_cleanup (void *cls)
{
struct LocalFinishedState *lfs = cls;
@@ -89,11 +75,9 @@ local_test_finished_cleanup (void *cls,
*/
static void
local_test_finished_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
struct GNUNET_TESTING_Interpreter *is)
{
struct LocalFinishedState *lfs = cls;
-
struct GNUNET_CMDS_LOCAL_FINISHED *reply;
size_t msg_length;
@@ -102,22 +86,8 @@ local_test_finished_run (void *cls,
reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED);
reply->header.size = htons ((uint16_t) msg_length);
lfs->reply = reply;
- lfs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
-}
-
-
-/**
- * This finish function will stop the local loop without shutting down the scheduler, because we do not call the continuation, which is the interpreter_next method.
- *
- */
-static int
-local_test_finished_finish (void *cls,
- GNUNET_SCHEDULER_TaskCallback cont,
- void *cont_cls)
-{
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Stopping local loop\n");
- return GNUNET_YES;
+ lfs->write_message ((struct GNUNET_MessageHeader *) reply,
+ msg_length);
}
@@ -129,23 +99,22 @@ local_test_finished_finish (void *cls,
* @return command.
*/
struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_local_test_finished (const char *label,
- TESTING_CMD_HELPER_write_cb
- write_message)
+GNUNET_TESTING_cmd_local_test_finished (
+ const char *label,
+ TESTING_CMD_HELPER_write_cb write_message)
{
struct LocalFinishedState *lfs;
lfs = GNUNET_new (struct LocalFinishedState);
lfs->write_message = write_message;
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = lfs,
- .label = label,
- .run = &local_test_finished_run,
- .finish = &local_test_finished_finish,
- .cleanup = &local_test_finished_cleanup,
- .traits = &local_test_finished_traits
- };
-
- return cmd;
+ {
+ struct GNUNET_TESTING_Command cmd = {
+ .cls = lfs,
+ .label = label,
+ .run = &local_test_finished_run,
+ .cleanup = &local_test_finished_cleanup,
+ };
+
+ return cmd;
+ }
}
diff --git a/src/testing/testing_api_cmd_netjail_start.c b/src/testing/testing_api_cmd_netjail_start.c
index 536b356a6..35fb90f3c 100644
--- a/src/testing/testing_api_cmd_netjail_start.c
+++ b/src/testing/testing_api_cmd_netjail_start.c
@@ -19,7 +19,7 @@
*/
/**
- * @file testing/testing_api_cmd_hello_world.c
+ * @file testing/testing_api_cmd_netjail_start.c
* @brief Command to start the netjail script.
* @author t3sserakt
*/
@@ -35,22 +35,24 @@
*/
struct NetJailState
{
+ /**
+ * Context for our asynchronous completion.
+ */
+ struct GNUNET_TESTING_AsyncContext ac;
+
// Child Wait handle
struct GNUNET_ChildWaitHandle *cwh;
- // Number of local nodes in each namespace.
- char *local_m;
-
- // The number of namespaces.
- char *global_n;
-
/**
* The process id of the start script.
*/
struct GNUNET_OS_Process *start_proc;
- // Flag indication if the script finished.
- unsigned int finished;
+ /**
+ * Configuration file for the test topology.
+ */
+ char *topology_config;
+
};
@@ -59,8 +61,7 @@ struct NetJailState
*
*/
static void
-netjail_start_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
+netjail_start_cleanup (void *cls)
{
struct NetJailState *ns = cls;
@@ -87,20 +88,6 @@ netjail_start_cleanup (void *cls,
/**
- * Trait function of this cmd does nothing.
- *
- */
-static int
-netjail_start_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- return GNUNET_OK;
-}
-
-
-/**
* Callback which will be called if the setup script finished.
*
*/
@@ -111,40 +98,40 @@ child_completed_callback (void *cls,
{
struct NetJailState *ns = cls;
+ GNUNET_OS_process_destroy (ns->start_proc);
+ ns->start_proc = NULL;
if (0 == exit_code)
{
- ns->finished = GNUNET_YES;
+ GNUNET_TESTING_async_finish (&ns->ac);
}
else
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Child completed with an error!\n");
- ns->finished = GNUNET_SYSERR;
+ "Child failed with error %lu!\n",
+ exit_code);
+ GNUNET_TESTING_async_fail (&ns->ac);
}
- GNUNET_OS_process_destroy (ns->start_proc);
- ns->start_proc = NULL;
}
-
/**
* The run method starts the script which setup the network namespaces.
*
* @param cls closure.
-* @param cmd CMD being run.
* @param is interpreter state.
*/
static void
netjail_start_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
struct GNUNET_TESTING_Interpreter *is)
{
struct NetJailState *ns = cls;
- char *const script_argv[] = {NETJAIL_START_SCRIPT,
- ns->local_m,
- ns->global_n,
- NULL};
- unsigned int helper_check = GNUNET_OS_check_helper_binary (
+ char pid[15];
+ enum GNUNET_GenericReturnValue helper_check;
+
+ // FIXME: NETJAIL_START_SCRIPT like this is bad,
+ // use location from share/gnunet/ of installed
+ // binary in case libgnunettesting is used as a lib!
+ helper_check = GNUNET_OS_check_helper_binary (
NETJAIL_START_SCRIPT,
GNUNET_YES,
NULL);
@@ -154,23 +141,38 @@ netjail_start_run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"No SUID for %s!\n",
NETJAIL_START_SCRIPT);
- GNUNET_TESTING_interpreter_fail ();
+ GNUNET_TESTING_interpreter_fail (is);
+ return;
}
- else if (GNUNET_NO == helper_check)
+ if (GNUNET_SYSERR == helper_check)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"%s not found!\n",
NETJAIL_START_SCRIPT);
- GNUNET_TESTING_interpreter_fail ();
+ GNUNET_TESTING_interpreter_fail (is);
+ return;
}
- ns->start_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
- NULL,
- NULL,
- NULL,
- NETJAIL_START_SCRIPT,
- script_argv);
-
+ GNUNET_snprintf (pid,
+ sizeof (pid),
+ "%u",
+ getpid ());
+ {
+ char *const script_argv[] = {
+ NETJAIL_START_SCRIPT,
+ ns->topology_config,
+ pid,
+ NULL
+ };
+
+ ns->start_proc
+ = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
+ NULL,
+ NULL,
+ NULL,
+ NETJAIL_START_SCRIPT,
+ script_argv);
+ }
ns->cwh = GNUNET_wait_child (ns->start_proc,
&child_completed_callback,
ns);
@@ -179,51 +181,29 @@ netjail_start_run (void *cls,
/**
- * This function checks the flag NetJailState#finished, if this cmd finished.
- *
- */
-static int
-netjail_start_finish (void *cls,
- GNUNET_SCHEDULER_TaskCallback cont,
- void *cont_cls)
-{
- struct NetJailState *ns = cls;
-
- if (ns->finished)
- {
- cont (cont_cls);
- }
- return ns->finished;
-}
-
-/**
* Create command.
*
* @param label name for command.
- * @param local_m Number of local nodes in each namespace.
- * @param global_n The number of namespaces.
+ * @param topology_config Configuration file for the test topology.
* @return command.
*/
struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_netjail_start (const char *label,
- char *local_m,
- char *global_n)
+ char *topology_config)
{
struct NetJailState *ns;
ns = GNUNET_new (struct NetJailState);
- ns->local_m = local_m;
- ns->global_n = global_n;
- ns->finished = GNUNET_NO;
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = ns,
- .label = label,
- .run = &netjail_start_run,
- .finish = &netjail_start_finish,
- .cleanup = &netjail_start_cleanup,
- .traits = &netjail_start_traits
- };
-
- return cmd;
+ ns->topology_config = topology_config;
+ {
+ struct GNUNET_TESTING_Command cmd = {
+ .cls = ns,
+ .label = label,
+ .run = &netjail_start_run,
+ .ac = &ns->ac,
+ .cleanup = &netjail_start_cleanup
+ };
+
+ return cmd;
+ }
}
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c
index 531621eb5..a1d71c436 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c
@@ -62,6 +62,16 @@ struct HelperMessage
struct NetJailState
{
/**
+ * Context for our asynchronous completion.
+ */
+ struct GNUNET_TESTING_AsyncContext ac;
+
+ /**
+ * The complete topology information.
+ */
+ struct GNUNET_TESTING_NetjailTopology *topology;
+
+ /**
* Pointer to the return value of the test.
*
*/
@@ -91,16 +101,22 @@ struct NetJailState
unsigned int n_helper;
/**
- * Number of nodes in a network namespace. //TODO make this a unsigned int
+ * Number of nodes in a natted subnet.
*
*/
- char *local_m;
+ unsigned int local_m;
/**
- * Number of network namespaces. //TODO make this a unsigned int
+ * Number of natted subnets.
*
*/
- char *global_n;
+ unsigned int global_n;
+
+ /**
+ * Number of global known nodes.
+ *
+ */
+ unsigned int known;
/**
* The send handle for the helper
@@ -194,11 +210,9 @@ struct TestingSystemCount
* Code to clean up resource this cmd used.
*
* @param cls closure
-* @param cmd current CMD being cleaned up.
*/
static void
-netjail_exec_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
+netjail_exec_cleanup (void *cls)
{
struct NetJailState *ns = cls;
struct HelperMessage *message_pos;
@@ -268,7 +282,8 @@ netjail_exec_traits (void *cls,
int
GNUNET_TESTING_get_trait_helper_handles (const struct
GNUNET_TESTING_Command *cmd,
- struct GNUNET_HELPER_Handle ***helper)
+ struct GNUNET_HELPER_Handle ***
+ helper)
{
return cmd->traits (cmd->cls,
(const void **) helper,
@@ -298,6 +313,43 @@ clear_msg (void *cls, int result)
}
+static void
+send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns)
+{
+ unsigned int total_number = ns->local_m * ns->global_n + ns->known;
+ struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
+ size_t msg_length;
+ struct GNUNET_HELPER_Handle *helper;
+ struct TestingSystemCount *tbc;
+
+ tbc = GNUNET_new (struct TestingSystemCount);
+ tbc->ns = ns;
+ // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone.
+ if (0 == i)
+ tbc->count = j + total_number;
+ else
+ tbc->count = (i - 1) * ns->local_m + j + total_number + ns->known;
+
+ helper = ns->helper[tbc->count - 1 - total_number];
+ msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
+ reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
+ reply->header.type = htons (
+ GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
+ reply->header.size = htons ((uint16_t) msg_length);
+
+ GNUNET_array_append (ns->msg, ns->n_msg, &reply->header);
+
+ struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send (
+ helper,
+ &reply->header,
+ GNUNET_NO,
+ &clear_msg,
+ tbc);
+
+ GNUNET_array_append (ns->shandle, ns->n_shandle, sh);
+}
+
+
/**
* Functions with this signature are called whenever a
* complete message is received by the tokenizer.
@@ -316,6 +368,7 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
struct TestingSystemCount *tbc = cls;
struct NetJailState *ns = tbc->ns;
struct HelperMessage *hp_msg;
+ unsigned int total_number = ns->local_m * ns->global_n + ns->known;
if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type))
{
@@ -325,11 +378,31 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
message->type))
{
ns->number_of_peers_started++;
+ if (ns->number_of_peers_started == total_number)
+ {
+ for (int i = 1; i <= ns->known; i++)
+ {
+ send_all_peers_started (0,i, ns);
+ }
+
+ for (int i = 1; i <= ns->global_n; i++)
+ {
+ for (int j = 1; j <= ns->local_m; j++)
+ {
+ send_all_peers_started (i,j, ns);
+ }
+ }
+ ns->number_of_peers_started = 0;
+ }
}
else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs (
message->type))
{
ns->number_of_local_test_finished++;
+ if (ns->number_of_local_test_finished == total_number)
+ {
+ GNUNET_TESTING_async_finish (&ns->ac);
+ }
}
else
{
@@ -340,6 +413,12 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
hp_msg);
}
+
+
+
+
+
+
return GNUNET_OK;
}
@@ -351,24 +430,21 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
static void
exp_cb (void *cls)
{
- struct NetJailState *ns = cls;
+ struct TestingSystemCount *tbc = cls;
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n");
- *ns->rv = 1;
+ GNUNET_TESTING_interpreter_fail (tbc->ns->ac.is);
}
/**
* Function to initialize a init message for the helper.
*
- * @param m_char The actual node in a namespace. //TODO Change this to unsigned int
- * @param n_char The actual namespace. //TODO Change this to unsigned int
* @param plugin_name Name of the test case plugin the helper will load.
*
*/
static struct GNUNET_CMDS_HelperInit *
-create_helper_init_msg_ (char *m_char,
- char *n_char,
- const char *plugin_name)
+create_helper_init_msg_ (const char *plugin_name)
{
struct GNUNET_CMDS_HelperInit *msg;
uint16_t plugin_name_len;
@@ -395,22 +471,49 @@ create_helper_init_msg_ (char *m_char,
static void
start_helper (struct NetJailState *ns, struct
GNUNET_CONFIGURATION_Handle *config,
- char *m_char,
- char *n_char)
+ unsigned int m,
+ unsigned int n)
{
struct GNUNET_HELPER_Handle *helper;
struct GNUNET_CMDS_HelperInit *msg;
struct TestingSystemCount *tbc;
+ char *m_char, *n_char, *global_n_char, *local_m_char, *known_char, *node_id,
+ *plugin;
+ pid_t pid;
+ unsigned int script_num;
+ struct GNUNET_ShortHashCode *hkey;
+ struct GNUNET_HashCode hc;
+ struct GNUNET_TESTING_NetjailTopology *topology = ns->topology;
+ struct GNUNET_TESTING_NetjailNode *node;
+ struct GNUNET_TESTING_NetjailNamespace *namespace;
+
+
+ if (0 == n)
+ script_num = m - 1;
+ else
+ script_num = n - 1 + (n - 1) * ns->local_m + m + ns->known;
+ pid = getpid ();
+
+ GNUNET_asprintf (&m_char, "%u", m);
+ GNUNET_asprintf (&n_char, "%u", n);
+ GNUNET_asprintf (&local_m_char, "%u", ns->local_m);
+ GNUNET_asprintf (&global_n_char, "%u",ns->global_n);
+ GNUNET_asprintf (&known_char, "%u",ns->known);
+ GNUNET_asprintf (&node_id, "%06x-%08x\n",
+ pid,
+ script_num);
+
+
char *const script_argv[] = {NETJAIL_EXEC_SCRIPT,
m_char,
n_char,
GNUNET_OS_get_libexec_binary_path (
HELPER_CMDS_BINARY),
- ns->global_n,
- ns->local_m,
+ global_n_char,
+ local_m_char,
+ node_id,
NULL};
- unsigned int m = atoi (m_char);
- unsigned int n = atoi (n_char);
+
unsigned int helper_check = GNUNET_OS_check_helper_binary (
NETJAIL_EXEC_SCRIPT,
GNUNET_YES,
@@ -418,7 +521,10 @@ start_helper (struct NetJailState *ns, struct
tbc = GNUNET_new (struct TestingSystemCount);
tbc->ns = ns;
- tbc->count = (n - 1) * atoi (ns->local_m) + m;
+ if (0 == n)
+ tbc->count = m;
+ else
+ tbc->count = (n - 1) * ns->local_m + m + ns->known;
GNUNET_CONTAINER_DLL_insert (ns->tbcs_head, ns->tbcs_tail,
tbc);
@@ -429,14 +535,14 @@ start_helper (struct NetJailState *ns, struct
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"No SUID for %s!\n",
NETJAIL_EXEC_SCRIPT);
- *ns->rv = 1;
+ GNUNET_TESTING_interpreter_fail (ns->ac.is);
}
else if (GNUNET_NO == helper_check)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"%s not found!\n",
NETJAIL_EXEC_SCRIPT);
- *ns->rv = 1;
+ GNUNET_TESTING_interpreter_fail (ns->ac.is);
}
GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start (
@@ -449,9 +555,57 @@ start_helper (struct NetJailState *ns, struct
helper = ns->helper[tbc->count - 1];
- msg = create_helper_init_msg_ (m_char,
- n_char,
- ns->plugin_name);
+ hkey = GNUNET_new (struct GNUNET_ShortHashCode);
+
+ plugin = topology->plugin;
+
+ if (0 == m)
+ {
+
+ GNUNET_CRYPTO_hash (&n, sizeof(n), &hc);
+ memcpy (hkey,
+ &hc,
+ sizeof (*hkey));
+ if (1 == GNUNET_CONTAINER_multishortmap_contains (topology->map_globals,
+ hkey))
+ {
+ node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
+ hkey);
+ if (NULL != node->plugin)
+ plugin = node->plugin;
+ }
+
+ }
+ else
+ {
+ GNUNET_CRYPTO_hash (&m, sizeof(m), &hc);
+ memcpy (hkey,
+ &hc,
+ sizeof (*hkey));
+ if (1 == GNUNET_CONTAINER_multishortmap_contains (topology->map_namespaces,
+ hkey))
+ {
+ namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
+ hkey);
+ GNUNET_CRYPTO_hash (&n, sizeof(n), &hc);
+ memcpy (hkey,
+ &hc,
+ sizeof (*hkey));
+ if (1 == GNUNET_CONTAINER_multishortmap_contains (namespace->nodes,
+ hkey))
+ {
+ node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
+ hkey);
+ if (NULL != node->plugin)
+ plugin = node->plugin;
+ }
+ }
+
+
+ }
+
+ msg = create_helper_init_msg_ (plugin);
+
GNUNET_array_append (ns->msg, ns->n_msg, &msg->header);
GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send (
@@ -466,7 +620,7 @@ start_helper (struct NetJailState *ns, struct
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Send handle is NULL!\n");
GNUNET_free (msg);
- *ns->rv = 1;
+ GNUNET_TESTING_interpreter_fail (ns->ac.is);
}
}
@@ -480,95 +634,28 @@ start_helper (struct NetJailState *ns, struct
*/
static void
netjail_exec_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
struct GNUNET_TESTING_Interpreter *is)
{
- char str_m[12];
- char str_n[12];
struct NetJailState *ns = cls;
struct GNUNET_CONFIGURATION_Handle *config =
GNUNET_CONFIGURATION_create ();
- for (int i = 1; i <= atoi (ns->global_n); i++)
+ for (int i = 1; i <= ns->known; i++)
{
- for (int j = 1; j <= atoi (ns->local_m); j++)
- {
- sprintf (str_n, "%d", i);
- sprintf (str_m, "%d", j);
- start_helper (ns, config,
- str_m,
- str_n);
- }
+ start_helper (ns, config,
+ i,
+ 0);
}
-}
-
-/**
- * This function checks on three different information.
- *
- * 1. Did all helpers start. This is only logged.
- * 2. Did all peer start.
- * In this case a GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED is send to all peers.
- * 3. Did all peers finished the test case. In this case interpreter_next will be called.
- *
- */
-static int
-netjail_start_finish (void *cls,
- GNUNET_SCHEDULER_TaskCallback cont,
- void *cont_cls)
-{
- unsigned int ret = GNUNET_NO;
- struct NetJailState *ns = cls;
- unsigned int total_number = atoi (ns->local_m) * atoi (ns->global_n);
- struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
- size_t msg_length;
- struct GNUNET_HELPER_Handle *helper;
- struct TestingSystemCount *tbc;
-
- if (ns->number_of_local_test_finished == total_number)
- {
- ret = GNUNET_YES;
- cont (cont_cls);
- }
-
- if (ns->number_of_testsystems_started == total_number)
- {
- ns->number_of_testsystems_started = 0;
- }
-
- if (ns->number_of_peers_started == total_number)
+ for (int i = 1; i <= ns->global_n; i++)
{
- for (int i = 1; i <= atoi (ns->global_n); i++)
+ for (int j = 1; j <= ns->local_m; j++)
{
- for (int j = 1; j <= atoi (ns->local_m); j++)
- {
- tbc = GNUNET_new (struct TestingSystemCount);
- tbc->ns = ns;
- // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone.
- tbc->count = (i - 1) * atoi (ns->local_m) + j + total_number;
-
- helper = ns->helper[tbc->count - 1 - total_number];
- msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
- reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
- reply->header.type = htons (
- GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
- reply->header.size = htons ((uint16_t) msg_length);
-
- GNUNET_array_append (ns->msg, ns->n_msg, &reply->header);
-
- struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send (
- helper,
- &reply->header,
- GNUNET_NO,
- &clear_msg,
- tbc);
-
- GNUNET_array_append (ns->shandle, ns->n_shandle, sh);
- }
+ start_helper (ns, config,
+ j,
+ i);
}
- ns->number_of_peers_started = 0;
}
- return ret;
}
@@ -576,32 +663,30 @@ netjail_start_finish (void *cls,
* Create command.
*
* @param label Name for the command.
- * @param local_m Number of nodes in a network namespace. //TODO make this a unsigned int
- * @param global_n Number of network namespaces. //TODO make this a unsigned int
- * @param plugin_name Name of the test case plugin the helper will load.
- * @param rv Pointer to the return value of the test.
+ * @param topology_config Configuration file for the test topology.
* @return command.
*/
struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label,
- char *local_m,
- char *global_n,
- char *plugin_name,
- unsigned int *rv)
+ const char *topology_config)
{
struct NetJailState *ns;
+ struct GNUNET_TESTING_NetjailTopology *topology =
+ GNUNET_TESTING_get_topo_from_file (topology_config);
+
ns = GNUNET_new (struct NetJailState);
- ns->local_m = local_m;
- ns->global_n = global_n;
- ns->plugin_name = plugin_name;
- ns->rv = rv;
+ ns->local_m = topology->nodes_m;
+ ns->global_n = topology->namespaces_n;
+ ns->known = topology->nodes_x;
+ ns->plugin_name = topology->plugin;
+ ns->topology = topology;
struct GNUNET_TESTING_Command cmd = {
.cls = ns,
.label = label,
.run = &netjail_exec_run,
- .finish = &netjail_start_finish,
+ .ac = &ns->ac,
.cleanup = &netjail_exec_cleanup,
.traits = &netjail_exec_traits
};
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c b/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
deleted file mode 100644
index 5e27a7a82..000000000
--- a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
+++ /dev/null
@@ -1,809 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2021 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-
-/**
- * @file testing/testing_api_cmd_hello_world.c
- * @brief Command to start the netjail peers.
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_testing_ng_lib.h"
-#include "testing_cmds.h"
-
-#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec_v2.sh"
-
-/**
- * Generic logging shortcut
- */
-#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
-
-/**
- * Struct to store messages send/received by the helper into a DLL
- *
- */
-struct HelperMessage
-{
-
- /**
- * Kept in a DLL.
- */
- struct HelperMessage *next;
-
- /**
- * Kept in a DLL.
- */
- struct HelperMessage *prev;
-
- /**
- * Size of the original message.
- */
- uint16_t bytes_msg;
-
- /* Followed by @e bytes_msg of msg.*/
-};
-
-
-/**
- * Struct to store information handed over to callbacks.
- *
- */
-struct NetJailState
-{
- /**
- * The complete topology information.
- */
- struct GNUNET_TESTING_NetjailTopology *topology;
-
- /**
- * Pointer to the return value of the test.
- *
- */
- unsigned int *rv;
-
- /**
- * Head of the DLL which stores messages received by the helper.
- *
- */
- struct HelperMessage *hp_messages_head;
-
- /**
- * Tail of the DLL which stores messages received by the helper.
- *
- */
- struct HelperMessage *hp_messages_tail;
-
- /**
- * Array with handles of helper processes.
- */
- struct GNUNET_HELPER_Handle **helper;
-
- /**
- * Size of the array NetJailState#helper.
- *
- */
- unsigned int n_helper;
-
- /**
- * Number of nodes in a natted subnet.
- *
- */
- unsigned int local_m;
-
- /**
- * Number of natted subnets.
- *
- */
- unsigned int global_n;
-
- /**
- * Number of global known nodes.
- *
- */
- unsigned int known;
-
- /**
- * The send handle for the helper
- */
- // struct GNUNET_HELPER_SendHandle **shandle;
-
- /**
- * Size of the array NetJailState#shandle.
- *
- */
- // unsigned int n_shandle;
-
- /**
- * The messages send to the helper.
- */
- struct GNUNET_MessageHeader **msg;
-
- /**
- * Size of the array NetJailState#msg.
- *
- */
- unsigned int n_msg;
-
- /**
- * Number of test environments started.
- *
- */
- unsigned int number_of_testsystems_started;
-
- /**
- * Number of peers started.
- *
- */
- unsigned int number_of_peers_started;
-
- /**
- * Number of local tests finished.
- *
- */
- unsigned int number_of_local_tests_finished;
-
- /**
- * Number of local tests prepared to finish.
- *
- */
- unsigned int number_of_local_tests_prepared;
-
- /**
- * Name of the test case plugin the helper will load.
- *
- */
- char *plugin_name;
-
- /**
- * HEAD of the DLL containing TestingSystemCount.
- *
- */
- struct TestingSystemCount *tbcs_head;
-
- /**
- * TAIL of the DLL containing TestingSystemCount.
- *
- */
- struct TestingSystemCount *tbcs_tail;
-};
-
-/**
- * Struct containing the number of the test environment and the NetJailState which
- * will be handed to callbacks specific to a test environment.
- */
-struct TestingSystemCount
-{
- /**
- * Kept in a DLL.
- */
- struct TestingSystemCount *next;
-
- /**
- * Kept in a DLL.
- */
- struct TestingSystemCount *prev;
-
- /**
- * The send handle for the helper
- */
- struct GNUNET_HELPER_SendHandle *shandle;// **shandle;
-
- /**
- * Size of the array NetJailState#shandle.
- *
- */
- // unsigned int n_shandle;
-
- /**
- * The number of the test environment.
- *
- */
- unsigned int count;
-
- /**
- * Struct to store information handed over to callbacks.
- *
- */
- struct NetJailState *ns;
-};
-
-/**
-* Code to clean up resource this cmd used.
-*
-* @param cls closure
-* @param cmd current CMD being cleaned up.
-*/
-static void
-netjail_exec_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
-{
- struct NetJailState *ns = cls;
- struct HelperMessage *message_pos;
- struct TestingSystemCount *tbc_pos;
-
- while (NULL != (message_pos = ns->hp_messages_head))
- {
- GNUNET_CONTAINER_DLL_remove (ns->hp_messages_head,
- ns->hp_messages_tail,
- message_pos);
- GNUNET_free (message_pos);
- }
- while (NULL != (tbc_pos = ns->tbcs_head))
- {
- GNUNET_CONTAINER_DLL_remove (ns->tbcs_head,
- ns->tbcs_tail,
- tbc_pos);
- GNUNET_free (tbc_pos);
- }
- GNUNET_free (ns);
-}
-
-
-/**
- * This function prepares an array with traits.
- *
- */
-static int
-netjail_exec_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- struct NetJailState *ns = cls;
- struct GNUNET_HELPER_Handle **helper = ns->helper;
- struct HelperMessage *hp_messages_head = ns->hp_messages_head;
-
-
- struct GNUNET_TESTING_Trait traits[] = {
- {
- .index = 0,
- .trait_name = "helper_handles",
- .ptr = (const void *) helper,
- },
- {
- .index = 1,
- .trait_name = "hp_msgs_head",
- .ptr = (const void *) hp_messages_head,
- },
- GNUNET_TESTING_trait_end ()
- };
-
- return GNUNET_TESTING_get_trait (traits,
- ret,
- trait,
- index);
-}
-
-
-/**
- * Offer handles to testing cmd helper from trait
- *
- * @param cmd command to extract the message from.
- * @param pt pointer to message.
- * @return #GNUNET_OK on success.
- */
-int
-GNUNET_TESTING_get_trait_helper_handles_v2 (
- const struct GNUNET_TESTING_Command *cmd,
- struct GNUNET_HELPER_Handle ***helper)
-{
- return cmd->traits (cmd->cls,
- (const void **) helper,
- "helper_handles",
- (unsigned int) 0);
-}
-
-
-/**
- * Continuation function from GNUNET_HELPER_send()
- *
- * @param cls closure
- * @param result #GNUNET_OK on success,
- * #GNUNET_NO if helper process died
- * #GNUNET_SYSERR during GNUNET_HELPER_stop
- */
-static void
-clear_msg (void *cls,
- int result)
-{
- struct TestingSystemCount *tbc = cls;
- struct NetJailState *ns = tbc->ns;
-
- GNUNET_assert (NULL != tbc->shandle);// [tbc->count - 1]);
- tbc->shandle = NULL;// [tbc->count - 1] = NULL;
- GNUNET_free (ns->msg[tbc->count - 1]);
- ns->msg[tbc->count - 1] = NULL;
-}
-
-
-/**
- * Functions with this signature are called whenever a
- * complete message is received by the tokenizer.
- *
- * Do not call GNUNET_SERVER_mst_destroy in callback
- *
- * @param cls closure
- * @param client identification of the client
- * @param message the actual message
- *
- * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
- */
-static int
-helper_mst (void *cls,
- const struct GNUNET_MessageHeader *message)
-{
- // struct TestingSystemCount *tbc = cls;
- struct NetJailState *ns = cls;// tbc->ns;
- struct HelperMessage *hp_msg;
-
- if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type))
- {
- ns->number_of_testsystems_started++;
- }
- else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED == ntohs (
- message->type))
- {
- ns->number_of_peers_started++;
- }
- else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED == ntohs (
- message->type))
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "received prepare msg %u\n",
- ns->number_of_local_tests_prepared);
- ns->number_of_local_tests_prepared++;
- }
- else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs (
- message->type))
- {
- ns->number_of_local_tests_finished++;
- }
- else
- {
- hp_msg = GNUNET_new (struct HelperMessage);
- hp_msg->bytes_msg = message->size;
- memcpy (&hp_msg[1], message, message->size);
- GNUNET_CONTAINER_DLL_insert (ns->hp_messages_head, ns->hp_messages_tail,
- hp_msg);
- }
-
- return GNUNET_OK;
-}
-
-
-/**
- * Callback called if there was an exception during execution of the helper.
- *
- */
-static void
-exp_cb (void *cls)
-{
- struct NetJailState *ns = cls;
- unsigned int *rv = ns->rv;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n");
- *rv = 1;
-}
-
-
-/**
- * Function to initialize a init message for the helper.
- *
- * @param m_char The actual node in a namespace. //TODO Change this to unsigned int
- * @param n_char The actual namespace. //TODO Change this to unsigned int
- * @param plugin_name Name of the test case plugin the helper will load.
- *
- */
-static struct GNUNET_CMDS_HelperInit *
-create_helper_init_msg_ (const char *plugin_name)
-{
- struct GNUNET_CMDS_HelperInit *msg;
- uint16_t plugin_name_len;
- uint16_t msg_size;
-
- GNUNET_assert (NULL != plugin_name);
- plugin_name_len = strlen (plugin_name);
- msg_size = sizeof(struct GNUNET_CMDS_HelperInit) + plugin_name_len;
- msg = GNUNET_malloc (msg_size);
- msg->header.size = htons (msg_size);
- msg->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT);
- msg->plugin_name_size = htons (plugin_name_len);
- GNUNET_memcpy ((char *) &msg[1],
- plugin_name,
- plugin_name_len);
- return msg;
-}
-
-
-/**
- * Function which start a single helper process.
- *
- */
-static void
-start_helper (struct NetJailState *ns, struct
- GNUNET_CONFIGURATION_Handle *config,
- unsigned int m,
- unsigned int n)
-{
- struct GNUNET_HELPER_Handle *helper;
- struct GNUNET_CMDS_HelperInit *msg;
- struct TestingSystemCount *tbc;
- char *m_char, *n_char, *global_n_char, *local_m_char, *known_char, *node_id,
- *plugin;
- pid_t pid;
- unsigned int script_num;
- struct GNUNET_ShortHashCode *hkey;
- struct GNUNET_HashCode hc;
- struct GNUNET_TESTING_NetjailTopology *topology = ns->topology;
- struct GNUNET_TESTING_NetjailNode *node;
- struct GNUNET_TESTING_NetjailNamespace *namespace;
- unsigned int *rv = ns->rv;
-
-
- if (0 == n)
- script_num = m - 1;
- else
- script_num = n - 1 + (n - 1) * ns->local_m + m + ns->known;
- pid = getpid ();
-
- GNUNET_asprintf (&m_char, "%u", m);
- GNUNET_asprintf (&n_char, "%u", n);
- GNUNET_asprintf (&local_m_char, "%u", ns->local_m);
- GNUNET_asprintf (&global_n_char, "%u",ns->global_n);
- GNUNET_asprintf (&known_char, "%u",ns->known);
- GNUNET_asprintf (&node_id, "%06x-%08x\n",
- pid,
- script_num);
-
-
- char *const script_argv[] = {NETJAIL_EXEC_SCRIPT,
- m_char,
- n_char,
- GNUNET_OS_get_libexec_binary_path (
- HELPER_CMDS_BINARY),
- global_n_char,
- local_m_char,
- node_id,
- NULL};
-
- unsigned int helper_check = GNUNET_OS_check_helper_binary (
- NETJAIL_EXEC_SCRIPT,
- GNUNET_YES,
- NULL);
-
- tbc = GNUNET_new (struct TestingSystemCount);
- tbc->ns = ns;
- if (0 == n)
- tbc->count = m;
- else
- tbc->count = (n - 1) * ns->local_m + m + ns->known;
-
- GNUNET_CONTAINER_DLL_insert (ns->tbcs_head,
- ns->tbcs_tail,
- tbc);
-
-
- if (GNUNET_NO == helper_check)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "No SUID for %s!\n",
- NETJAIL_EXEC_SCRIPT);
- *rv = 1;
- }
- else if (GNUNET_NO == helper_check)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%s not found!\n",
- NETJAIL_EXEC_SCRIPT);
- *rv = 1;
- }
-
- GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start (
- GNUNET_YES,
- NETJAIL_EXEC_SCRIPT,
- script_argv,
- &helper_mst,
- &exp_cb,
- ns));
-
- helper = ns->helper[tbc->count - 1];
-
- hkey = GNUNET_new (struct GNUNET_ShortHashCode);
-
- plugin = topology->plugin;
-
- if (0 == m)
- {
-
- GNUNET_CRYPTO_hash (&n, sizeof(n), &hc);
- memcpy (hkey,
- &hc,
- sizeof (*hkey));
- if (1 == GNUNET_CONTAINER_multishortmap_contains (topology->map_globals,
- hkey))
- {
- node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
- hkey);
- if (NULL != node->plugin)
- plugin = node->plugin;
- }
-
- }
- else
- {
- GNUNET_CRYPTO_hash (&m, sizeof(m), &hc);
- memcpy (hkey,
- &hc,
- sizeof (*hkey));
- if (1 == GNUNET_CONTAINER_multishortmap_contains (topology->map_namespaces,
- hkey))
- {
- namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
- hkey);
- GNUNET_CRYPTO_hash (&n, sizeof(n), &hc);
- memcpy (hkey,
- &hc,
- sizeof (*hkey));
- if (1 == GNUNET_CONTAINER_multishortmap_contains (namespace->nodes,
- hkey))
- {
- node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
- hkey);
- if (NULL != node->plugin)
- plugin = node->plugin;
- }
- }
-
-
- }
-
- msg = create_helper_init_msg_ (plugin);
-
- GNUNET_array_append (ns->msg, ns->n_msg, &msg->header);
-
- // GNUNET_array_append (tbc->shandle, tbc->n_shandle,
- tbc->shandle = GNUNET_HELPER_send (
- helper,
- &msg->header,
- GNUNET_NO,
- &clear_msg,
- tbc); // );
-
- if (NULL == tbc->shandle)// [tbc->count - 1])
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Send handle is NULL!\n");
- GNUNET_free (msg);
- *rv = 1;
- }
-}
-
-
-/**
-* This function starts a helper process for each node.
-*
-* @param cls closure.
-* @param cmd CMD being run.
-* @param is interpreter state.
-*/
-static void
-netjail_exec_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
- struct GNUNET_TESTING_Interpreter *is)
-{
- struct NetJailState *ns = cls;
- struct GNUNET_CONFIGURATION_Handle *config =
- GNUNET_CONFIGURATION_create ();
-
- for (int i = 1; i <= ns->known; i++)
- {
- start_helper (ns, config,
- i,
- 0);
- }
-
- for (int i = 1; i <= ns->global_n; i++)
- {
- for (int j = 1; j <= ns->local_m; j++)
- {
- start_helper (ns, config,
- j,
- i);
- }
- }
-}
-
-
-static void
-send_message_to_locals (
- unsigned int i,
- unsigned int j,
- struct NetJailState *ns,
- struct GNUNET_MessageHeader *header
- )
-{
- // unsigned int total_number = ns->local_m * ns->global_n + ns->known;
- struct GNUNET_HELPER_Handle *helper;
- struct TestingSystemCount *tbc;
-
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "send message to locals\n");
- tbc = GNUNET_new (struct TestingSystemCount);
- tbc->ns = ns;
- // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone.
- if (0 == i)
- tbc->count = j; // + total_number;
- else
- tbc->count = (i - 1) * ns->local_m + j + ns->known; // + total_number ;
-
- helper = ns->helper[tbc->count - 1];// - total_number];
-
- GNUNET_array_append (ns->msg, ns->n_msg, header);
-
- struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send (
- helper,
- header,
- GNUNET_NO,
- &clear_msg,
- tbc);
-
- tbc->shandle = sh;
- // GNUNET_array_append (tbc->shandle, tbc->n_shandle, sh);
-}
-
-
-static void
-send_all_local_tests_prepared (unsigned int i, unsigned int j, struct
- NetJailState *ns)
-{
- struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED *reply;
- size_t msg_length;
-
-
- msg_length = sizeof(struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED);
- reply = GNUNET_new (struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED);
- reply->header.type = htons (
- GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED);
- reply->header.size = htons ((uint16_t) msg_length);
-
- send_message_to_locals (i, j, ns, &reply->header);
-}
-
-
-static void
-send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns)
-{
-
- struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
- size_t msg_length;
-
-
- msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
- reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
- reply->header.type = htons (
- GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
- reply->header.size = htons ((uint16_t) msg_length);
-
- send_message_to_locals (i, j, ns, &reply->header);
-}
-
-
-/**
- * This function checks on three different information.
- *
- * 1. Did all helpers start. This is only logged.
- * 2. Did all peer start.
- * In this case a GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED is send to all peers.
- * 3. Did all peers finished the test case. In this case interpreter_next will be called.
- *
- */
-static int
-netjail_start_finish (void *cls,
- GNUNET_SCHEDULER_TaskCallback cont,
- void *cont_cls)
-{
- unsigned int ret = GNUNET_NO;
- struct NetJailState *ns = cls;
- unsigned int total_number = ns->local_m * ns->global_n + ns->known;
-
-
- if (ns->number_of_local_tests_finished == total_number)
- {
- ret = GNUNET_YES;
- cont (cont_cls);
- }
-
- if (ns->number_of_local_tests_prepared == total_number)
- {
- for (int i = 1; i <= ns->known; i++)
- {
- send_all_local_tests_prepared (0,i, ns);
- }
-
- for (int i = 1; i <= ns->global_n; i++)
- {
- for (int j = 1; j <= ns->local_m; j++)
- {
- send_all_local_tests_prepared (i,j, ns);
- }
- }
- }
-
- if (ns->number_of_testsystems_started == total_number)
- {
- ns->number_of_testsystems_started = 0;
- }
-
- if (ns->number_of_peers_started == total_number)
- {
- for (int i = 1; i <= ns->known; i++)
- {
- send_all_peers_started (0,i, ns);
- }
-
- for (int i = 1; i <= ns->global_n; i++)
- {
- for (int j = 1; j <= ns->local_m; j++)
- {
- send_all_peers_started (i,j, ns);
- }
- }
- ns->number_of_peers_started = 0;
- }
- return ret;
-}
-
-
-/**
- * Create command.
- *
- * @param label Name for the command.
- * @param topology_config Configuration file for the test topology.
- * @param rv Pointer to the return value of the test.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_netjail_start_testing_system_v2 (const char *label,
- const char *topology_config,
- unsigned int *rv)
-{
- struct NetJailState *ns;
-
- struct GNUNET_TESTING_NetjailTopology *topology =
- GNUNET_TESTING_get_topo_from_file (topology_config);
-
- ns = GNUNET_new (struct NetJailState);
- ns->rv = rv;
- ns->local_m = topology->nodes_m;
- ns->global_n = topology->namespaces_n;
- ns->known = topology->nodes_x;
- ns->plugin_name = topology->plugin;
- ns->topology = topology;
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = ns,
- .label = label,
- .run = &netjail_exec_run,
- .finish = &netjail_start_finish,
- .cleanup = &netjail_exec_cleanup,
- .traits = &netjail_exec_traits
- };
-
- return cmd;
-}
diff --git a/src/testing/testing_api_cmd_netjail_start_v2.c b/src/testing/testing_api_cmd_netjail_start_v2.c
deleted file mode 100644
index 7d802db6a..000000000
--- a/src/testing/testing_api_cmd_netjail_start_v2.c
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2021 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-
-/**
- * @file testing/testing_api_cmd_hello_world.c
- * @brief Command to start the netjail script.
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testing_ng_lib.h"
-
-#define NETJAIL_START_SCRIPT "./../testing/netjail_start_v2.sh"
-
-/**
- * Struct to hold information for callbacks.
- *
- */
-struct NetJailState
-{
- // Child Wait handle
- struct GNUNET_ChildWaitHandle *cwh;
-
- /**
- * Configuration file for the test topology.
- */
- char *topology_config;
-
- /**
- * The process id of the start script.
- */
- struct GNUNET_OS_Process *start_proc;
-
- // Flag indication if the script finished.
- unsigned int finished;
-};
-
-
-/**
- * The cleanup function of this cmd frees resources the cmd allocated.
- *
- */
-static void
-netjail_start_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
-{
- struct NetJailState *ns = cls;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "netjail_start_cleanup!\n");
-
- if (NULL != ns->cwh)
- {
- GNUNET_wait_child_cancel (ns->cwh);
- ns->cwh = NULL;
- }
- if (NULL != ns->start_proc)
- {
- GNUNET_assert (0 ==
- GNUNET_OS_process_kill (ns->start_proc,
- SIGTERM));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_OS_process_wait (ns->start_proc));
- GNUNET_OS_process_destroy (ns->start_proc);
- ns->start_proc = NULL;
- }
- GNUNET_free (ns);
-}
-
-
-/**
- * Trait function of this cmd does nothing.
- *
- */
-static int
-netjail_start_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- return GNUNET_OK;
-}
-
-
-/**
- * Callback which will be called if the setup script finished.
- *
- */
-static void
-child_completed_callback (void *cls,
- enum GNUNET_OS_ProcessStatusType type,
- long unsigned int exit_code)
-{
- struct NetJailState *ns = cls;
-
- if (0 == exit_code)
- {
- ns->finished = GNUNET_YES;
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Child completed with an error!\n");
- ns->finished = GNUNET_SYSERR;
- }
- GNUNET_OS_process_destroy (ns->start_proc);
- ns->start_proc = NULL;
-}
-
-
-
-/**
-* The run method starts the script which setup the network namespaces.
-*
-* @param cls closure.
-* @param cmd CMD being run.
-* @param is interpreter state.
-*/
-static void
-netjail_start_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
- struct GNUNET_TESTING_Interpreter *is)
-{
- struct NetJailState *ns = cls;
- char *pid;
- GNUNET_asprintf (&pid,
- "%u",
- getpid ());
- char *const script_argv[] = {NETJAIL_START_SCRIPT,
- ns->topology_config,
- pid,
- NULL};
- unsigned int helper_check = GNUNET_OS_check_helper_binary (
- NETJAIL_START_SCRIPT,
- GNUNET_YES,
- NULL);
-
- if (GNUNET_NO == helper_check)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "No SUID for %s!\n",
- NETJAIL_START_SCRIPT);
- GNUNET_TESTING_interpreter_fail ();
- }
- else if (GNUNET_NO == helper_check)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%s not found!\n",
- NETJAIL_START_SCRIPT);
- GNUNET_TESTING_interpreter_fail ();
- }
-
- ns->start_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
- NULL,
- NULL,
- NULL,
- NETJAIL_START_SCRIPT,
- script_argv);
-
- ns->cwh = GNUNET_wait_child (ns->start_proc,
- &child_completed_callback,
- ns);
- GNUNET_break (NULL != ns->cwh);
-}
-
-
-/**
- * This function checks the flag NetJailState#finished, if this cmd finished.
- *
- */
-static int
-netjail_start_finish (void *cls,
- GNUNET_SCHEDULER_TaskCallback cont,
- void *cont_cls)
-{
- struct NetJailState *ns = cls;
-
- if (ns->finished)
- {
- cont (cont_cls);
- }
- return ns->finished;
-}
-
-/**
- * Create command.
- *
- * @param label name for command.
- * @param topology_config Configuration file for the test topology.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_netjail_start_v2 (const char *label,
- char *topology_config)
-{
- struct NetJailState *ns;
-
- ns = GNUNET_new (struct NetJailState);
- ns->finished = GNUNET_NO;
- ns->topology_config = topology_config;
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = ns,
- .label = label,
- .run = &netjail_start_run,
- .finish = &netjail_start_finish,
- .cleanup = &netjail_start_cleanup,
- .traits = &netjail_start_traits
- };
-
- return cmd;
-}
diff --git a/src/testing/testing_api_cmd_netjail_stop.c b/src/testing/testing_api_cmd_netjail_stop.c
index 99084d9af..5033272a3 100644
--- a/src/testing/testing_api_cmd_netjail_stop.c
+++ b/src/testing/testing_api_cmd_netjail_stop.c
@@ -19,7 +19,7 @@
*/
/**
- * @file testing/testing_api_cmd_hello_world.c
+ * @file testing/testing_api_cmd_netjail_stop.c
* @brief Command to stop the netjail script.
* @author t3sserakt
*/
@@ -31,7 +31,7 @@
#define NETJAIL_STOP_SCRIPT "./../testing/netjail_stop.sh"
// Child Wait handle
-struct GNUNET_ChildWaitHandle *cwh;
+static struct GNUNET_ChildWaitHandle *cwh;
/**
* Struct to hold information for callbacks.
@@ -39,19 +39,21 @@ struct GNUNET_ChildWaitHandle *cwh;
*/
struct NetJailState
{
- // Number of local nodes in each namespace.
- char *local_m;
+ /**
+ * Context for our asynchronous completion.
+ */
+ struct GNUNET_TESTING_AsyncContext ac;
- // The number of namespaces.
- char *global_n;
+ /**
+ * Configuration file for the test topology.
+ */
+ char *topology_config;
/**
* The process id of the start script.
*/
struct GNUNET_OS_Process *stop_proc;
- // Flag indication if the script finished.
- unsigned int finished;
};
@@ -60,8 +62,7 @@ struct NetJailState
*
*/
static void
-netjail_stop_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
+netjail_stop_cleanup (void *cls)
{
struct NetJailState *ns = cls;
@@ -84,20 +85,6 @@ netjail_stop_cleanup (void *cls,
/**
- * Trait function of this cmd does nothing.
- *
- */
-static int
-netjail_stop_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- return GNUNET_OK;
-}
-
-
-/**
* Callback which will be called if the setup script finished.
*
*/
@@ -108,17 +95,17 @@ child_completed_callback (void *cls,
{
struct NetJailState *ns = cls;
- cwh = NULL;
+ cwh = NULL; // WTF? globals!?!?!
+ GNUNET_OS_process_destroy (ns->stop_proc);
+ ns->stop_proc = NULL;
if (0 == exit_code)
{
- ns->finished = GNUNET_YES;
+ GNUNET_TESTING_async_finish (&ns->ac);
}
else
{
- ns->finished = GNUNET_SYSERR;
+ GNUNET_TESTING_async_fail (&ns->ac);
}
- GNUNET_OS_process_destroy (ns->stop_proc);
- ns->stop_proc = NULL;
}
@@ -126,18 +113,21 @@ child_completed_callback (void *cls,
* The run method starts the script which deletes the network namespaces.
*
* @param cls closure.
-* @param cmd CMD being run.
* @param is interpreter state.
*/
static void
netjail_stop_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
struct GNUNET_TESTING_Interpreter *is)
{
struct NetJailState *ns = cls;
+ char *pid;
+
+ GNUNET_asprintf (&pid,
+ "%u",
+ getpid ());
char *const script_argv[] = {NETJAIL_STOP_SCRIPT,
- ns->local_m,
- ns->global_n,
+ ns->topology_config,
+ pid,
NULL};
unsigned int helper_check = GNUNET_OS_check_helper_binary (
NETJAIL_STOP_SCRIPT,
@@ -149,14 +139,14 @@ netjail_stop_run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"No SUID for %s!\n",
NETJAIL_STOP_SCRIPT);
- GNUNET_TESTING_interpreter_fail ();
+ GNUNET_TESTING_interpreter_fail (is);
}
else if (GNUNET_NO == helper_check)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"%s not found!\n",
NETJAIL_STOP_SCRIPT);
- GNUNET_TESTING_interpreter_fail ();
+ GNUNET_TESTING_interpreter_fail (is);
}
ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
@@ -170,56 +160,26 @@ netjail_stop_run (void *cls,
&child_completed_callback,
ns);
GNUNET_break (NULL != cwh);
-
}
-/**
- * This function checks the flag NetJailState#finished, if this cmd finished.
- *
- */
-static int
-netjail_stop_finish (void *cls,
- GNUNET_SCHEDULER_TaskCallback cont,
- void *cont_cls)
-{
- struct NetJailState *ns = cls;
-
- if (ns->finished)
- {
- cont (cont_cls);
- }
- return ns->finished;
-}
-
-
-/**
- * Create command.
- *
- * @param label name for command.
- * @param local_m Number of local nodes in each namespace.
- * @param global_n The number of namespaces.
- * @return command.
- */
struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_netjail_stop (const char *label,
- char *local_m,
- char *global_n)
+ char *topology_config)
{
struct NetJailState *ns;
ns = GNUNET_new (struct NetJailState);
- ns->local_m = local_m;
- ns->global_n = global_n;
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = ns,
- .label = label,
- .run = &netjail_stop_run,
- .finish = &netjail_stop_finish,
- .cleanup = &netjail_stop_cleanup,
- .traits = &netjail_stop_traits
- };
-
- return cmd;
+ ns->topology_config = topology_config;
+ {
+ struct GNUNET_TESTING_Command cmd = {
+ .cls = ns,
+ .label = label,
+ .run = &netjail_stop_run,
+ .ac = &ns->ac,
+ .cleanup = &netjail_stop_cleanup
+ };
+
+ return cmd;
+ }
}
diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem.c b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
index 0ae82a26a..d3754153d 100644
--- a/src/testing/testing_api_cmd_netjail_stop_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
@@ -42,9 +42,15 @@ struct StopHelperState
*/
struct GNUNET_HELPER_Handle **helper;
- char *local_m;
+ unsigned int local_m;
- char *global_n;
+ unsigned int global_n;
+
+ /**
+ * Number of global known nodes.
+ *
+ */
+ unsigned int known;
};
@@ -55,8 +61,7 @@ struct StopHelperState
* @param cmd current CMD being cleaned up.
*/
static void
-stop_testing_system_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
+stop_testing_system_cleanup (void *cls)
{
}
@@ -80,28 +85,40 @@ stop_testing_system_traits (void *cls,
* This function stops the helper process for each node.
*
* @param cls closure.
-* @param cmd CMD being run.
* @param is interpreter state.
*/
static void
stop_testing_system_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
struct GNUNET_TESTING_Interpreter *is)
{
struct StopHelperState *shs = cls;
struct GNUNET_HELPER_Handle **helper;
const struct GNUNET_TESTING_Command *start_helper_cmd;
- start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (
- shs->helper_start_label);
+ start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (NULL,
+ shs->
+ helper_start_label);
GNUNET_TESTING_get_trait_helper_handles (start_helper_cmd,
&helper);
- for (int i = 1; i <= atoi (shs->global_n); i++)
+ for (int i = 1; i <= shs->known; i++)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "i: %u\n",
+ i);
+ GNUNET_HELPER_stop (helper[i - 1],
+ GNUNET_YES);
+ }
+
+ for (int i = 1; i <= shs->global_n; i++)
{
- for (int j = 1; j <= atoi (shs->local_m); j++)
+ for (int j = 1; j <= shs->local_m; j++)
{
- GNUNET_HELPER_stop (helper[(i - 1) * atoi (shs->local_m) + j - 1],
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "i: %u j: %u\n",
+ i,
+ j);
+ GNUNET_HELPER_stop (helper[(i - 1) * shs->local_m + j + shs->known - 1],
GNUNET_YES);
}
}
@@ -110,26 +127,27 @@ stop_testing_system_run (void *cls,
/**
* Create command.
- * @param helper_start_label label of the cmd to start the test system.
+ *
* @param label name for command.
- * @param .
- * @param local_m Number of nodes in a network namespace. //TODO make this a unsigned int
- * @param global_n Number of network namespaces. //TODO make this a unsigned int
+ * @param helper_start_label label of the cmd to start the test system.
+ * @param topology_config Configuration file for the test topology.
* @return command.
*/
struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_stop_testing_system (const char *label,
const char *helper_start_label,
- char *local_m,
- char *global_n
- )
+ const char *topology_config)
{
struct StopHelperState *shs;
+ struct GNUNET_TESTING_NetjailTopology *topology =
+ GNUNET_TESTING_get_topo_from_file (topology_config);
+
shs = GNUNET_new (struct StopHelperState);
shs->helper_start_label = helper_start_label;
- shs->local_m = local_m;
- shs->global_n = global_n;
+ shs->local_m = topology->nodes_m;
+ shs->global_n = topology->namespaces_n;
+ shs->known = topology->nodes_x;
struct GNUNET_TESTING_Command cmd = {
.cls = shs,
diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c b/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c
deleted file mode 100644
index 6ce106eaa..000000000
--- a/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2021 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-
-/**
- * @file testing/testing_api_cmd_hello_world.c
- * @brief Command to start the netjail peers.
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_testing_ng_lib.h"
-#include "testing_cmds.h"
-
-
-/**
- * Struct to store information handed over to callbacks.
- *
- */
-struct StopHelperState
-{
-
- const char *helper_start_label;
-
- /**
- * The process handle
- */
- struct GNUNET_HELPER_Handle **helper;
-
- unsigned int local_m;
-
- unsigned int global_n;
-
- /**
- * Number of global known nodes.
- *
- */
- unsigned int known;
-};
-
-
-/**
-* Code to clean up resource this cmd used.
-*
-* @param cls closure
-* @param cmd current CMD being cleaned up.
-*/
-static void
-stop_testing_system_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
-{
-
-}
-
-
-/**
- * Trait function of this cmd does nothing.
- *
- */
-static int
-stop_testing_system_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- return GNUNET_OK;
-}
-
-
-/**
-* This function stops the helper process for each node.
-*
-* @param cls closure.
-* @param cmd CMD being run.
-* @param is interpreter state.
-*/
-static void
-stop_testing_system_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
- struct GNUNET_TESTING_Interpreter *is)
-{
- struct StopHelperState *shs = cls;
- struct GNUNET_HELPER_Handle **helper;
- const struct GNUNET_TESTING_Command *start_helper_cmd;
-
- start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (
- shs->helper_start_label);
- GNUNET_TESTING_get_trait_helper_handles (start_helper_cmd,
- &helper);
-
- for (int i = 1; i <= shs->known; i++)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "i: %u\n",
- i);
- GNUNET_HELPER_stop (helper[i - 1],
- GNUNET_YES);
- }
-
- for (int i = 1; i <= shs->global_n; i++)
- {
- for (int j = 1; j <= shs->local_m; j++)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "i: %u j: %u\n",
- i,
- j);
- GNUNET_HELPER_stop (helper[(i - 1) * shs->local_m + j + shs->known - 1],
- GNUNET_YES);
- }
- }
-}
-
-
-/**
- * Create command.
- *
- * @param label name for command.
- * @param helper_start_label label of the cmd to start the test system.
- * @param topology_config Configuration file for the test topology.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_stop_testing_system_v2 (const char *label,
- const char *helper_start_label,
- const char *topology_config)
-{
- struct StopHelperState *shs;
-
- struct GNUNET_TESTING_NetjailTopology *topology =
- GNUNET_TESTING_get_topo_from_file (topology_config);
-
- shs = GNUNET_new (struct StopHelperState);
- shs->helper_start_label = helper_start_label;
- shs->local_m = topology->nodes_m;
- shs->global_n = topology->namespaces_n;
- shs->known = topology->nodes_x;
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = shs,
- .label = label,
- .run = &stop_testing_system_run,
- .cleanup = &stop_testing_system_cleanup,
- .traits = &stop_testing_system_traits
- };
-
- return cmd;
-}
diff --git a/src/testing/testing_api_cmd_netjail_stop_v2.c b/src/testing/testing_api_cmd_netjail_stop_v2.c
deleted file mode 100644
index 8c1f3cedd..000000000
--- a/src/testing/testing_api_cmd_netjail_stop_v2.c
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2021 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-
-/**
- * @file testing/testing_api_cmd_hello_world.c
- * @brief Command to stop the netjail script.
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testing_ng_lib.h"
-
-
-#define NETJAIL_STOP_SCRIPT "./../testing/netjail_stop_v2.sh"
-
-// Child Wait handle
-static struct GNUNET_ChildWaitHandle *cwh;
-
-/**
- * Struct to hold information for callbacks.
- *
- */
-struct NetJailState
-{
- /**
- * Configuration file for the test topology.
- */
- char *topology_config;
-
- /**
- * The process id of the start script.
- */
- struct GNUNET_OS_Process *stop_proc;
-
- // Flag indication if the script finished.
- unsigned int finished;
-};
-
-
-/**
- * The cleanup function of this cmd frees resources the cmd allocated.
- *
- */
-static void
-netjail_stop_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
-{
- struct NetJailState *ns = cls;
-
- if (NULL != cwh)
- {
- GNUNET_wait_child_cancel (cwh);
- cwh = NULL;
- }
- if (NULL != ns->stop_proc)
- {
- GNUNET_assert (0 ==
- GNUNET_OS_process_kill (ns->stop_proc,
- SIGKILL));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_OS_process_wait (ns->stop_proc));
- GNUNET_OS_process_destroy (ns->stop_proc);
- ns->stop_proc = NULL;
- }
-}
-
-
-/**
- * Trait function of this cmd does nothing.
- *
- */
-static int
-netjail_stop_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- return GNUNET_OK;
-}
-
-
-/**
- * Callback which will be called if the setup script finished.
- *
- */
-static void
-child_completed_callback (void *cls,
- enum GNUNET_OS_ProcessStatusType type,
- long unsigned int exit_code)
-{
- struct NetJailState *ns = cls;
-
- cwh = NULL;
- if (0 == exit_code)
- {
- ns->finished = GNUNET_YES;
- }
- else
- {
- ns->finished = GNUNET_SYSERR;
- }
- GNUNET_OS_process_destroy (ns->stop_proc);
- ns->stop_proc = NULL;
-}
-
-
-/**
-* The run method starts the script which deletes the network namespaces.
-*
-* @param cls closure.
-* @param cmd CMD being run.
-* @param is interpreter state.
-*/
-static void
-netjail_stop_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
- struct GNUNET_TESTING_Interpreter *is)
-{
- struct NetJailState *ns = cls;
- char *pid;
- GNUNET_asprintf (&pid,
- "%u",
- getpid ());
- char *const script_argv[] = {NETJAIL_STOP_SCRIPT,
- ns->topology_config,
- pid,
- NULL};
- unsigned int helper_check = GNUNET_OS_check_helper_binary (
- NETJAIL_STOP_SCRIPT,
- GNUNET_YES,
- NULL);
-
- if (GNUNET_NO == helper_check)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "No SUID for %s!\n",
- NETJAIL_STOP_SCRIPT);
- GNUNET_TESTING_interpreter_fail ();
- }
- else if (GNUNET_NO == helper_check)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%s not found!\n",
- NETJAIL_STOP_SCRIPT);
- GNUNET_TESTING_interpreter_fail ();
- }
-
- ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
- NULL,
- NULL,
- NULL,
- NETJAIL_STOP_SCRIPT,
- script_argv);
-
- cwh = GNUNET_wait_child (ns->stop_proc,
- &child_completed_callback,
- ns);
- GNUNET_break (NULL != cwh);
-
-}
-
-
-/**
- * This function checks the flag NetJailState#finished, if this cmd finished.
- *
- */
-static int
-netjail_stop_finish (void *cls,
- GNUNET_SCHEDULER_TaskCallback cont,
- void *cont_cls)
-{
- struct NetJailState *ns = cls;
-
- if (ns->finished)
- {
- cont (cont_cls);
- }
- return ns->finished;
-}
-
-
-/**
- * Create command.
- *
- * @param label name for command.
- * @param topology_config Configuration file for the test topology.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_netjail_stop_v2 (const char *label,
- char *topology_config)
-{
- struct NetJailState *ns;
-
- ns = GNUNET_new (struct NetJailState);
- ns->topology_config = topology_config;
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = ns,
- .label = label,
- .run = &netjail_stop_run,
- .finish = &netjail_stop_finish,
- .cleanup = &netjail_stop_cleanup,
- .traits = &netjail_stop_traits
- };
-
- return cmd;
-}
diff --git a/src/testing/testing_api_cmd_send_peer_ready.c b/src/testing/testing_api_cmd_send_peer_ready.c
index 016837214..8b4c11deb 100644
--- a/src/testing/testing_api_cmd_send_peer_ready.c
+++ b/src/testing/testing_api_cmd_send_peer_ready.c
@@ -53,13 +53,13 @@ struct SendPeerReadyState
* Trait function of this cmd does nothing.
*
*/
-static int
+static enum GNUNET_GenericReturnValue
send_peer_ready_traits (void *cls,
const void **ret,
const char *trait,
unsigned int index)
{
- return GNUNET_OK;
+ return GNUNET_NO;
}
@@ -68,8 +68,7 @@ send_peer_ready_traits (void *cls,
*
*/
static void
-send_peer_ready_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
+send_peer_ready_cleanup (void *cls)
{
struct SendPeerReadyState *sprs = cls;
@@ -84,7 +83,6 @@ send_peer_ready_cleanup (void *cls,
*/
static void
send_peer_ready_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
struct GNUNET_TESTING_Interpreter *is)
{
struct SendPeerReadyState *sprs = cls;
@@ -115,14 +113,15 @@ GNUNET_TESTING_cmd_send_peer_ready (const char *label,
sprs = GNUNET_new (struct SendPeerReadyState);
sprs->write_message = write_message;
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = sprs,
- .label = label,
- .run = &send_peer_ready_run,
- .cleanup = &send_peer_ready_cleanup,
- .traits = &send_peer_ready_traits
- };
-
- return cmd;
+ {
+ struct GNUNET_TESTING_Command cmd = {
+ .cls = sprs,
+ .label = label,
+ .run = &send_peer_ready_run,
+ .cleanup = &send_peer_ready_cleanup,
+ .traits = &send_peer_ready_traits
+ };
+
+ return cmd;
+ }
}
diff --git a/src/testing/testing_api_cmd_system_create.c b/src/testing/testing_api_cmd_system_create.c
index f3a0b1a4c..820adf1bd 100644
--- a/src/testing/testing_api_cmd_system_create.c
+++ b/src/testing/testing_api_cmd_system_create.c
@@ -46,7 +46,6 @@ struct TestSystemState
*/
static void
system_create_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
struct GNUNET_TESTING_Interpreter *is)
{
struct TestSystemState *tss = cls;
@@ -115,8 +114,7 @@ GNUNET_TESTING_get_trait_test_system (const struct
*
*/
static void
-system_create_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
+system_create_cleanup (void *cls)
{
struct TestSystemState *tss = cls;
diff --git a/src/testing/testing_api_cmd_system_destroy.c b/src/testing/testing_api_cmd_system_destroy.c
index 5ed0c2fd2..338123d91 100644
--- a/src/testing/testing_api_cmd_system_destroy.c
+++ b/src/testing/testing_api_cmd_system_destroy.c
@@ -46,17 +46,18 @@ struct TestSystemState
*/
static void
system_destroy_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
struct GNUNET_TESTING_Interpreter *is)
{
struct TestSystemState *tss = cls;
const struct GNUNET_TESTING_Command *system_cmd;
struct GNUNET_TESTING_System *tl_system;
- system_cmd = GNUNET_TESTING_interpreter_lookup_command (tss->create_label);
+ system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
+ tss->create_label);
GNUNET_TESTING_get_trait_test_system (system_cmd,
&tl_system);
- GNUNET_TESTING_system_destroy (tl_system, GNUNET_YES);
+ GNUNET_TESTING_system_destroy (tl_system,
+ GNUNET_YES);
}
@@ -65,8 +66,7 @@ system_destroy_run (void *cls,
*
*/
static void
-system_destroy_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
+system_destroy_cleanup (void *cls)
{
struct TestSystemState *tss = cls;
@@ -78,7 +78,7 @@ system_destroy_cleanup (void *cls,
* Trait function of this cmd does nothing.
*
*/
-static int
+static enum GNUNET_GenericReturnValue
system_destroy_traits (void *cls,
const void **ret,
const char *trait,
@@ -103,14 +103,15 @@ GNUNET_TESTING_cmd_system_destroy (const char *label,
tss = GNUNET_new (struct TestSystemState);
tss->create_label = create_label;
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = tss,
- .label = label,
- .run = &system_destroy_run,
- .cleanup = &system_destroy_cleanup,
- .traits = &system_destroy_traits
- };
-
- return cmd;
+ {
+ struct GNUNET_TESTING_Command cmd = {
+ .cls = tss,
+ .label = label,
+ .run = &system_destroy_run,
+ .cleanup = &system_destroy_cleanup,
+ .traits = &system_destroy_traits
+ };
+
+ return cmd;
+ }
}
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c
index bb04280a9..3727d2543 100644
--- a/src/testing/testing_api_loop.c
+++ b/src/testing/testing_api_loop.c
@@ -24,67 +24,68 @@
* @author Christian Grothoff (GNU Taler testing)
* @author Marcello Stanisci (GNU Taler testing)
* @author t3sserakt
-*/
+ */
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
#include "testing.h"
-#define CHECK_FINISHED_PERIOD \
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
-
-struct GNUNET_TESTING_Interpreter *is;
-
-
/**
- * Closure used to sync an asynchronous with an synchronous command.
+ * Global state of the interpreter, used by a command
+ * to access information about other commands.
*/
-struct SyncTaskClosure
+struct GNUNET_TESTING_Interpreter
{
/**
- * The asynchronous command the synchronous command waits for.
+ * Function to call with the test result.
*/
- const struct GNUNET_TESTING_Command *async_cmd;
+ GNUNET_TESTING_ResultCallback rc;
/**
- * The synchronous command that waits for the asynchronous command.
+ * Closure for @e rc.
*/
- const struct GNUNET_TESTING_Command *sync_cmd;
+ void *rc_cls;
/**
- * The interpreter of the test.
+ * Commands the interpreter will run.
*/
- struct GNUNET_TESTING_Interpreter *is;
-};
+ struct GNUNET_TESTING_Command *commands;
+ /**
+ * Interpreter task (if one is scheduled).
+ */
+ struct GNUNET_SCHEDULER_Task *task;
-/**
-* Closure used to run the finish task.
-*/
-struct FinishTaskClosure
-{
+ /**
+ * Final task that returns the result.
+ */
+ struct GNUNET_SCHEDULER_Task *final_task;
/**
- * The asynchronous command the synchronous command waits for.
+ * Task run on timeout.
*/
- const struct GNUNET_TESTING_Command *cmd;
+ struct GNUNET_SCHEDULER_Task *timeout_task;
/**
- * The interpreter of the test.
+ * Instruction pointer. Tells #interpreter_run() which instruction to run
+ * next. Need (signed) int because it gets -1 when rewinding the
+ * interpreter to the first CMD.
*/
- struct GNUNET_TESTING_Interpreter *is;
+ int ip;
+
+ /**
+ * Result of the testcases, #GNUNET_OK on success
+ */
+ enum GNUNET_GenericReturnValue result;
+
};
-/**
- * Lookup command by label.
- *
- * @param label label to look for
- * @return NULL if command was not found
- */
const struct GNUNET_TESTING_Command *
-GNUNET_TESTING_interpreter_lookup_command (const char *label)
+GNUNET_TESTING_interpreter_lookup_command (
+ struct GNUNET_TESTING_Interpreter *is,
+ const char *label)
{
if (NULL == label)
{
@@ -103,7 +104,7 @@ GNUNET_TESTING_interpreter_lookup_command (const char *label)
label)) )
return cmd;
- if (GNUNET_TESTING_cmd_is_batch (cmd))
+ if (GNUNET_TESTING_cmd_is_batch_ (cmd))
{
#define BATCH_INDEX 1
struct GNUNET_TESTING_Command *batch;
@@ -111,7 +112,7 @@ GNUNET_TESTING_interpreter_lookup_command (const char *label)
struct GNUNET_TESTING_Command *icmd;
const struct GNUNET_TESTING_Command *match;
- current = GNUNET_TESTING_cmd_batch_get_current (cmd);
+ current = GNUNET_TESTING_cmd_batch_get_current_ (cmd);
GNUNET_assert (GNUNET_OK ==
GNUNET_TESTING_get_trait_cmd (cmd,
BATCH_INDEX,
@@ -134,10 +135,58 @@ GNUNET_TESTING_interpreter_lookup_command (const char *label)
}
}
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Command not found: %s\n",
+ "Command `%s' not found\n",
label);
return NULL;
+}
+
+
+/**
+ * Finish the test run, return the final result.
+ *
+ * @param cls the `struct GNUNET_TESTING_Interpreter`
+ */
+static void
+finish_test (void *cls)
+{
+ struct GNUNET_TESTING_Interpreter *is = cls;
+ struct GNUNET_TESTING_Command *cmd;
+ const char *label;
+ is->final_task = NULL;
+ label = is->commands[is->ip].label;
+ if (NULL == label)
+ label = "END";
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Interpreter finishes at `%s' with status %d\n",
+ label,
+ is->result);
+ for (unsigned int j = 0;
+ NULL != (cmd = &is->commands[j])->label;
+ j++)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Cleaning up cmd %s\n",
+ cmd->label);
+ cmd->cleanup (cmd->cls);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Cleaned up cmd %s\n",
+ cmd->label);
+ }
+ if (NULL != is->task)
+ {
+ GNUNET_SCHEDULER_cancel (is->task);
+ is->task = NULL;
+ }
+ if (NULL != is->timeout_task)
+ {
+ GNUNET_SCHEDULER_cancel (is->timeout_task);
+ is->timeout_task = NULL;
+ }
+ GNUNET_free (is->commands);
+ is->rc (is->rc_cls,
+ is->result);
+ GNUNET_free (is);
}
@@ -163,15 +212,10 @@ interpreter_next (void *cls)
if (GNUNET_SYSERR == is->result)
return; /* ignore, we already failed! */
- if (GNUNET_TESTING_cmd_is_batch (cmd))
- {
- GNUNET_TESTING_cmd_batch_next (is);
- }
- else
- {
- cmd->finish_time = GNUNET_TIME_absolute_get ();
+ cmd->finish_time = GNUNET_TIME_absolute_get ();
+ if ( (! GNUNET_TESTING_cmd_is_batch_ (cmd)) ||
+ (! GNUNET_TESTING_cmd_batch_next_ (cmd->cls)) )
is->ip++;
- }
if (0 == (ipc % 1000))
{
if (0 != ipc)
@@ -188,253 +232,44 @@ interpreter_next (void *cls)
}
-/**
- * This function checks if the finish function of a command returns GNUNET_YES, when the command is finished. In this case the finish function might have called interpreter_next. IF GNUNET_NO was returned this function is added to the scheduler again. In case of an error interpreter_fail is called.
- *
- */
-static void
-run_finish_task_next (void *cls)
-{
- struct FinishTaskClosure *ftc = cls;
- const struct GNUNET_TESTING_Command *cmd = ftc->cmd;
- struct GNUNET_TESTING_Interpreter *is = ftc->is;
- unsigned int finished = cmd->finish (cmd->cls, &interpreter_next, is);
-
- if (GNUNET_YES == finished)
- {
- is->finish_task = NULL;
- }
- else if (GNUNET_NO == finished)
- {
- is->finish_task = GNUNET_SCHEDULER_add_delayed (CHECK_FINISHED_PERIOD,
- &run_finish_task_next, ftc);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Next task finished with an error.\n");
- GNUNET_TESTING_interpreter_fail ();
- }
-
-}
-
-
-/**
- * This function checks if the finish function of an asynchronous command returns GNUNET_YES, when the command is finished. In this case the finish function might have called interpreter_next. IF GNUNET_NO was returned this function is added to the scheduler again. In case of an error interpreter_fail is called.
- *
- * //TODO run_finish_task_next and this function can be merged.
- *
- */
-static void
-run_finish_task_sync (void *cls)
-{
- struct SyncTaskClosure *stc = cls;
- const struct GNUNET_TESTING_Command *cmd = stc->async_cmd;
- const struct GNUNET_TESTING_Command *sync_cmd = stc->sync_cmd;
- struct FinishTaskClosure *ftc;
- struct SyncState *sync_state = sync_cmd->cls;
- struct GNUNET_SCHEDULER_Task *finish_task = sync_state->finish_task;
- unsigned int finished = cmd->finish (cmd->cls, &interpreter_next, is);
-
- GNUNET_assert (NULL != finish_task);
- ftc = GNUNET_new (struct FinishTaskClosure);
- ftc->cmd = stc->sync_cmd;
- ftc->is = stc->is;
- struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
- if (cmd->default_timeout.rel_value_us < now.abs_value_us
- - sync_state->start_finish_time.abs_value_us)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "The command with label %s did not finish its asynchronous task in time.\n",
- cmd->label);
- GNUNET_TESTING_interpreter_fail ();
- }
-
- if (GNUNET_YES == finished)
- {
- finish_task = NULL;
- }
- else if (GNUNET_NO == finished)
- {
- finish_task = GNUNET_SCHEDULER_add_delayed (CHECK_FINISHED_PERIOD,
- &run_finish_task_sync, stc);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Sync task finished with an error.\n");
- GNUNET_TESTING_interpreter_fail ();
- }
-}
-
-
-/**
- * run method of the command created by the interpreter to wait for another command to finish.
- *
- */
-static void
-start_finish_on_ref (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
- struct GNUNET_TESTING_Interpreter *is)
-{
- struct SyncState *sync_state = cls;
- struct SyncTaskClosure *stc;
- const struct GNUNET_TESTING_Command *async_cmd;
-
- async_cmd = sync_state->async_cmd;
- stc = GNUNET_new (struct SyncTaskClosure);
- stc->async_cmd = async_cmd;
- stc->sync_cmd = cmd;
- stc->is = is;
- sync_state->start_finish_time = GNUNET_TIME_absolute_get ();
- sync_state->finish_task = GNUNET_SCHEDULER_add_delayed (
- CHECK_FINISHED_PERIOD,
- &run_finish_task_sync,
- stc);
-}
-
-
-/**
- * Create (synchronous) command that waits for another command to finish.
- * If @a cmd_ref did not finish after @a timeout, this command will fail
- * the test case.
- *
- * @param finish_label label for this command
- * @param cmd_ref reference to a previous command which we should
- * wait for (call `finish()` on)
- * @param timeout how long to wait at most for @a cmd_ref to finish
- * @return a finish-command.
- */
-const struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_finish (const char *finish_label,
- const char *cmd_ref,
- struct GNUNET_TIME_Relative timeout)
-{
- const struct GNUNET_TESTING_Command *async_cmd;
- struct SyncState *sync_state;
-
- async_cmd = GNUNET_TESTING_interpreter_lookup_command (cmd_ref);
- sync_state = GNUNET_new (struct SyncState);
- sync_state->async_cmd = async_cmd;
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = sync_state,
- .label = finish_label,
- .run = &start_finish_on_ref,
- .asynchronous_finish = GNUNET_NO
- };
-
- return cmd;
-}
-
-
-const struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_make_unblocking (const struct GNUNET_TESTING_Command cmd)
-{
-
- GNUNET_assert (NULL != cmd.finish);
- const struct GNUNET_TESTING_Command async_cmd = {
- .cls = cmd.cls,
- .label = cmd.label,
- .run = cmd.run,
- .cleanup = cmd.cleanup,
- .traits = cmd.traits,
- .finish = cmd.finish,
- .asynchronous_finish = GNUNET_YES
- };
-
- return async_cmd;
-}
-
-
-/**
- * Current command failed, clean up and fail the test case.
- *
- * @param is interpreter of the test
- */
void
-GNUNET_TESTING_interpreter_fail ()
+GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is)
{
struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
if (GNUNET_SYSERR == is->result)
+ {
+ GNUNET_break (0);
return; /* ignore, we already failed! */
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "interpreter_fail!\n");
-
+ }
if (NULL != cmd)
{
- while (GNUNET_TESTING_cmd_is_batch (cmd))
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed at command `%s'\n",
+ cmd->label);
+ while (GNUNET_TESTING_cmd_is_batch_ (cmd))
{
- cmd = GNUNET_TESTING_cmd_batch_get_current (cmd);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Batch is at command `%s'\n",
+ cmd = GNUNET_TESTING_cmd_batch_get_current_ (cmd);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed in batch at command `%s'\n",
cmd->label);
}
-
}
else
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "cmd is NULL.\n");
+ "Failed with CMD being NULL!\n");
}
-
- if (NULL == cmd->label)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed at command `%s'\n",
- cmd->label);
-
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "cmd->label is NULL.\n");
- }
-
is->result = GNUNET_SYSERR;
- GNUNET_SCHEDULER_shutdown ();
-}
-
-
-/**
- * Create command array terminator.
- *
- * @return a end-command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_end (void)
-{
- static struct GNUNET_TESTING_Command cmd;
- cmd.label = NULL;
- cmd.shutdown_on_end = GNUNET_YES;
-
- return cmd;
-}
-
-/**
- * Create command array terminator without shutdown.
- *
- * @return a end-command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_end_without_shutdown (void)
-{
- static struct GNUNET_TESTING_Command cmd;
- cmd.label = NULL;
- cmd.shutdown_on_end = GNUNET_NO;
-
- return cmd;
+ GNUNET_assert (NULL == is->final_task);
+ is->final_task = GNUNET_SCHEDULER_add_now (&finish_test,
+ is);
}
-/**
- * Obtain current label.
- */
const char *
-GNUNET_TESTING_interpreter_get_current_label (struct
- GNUNET_TESTING_Interpreter *is)
+GNUNET_TESTING_interpreter_get_current_label (
+ struct GNUNET_TESTING_Interpreter *is)
{
struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
@@ -450,189 +285,195 @@ GNUNET_TESTING_interpreter_get_current_label (struct
static void
interpreter_run (void *cls)
{
- struct FinishTaskClosure *ftc;
struct GNUNET_TESTING_Interpreter *is = cls;
struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
- bool shutdown_on_end = cmd->shutdown_on_end;
is->task = NULL;
-
if (NULL == cmd->label)
{
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Running command END %p %u\n",
- is,
- shutdown_on_end);
+ "Running command END\n");
is->result = GNUNET_OK;
- if (GNUNET_YES == shutdown_on_end)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Running command END with shutdown\n");
- GNUNET_SCHEDULER_shutdown ();
- }
+ finish_test (is);
return;
}
- else if (NULL != cmd)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Running command `%s' %p\n",
- cmd->label,
- is);
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Running command `%s'\n",
+ cmd->label);
cmd->start_time
= cmd->last_req_time
= GNUNET_TIME_absolute_get ();
cmd->num_tries = 1;
+ if (NULL != cmd->ac)
+ {
+ cmd->ac->is = is;
+ cmd->ac->cont = &interpreter_next;
+ cmd->ac->cont_cls = is;
+ cmd->ac->finished = GNUNET_NO;
+ }
cmd->run (cmd->cls,
- cmd,
is);
- if ((NULL != cmd->finish) && (GNUNET_NO == cmd->asynchronous_finish))
+ if (NULL == cmd->ac)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Next task will not be called directly!\n");
- ftc = GNUNET_new (struct FinishTaskClosure);
- ftc->cmd = cmd;
- ftc->is = is;
- is->finish_task = GNUNET_SCHEDULER_add_delayed (CHECK_FINISHED_PERIOD,
- &run_finish_task_next,
- ftc);
+ interpreter_next (is);
}
- else
+ else if ( (cmd->asynchronous_finish) &&
+ (NULL != cmd->ac->cont) )
{
+ cmd->ac->cont = NULL;
interpreter_next (is);
}
}
/**
- * Function run when the test terminates (good or bad).
- * Cleans up our state.
+ * Function run when the test terminates (good or bad) with timeout.
*
- * @param cls the interpreter state.
+ * @param cls the interpreter state
*/
static void
-do_shutdown (void *cls)
+do_timeout (void *cls)
{
- (void) cls;
- struct GNUNET_TESTING_Command *cmd;
- const char *label;
+ struct GNUNET_TESTING_Interpreter *is = cls;
- label = is->commands[is->ip].label;
- if (NULL == label)
- label = "END";
+ is->timeout_task = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Terminating test due to global timeout\n");
+ is->result = GNUNET_SYSERR;
+ finish_test (is);
+}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Executing shutdown at `%s'\n",
- label);
- for (unsigned int j = 0;
- NULL != (cmd = &is->commands[j])->label;
- j++) {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Cleaning up cmd %s\n",
- cmd->label);
- cmd->cleanup (cmd->cls,
- cmd);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Cleaned up cmd %s\n",
- cmd->label);
- }
-
- if (NULL != is->finish_task)
- {
- GNUNET_SCHEDULER_cancel (is->finish_task);
- cmd->finish_task = NULL;
- }
+void
+GNUNET_TESTING_run (struct GNUNET_TESTING_Command *commands,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_TESTING_ResultCallback rc,
+ void *rc_cls)
+{
+ struct GNUNET_TESTING_Interpreter *is;
+ unsigned int i;
- if (NULL != is->task)
- {
- GNUNET_SCHEDULER_cancel (is->task);
- is->task = NULL;
- }
- if (NULL != is->timeout_task)
- {
- GNUNET_SCHEDULER_cancel (is->timeout_task);
- is->timeout_task = NULL;
- }
- GNUNET_free (is->commands);
+ is = GNUNET_new (struct GNUNET_TESTING_Interpreter);
+ is->rc = rc;
+ is->rc_cls = rc_cls;
+ /* get the number of commands */
+ for (i = 0; NULL != commands[i].label; i++)
+ ;
+ is->commands = GNUNET_new_array (i + 1,
+ struct GNUNET_TESTING_Command);
+ memcpy (is->commands,
+ commands,
+ sizeof (struct GNUNET_TESTING_Command) * i);
+ is->timeout_task
+ = GNUNET_SCHEDULER_add_delayed (timeout,
+ &do_timeout,
+ is);
+ is->task = GNUNET_SCHEDULER_add_now (&interpreter_run,
+ is);
}
/**
- * Function run when the test terminates (good or bad) with timeout.
+ * Closure for #loop_run().
+ */
+struct MainParams
+{
+
+ /**
+ * NULL-label terminated array of commands.
+ */
+ struct GNUNET_TESTING_Command *commands;
+
+ /**
+ * Global timeout for the test.
+ */
+ struct GNUNET_TIME_Relative timeout;
+
+ /**
+ * Set to #EXIT_FAILURE on error.
+ */
+ int rv;
+};
+
+
+/**
+ * Function called with the final result of the test.
*
- * @param cls NULL
+ * @param cls the `struct MainParams`
+ * @param rv #GNUNET_OK if the test passed
*/
static void
-do_timeout (void *cls)
+handle_result (void *cls,
+ enum GNUNET_GenericReturnValue rv)
{
- (void) cls;
+ struct MainParams *mp = cls;
- is->timeout_task = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Terminating test due to timeout\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Test exits with status %d\n",
+ rv);
+ if (GNUNET_OK != rv)
+ mp->rv = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
}
/**
- * Run the testsuite. Note, CMDs are copied into
- * the interpreter state because they are _usually_
- * defined into the "run" method that returns after
- * having scheduled the test interpreter.
+ * Main function to run the test cases.
*
- * @param is the interpreter state
- * @param commands the list of command to execute
- * @param timeout how long to wait
+ * @param cls a `struct MainParams *`
*/
+static void
+loop_run (void *cls)
+{
+ struct MainParams *mp = cls;
+
+ GNUNET_TESTING_run (mp->commands,
+ mp->timeout,
+ &handle_result,
+ mp);
+}
+
+
int
-GNUNET_TESTING_run (const char *cfg_filename,
- struct GNUNET_TESTING_Command *commands,
- struct GNUNET_TIME_Relative timeout)
+GNUNET_TESTING_main (struct GNUNET_TESTING_Command *commands,
+ struct GNUNET_TIME_Relative timeout)
{
- unsigned int i;
+ struct MainParams mp = {
+ .commands = commands,
+ .timeout = timeout,
+ .rv = EXIT_SUCCESS
+ };
- is = GNUNET_new (struct GNUNET_TESTING_Interpreter);
+ GNUNET_SCHEDULER_run (&loop_run,
+ &mp);
+ return mp.rv;
+}
- if (NULL != is->timeout_task)
- {
- GNUNET_SCHEDULER_cancel (is->timeout_task);
- is->timeout_task = NULL;
- }
- /* get the number of commands */
- for (i = 0; NULL != commands[i].label; i++)
+
+void
+GNUNET_TESTING_async_fail (struct GNUNET_TESTING_AsyncContext *ac)
+{
+ GNUNET_assert (GNUNET_NO == ac->finished);
+ ac->finished = GNUNET_SYSERR;
+ GNUNET_TESTING_interpreter_fail (ac->is);
+ if (NULL != ac->cont)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "on end %u\n",
- commands[i].shutdown_on_end);
+ ac->cont (ac->cont_cls);
+ ac->cont = NULL;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "on end %u\n",
- commands[i].shutdown_on_end);
- // ;
- is->commands = GNUNET_new_array (i + 1,
- struct GNUNET_TESTING_Command);
- memcpy (is->commands,
- commands,
- sizeof (struct GNUNET_TESTING_Command) * (i + 1));
+}
+
- for (i = 0; NULL != is->commands[i].label; i++)
+void
+GNUNET_TESTING_async_finish (struct GNUNET_TESTING_AsyncContext *ac)
+{
+ GNUNET_assert (GNUNET_NO == ac->finished);
+ ac->finished = GNUNET_OK;
+ if (NULL != ac->cont)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "on end %u\n",
- is->commands[i].shutdown_on_end);
+ ac->cont (ac->cont_cls);
+ ac->cont = NULL;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "on end %u\n",
- is->commands[i].shutdown_on_end);
- is->timeout_task = GNUNET_SCHEDULER_add_delayed
- (timeout,
- &do_timeout,
- is);
- GNUNET_SCHEDULER_add_shutdown (&do_shutdown, is);
- is->task = GNUNET_SCHEDULER_add_now (&interpreter_run, is);
- return GNUNET_OK;
}
diff --git a/src/testing/testing_api_trait_cmd.c b/src/testing/testing_api_trait_cmd.c
index 886baee5b..7afa8b264 100644
--- a/src/testing/testing_api_trait_cmd.c
+++ b/src/testing/testing_api_trait_cmd.c
@@ -41,7 +41,7 @@
* @param[out] _cmd where to write the wire details.
* @return #GNUNET_OK on success.
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_TESTING_get_trait_cmd (const struct GNUNET_TESTING_Command *cmd,
unsigned int index,
struct GNUNET_TESTING_Command **_cmd)
diff --git a/src/testing/testing_api_traits.c b/src/testing/testing_api_traits.c
index 66626833d..2f836ddfa 100644
--- a/src/testing/testing_api_traits.c
+++ b/src/testing/testing_api_traits.c
@@ -55,7 +55,7 @@ GNUNET_TESTING_trait_end ()
* @param index index number of the object to extract.
* @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits,
const void **ret,
const char *trait,
diff --git a/src/testing/testing_cmds.h b/src/testing/testing_cmds.h
index 005402a73..12db87d19 100644
--- a/src/testing/testing_cmds.h
+++ b/src/testing/testing_cmds.h
@@ -83,6 +83,8 @@ struct GNUNET_CMDS_LOCAL_FINISHED
* Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED
*/
struct GNUNET_MessageHeader header;
+
+ enum GNUNET_GenericReturnValue result;
};
struct GNUNET_CMDS_LOCAL_TEST_PREPARED