kunit_platfo...ver_register(9)
β¨ 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:
kunit_platform_device_alloc(9)kunit_platform_device_add(9)kunit_platform_device_register_full(9)kunit_platform_device_unregister(9)kunit_platform_device_prepare_wait_for_probe(9)
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
- 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