TEST_F(9)
๐ TEST_F(9) โ the kselftest harness glow-up, fixture edition
okay so bestie, real talk: this is a page from the Kernel API Manual, and it's literally about TEST_F. yes, that TEST_F. the fixture-based test case one. buckle up ๐
โจ NAME โจ
TEST_F โ emits test registration and helpers for fixture-based test cases. that's the whole vibe, no notes ๐
๐ฆ SYNOPSIS ๐ฆ
TEST_F (fixture_name , test_name );
yes that's the whole call. two arguments, no cap. ๐ฅ
๐ธ ARGUMENTS ๐ธ
fixture_nameโ the fixture name. that's it, that's the girl ๐ซถtest_nameโ the test name. also exactly what it sounds like โจ
๐ DESCRIPTION ๐
so here's the shape of it, and it's giving iconic:
TEST_F(fixture, name) { implementation }
what this does is defines a test that depends on a fixture (like, it's part of a test case, iykyk). it's very similar to TEST, except โ and this is the main character moment โ self is the setup instance of the fixture's datatype, exposed for use by the implementation. so your implementation gets to just... use it. slay. ๐
now for the slightly unhinged but extremely important part, so pay attention bestie:
the _metadata object is shared (MAP_SHARED) with all the potential forked processes, which enables them to use EXCEPT_*() and ASSERT_*(). shared memory, shared dreams, fr fr ๐
but the self object? that one is only shared with the potential forked processes if FIXTURE_TEARDOWN_PARENT is used instead of FIXTURE_TEARDOWN. so like. vibe check your teardown choice, okay? because that's literally the difference. ๐ญ
๐ฎ SEE ALSO ๐ฎ
the whole squad, and yes, we're listing every single one, because none of them are getting left on read:
- the Kernel file
./tools/testing/selftests/kselftest_harness.h(the source of truth, the blueprint, the moment) andexample(9) 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_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)
like... that's the whole friend group and they ALL showed up ๐
ok and one last thing before you go โ this page lives at./tools/testing/selftests, it's dated October 2026, and it's pageTEST_F(9)of the Kernel API Manual. write it down, screenshot it, tattoo it, whatever. mwah ๐ ๐ธ ๐งโโ๏ธ
๐ฆ 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