Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 1 | /* |
| 2 | * test_kprobes.c - simple sanity test for *probes |
| 3 | * |
| 4 | * Copyright IBM Corp. 2008 |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it would be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 14 | * the GNU General Public License for more details. |
| 15 | */ |
| 16 | |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 17 | #define pr_fmt(fmt) "Kprobe smoke test: " fmt |
| 18 | |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 19 | #include <linux/kernel.h> |
| 20 | #include <linux/kprobes.h> |
| 21 | #include <linux/random.h> |
| 22 | |
| 23 | #define div_factor 3 |
| 24 | |
| 25 | static u32 rand1, preh_val, posth_val, jph_val; |
| 26 | static int errors, handler_errors, num_tests; |
Masami Hiramatsu | 8e11440 | 2009-01-06 14:41:47 -0800 | [diff] [blame] | 27 | static u32 (*target)(u32 value); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 28 | static u32 (*target2)(u32 value); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 29 | |
| 30 | static noinline u32 kprobe_target(u32 value) |
| 31 | { |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 32 | return (value / div_factor); |
| 33 | } |
| 34 | |
| 35 | static int kp_pre_handler(struct kprobe *p, struct pt_regs *regs) |
| 36 | { |
Masami Hiramatsu | 3539d09 | 2017-09-19 18:59:00 +0900 | [diff] [blame^] | 37 | if (preemptible()) { |
| 38 | handler_errors++; |
| 39 | pr_err("pre-handler is preemptible\n"); |
| 40 | } |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 41 | preh_val = (rand1 / div_factor); |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | static void kp_post_handler(struct kprobe *p, struct pt_regs *regs, |
| 46 | unsigned long flags) |
| 47 | { |
Masami Hiramatsu | 3539d09 | 2017-09-19 18:59:00 +0900 | [diff] [blame^] | 48 | if (preemptible()) { |
| 49 | handler_errors++; |
| 50 | pr_err("post-handler is preemptible\n"); |
| 51 | } |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 52 | if (preh_val != (rand1 / div_factor)) { |
| 53 | handler_errors++; |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 54 | pr_err("incorrect value in post_handler\n"); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 55 | } |
| 56 | posth_val = preh_val + div_factor; |
| 57 | } |
| 58 | |
| 59 | static struct kprobe kp = { |
| 60 | .symbol_name = "kprobe_target", |
| 61 | .pre_handler = kp_pre_handler, |
| 62 | .post_handler = kp_post_handler |
| 63 | }; |
| 64 | |
| 65 | static int test_kprobe(void) |
| 66 | { |
| 67 | int ret; |
| 68 | |
| 69 | ret = register_kprobe(&kp); |
| 70 | if (ret < 0) { |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 71 | pr_err("register_kprobe returned %d\n", ret); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 72 | return ret; |
| 73 | } |
| 74 | |
Masami Hiramatsu | 8e11440 | 2009-01-06 14:41:47 -0800 | [diff] [blame] | 75 | ret = target(rand1); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 76 | unregister_kprobe(&kp); |
| 77 | |
| 78 | if (preh_val == 0) { |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 79 | pr_err("kprobe pre_handler not called\n"); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 80 | handler_errors++; |
| 81 | } |
| 82 | |
| 83 | if (posth_val == 0) { |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 84 | pr_err("kprobe post_handler not called\n"); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 85 | handler_errors++; |
| 86 | } |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 91 | static noinline u32 kprobe_target2(u32 value) |
| 92 | { |
| 93 | return (value / div_factor) + 1; |
| 94 | } |
| 95 | |
| 96 | static int kp_pre_handler2(struct kprobe *p, struct pt_regs *regs) |
| 97 | { |
| 98 | preh_val = (rand1 / div_factor) + 1; |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | static void kp_post_handler2(struct kprobe *p, struct pt_regs *regs, |
| 103 | unsigned long flags) |
| 104 | { |
| 105 | if (preh_val != (rand1 / div_factor) + 1) { |
| 106 | handler_errors++; |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 107 | pr_err("incorrect value in post_handler2\n"); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 108 | } |
| 109 | posth_val = preh_val + div_factor; |
| 110 | } |
| 111 | |
| 112 | static struct kprobe kp2 = { |
| 113 | .symbol_name = "kprobe_target2", |
| 114 | .pre_handler = kp_pre_handler2, |
| 115 | .post_handler = kp_post_handler2 |
| 116 | }; |
| 117 | |
| 118 | static int test_kprobes(void) |
| 119 | { |
| 120 | int ret; |
| 121 | struct kprobe *kps[2] = {&kp, &kp2}; |
| 122 | |
Masami Hiramatsu | fd02e6f | 2010-10-14 12:10:24 +0900 | [diff] [blame] | 123 | /* addr and flags should be cleard for reusing kprobe. */ |
| 124 | kp.addr = NULL; |
| 125 | kp.flags = 0; |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 126 | ret = register_kprobes(kps, 2); |
| 127 | if (ret < 0) { |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 128 | pr_err("register_kprobes returned %d\n", ret); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 129 | return ret; |
| 130 | } |
| 131 | |
| 132 | preh_val = 0; |
| 133 | posth_val = 0; |
| 134 | ret = target(rand1); |
| 135 | |
| 136 | if (preh_val == 0) { |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 137 | pr_err("kprobe pre_handler not called\n"); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 138 | handler_errors++; |
| 139 | } |
| 140 | |
| 141 | if (posth_val == 0) { |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 142 | pr_err("kprobe post_handler not called\n"); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 143 | handler_errors++; |
| 144 | } |
| 145 | |
| 146 | preh_val = 0; |
| 147 | posth_val = 0; |
| 148 | ret = target2(rand1); |
| 149 | |
| 150 | if (preh_val == 0) { |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 151 | pr_err("kprobe pre_handler2 not called\n"); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 152 | handler_errors++; |
| 153 | } |
| 154 | |
| 155 | if (posth_val == 0) { |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 156 | pr_err("kprobe post_handler2 not called\n"); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 157 | handler_errors++; |
| 158 | } |
| 159 | |
| 160 | unregister_kprobes(kps, 2); |
| 161 | return 0; |
| 162 | |
| 163 | } |
| 164 | |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 165 | static u32 j_kprobe_target(u32 value) |
| 166 | { |
Masami Hiramatsu | 3539d09 | 2017-09-19 18:59:00 +0900 | [diff] [blame^] | 167 | if (preemptible()) { |
| 168 | handler_errors++; |
| 169 | pr_err("jprobe-handler is preemptible\n"); |
| 170 | } |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 171 | if (value != rand1) { |
| 172 | handler_errors++; |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 173 | pr_err("incorrect value in jprobe handler\n"); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | jph_val = rand1; |
| 177 | jprobe_return(); |
| 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | static struct jprobe jp = { |
| 182 | .entry = j_kprobe_target, |
| 183 | .kp.symbol_name = "kprobe_target" |
| 184 | }; |
| 185 | |
| 186 | static int test_jprobe(void) |
| 187 | { |
| 188 | int ret; |
| 189 | |
| 190 | ret = register_jprobe(&jp); |
| 191 | if (ret < 0) { |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 192 | pr_err("register_jprobe returned %d\n", ret); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 193 | return ret; |
| 194 | } |
| 195 | |
Masami Hiramatsu | 8e11440 | 2009-01-06 14:41:47 -0800 | [diff] [blame] | 196 | ret = target(rand1); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 197 | unregister_jprobe(&jp); |
| 198 | if (jph_val == 0) { |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 199 | pr_err("jprobe handler not called\n"); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 200 | handler_errors++; |
| 201 | } |
| 202 | |
| 203 | return 0; |
| 204 | } |
| 205 | |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 206 | static struct jprobe jp2 = { |
| 207 | .entry = j_kprobe_target, |
| 208 | .kp.symbol_name = "kprobe_target2" |
| 209 | }; |
| 210 | |
| 211 | static int test_jprobes(void) |
| 212 | { |
| 213 | int ret; |
| 214 | struct jprobe *jps[2] = {&jp, &jp2}; |
| 215 | |
Masami Hiramatsu | fd02e6f | 2010-10-14 12:10:24 +0900 | [diff] [blame] | 216 | /* addr and flags should be cleard for reusing kprobe. */ |
| 217 | jp.kp.addr = NULL; |
| 218 | jp.kp.flags = 0; |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 219 | ret = register_jprobes(jps, 2); |
| 220 | if (ret < 0) { |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 221 | pr_err("register_jprobes returned %d\n", ret); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 222 | return ret; |
| 223 | } |
| 224 | |
| 225 | jph_val = 0; |
| 226 | ret = target(rand1); |
| 227 | if (jph_val == 0) { |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 228 | pr_err("jprobe handler not called\n"); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 229 | handler_errors++; |
| 230 | } |
| 231 | |
| 232 | jph_val = 0; |
| 233 | ret = target2(rand1); |
| 234 | if (jph_val == 0) { |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 235 | pr_err("jprobe handler2 not called\n"); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 236 | handler_errors++; |
| 237 | } |
| 238 | unregister_jprobes(jps, 2); |
| 239 | |
| 240 | return 0; |
| 241 | } |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 242 | #ifdef CONFIG_KRETPROBES |
| 243 | static u32 krph_val; |
| 244 | |
Abhishek Sagar | f47cd9b | 2008-02-06 01:38:22 -0800 | [diff] [blame] | 245 | static int entry_handler(struct kretprobe_instance *ri, struct pt_regs *regs) |
| 246 | { |
Masami Hiramatsu | 3539d09 | 2017-09-19 18:59:00 +0900 | [diff] [blame^] | 247 | if (preemptible()) { |
| 248 | handler_errors++; |
| 249 | pr_err("kretprobe entry handler is preemptible\n"); |
| 250 | } |
Abhishek Sagar | f47cd9b | 2008-02-06 01:38:22 -0800 | [diff] [blame] | 251 | krph_val = (rand1 / div_factor); |
| 252 | return 0; |
| 253 | } |
| 254 | |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 255 | static int return_handler(struct kretprobe_instance *ri, struct pt_regs *regs) |
| 256 | { |
| 257 | unsigned long ret = regs_return_value(regs); |
| 258 | |
Masami Hiramatsu | 3539d09 | 2017-09-19 18:59:00 +0900 | [diff] [blame^] | 259 | if (preemptible()) { |
| 260 | handler_errors++; |
| 261 | pr_err("kretprobe return handler is preemptible\n"); |
| 262 | } |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 263 | if (ret != (rand1 / div_factor)) { |
| 264 | handler_errors++; |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 265 | pr_err("incorrect value in kretprobe handler\n"); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 266 | } |
Abhishek Sagar | f47cd9b | 2008-02-06 01:38:22 -0800 | [diff] [blame] | 267 | if (krph_val == 0) { |
| 268 | handler_errors++; |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 269 | pr_err("call to kretprobe entry handler failed\n"); |
Abhishek Sagar | f47cd9b | 2008-02-06 01:38:22 -0800 | [diff] [blame] | 270 | } |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 271 | |
Abhishek Sagar | f47cd9b | 2008-02-06 01:38:22 -0800 | [diff] [blame] | 272 | krph_val = rand1; |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | static struct kretprobe rp = { |
| 277 | .handler = return_handler, |
Abhishek Sagar | f47cd9b | 2008-02-06 01:38:22 -0800 | [diff] [blame] | 278 | .entry_handler = entry_handler, |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 279 | .kp.symbol_name = "kprobe_target" |
| 280 | }; |
| 281 | |
| 282 | static int test_kretprobe(void) |
| 283 | { |
| 284 | int ret; |
| 285 | |
| 286 | ret = register_kretprobe(&rp); |
| 287 | if (ret < 0) { |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 288 | pr_err("register_kretprobe returned %d\n", ret); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 289 | return ret; |
| 290 | } |
| 291 | |
Masami Hiramatsu | 8e11440 | 2009-01-06 14:41:47 -0800 | [diff] [blame] | 292 | ret = target(rand1); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 293 | unregister_kretprobe(&rp); |
Abhishek Sagar | f47cd9b | 2008-02-06 01:38:22 -0800 | [diff] [blame] | 294 | if (krph_val != rand1) { |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 295 | pr_err("kretprobe handler not called\n"); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 296 | handler_errors++; |
| 297 | } |
| 298 | |
| 299 | return 0; |
| 300 | } |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 301 | |
| 302 | static int return_handler2(struct kretprobe_instance *ri, struct pt_regs *regs) |
| 303 | { |
| 304 | unsigned long ret = regs_return_value(regs); |
| 305 | |
| 306 | if (ret != (rand1 / div_factor) + 1) { |
| 307 | handler_errors++; |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 308 | pr_err("incorrect value in kretprobe handler2\n"); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 309 | } |
| 310 | if (krph_val == 0) { |
| 311 | handler_errors++; |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 312 | pr_err("call to kretprobe entry handler failed\n"); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | krph_val = rand1; |
| 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | static struct kretprobe rp2 = { |
| 320 | .handler = return_handler2, |
| 321 | .entry_handler = entry_handler, |
| 322 | .kp.symbol_name = "kprobe_target2" |
| 323 | }; |
| 324 | |
| 325 | static int test_kretprobes(void) |
| 326 | { |
| 327 | int ret; |
| 328 | struct kretprobe *rps[2] = {&rp, &rp2}; |
| 329 | |
Masami Hiramatsu | fd02e6f | 2010-10-14 12:10:24 +0900 | [diff] [blame] | 330 | /* addr and flags should be cleard for reusing kprobe. */ |
| 331 | rp.kp.addr = NULL; |
| 332 | rp.kp.flags = 0; |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 333 | ret = register_kretprobes(rps, 2); |
| 334 | if (ret < 0) { |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 335 | pr_err("register_kretprobe returned %d\n", ret); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 336 | return ret; |
| 337 | } |
| 338 | |
| 339 | krph_val = 0; |
| 340 | ret = target(rand1); |
| 341 | if (krph_val != rand1) { |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 342 | pr_err("kretprobe handler not called\n"); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 343 | handler_errors++; |
| 344 | } |
| 345 | |
| 346 | krph_val = 0; |
| 347 | ret = target2(rand1); |
| 348 | if (krph_val != rand1) { |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 349 | pr_err("kretprobe handler2 not called\n"); |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 350 | handler_errors++; |
| 351 | } |
| 352 | unregister_kretprobes(rps, 2); |
| 353 | return 0; |
| 354 | } |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 355 | #endif /* CONFIG_KRETPROBES */ |
| 356 | |
| 357 | int init_test_probes(void) |
| 358 | { |
| 359 | int ret; |
| 360 | |
Masami Hiramatsu | 8e11440 | 2009-01-06 14:41:47 -0800 | [diff] [blame] | 361 | target = kprobe_target; |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 362 | target2 = kprobe_target2; |
Masami Hiramatsu | 8e11440 | 2009-01-06 14:41:47 -0800 | [diff] [blame] | 363 | |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 364 | do { |
Akinobu Mita | 6d65df3 | 2013-04-29 16:21:30 -0700 | [diff] [blame] | 365 | rand1 = prandom_u32(); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 366 | } while (rand1 <= div_factor); |
| 367 | |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 368 | pr_info("started\n"); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 369 | num_tests++; |
| 370 | ret = test_kprobe(); |
| 371 | if (ret < 0) |
| 372 | errors++; |
| 373 | |
| 374 | num_tests++; |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 375 | ret = test_kprobes(); |
| 376 | if (ret < 0) |
| 377 | errors++; |
| 378 | |
| 379 | num_tests++; |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 380 | ret = test_jprobe(); |
| 381 | if (ret < 0) |
| 382 | errors++; |
| 383 | |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 384 | num_tests++; |
| 385 | ret = test_jprobes(); |
| 386 | if (ret < 0) |
| 387 | errors++; |
| 388 | |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 389 | #ifdef CONFIG_KRETPROBES |
| 390 | num_tests++; |
| 391 | ret = test_kretprobe(); |
| 392 | if (ret < 0) |
| 393 | errors++; |
Masami Hiramatsu | 12da3b8 | 2009-01-06 14:41:48 -0800 | [diff] [blame] | 394 | |
| 395 | num_tests++; |
| 396 | ret = test_kretprobes(); |
| 397 | if (ret < 0) |
| 398 | errors++; |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 399 | #endif /* CONFIG_KRETPROBES */ |
| 400 | |
| 401 | if (errors) |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 402 | pr_err("BUG: %d out of %d tests failed\n", errors, num_tests); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 403 | else if (handler_errors) |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 404 | pr_err("BUG: %d error(s) running handlers\n", handler_errors); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 405 | else |
Fabian Frederick | 4878b14 | 2014-08-08 14:19:48 -0700 | [diff] [blame] | 406 | pr_info("passed successfully\n"); |
Ananth N Mavinakayanahalli | 8c1c935 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 407 | |
| 408 | return 0; |
| 409 | } |