Thomas Gleixner | 7170066 | 2019-05-19 15:51:55 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 2 | /* |
| 3 | * test_kprobes.c - simple sanity test for *probes |
| 4 | * |
| 5 | * Copyright IBM Corp. 2008 |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/kernel.h> |
| 9 | #include <linux/kprobes.h> |
| 10 | #include <linux/random.h> |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 11 | #include <kunit/test.h> |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 12 | |
| 13 | #define div_factor 3 |
| 14 | |
Masami Hiramatsu | 2c7d662 | 2017-10-06 08:15:17 +0900 | [diff] [blame] | 15 | static u32 rand1, preh_val, posth_val; |
Masami Hiramatsu | 8e11440 | 2009-01-06 14:41:47 -0800 | [diff] [blame] | 16 | static u32 (*target)(u32 value); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 17 | static u32 (*target2)(u32 value); |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 18 | static struct kunit *current_test; |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 19 | |
Masami Hiramatsu | 1f6d3a8 | 2021-10-25 20:41:52 +0900 | [diff] [blame] | 20 | static unsigned long (*internal_target)(void); |
| 21 | static unsigned long (*stacktrace_target)(void); |
| 22 | static unsigned long (*stacktrace_driver)(void); |
| 23 | static unsigned long target_return_address[2]; |
| 24 | |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 25 | static noinline u32 kprobe_target(u32 value) |
| 26 | { |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 27 | return (value / div_factor); |
| 28 | } |
| 29 | |
| 30 | static int kp_pre_handler(struct kprobe *p, struct pt_regs *regs) |
| 31 | { |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 32 | KUNIT_EXPECT_FALSE(current_test, preemptible()); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 33 | preh_val = (rand1 / div_factor); |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | static void kp_post_handler(struct kprobe *p, struct pt_regs *regs, |
| 38 | unsigned long flags) |
| 39 | { |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 40 | KUNIT_EXPECT_FALSE(current_test, preemptible()); |
| 41 | KUNIT_EXPECT_EQ(current_test, preh_val, (rand1 / div_factor)); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 42 | posth_val = preh_val + div_factor; |
| 43 | } |
| 44 | |
| 45 | static struct kprobe kp = { |
| 46 | .symbol_name = "kprobe_target", |
| 47 | .pre_handler = kp_pre_handler, |
| 48 | .post_handler = kp_post_handler |
| 49 | }; |
| 50 | |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 51 | static void test_kprobe(struct kunit *test) |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 52 | { |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 53 | current_test = test; |
| 54 | KUNIT_EXPECT_EQ(test, 0, register_kprobe(&kp)); |
| 55 | target(rand1); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 56 | unregister_kprobe(&kp); |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 57 | KUNIT_EXPECT_NE(test, 0, preh_val); |
| 58 | KUNIT_EXPECT_NE(test, 0, posth_val); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 59 | } |
| 60 | |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 61 | static noinline u32 kprobe_target2(u32 value) |
| 62 | { |
| 63 | return (value / div_factor) + 1; |
| 64 | } |
| 65 | |
Masami Hiramatsu | 1f6d3a8 | 2021-10-25 20:41:52 +0900 | [diff] [blame] | 66 | static noinline unsigned long kprobe_stacktrace_internal_target(void) |
| 67 | { |
| 68 | if (!target_return_address[0]) |
| 69 | target_return_address[0] = (unsigned long)__builtin_return_address(0); |
| 70 | return target_return_address[0]; |
| 71 | } |
| 72 | |
| 73 | static noinline unsigned long kprobe_stacktrace_target(void) |
| 74 | { |
| 75 | if (!target_return_address[1]) |
| 76 | target_return_address[1] = (unsigned long)__builtin_return_address(0); |
| 77 | |
| 78 | if (internal_target) |
| 79 | internal_target(); |
| 80 | |
| 81 | return target_return_address[1]; |
| 82 | } |
| 83 | |
| 84 | static noinline unsigned long kprobe_stacktrace_driver(void) |
| 85 | { |
| 86 | if (stacktrace_target) |
| 87 | stacktrace_target(); |
| 88 | |
| 89 | /* This is for preventing inlining the function */ |
| 90 | return (unsigned long)__builtin_return_address(0); |
| 91 | } |
| 92 | |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 93 | static int kp_pre_handler2(struct kprobe *p, struct pt_regs *regs) |
| 94 | { |
| 95 | preh_val = (rand1 / div_factor) + 1; |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | static void kp_post_handler2(struct kprobe *p, struct pt_regs *regs, |
| 100 | unsigned long flags) |
| 101 | { |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 102 | KUNIT_EXPECT_EQ(current_test, preh_val, (rand1 / div_factor) + 1); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 103 | posth_val = preh_val + div_factor; |
| 104 | } |
| 105 | |
| 106 | static struct kprobe kp2 = { |
| 107 | .symbol_name = "kprobe_target2", |
| 108 | .pre_handler = kp_pre_handler2, |
| 109 | .post_handler = kp_post_handler2 |
| 110 | }; |
| 111 | |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 112 | static void test_kprobes(struct kunit *test) |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 113 | { |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 114 | struct kprobe *kps[2] = {&kp, &kp2}; |
| 115 | |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 116 | current_test = test; |
| 117 | |
Masami Hiramatsu | fd02e6f | 2010-10-14 12:10:24 +0900 | [diff] [blame] | 118 | /* addr and flags should be cleard for reusing kprobe. */ |
| 119 | kp.addr = NULL; |
| 120 | kp.flags = 0; |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 121 | |
| 122 | KUNIT_EXPECT_EQ(test, 0, register_kprobes(kps, 2)); |
| 123 | preh_val = 0; |
| 124 | posth_val = 0; |
| 125 | target(rand1); |
| 126 | |
| 127 | KUNIT_EXPECT_NE(test, 0, preh_val); |
| 128 | KUNIT_EXPECT_NE(test, 0, posth_val); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 129 | |
| 130 | preh_val = 0; |
| 131 | posth_val = 0; |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 132 | target2(rand1); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 133 | |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 134 | KUNIT_EXPECT_NE(test, 0, preh_val); |
| 135 | KUNIT_EXPECT_NE(test, 0, posth_val); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 136 | unregister_kprobes(kps, 2); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 137 | } |
| 138 | |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 139 | #ifdef CONFIG_KRETPROBES |
| 140 | static u32 krph_val; |
| 141 | |
Abhishek Sagar | f47cd9b | 2008-02-06 01:38:22 -0800 | [diff] [blame] | 142 | static int entry_handler(struct kretprobe_instance *ri, struct pt_regs *regs) |
| 143 | { |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 144 | KUNIT_EXPECT_FALSE(current_test, preemptible()); |
Abhishek Sagar | f47cd9b | 2008-02-06 01:38:22 -0800 | [diff] [blame] | 145 | krph_val = (rand1 / div_factor); |
| 146 | return 0; |
| 147 | } |
| 148 | |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 149 | static int return_handler(struct kretprobe_instance *ri, struct pt_regs *regs) |
| 150 | { |
| 151 | unsigned long ret = regs_return_value(regs); |
| 152 | |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 153 | KUNIT_EXPECT_FALSE(current_test, preemptible()); |
| 154 | KUNIT_EXPECT_EQ(current_test, ret, rand1 / div_factor); |
| 155 | KUNIT_EXPECT_NE(current_test, krph_val, 0); |
Abhishek Sagar | f47cd9b | 2008-02-06 01:38:22 -0800 | [diff] [blame] | 156 | krph_val = rand1; |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | static struct kretprobe rp = { |
| 161 | .handler = return_handler, |
Abhishek Sagar | f47cd9b | 2008-02-06 01:38:22 -0800 | [diff] [blame] | 162 | .entry_handler = entry_handler, |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 163 | .kp.symbol_name = "kprobe_target" |
| 164 | }; |
| 165 | |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 166 | static void test_kretprobe(struct kunit *test) |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 167 | { |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 168 | current_test = test; |
| 169 | KUNIT_EXPECT_EQ(test, 0, register_kretprobe(&rp)); |
| 170 | target(rand1); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 171 | unregister_kretprobe(&rp); |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 172 | KUNIT_EXPECT_EQ(test, krph_val, rand1); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 173 | } |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 174 | |
| 175 | static int return_handler2(struct kretprobe_instance *ri, struct pt_regs *regs) |
| 176 | { |
| 177 | unsigned long ret = regs_return_value(regs); |
| 178 | |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 179 | KUNIT_EXPECT_EQ(current_test, ret, (rand1 / div_factor) + 1); |
| 180 | KUNIT_EXPECT_NE(current_test, krph_val, 0); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 181 | krph_val = rand1; |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | static struct kretprobe rp2 = { |
| 186 | .handler = return_handler2, |
| 187 | .entry_handler = entry_handler, |
| 188 | .kp.symbol_name = "kprobe_target2" |
| 189 | }; |
| 190 | |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 191 | static void test_kretprobes(struct kunit *test) |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 192 | { |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 193 | struct kretprobe *rps[2] = {&rp, &rp2}; |
| 194 | |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 195 | current_test = test; |
Masami Hiramatsu | fd02e6f | 2010-10-14 12:10:24 +0900 | [diff] [blame] | 196 | /* addr and flags should be cleard for reusing kprobe. */ |
| 197 | rp.kp.addr = NULL; |
| 198 | rp.kp.flags = 0; |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 199 | KUNIT_EXPECT_EQ(test, 0, register_kretprobes(rps, 2)); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 200 | |
| 201 | krph_val = 0; |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 202 | target(rand1); |
| 203 | KUNIT_EXPECT_EQ(test, krph_val, rand1); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 204 | |
| 205 | krph_val = 0; |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 206 | target2(rand1); |
| 207 | KUNIT_EXPECT_EQ(test, krph_val, rand1); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 208 | unregister_kretprobes(rps, 2); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 209 | } |
Masami Hiramatsu | 1f6d3a8 | 2021-10-25 20:41:52 +0900 | [diff] [blame] | 210 | |
| 211 | #ifdef CONFIG_ARCH_CORRECT_STACKTRACE_ON_KRETPROBE |
| 212 | #define STACK_BUF_SIZE 16 |
| 213 | static unsigned long stack_buf[STACK_BUF_SIZE]; |
| 214 | |
| 215 | static int stacktrace_return_handler(struct kretprobe_instance *ri, struct pt_regs *regs) |
| 216 | { |
| 217 | unsigned long retval = regs_return_value(regs); |
| 218 | int i, ret; |
| 219 | |
| 220 | KUNIT_EXPECT_FALSE(current_test, preemptible()); |
| 221 | KUNIT_EXPECT_EQ(current_test, retval, target_return_address[1]); |
| 222 | |
| 223 | /* |
| 224 | * Test stacktrace inside the kretprobe handler, this will involves |
| 225 | * kretprobe trampoline, but must include correct return address |
| 226 | * of the target function. |
| 227 | */ |
| 228 | ret = stack_trace_save(stack_buf, STACK_BUF_SIZE, 0); |
| 229 | KUNIT_EXPECT_NE(current_test, ret, 0); |
| 230 | |
| 231 | for (i = 0; i < ret; i++) { |
| 232 | if (stack_buf[i] == target_return_address[1]) |
| 233 | break; |
| 234 | } |
| 235 | KUNIT_EXPECT_NE(current_test, i, ret); |
| 236 | |
| 237 | #if !IS_MODULE(CONFIG_KPROBES_SANITY_TEST) |
| 238 | /* |
| 239 | * Test stacktrace from pt_regs at the return address. Thus the stack |
| 240 | * trace must start from the target return address. |
| 241 | */ |
| 242 | ret = stack_trace_save_regs(regs, stack_buf, STACK_BUF_SIZE, 0); |
| 243 | KUNIT_EXPECT_NE(current_test, ret, 0); |
| 244 | KUNIT_EXPECT_EQ(current_test, stack_buf[0], target_return_address[1]); |
| 245 | #endif |
| 246 | |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | static struct kretprobe rp3 = { |
| 251 | .handler = stacktrace_return_handler, |
| 252 | .kp.symbol_name = "kprobe_stacktrace_target" |
| 253 | }; |
| 254 | |
| 255 | static void test_stacktrace_on_kretprobe(struct kunit *test) |
| 256 | { |
| 257 | unsigned long myretaddr = (unsigned long)__builtin_return_address(0); |
| 258 | |
| 259 | current_test = test; |
| 260 | rp3.kp.addr = NULL; |
| 261 | rp3.kp.flags = 0; |
| 262 | |
| 263 | /* |
| 264 | * Run the stacktrace_driver() to record correct return address in |
| 265 | * stacktrace_target() and ensure stacktrace_driver() call is not |
| 266 | * inlined by checking the return address of stacktrace_driver() |
| 267 | * and the return address of this function is different. |
| 268 | */ |
| 269 | KUNIT_ASSERT_NE(test, myretaddr, stacktrace_driver()); |
| 270 | |
| 271 | KUNIT_ASSERT_EQ(test, 0, register_kretprobe(&rp3)); |
| 272 | KUNIT_ASSERT_NE(test, myretaddr, stacktrace_driver()); |
| 273 | unregister_kretprobe(&rp3); |
| 274 | } |
| 275 | |
| 276 | static int stacktrace_internal_return_handler(struct kretprobe_instance *ri, struct pt_regs *regs) |
| 277 | { |
| 278 | unsigned long retval = regs_return_value(regs); |
| 279 | int i, ret; |
| 280 | |
| 281 | KUNIT_EXPECT_FALSE(current_test, preemptible()); |
| 282 | KUNIT_EXPECT_EQ(current_test, retval, target_return_address[0]); |
| 283 | |
| 284 | /* |
| 285 | * Test stacktrace inside the kretprobe handler for nested case. |
| 286 | * The unwinder will find the kretprobe_trampoline address on the |
| 287 | * return address, and kretprobe must solve that. |
| 288 | */ |
| 289 | ret = stack_trace_save(stack_buf, STACK_BUF_SIZE, 0); |
| 290 | KUNIT_EXPECT_NE(current_test, ret, 0); |
| 291 | |
| 292 | for (i = 0; i < ret - 1; i++) { |
| 293 | if (stack_buf[i] == target_return_address[0]) { |
| 294 | KUNIT_EXPECT_EQ(current_test, stack_buf[i + 1], target_return_address[1]); |
| 295 | break; |
| 296 | } |
| 297 | } |
| 298 | KUNIT_EXPECT_NE(current_test, i, ret); |
| 299 | |
| 300 | #if !IS_MODULE(CONFIG_KPROBES_SANITY_TEST) |
| 301 | /* Ditto for the regs version. */ |
| 302 | ret = stack_trace_save_regs(regs, stack_buf, STACK_BUF_SIZE, 0); |
| 303 | KUNIT_EXPECT_NE(current_test, ret, 0); |
| 304 | KUNIT_EXPECT_EQ(current_test, stack_buf[0], target_return_address[0]); |
| 305 | KUNIT_EXPECT_EQ(current_test, stack_buf[1], target_return_address[1]); |
| 306 | #endif |
| 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | static struct kretprobe rp4 = { |
| 312 | .handler = stacktrace_internal_return_handler, |
| 313 | .kp.symbol_name = "kprobe_stacktrace_internal_target" |
| 314 | }; |
| 315 | |
| 316 | static void test_stacktrace_on_nested_kretprobe(struct kunit *test) |
| 317 | { |
| 318 | unsigned long myretaddr = (unsigned long)__builtin_return_address(0); |
| 319 | struct kretprobe *rps[2] = {&rp3, &rp4}; |
| 320 | |
| 321 | current_test = test; |
| 322 | rp3.kp.addr = NULL; |
| 323 | rp3.kp.flags = 0; |
| 324 | |
| 325 | //KUNIT_ASSERT_NE(test, myretaddr, stacktrace_driver()); |
| 326 | |
| 327 | KUNIT_ASSERT_EQ(test, 0, register_kretprobes(rps, 2)); |
| 328 | KUNIT_ASSERT_NE(test, myretaddr, stacktrace_driver()); |
| 329 | unregister_kretprobes(rps, 2); |
| 330 | } |
| 331 | #endif /* CONFIG_ARCH_CORRECT_STACKTRACE_ON_KRETPROBE */ |
| 332 | |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 333 | #endif /* CONFIG_KRETPROBES */ |
| 334 | |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 335 | static int kprobes_test_init(struct kunit *test) |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 336 | { |
Masami Hiramatsu | 8e11440 | 2009-01-06 14:41:47 -0800 | [diff] [blame] | 337 | target = kprobe_target; |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 338 | target2 = kprobe_target2; |
Masami Hiramatsu | 1f6d3a8 | 2021-10-25 20:41:52 +0900 | [diff] [blame] | 339 | stacktrace_target = kprobe_stacktrace_target; |
| 340 | internal_target = kprobe_stacktrace_internal_target; |
| 341 | stacktrace_driver = kprobe_stacktrace_driver; |
Masami Hiramatsu | 8e11440 | 2009-01-06 14:41:47 -0800 | [diff] [blame] | 342 | |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 343 | do { |
Akinobu Mita | 6d65df3 | 2013-04-29 16:21:30 -0700 | [diff] [blame] | 344 | rand1 = prandom_u32(); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 345 | } while (rand1 <= div_factor); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 346 | return 0; |
| 347 | } |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 348 | |
| 349 | static struct kunit_case kprobes_testcases[] = { |
| 350 | KUNIT_CASE(test_kprobe), |
| 351 | KUNIT_CASE(test_kprobes), |
| 352 | #ifdef CONFIG_KRETPROBES |
| 353 | KUNIT_CASE(test_kretprobe), |
| 354 | KUNIT_CASE(test_kretprobes), |
Masami Hiramatsu | 1f6d3a8 | 2021-10-25 20:41:52 +0900 | [diff] [blame] | 355 | #ifdef CONFIG_ARCH_CORRECT_STACKTRACE_ON_KRETPROBE |
| 356 | KUNIT_CASE(test_stacktrace_on_kretprobe), |
| 357 | KUNIT_CASE(test_stacktrace_on_nested_kretprobe), |
| 358 | #endif |
Sven Schnelle | e44e81c | 2021-10-21 09:54:24 +0900 | [diff] [blame] | 359 | #endif |
| 360 | {} |
| 361 | }; |
| 362 | |
| 363 | static struct kunit_suite kprobes_test_suite = { |
| 364 | .name = "kprobes_test", |
| 365 | .init = kprobes_test_init, |
| 366 | .test_cases = kprobes_testcases, |
| 367 | }; |
| 368 | |
| 369 | kunit_test_suites(&kprobes_test_suite); |
| 370 | |
| 371 | MODULE_LICENSE("GPL"); |