Testing
Tempesta Kernel Emulation Framework for Unit Testing
Ktest is just a set of C headers with very close hierarchy to the original Linux, but much simplified and combined with some additional helpers. This headers provide only most usable stubs for real kernel headers to launch a relatively standalone logic under the test.
The good examples of the code suitable for the testing with the framework are data strucures like HTrie, mathematic functions like APM maths or multi-precission math.
The framework emphasises simplicity to make debugging of complicated and standalone logic as productive as possible: (re-)run quickly, easily traced with gdb and valgrind.
What about KUnit?
KUnit, available in the mainstream
kernels at linux/tools/testing/kunit/
, is essentially a bunch of Python
scripts around User-mode Linux (UML).
UML is also in the mainstream kernel and one just needs to
buid the kernel for um
architecture.
The most important thing bout KUnit/UML is that this is a fully functional Linux kernel, so you need a fake filesystem, login to the console and so on. It can be debugged with gdb (see example), but special steps are required. All in all, this can be and should be treated as a virtualization solution.
Tests are developed for KUnit/UML as Linux kernel modules (this
LWN article provides a good intro into the
framework), which is somewhat close to current tempesta_fw/t/unit
framework
operation. As discussed in another
LWN article the framework emulates device
initialization, making tests (re-)run faster than in KVM, which we use.
Ext4 tests, as one of the good use case for the framework, require a filesystem
anyhow and they do required significant underlaying layers (block IO) emulation.
This is example of non-standalone logic, which can not be tested with our
ktest
framework.
Thus, KUnit/UML is closer to tempesta_fw/t/unit
tests than to ktest
. In
future, if tempesta_fw/t/unit
grows or become more complex, e.g. require
the TCP stack, it could make sense to port tempesta_fw/t/unit
to KUnit/UML.
Linux Kernel Library
Linux Kernel Library (see also LWN anritcle) build the Linux kernel as a library, so a user space application can use the Linux API. Unfortunately, the project isn’t mainstream and it looks like an overkill for us to apply and support the Tempesta patch for the LKL kernel and build the separate kernel just for the couple tests for the standalone logic. dd
Further development
At the moment we have only 3 types of tests and they are well covered by the current frameworks:
-
The most developed and the largest framework is the functional test Python framework (https://github.com/tempesta-tech/tempesta-test/). This type of the tests are most beneficial because (1) they emulate cases very close to the real life scenatios and (2) they test quite a bunch of logic at once.
-
Complex standalone logic (HTrie, TLS, math in
tempesta_fw/t/unit/user_space/
) are covered with thektest
. -
Linux kernel module for unit tests (https://github.com/tempesta-tech/tempesta/tree/master/tempesta_fw/t). At the moment the module is quite small and some of the tests, e.g. HTTP parser or TfwStr, are likely to be moved to ktest framework. However, at some point we might need to develop tests which (1) require to reproduce specific and rare scenarios unreachable for the functional tests framework and (2) depend on significant Linux kernel logic unmockable by the
ktest
. At this moment we might need to use either LKL or KUnit/UML.