#include <kunit/test.h>
#include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/kfence.h>
#include <linux/mm.h>
#include <linux/random.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/string.h>
#include <linux/tracepoint.h>
#include <trace/events/printk.h>
#include <asm/kfence.h>
#include "kfence.h"
#ifndef arch_kfence_test_address
#define arch_kfence_test_address(addr) …
#endif
#define KFENCE_TEST_REQUIRES(test, cond) …
static struct { … } observed = …;
static void probe_console(void *ignore, const char *buf, size_t len)
{ … }
static bool report_available(void)
{ … }
struct expect_report { … };
static const char *get_access_type(const struct expect_report *r)
{ … }
static bool report_matches(const struct expect_report *r)
{ … }
#define TEST_PRIV_WANT_MEMCACHE …
static struct kmem_cache *test_cache;
static size_t setup_test_cache(struct kunit *test, size_t size, slab_flags_t flags,
void (*ctor)(void *))
{ … }
static void test_cache_destroy(void)
{ … }
static inline size_t kmalloc_cache_alignment(size_t size)
{ … }
static __always_inline void test_free(void *ptr)
{ … }
enum allocation_policy { … };
static void *test_alloc(struct kunit *test, size_t size, gfp_t gfp, enum allocation_policy policy)
{ … }
static void test_out_of_bounds_read(struct kunit *test)
{ … }
static void test_out_of_bounds_write(struct kunit *test)
{ … }
static void test_use_after_free_read(struct kunit *test)
{ … }
static void test_double_free(struct kunit *test)
{ … }
static void test_invalid_addr_free(struct kunit *test)
{ … }
static void test_corruption(struct kunit *test)
{ … }
static void test_kmalloc_aligned_oob_read(struct kunit *test)
{ … }
static void test_kmalloc_aligned_oob_write(struct kunit *test)
{ … }
static void test_shrink_memcache(struct kunit *test)
{ … }
static void ctor_set_x(void *obj)
{ … }
static void test_free_bulk(struct kunit *test)
{ … }
static void test_init_on_free(struct kunit *test)
{ … }
static void test_memcache_ctor(struct kunit *test)
{ … }
static void test_gfpzero(struct kunit *test)
{ … }
static void test_invalid_access(struct kunit *test)
{ … }
static void test_memcache_typesafe_by_rcu(struct kunit *test)
{ … }
static void test_krealloc(struct kunit *test)
{ … }
static void test_memcache_alloc_bulk(struct kunit *test)
{ … }
#define KFENCE_KUNIT_CASE(test_name) …
static struct kunit_case kfence_test_cases[] = …;
static int test_init(struct kunit *test)
{ … }
static void test_exit(struct kunit *test)
{ … }
static int kfence_suite_init(struct kunit_suite *suite)
{ … }
static void kfence_suite_exit(struct kunit_suite *suite)
{ … }
static struct kunit_suite kfence_test_suite = …;
kunit_test_suites(…);
MODULE_LICENSE(…) …;
MODULE_AUTHOR(…) …;
MODULE_DESCRIPTION(…) …;