oracle / ktf

Kernel Test Framework - a unit test framework for the Linux kernel
Other
95 stars 43 forks source link
kernel linux testing-framework

Kernel Test Framework (KTF)

KTF is a Google Test-like environment for writing C unit tests for kernel code. Tests are implemented as kernel modules which declare each test as part of a test case. The body of each test case consists of assertions. Tests look like this:

TEST(examples, hello_ok)
{
    EXPECT_TRUE(true);
}

"examples" is the test case name, "hello_ok" the test. KTF provides many different types of assertions, see kernel/ktf.h for the complete list.

Usually tests are added on test module init via

ADD_TEST(test_name);

This registers the test with the KTF framework for later execution. There are many examples in the examples/ directory.

"ktfrun" is provided to execute tests, it communicates with the KTF kernel module via netlink socket to query available tests and trigger test execution.

The design priorities for KTF are to make it

All of the above will hopefully help Linux kernel engineers practice continuous integration and more thoroughly unit test their code.

User Documentation

See ./doc