kunit_platfo...ver_register(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ NAME ✨

okay so kunit_platform_driver_register β€” from the Kernel API Manual β€” is literally the function for registering a KUnit test managed platform driver. bestie, it’s giving β€œdriver registration but make it test-managed.” πŸ’…


🌸 SYNOPSIS 🌸

int kunit_platform_driver_register (struct kunit *test , struct platform_driver *drv );

πŸŽ€ ARGUMENTS πŸŽ€

  • test β€” test context πŸ§ͺ
  • drv β€” platform driver to register 🧩

πŸ¦‹ DESCRIPTION πŸ¦‹

Register a test managed platform driver. This is the main character move that allows callers to embed the drv in a container structure and use container_of in the probe function to pass information to KUnit tests. no cap, that’s the whole point. 🫢

πŸ’– Example πŸ’–

struct kunit_test_context {
        struct platform_driver pdrv;
        const char *data;
};

static inline struct kunit_test_context *
to_test_context(struct platform_device *pdev)
{
        return container_of(to_platform_driver(pdev->dev.driver),
                            struct kunit_test_context,
                            pdrv);
}

static int kunit_platform_driver_probe(struct platform_device *pdev)
{
        struct kunit_test_context *ctx;

        ctx = to_test_context(pdev);
        ctx->data = "test data";

        return 0;
}

static void kunit_platform_driver_test(struct kunit *test)
{
        struct kunit_test_context *ctx;

        ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
        KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx);

        ctx->pdrv.probe = kunit_platform_driver_probe;
        ctx->pdrv.driver.name = "kunit-platform";
        ctx->pdrv.driver.owner = THIS_MODULE;

        KUNIT_EXPECT_EQ(test, 0, kunit_platform_driver_register(test, ctx->pdrv));
        <... wait for driver to probe ...>
        KUNIT_EXPECT_STREQ(test, ctx->data, "test data");
}

πŸ” RETURN πŸ”

0 on success, negative errno on failure. that’s it, bestie β€” zero is slay, negative errno is the vibe check saying β€œnope.” 😭✨


πŸ‘‘ SEE ALSO πŸ‘‘

bestie, please also peek at the Kernel file ./lib/kunit/platform.c and these linked besties:


mwah πŸ’‹ β€” this page comes from ./lib/kunit, dated October 2026, and its footer title is kunit_platfo...ver_register(9). fr fr, that’s the whole page. 🫢

πŸ“¦ where this page comes from