-
Notifications
You must be signed in to change notification settings - Fork 2k
Writing tests for ng_netapi modules
ng_nettest
provides functionality to test ng_netapi
based modules. For every ng_netapi
message call there are functions to test this message:
-
NG_NETAPI_MSG_TYPE_SND
:-
ng_nettest_send()
: to test inner-stack modules (modules that get all their communication partners throughng_netreg
) -
ng_nettest_send_iface()
: to test modules communicating with at least oneng_netif
interface.
-
-
NG_NETAPI_MSG_TYPE_RCV
:ng_nettest_receive()
-
NG_NETAPI_MSG_TYPE_GET
:ng_nettest_get()
-
NG_NETAPI_MSG_TYPE_SET
:ng_nettest_set()
There are also functions to manipulate the behavior of ng_nettest
itself, so that you can set option behavior the module the module you like to test expects from its neighboring modules:
-
ng_nettest_register_get()
: set a getter for an option. -
ng_nettest_register_set()
: set a setter for an option.
The tests for NG_NETAPI_MSG_TYPE_SND
and NG_NETAPI_MSG_TYPE_RCV
are based on the principle that a ng_netapi
module gets some kind of input which triggers some kind of output. For ng_nettest
both input and output must be handled through ng_netapi
, other kinds of output or input (e.g. for interfaces) are out of scope of ng_nettest
. Each of the test functions for this modules have four parameters that are relevant for this:
-
ng_pktsnip_t *in
: the input that triggers the output -
unsigned int exp_pkts
: the numbers of packets expected in output (may be 0) -
const kernel_pid_t *exp_senders
: the expected senders of the output (may beNULL
ifexp_pkts
is 0) -
const ng_pktsnip_t **exp_out
: the expected output packets (may beNULL
ifexp_pkts
is 0)
If the module you test needs to set or get some kind of option from the layer it is supposed to output to (e.g. hardware address from the interface) you can use ng_nettest_register_get()
and ng_nettest_register_set()
to set getters/setters for these options for the neighboring layers.
If exp_pkts
is 0, the tested module's priority MUST be equal or higher to the testing threads priority to ensure that the in packets are handled by the tested module.
You can test getting and setting options with ng_nettest_get()
and ng_nettest_set()
by just using the parameters as documented.
If the module you test needs to set or get some kind of option to set or get its own options you can use ng_nettest_register_get()
and ng_nettest_register_set()
to set getters/setters for these options for the neighboring layers.
Have look at tests/udp/
(currently PR'd at #3248) for an example.