0001
0002
0003 #include <linux/kernel.h>
0004 #include <linux/kprobes.h>
0005 #include <linux/random.h>
0006 #include <kunit/test.h>
0007 #include "test_kprobes.h"
0008
0009 static struct kprobe kp;
0010
0011 static void setup_kprobe(struct kunit *test, struct kprobe *kp,
0012 const char *symbol, int offset)
0013 {
0014 kp->offset = offset;
0015 kp->addr = NULL;
0016 kp->symbol_name = symbol;
0017 }
0018
0019 static void test_kprobe_offset(struct kunit *test, struct kprobe *kp,
0020 const char *target, int offset)
0021 {
0022 int ret;
0023
0024 setup_kprobe(test, kp, target, 0);
0025 ret = register_kprobe(kp);
0026 if (!ret)
0027 unregister_kprobe(kp);
0028 KUNIT_EXPECT_EQ(test, 0, ret);
0029 setup_kprobe(test, kp, target, offset);
0030 ret = register_kprobe(kp);
0031 KUNIT_EXPECT_EQ(test, -EINVAL, ret);
0032 if (!ret)
0033 unregister_kprobe(kp);
0034 }
0035
0036 static void test_kprobe_odd(struct kunit *test)
0037 {
0038 test_kprobe_offset(test, &kp, "kprobes_target_odd",
0039 kprobes_target_odd_offs);
0040 }
0041
0042 static void test_kprobe_in_insn4(struct kunit *test)
0043 {
0044 test_kprobe_offset(test, &kp, "kprobes_target_in_insn4",
0045 kprobes_target_in_insn4_offs);
0046 }
0047
0048 static void test_kprobe_in_insn6_lo(struct kunit *test)
0049 {
0050 test_kprobe_offset(test, &kp, "kprobes_target_in_insn6_lo",
0051 kprobes_target_in_insn6_lo_offs);
0052 }
0053
0054 static void test_kprobe_in_insn6_hi(struct kunit *test)
0055 {
0056 test_kprobe_offset(test, &kp, "kprobes_target_in_insn6_hi",
0057 kprobes_target_in_insn6_hi_offs);
0058 }
0059
0060 static struct kunit_case kprobes_testcases[] = {
0061 KUNIT_CASE(test_kprobe_odd),
0062 KUNIT_CASE(test_kprobe_in_insn4),
0063 KUNIT_CASE(test_kprobe_in_insn6_lo),
0064 KUNIT_CASE(test_kprobe_in_insn6_hi),
0065 {}
0066 };
0067
0068 static struct kunit_suite kprobes_test_suite = {
0069 .name = "kprobes_test_s390",
0070 .test_cases = kprobes_testcases,
0071 };
0072
0073 kunit_test_suites(&kprobes_test_suite);
0074
0075 MODULE_LICENSE("GPL");