kunit_alloc_resource(9)
π 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, useGFP_KERNEL. lowkey just useGFP_KERNELbestie π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 akunit_resourceobject. You must specify aninternal_gfpthat 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
- 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