kunit_kmalloc_array(9)
π kunit_kmalloc_array β Kernel API Manual, bestie edition π
okay so you're reading the kunit_kmalloc_array(9) page, welcome, this one's actually so good. it lives in the Kernel API Manual and honestly it's giving "small function, huge convenience" energy. let's get into it β¨
β¨ NAME β¨
kunit_kmalloc_array β literally like kmalloc_array() except the allocation is test managed. no cap. that's the whole vibe. π«Ά
πΈ SYNOPSIS πΈ
void * kunit_kmalloc_array (struct kunit *test , size_t n , size_t size
, gfp_t gfp );
look at her. four args, returns a void *. iconic signature tbh π
π¦ ARGUMENTS π¦
testβ the test context object. your main character struct, the whole test revolves around her πnβ number of elements. like, how many of the thing do you want πsizeβ the size in bytes of the desired memory. yes, bytes, not vibes πgfpβ flags passed to the underlyingkmalloc. forwarding them straight through, no edits, no notes π
β DESCRIPTION β
okay so it's just like kmalloc_array(...), except the allocation is managed by the test case and gets automatically cleaned up after the test case concludes. so you don't have to remember to free it, she remembers for you. that's the whole slay π₯
if you want the deeper lore on how that cleanup actually works, go see kunit_add_action for more information. iykyk π§
β οΈ note that some internal context data is also allocated withGFP_KERNEL, regardless of thegfpyou passed in. so like, don't assume your flags cover everything bestie, that's not the deal here π
π SEE ALSO π
so many friends, we love a connected ecosystem π first up, the kernel file ./include/kunit/test.h and enum kunit_status(9), plus these:
struct kunit_case(9),KUNIT_CASE(9),KUNIT_CASE_ATTR(9),KUNIT_CASE_SLOW(9),KUNIT_CASE_PARAM(9),KUNIT_CASE_PARAM_ATTR(9),KUNIT_CASE_PARAM_WITH_INIT(9)struct kunit_suite(9),struct kunit(9),kunit_test_suites(9),kunit_test_init_section_suites(9)- the allocation girlies:
kunit_kmalloc(9),kunit_kfree(9),kunit_kzalloc(9),kunit_kcalloc(9),kunit_kfree_const(9),kunit_kstrdup(9),kunit_kstrdup_const(9) kunit_attach_mm(9),kunit_vm_mmap(9)kunit_mark_skipped(9),kunit_skip(9),kunit_info(9),kunit_warn(9),kunit_err(9)KUNIT_SUCCEED(9),KUNIT_FAIL(9)- the expect squad, all seventeen of them:
KUNIT_EXPECT_TRUE(9),KUNIT_EXPECT_FALSE(9),KUNIT_EXPECT_EQ(9),KUNIT_EXPECT_PTR_EQ(9),KUNIT_EXPECT_NE(9),KUNIT_EXPECT_PTR_NE(9),KUNIT_EXPECT_LT(9),KUNIT_EXPECT_LE(9),KUNIT_EXPECT_GT(9),KUNIT_EXPECT_GE(9),KUNIT_EXPECT_STREQ(9),KUNIT_EXPECT_STRNEQ(9),KUNIT_EXPECT_MEMEQ(9),KUNIT_EXPECT_MEMNEQ(9),KUNIT_EXPECT_NULL(9),KUNIT_EXPECT_NOT_NULL(9),KUNIT_EXPECT_NOT_ERR_OR_NULL(9) KUNIT_FAIL_AND_ABORT(9)- the assert squad, matching energy:
KUNIT_ASSERT_TRUE(9),KUNIT_ASSERT_FALSE(9),KUNIT_ASSERT_EQ(9),KUNIT_ASSERT_PTR_EQ(9),KUNIT_ASSERT_NE(9),KUNIT_ASSERT_PTR_NE(9),KUNIT_ASSERT_LT(9),KUNIT_ASSERT_LE(9),KUNIT_ASSERT_GT(9),KUNIT_ASSERT_GE(9),KUNIT_ASSERT_STREQ(9),KUNIT_ASSERT_STRNEQ(9),KUNIT_ASSERT_MEMEQ(9),KUNIT_ASSERT_MEMNEQ(9),KUNIT_ASSERT_NULL(9),KUNIT_ASSERT_NOT_NULL(9),KUNIT_ASSERT_NOT_ERR_OR_NULL(9) - parameter passing cuties:
KUNIT_ARRAY_PARAM(9),KUNIT_ARRAY_PARAM_DESC(9),kunit_register_params_array(9) - warning-suppression besties:
kunit_warning_suppress(9),KUNIT_SUPPRESSED_WARNING_COUNT(9),KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(9),KUNIT_ASSERT_SUPPRESSED_WARNING_COUNT(9)
okay that's the whole page, you ate that π
this one came from ./include/kunit, October 2026 (Kernel API Manual), and honestly? go forth and let the test manage your memory for you. periodt. πβ¨π¦
π¦ 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