The network tests run the TCP/IP stack as a native build on a Linux TAP
interface and check it against the host’s own stack and tools: ping,
a router advertisement daemon, and hand-made packets sent with
Scapy. They live in tests/net/, written in Python with
pytest.
The tests need Linux and the right to create network interfaces, so they run in a container with a network of its own, which leaves the host’s alone. On Linux or macOS, with Docker:
tests/net/run.sh
The script builds the container’s image, then builds tests/net/app for
native with the address and undefined behaviour sanitizers, and runs
pytest; arguments go to pytest, such as -k slaac or -x. The build is
kept in a Docker volume between runs.
Each test creates the tap0 interface, with 192.0.2.1/24 on the host side,
and starts the stack on it with the -e option of the native build (see
Native simulator). The test application takes
192.0.2.2/24 and prints its IPv6 addresses whenever they change, which the
tests wait on. The stack’s MAC address is derived from the interface name.
Tests that watch the traffic sniff the interface with Scapy, and those that
need a router run radvd on it, advertising 2001:db8:1::/64.
tests/fuzz/net runs the receive path of the stack under
libFuzzer, with the address and
undefined behaviour sanitizers, in the same container:
tests/fuzz/net/run.sh 600
The first argument is how long to fuzz, in seconds, 60 by default; the others go to libFuzzer. The harness feeds the stack frames and the passing of time, with a deterministic clock and random numbers, on an interface configured as the tests’ with a link-local address either checked or still being checked, and with checksum offload or without. Frames may have their IP length and checksums made right first, so that mutations reach past them.
Each input fails on a sanitizer error or a failed assertion in the stack, on
a frame the stack sends that is malformed or whose checksums are wrong, or on
a packet buffer not given back once the stack’s state is reset.
tests/fuzz/net/seeds.py writes the seeds, a frame or two of each protocol
the stack takes. The corpus grows in build/fuzz-net/corpus, and failing
inputs land in build/fuzz-net/artifacts. Given files, the script replays
them instead:
tests/fuzz/net/run.sh build/fuzz-net/artifacts/crash-…
CI fuzzes for five minutes on every change to the stack.
Generated from PebbleOS 7416f78a1. This page is maintained in the pebbleos repository: docs/development/tests/network.md.