FILE
test-kprobes.c
File preview with syntax highlighting.
linux-6.19.14/arch/riscv/kernel/tests/kprobes/test-kprobes.c
1// SPDX-License-Identifier: GPL-2.0+ 2 3#include <linux/kernel.h> 4#include <linux/kprobes.h> 5#include <kunit/test.h> 6#include "test-kprobes.h" 7 8static int kprobe_dummy_handler(struct kprobe *kp, struct pt_regs *regs) 9{ 10 return 0; 11} 12 13static void test_kprobe_riscv(struct kunit *test) 14{ 15 unsigned int num_kprobe = 0; 16 long (*func)(void); 17 struct kprobe *kp; 18 int i; 19 20 while (test_kprobes_addresses[num_kprobe]) 21 num_kprobe++; 22 23 kp = kcalloc(num_kprobe, sizeof(*kp), GFP_KERNEL); 24 KUNIT_EXPECT_TRUE(test, kp); 25 if (!kp) 26 return; 27 28 for (i = 0; i < num_kprobe; ++i) { 29 kp[i].addr = test_kprobes_addresses[i]; 30 kp[i].pre_handler = kprobe_dummy_handler; 31 KUNIT_EXPECT_EQ(test, 0, register_kprobe(&kp[i])); 32 } 33 34 for (i = 0;; ++i) { 35 func = test_kprobes_functions[i]; 36 if (!func) 37 break; 38 KUNIT_EXPECT_EQ_MSG(test, KPROBE_TEST_MAGIC, func(), "function %d broken", i); 39 } 40 41 for (i = 0; i < num_kprobe; ++i) 42 unregister_kprobe(&kp[i]); 43 kfree(kp); 44} 45 46static struct kunit_case kprobes_testcases[] = { 47 KUNIT_CASE(test_kprobe_riscv), 48 {} 49}; 50 51static struct kunit_suite kprobes_test_suite = { 52 .name = "kprobes_riscv", 53 .test_cases = kprobes_testcases, 54}; 55 56kunit_test_suites(&kprobes_test_suite); 57 58MODULE_LICENSE("GPL"); 59MODULE_DESCRIPTION("KUnit test for riscv kprobes");
~/
Read-only file preview.