example(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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:


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