example(9)
π example(9) π
okay so bestie, this is example, from the Kernel API Manual, section 9. And listen β this page has no NAME, no SYNOPSIS, no big fancy DESCRIPTION. It's literally one code block and a SEE ALSO, and honestly? main character energy. The professor just posted the example and said "figure it out." π
What you're getting is the kselftest harness demo: a standalone <purple>TEST</purple>, a <purple>FIXTURE</purple> with its setup and teardown, a <purple>TEST_F</purple> that actually uses that fixture, and <purple>TEST_HARNESS_MAIN</purple> to glue it together. Here's the whole entire thing, verbatim, no edits, don't @ me:
#include "kselftest_harness.h"
TEST(standalone_test) {
do_some_stuff;
EXPECT_GT(10, stuff) {
stuff_state_t state;
enumerate_stuff_state(state);
TH_LOG("expectation failed with state: s", state.msg);
}
more_stuff;
ASSERT_NE(some_stuff, NULL) TH_LOG("how did it happen?!");
last_stuff;
EXPECT_EQ(0, last_stuff);
}
FIXTURE(my_fixture) {
mytype_t *data;
int awesomeness_level;
};
FIXTURE_SETUP(my_fixture) {
self->data = mytype_new;
ASSERT_NE(NULL, self->data);
}
FIXTURE_TEARDOWN(my_fixture) {
mytype_free(self->data);
}
TEST_F(my_fixture, data_is_good) {
EXPECT_EQ(1, is_my_data_good(self->data));
}
TEST_HARNESS_MAIN
like β ASSERT_NE(some_stuff, NULL) TH_LOG("how did it happen?!") π the panic is so real. and int awesomeness_level; sitting in the fixture just existing. we stan a struct with priorities. π
π SEE ALSO π
the whole squad, in order, because we do not do partial credit here π«Ά β start with the actual source of truth:
- Kernel file
./tools/testing/selftests/kselftest_harness.h TH_LOG(9)SKIP(9)TEST(9)TEST_SIGNAL(9)FIXTURE_DATA(9)FIXTURE(9)FIXTURE_SETUP(9)FIXTURE_TEARDOWN(9)FIXTURE_TEARDOWN_PARENT(9)FIXTURE_VARIANT(9)FIXTURE_VARIANT_ADD(9)TEST_F(9)TEST_HARNESS_MAIN(9)operators(9)ASSERT_EQ(9)ASSERT_NE(9)ASSERT_LT(9)ASSERT_LE(9)ASSERT_GT(9)ASSERT_GE(9)ASSERT_NULL(9)ASSERT_TRUE(9)ASSERT_FALSE(9)ASSERT_STREQ(9)ASSERT_STRNE(9)EXPECT_EQ(9)EXPECT_NE(9)EXPECT_LT(9)EXPECT_LE(9)EXPECT_GT(9)EXPECT_GE(9)EXPECT_NULL(9)EXPECT_TRUE(9)EXPECT_FALSE(9)EXPECT_STREQ(9)EXPECT_STRNE(9)XFAIL_ADD(9)
bestie the way this is a whole thirty-eight item SEE ALSO and not a single prose sentence. highkey iconic. π
and that's the page!! π¦ it ships out of ./tools/testing/selftests, stamped October 2026, and it signs itself example(9) like the little main character it is. periodt. πβ¨
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms