Lines Matching refs:test

169 static size_t setup_test_cache(struct kunit *test, size_t size, slab_flags_t flags,  in setup_test_cache()  argument
172 if (test->priv != TEST_PRIV_WANT_MEMCACHE) in setup_test_cache()
175 kunit_info(test, "%s: size=%zu, ctor=%ps\n", __func__, size, ctor); in setup_test_cache()
184 KUNIT_ASSERT_TRUE_MSG(test, test_cache, "could not create cache"); in setup_test_cache()
227 static void *test_alloc(struct kunit *test, size_t size, gfp_t gfp, enum allocation_policy policy) in test_alloc() argument
248 kunit_info(test, "%s: size=%zu, gfp=%x, policy=%s, cache=%i\n", __func__, size, gfp, in test_alloc()
277 KUNIT_EXPECT_EQ(test, obj_to_index(s, page, alloc), 0U); in test_alloc()
278 KUNIT_EXPECT_EQ(test, objs_per_slab_page(s, page), 1); in test_alloc()
296 KUNIT_ASSERT_TRUE_MSG(test, false, "failed to allocate from KFENCE"); in test_alloc()
300 static void test_out_of_bounds_read(struct kunit *test) in test_out_of_bounds_read() argument
310 setup_test_cache(test, size, 0, NULL); in test_out_of_bounds_read()
321 buf = test_alloc(test, size, GFP_KERNEL, ALLOCATE_LEFT); in test_out_of_bounds_read()
324 KUNIT_EXPECT_TRUE(test, report_matches(&expect)); in test_out_of_bounds_read()
327 buf = test_alloc(test, size, GFP_KERNEL, ALLOCATE_RIGHT); in test_out_of_bounds_read()
330 KUNIT_EXPECT_TRUE(test, report_matches(&expect)); in test_out_of_bounds_read()
334 static void test_out_of_bounds_write(struct kunit *test) in test_out_of_bounds_write() argument
344 setup_test_cache(test, size, 0, NULL); in test_out_of_bounds_write()
345 buf = test_alloc(test, size, GFP_KERNEL, ALLOCATE_LEFT); in test_out_of_bounds_write()
348 KUNIT_EXPECT_TRUE(test, report_matches(&expect)); in test_out_of_bounds_write()
352 static void test_use_after_free_read(struct kunit *test) in test_use_after_free_read() argument
361 setup_test_cache(test, size, 0, NULL); in test_use_after_free_read()
362 expect.addr = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY); in test_use_after_free_read()
365 KUNIT_EXPECT_TRUE(test, report_matches(&expect)); in test_use_after_free_read()
368 static void test_double_free(struct kunit *test) in test_double_free() argument
376 setup_test_cache(test, size, 0, NULL); in test_double_free()
377 expect.addr = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY); in test_double_free()
380 KUNIT_EXPECT_TRUE(test, report_matches(&expect)); in test_double_free()
383 static void test_invalid_addr_free(struct kunit *test) in test_invalid_addr_free() argument
392 setup_test_cache(test, size, 0, NULL); in test_invalid_addr_free()
393 buf = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY); in test_invalid_addr_free()
397 KUNIT_EXPECT_TRUE(test, report_matches(&expect)); in test_invalid_addr_free()
400 static void test_corruption(struct kunit *test) in test_corruption() argument
409 setup_test_cache(test, size, 0, NULL); in test_corruption()
413 buf = test_alloc(test, size, GFP_KERNEL, ALLOCATE_LEFT); in test_corruption()
417 KUNIT_EXPECT_TRUE(test, report_matches(&expect)); in test_corruption()
419 buf = test_alloc(test, size, GFP_KERNEL, ALLOCATE_RIGHT); in test_corruption()
423 KUNIT_EXPECT_TRUE(test, report_matches(&expect)); in test_corruption()
436 static void test_kmalloc_aligned_oob_read(struct kunit *test) in test_kmalloc_aligned_oob_read() argument
447 buf = test_alloc(test, size, GFP_KERNEL, ALLOCATE_RIGHT); in test_kmalloc_aligned_oob_read()
454 KUNIT_EXPECT_FALSE(test, report_available()); in test_kmalloc_aligned_oob_read()
461 KUNIT_EXPECT_FALSE(test, report_available()); in test_kmalloc_aligned_oob_read()
466 KUNIT_EXPECT_TRUE(test, report_matches(&expect)); in test_kmalloc_aligned_oob_read()
471 static void test_kmalloc_aligned_oob_write(struct kunit *test) in test_kmalloc_aligned_oob_write() argument
480 buf = test_alloc(test, size, GFP_KERNEL, ALLOCATE_RIGHT); in test_kmalloc_aligned_oob_write()
487 KUNIT_EXPECT_FALSE(test, report_available()); in test_kmalloc_aligned_oob_write()
489 KUNIT_EXPECT_TRUE(test, report_matches(&expect)); in test_kmalloc_aligned_oob_write()
493 static void test_shrink_memcache(struct kunit *test) in test_shrink_memcache() argument
498 setup_test_cache(test, size, 0, NULL); in test_shrink_memcache()
499 KUNIT_EXPECT_TRUE(test, test_cache); in test_shrink_memcache()
500 buf = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY); in test_shrink_memcache()
504 KUNIT_EXPECT_FALSE(test, report_available()); in test_shrink_memcache()
514 static void test_free_bulk(struct kunit *test) in test_free_bulk() argument
519 const size_t size = setup_test_cache(test, 8 + prandom_u32_max(300), 0, in test_free_bulk()
522 test_alloc(test, size, GFP_KERNEL, ALLOCATE_RIGHT), in test_free_bulk()
523 test_alloc(test, size, GFP_KERNEL, ALLOCATE_NONE), in test_free_bulk()
524 test_alloc(test, size, GFP_KERNEL, ALLOCATE_LEFT), in test_free_bulk()
525 test_alloc(test, size, GFP_KERNEL, ALLOCATE_NONE), in test_free_bulk()
526 test_alloc(test, size, GFP_KERNEL, ALLOCATE_NONE), in test_free_bulk()
530 KUNIT_ASSERT_FALSE(test, report_available()); in test_free_bulk()
536 static void test_init_on_free(struct kunit *test) in test_init_on_free() argument
550 setup_test_cache(test, size, 0, NULL); in test_init_on_free()
551 expect.addr = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY); in test_init_on_free()
562 KUNIT_EXPECT_EQ(test, expect.addr[i], (char)0); in test_init_on_free()
565 KUNIT_EXPECT_TRUE(test, report_matches(&expect)); in test_init_on_free()
570 static void test_memcache_ctor(struct kunit *test) in test_memcache_ctor() argument
576 setup_test_cache(test, size, 0, ctor_set_x); in test_memcache_ctor()
577 buf = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY); in test_memcache_ctor()
580 KUNIT_EXPECT_EQ(test, buf[i], (char)'x'); in test_memcache_ctor()
584 KUNIT_EXPECT_FALSE(test, report_available()); in test_memcache_ctor()
588 static void test_gfpzero(struct kunit *test) in test_gfpzero() argument
595 kunit_warn(test, "skipping ... would take too long\n"); in test_gfpzero()
599 setup_test_cache(test, size, 0, NULL); in test_gfpzero()
600 buf1 = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY); in test_gfpzero()
607 buf2 = test_alloc(test, size, GFP_KERNEL | __GFP_ZERO, ALLOCATE_ANY); in test_gfpzero()
613 kunit_warn(test, "giving up ... cannot get same object back\n"); in test_gfpzero()
619 KUNIT_EXPECT_EQ(test, buf2[i], (char)0); in test_gfpzero()
623 KUNIT_EXPECT_FALSE(test, report_available()); in test_gfpzero()
626 static void test_invalid_access(struct kunit *test) in test_invalid_access() argument
636 KUNIT_EXPECT_TRUE(test, report_matches(&expect)); in test_invalid_access()
640 static void test_memcache_typesafe_by_rcu(struct kunit *test) in test_memcache_typesafe_by_rcu() argument
649 setup_test_cache(test, size, SLAB_TYPESAFE_BY_RCU, NULL); in test_memcache_typesafe_by_rcu()
650 KUNIT_EXPECT_TRUE(test, test_cache); /* Want memcache. */ in test_memcache_typesafe_by_rcu()
652 expect.addr = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY); in test_memcache_typesafe_by_rcu()
657 KUNIT_EXPECT_EQ(test, *expect.addr, (char)42); in test_memcache_typesafe_by_rcu()
665 KUNIT_EXPECT_FALSE(test, report_available()); in test_memcache_typesafe_by_rcu()
671 KUNIT_EXPECT_EQ(test, *expect.addr, (char)42); in test_memcache_typesafe_by_rcu()
672 KUNIT_EXPECT_TRUE(test, report_matches(&expect)); in test_memcache_typesafe_by_rcu()
676 static void test_krealloc(struct kunit *test) in test_krealloc() argument
682 .addr = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY), in test_krealloc()
688 KUNIT_EXPECT_FALSE(test, test_cache); in test_krealloc()
689 KUNIT_EXPECT_EQ(test, ksize(buf), size); /* Precise size match after KFENCE alloc. */ in test_krealloc()
696 KUNIT_EXPECT_GE(test, ksize(buf), size * 3); in test_krealloc()
698 KUNIT_EXPECT_EQ(test, buf[i], (char)(i + 1)); in test_krealloc()
703 KUNIT_EXPECT_GE(test, ksize(buf), size * 2); in test_krealloc()
705 KUNIT_EXPECT_EQ(test, buf[i], (char)(i + 1)); in test_krealloc()
708 KUNIT_EXPECT_EQ(test, (unsigned long)buf, (unsigned long)ZERO_SIZE_PTR); in test_krealloc()
709 KUNIT_ASSERT_FALSE(test, report_available()); /* No reports yet! */ in test_krealloc()
712 KUNIT_ASSERT_TRUE(test, report_matches(&expect)); in test_krealloc()
716 static void test_memcache_alloc_bulk(struct kunit *test) in test_memcache_alloc_bulk() argument
722 setup_test_cache(test, size, 0, NULL); in test_memcache_alloc_bulk()
723 KUNIT_EXPECT_TRUE(test, test_cache); /* Want memcache. */ in test_memcache_alloc_bulk()
750 KUNIT_EXPECT_TRUE(test, pass); in test_memcache_alloc_bulk()
751 KUNIT_EXPECT_FALSE(test, report_available()); in test_memcache_alloc_bulk()
786 static int test_init(struct kunit *test) in test_init() argument
798 if (strstr(test->name, "memcache")) in test_init()
799 test->priv = TEST_PRIV_WANT_MEMCACHE; in test_init()
801 test->priv = NULL; in test_init()
806 static void test_exit(struct kunit *test) in test_exit() argument