µD3TN relies on intensive testing to ensure system stability as well as project quality. The following information should be taken into account by all project contributors.
The tests can be either executed manually, or automatically via a Continuous Integration server. This document summarizes which tests are available and how to execute them.
For patches or pull requests to be accepted, _all_ of the below-listed tests have to return a successful result on _all_ platforms.
Most of the available compiler warnings are turned on automatically in the Makefile. This usually gives already an indication of some obvious problems in new code. To check that there are no problems compiling µD3TN for various platforms, the following commands should be run:
The `checkpatch.pl` utility available in the Linux kernel source tree is used for µD3TN to enforce compatibility with the project's coding style which is the one used for the Linux kernel.
For unit testing, the lightweight [Unity](http://www.throwtheswitch.org/unity/) test framework is used. It provides a simple API and everything necessary to check assertions and generate a test report.
The tests are located in [`test/unit`](https://gitlab.com/d3tn/ud3tn/-/tree/master/test/unit) and, including the Unity test framework, are compiled into the µD3TN test binary (via `make unittest-posix`).
There are several integration test scenarios which check µD3TN's behavior. For the integration tests to work, an instance of µD3TN first has to be started and the Python [`venv`](python-venv.md) has to be activated.
µD3TN needs to be started with the flags `-R`, `--allow-remote-config` and `-r`, `--status-reports` as both features are needed by the integration tests.
The integration tests can also be run against µD3TN combined with the compatible external BDM. This is achieved by specifying the `-d, --external-dispatch` command line argument when invoking µD3TN and starting the BDM service additionally via `aap2-bdm-ud3tn-routing --insecure-config` (inside the Python virtual environment). The `--insecure-config` flag is necessary as some integration tests inject configuration commands as if they were received from an external source.
µD3TN ships with simple interoperability test scenarios that validate BPv6 and BPv7 interoperability with JPL's ION and are described in the following subsections.
At the end of this section, some hints on doing manual interoperability tests are provided.
### Prerequisites
All tests expect an environment with ION and µD3TN (incl. Python dependencies) installed. There are two options to set up all requirements:
1. Use the Docker image:
- Run a container built from the [`registry.gitlab.com/d3tn/ud3tn-docker-images/ion-interop:<version>`](https://gitlab.com/d3tn/ud3tn-docker-images/container_registry/3909796) image, whereas `<version>` is the ION version you would like to test against. The µD3TN installation/source should be mounted inside the container and the µD3TN binary should be built with the settings you would like to test.
- You can accelerate these two steps by using the script we maintain for our CI toolchain. Replace `<version>` by the ION version and `<build-args>` by additional arguments to be passed to µD3TN's `make` command (e.g. for enabling sanitizers or other compile-time preferences; may be left out). The script builds µD3TN and sets up the Python dependencies. It assumes that the µD3TN source is mounted under `/ud3tn` and one of our Docker images is used.
- Install [ION](https://github.com/nasa-jpl/ION-DTN) according to the instructions provided with it.
- Obtain the [version](https://gitlab.com/d3tn/ud3tn/-/releases) of µD3TN you would like to test (or mount it as a volume if you are using a container).
- Install µD3TN's dependencies and build µD3TN as documented in [README.md](https://gitlab.com/d3tn/ud3tn/-/blob/master/README.md?ref_type=heads#develop) and the [Quick Start Guide](./posix_quick_start_guide.md#prerequisites).
- Install the Python dependencies as documented in the [Quick Start Guide](./posix_quick_start_guide.md#python-dependencies).
This test, provided in [`test/ion_interoperability/minimal_forwarding_test`](https://gitlab.com/d3tn/ud3tn/-/blob/master/test/ion_interoperability/minimal_forwarding_test), checks the following aspects:
The script [`run.sh`](https://gitlab.com/d3tn/ud3tn/-/blob/master/test/ion_interoperability/minimal_forwarding_test/run.sh?ref_type=heads) expects two arguments:
-`<bp-version>`: the Bundle Protocol version to be used, i.e., `6` or `7`
-`<scheme>`: the EID scheme to be used, i.e., `dtn` or `ipn`
When invoked, the script will start ION (via `ionstart -I`) and two µD3TN instances, configure µD3TN to connect to ION via TCPCL, and try to send three bundles to test the three aspects mentioned above.
The ION configuration (`rc`) files can be found in the same directory as `run.sh`, for the `dtn` and `ipn` EID schemes, respectively.
On completion, ION will be shut down using `ionstop` and the µD3TN instances will receive a `SIGTERM`.
A second test script checks whether forwarding of a bundle encapsulated using [BIBE](https://datatracker.ietf.org/doc/draft-ietf-dtn-bibect/) works via ION, to validate µD3TN's [BIBE implementation](./Bundle-in-Bundle%20Encapsulation_(BIBE).md).
This test always uses BPv7 and the `dtn` scheme, thus, no command line arguments are necessary. The used ION configuration ([`ionstart.rc`](https://gitlab.com/d3tn/ud3tn/-/blob/master/test/ion_interoperability/bibe_forwarding_test/ionstart.rc?ref_type=heads)) can be found in the [`test`](https://gitlab.com/d3tn/ud3tn/-/tree/master/test) directory.
Beside using the prepared test scripts, manual interoperability testing is possible. Developers are advised to check out the "minimal forwarding test" shell script ([`run.sh`](https://gitlab.com/d3tn/ud3tn/-/blob/master/test/ion_interoperability/minimal_forwarding_test/run.sh?ref_type=heads)) to get an idea which commands have to be executed.
- If ION should send bundles to µD3TN, you should configure a) an outduct and b) an egress plan. Check out the [configuration of the minimal forwarding test](https://gitlab.com/d3tn/ud3tn/-/blob/master/test/ion_interoperability/minimal_forwarding_test/ipn.rc?ref_type=heads) to get an idea of this.
3. Start µD3TN instances as needed. If you want to test with multiple instances, don't forget to specify different sockets/ports for AAP (via `-s` or `-a`/`-p`) and the CLAs (via `-c`). Refer to the [README.md](https://gitlab.com/d3tn/ud3tn/-/blob/master/README.md?ref_type=heads#usage) concerning the command line syntax. You can also find some pointers on running multiple instances in the [Quick Start Guide](./posix_quick_start_guide.md).