kunit_alloc_resource(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… kunit_alloc_resource(9)

okay so bestie, welcome to the Kernel API Manual β€” this one's about kunit_alloc_resource, and it's literally the resource-wrangling queen of KUnit. buckle up πŸŽ€


✨ NAME ✨

kunit_alloc_resource β€” Allocates a test managed resource. 🫢


🌸 SYNOPSIS 🌸

void * kunit_alloc_resource (struct kunit *test , kunit_resource_init_t
init , kunit_resource_free_t free , gfp_t internal_gfp , void *context
);

πŸ¦‹ ARGUMENTS πŸ¦‹

  • test β€” The test context object. it's the main character of your test, obviously πŸ‘‘
  • init β€” a user supplied function to initialize the resource. you write it, you own it πŸ’–
  • free β€” a user supplied function to free the resource (if needed). only if needed, no pressure ✨
  • internal_gfp β€” gfp to use for internal allocations, if unsure, use GFP_KERNEL. lowkey just use GFP_KERNEL bestie 🌈
  • context β€” for the user to pass in arbitrary data to the init function. your little care package of vibes 🎁

πŸ’œ DESCRIPTION πŸ’œ

Allocates a test managed resource β€” a resource which will automatically be cleaned up at the end of a test case. like, it cleans up after itself?? self-care icon behavior fr fr πŸ˜­πŸ’…

See struct kunit_resource for an example. it ate, honestly.


⭐ NOTE ⭐

KUnit needs to allocate memory for a kunit_resource object. You must specify an internal_gfp that is compatible with the use context of your resource. this is not optional, bestie β€” mismatched gfp = chaos energy πŸ’€

πŸ”₯ SEE ALSO πŸ”₯

Kernel file ./include/kunit/resource.h struct kunit_resource(9), kunit_get_resource(9), kunit_put_resource(9), __kunit_add_resource(9), kunit_add_resource(9), kunit_add_named_resource(9), kunit_alloc_and_get_resource(9), kunit_resource_name_match(9), kunit_find_resource(9), kunit_find_named_resource(9), kunit_destroy_resource(9), kunit_remove_resource(9), KUNIT_DEFINE_ACTION_WRAPPER(9), kunit_add_action(9), kunit_add_action_or_reset(9), kunit_remove_action(9), kunit_release_action(9) β€” the whole friend group, go read them all, iykyk πŸ‘‘βœ¨


and that's the tea πŸ“ this page came straight out of ./include/kunit, dated October 2026 β€” slay, bye bestie! πŸ’–πŸ§šβ€β™€οΈπŸŒΈ

πŸ“¦ where this page comes from