Skip to content

Writing tests for ng_netapi modules

Martine Lenders edited this page Jun 25, 2015 · 9 revisions

Overview

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 through ng_netreg)
    • ng_nettest_send_iface(): to test modules communicating with at least one ng_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.

Testing data tranfer

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 be NULL if exp_pkts is 0)
  • const ng_pktsnip_t **exp_out: the expected output packets (may be NULL if exp_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.

Testing options

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.

Example

Have look at tests/udp/ (currently PR'd at #3248) for an example.

Clone this wiki locally