diff options
| author | Fabian Frederick <fabf@skynet.be> | 2014-08-08 17:19:48 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-08-08 18:57:18 -0400 |
| commit | 4878b14b43188ffeceecfc32295ed2a783b7aa7a (patch) | |
| tree | 8a9bdf6b822d2863cf1264ec00c2b5eef7da3034 /kernel | |
| parent | 4dfe694f616e00e6fd83e5bbcd7a3c4d7113493d (diff) | |
kernel/test_kprobes.c: use current logging functions
- Add pr_fmt
- Coalesce formats
- Use current pr_foo() functions instead of printk
- Remove unnecessary "failed" display (already in log level).
Signed-off-by: Fabian Frederick <fabf@skynet.be>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/test_kprobes.c | 87 |
1 files changed, 31 insertions, 56 deletions
diff --git a/kernel/test_kprobes.c b/kernel/test_kprobes.c index 12d6ebbfdd83..0dbab6d1acb4 100644 --- a/kernel/test_kprobes.c +++ b/kernel/test_kprobes.c | |||
| @@ -14,6 +14,8 @@ | |||
| 14 | * the GNU General Public License for more details. | 14 | * the GNU General Public License for more details. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | #define pr_fmt(fmt) "Kprobe smoke test: " fmt | ||
| 18 | |||
| 17 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
| 18 | #include <linux/kprobes.h> | 20 | #include <linux/kprobes.h> |
| 19 | #include <linux/random.h> | 21 | #include <linux/random.h> |
| @@ -41,8 +43,7 @@ static void kp_post_handler(struct kprobe *p, struct pt_regs *regs, | |||
| 41 | { | 43 | { |
| 42 | if (preh_val != (rand1 / div_factor)) { | 44 | if (preh_val != (rand1 / div_factor)) { |
| 43 | handler_errors++; | 45 | handler_errors++; |
| 44 | printk(KERN_ERR "Kprobe smoke test failed: " | 46 | pr_err("incorrect value in post_handler\n"); |
| 45 | "incorrect value in post_handler\n"); | ||
| 46 | } | 47 | } |
| 47 | posth_val = preh_val + div_factor; | 48 | posth_val = preh_val + div_factor; |
| 48 | } | 49 | } |
| @@ -59,8 +60,7 @@ static int test_kprobe(void) | |||
| 59 | 60 | ||
| 60 | ret = register_kprobe(&kp); | 61 | ret = register_kprobe(&kp); |
| 61 | if (ret < 0) { | 62 | if (ret < 0) { |
| 62 | printk(KERN_ERR "Kprobe smoke test failed: " | 63 | pr_err("register_kprobe returned %d\n", ret); |
| 63 | "register_kprobe returned %d\n", ret); | ||
| 64 | return ret; | 64 | return ret; |
| 65 | } | 65 | } |
| 66 | 66 | ||
| @@ -68,14 +68,12 @@ static int test_kprobe(void) | |||
| 68 | unregister_kprobe(&kp); | 68 | unregister_kprobe(&kp); |
| 69 | 69 | ||
| 70 | if (preh_val == 0) { | 70 | if (preh_val == 0) { |
| 71 | printk(KERN_ERR "Kprobe smoke test failed: " | 71 | pr_err("kprobe pre_handler not called\n"); |
| 72 | "kprobe pre_handler not called\n"); | ||
| 73 | handler_errors++; | 72 | handler_errors++; |
| 74 | } | 73 | } |
| 75 | 74 | ||
| 76 | if (posth_val == 0) { | 75 | if (posth_val == 0) { |
| 77 | printk(KERN_ERR "Kprobe smoke test failed: " | 76 | pr_err("kprobe post_handler not called\n"); |
| 78 | "kprobe post_handler not called\n"); | ||
| 79 | handler_errors++; | 77 | handler_errors++; |
| 80 | } | 78 | } |
| 81 | 79 | ||
| @@ -98,8 +96,7 @@ static void kp_post_handler2(struct kprobe *p, struct pt_regs *regs, | |||
| 98 | { | 96 | { |
| 99 | if (preh_val != (rand1 / div_factor) + 1) { | 97 | if (preh_val != (rand1 / div_factor) + 1) { |
| 100 | handler_errors++; | 98 | handler_errors++; |
| 101 | printk(KERN_ERR "Kprobe smoke test failed: " | 99 | pr_err("incorrect value in post_handler2\n"); |
| 102 | "incorrect value in post_handler2\n"); | ||
| 103 | } | 100 | } |
| 104 | posth_val = preh_val + div_factor; | 101 | posth_val = preh_val + div_factor; |
| 105 | } | 102 | } |
| @@ -120,8 +117,7 @@ static int test_kprobes(void) | |||
| 120 | kp.flags = 0; | 117 | kp.flags = 0; |
| 121 | ret = register_kprobes(kps, 2); | 118 | ret = register_kprobes(kps, 2); |
| 122 | if (ret < 0) { | 119 | if (ret < 0) { |
| 123 | printk(KERN_ERR "Kprobe smoke test failed: " | 120 | pr_err("register_kprobes returned %d\n", ret); |
| 124 | "register_kprobes returned %d\n", ret); | ||
| 125 | return ret; | 121 | return ret; |
| 126 | } | 122 | } |
| 127 | 123 | ||
| @@ -130,14 +126,12 @@ static int test_kprobes(void) | |||
| 130 | ret = target(rand1); | 126 | ret = target(rand1); |
| 131 | 127 | ||
| 132 | if (preh_val == 0) { | 128 | if (preh_val == 0) { |
| 133 | printk(KERN_ERR "Kprobe smoke test failed: " | 129 | pr_err("kprobe pre_handler not called\n"); |
| 134 | "kprobe pre_handler not called\n"); | ||
| 135 | handler_errors++; | 130 | handler_errors++; |
| 136 | } | 131 | } |
| 137 | 132 | ||
| 138 | if (posth_val == 0) { | 133 | if (posth_val == 0) { |
| 139 | printk(KERN_ERR "Kprobe smoke test failed: " | 134 | pr_err("kprobe post_handler not called\n"); |
| 140 | "kprobe post_handler not called\n"); | ||
| 141 | handler_errors++; | 135 | handler_errors++; |
| 142 | } | 136 | } |
| 143 | 137 | ||
| @@ -146,14 +140,12 @@ static int test_kprobes(void) | |||
| 146 | ret = target2(rand1); | 140 | ret = target2(rand1); |
| 147 | 141 | ||
| 148 | if (preh_val == 0) { | 142 | if (preh_val == 0) { |
| 149 | printk(KERN_ERR "Kprobe smoke test failed: " | 143 | pr_err("kprobe pre_handler2 not called\n"); |
| 150 | "kprobe pre_handler2 not called\n"); | ||
| 151 | handler_errors++; | 144 | handler_errors++; |
| 152 | } | 145 | } |
| 153 | 146 | ||
| 154 | if (posth_val == 0) { | 147 | if (posth_val == 0) { |
| 155 | printk(KERN_ERR "Kprobe smoke test failed: " | 148 | pr_err("kprobe post_handler2 not called\n"); |
| 156 | "kprobe post_handler2 not called\n"); | ||
| 157 | handler_errors++; | 149 | handler_errors++; |
| 158 | } | 150 | } |
| 159 | 151 | ||
| @@ -166,8 +158,7 @@ static u32 j_kprobe_target(u32 value) | |||
| 166 | { | 158 | { |
| 167 | if (value != rand1) { | 159 | if (value != rand1) { |
| 168 | handler_errors++; | 160 | handler_errors++; |
| 169 | printk(KERN_ERR "Kprobe smoke test failed: " | 161 | pr_err("incorrect value in jprobe handler\n"); |
| 170 | "incorrect value in jprobe handler\n"); | ||
| 171 | } | 162 | } |
| 172 | 163 | ||
| 173 | jph_val = rand1; | 164 | jph_val = rand1; |
| @@ -186,16 +177,14 @@ static int test_jprobe(void) | |||
| 186 | 177 | ||
| 187 | ret = register_jprobe(&jp); | 178 | ret = register_jprobe(&jp); |
| 188 | if (ret < 0) { | 179 | if (ret < 0) { |
| 189 | printk(KERN_ERR "Kprobe smoke test failed: " | 180 | pr_err("register_jprobe returned %d\n", ret); |
| 190 | "register_jprobe returned %d\n", ret); | ||
| 191 | return ret; | 181 | return ret; |
| 192 | } | 182 | } |
| 193 | 183 | ||
| 194 | ret = target(rand1); | 184 | ret = target(rand1); |
| 195 | unregister_jprobe(&jp); | 185 | unregister_jprobe(&jp); |
| 196 | if (jph_val == 0) { | 186 | if (jph_val == 0) { |
| 197 | printk(KERN_ERR "Kprobe smoke test failed: " | 187 | pr_err("jprobe handler not called\n"); |
| 198 | "jprobe handler not called\n"); | ||
| 199 | handler_errors++; | 188 | handler_errors++; |
| 200 | } | 189 | } |
| 201 | 190 | ||
| @@ -217,24 +206,21 @@ static int test_jprobes(void) | |||
| 217 | jp.kp.flags = 0; | 206 | jp.kp.flags = 0; |
| 218 | ret = register_jprobes(jps, 2); | 207 | ret = register_jprobes(jps, 2); |
| 219 | if (ret < 0) { | 208 | if (ret < 0) { |
| 220 | printk(KERN_ERR "Kprobe smoke test failed: " | 209 | pr_err("register_jprobes returned %d\n", ret); |
| 221 | "register_jprobes returned %d\n", ret); | ||
| 222 | return ret; | 210 | return ret; |
| 223 | } | 211 | } |
| 224 | 212 | ||
| 225 | jph_val = 0; | 213 | jph_val = 0; |
| 226 | ret = target(rand1); | 214 | ret = target(rand1); |
| 227 | if (jph_val == 0) { | 215 | if (jph_val == 0) { |
| 228 | printk(KERN_ERR "Kprobe smoke test failed: " | 216 | pr_err("jprobe handler not called\n"); |
| 229 | "jprobe handler not called\n"); | ||
| 230 | handler_errors++; | 217 | handler_errors++; |
| 231 | } | 218 | } |
| 232 | 219 | ||
| 233 | jph_val = 0; | 220 | jph_val = 0; |
| 234 | ret = target2(rand1); | 221 | ret = target2(rand1); |
| 235 | if (jph_val == 0) { | 222 | if (jph_val == 0) { |
| 236 | printk(KERN_ERR "Kprobe smoke test failed: " | 223 | pr_err("jprobe handler2 not called\n"); |
| 237 | "jprobe handler2 not called\n"); | ||
| 238 | handler_errors++; | 224 | handler_errors++; |
| 239 | } | 225 | } |
| 240 | unregister_jprobes(jps, 2); | 226 | unregister_jprobes(jps, 2); |
| @@ -256,13 +242,11 @@ static int return_handler(struct kretprobe_instance *ri, struct pt_regs *regs) | |||
| 256 | 242 | ||
| 257 | if (ret != (rand1 / div_factor)) { | 243 | if (ret != (rand1 / div_factor)) { |
| 258 | handler_errors++; | 244 | handler_errors++; |
| 259 | printk(KERN_ERR "Kprobe smoke test failed: " | 245 | pr_err("incorrect value in kretprobe handler\n"); |
| 260 | "incorrect value in kretprobe handler\n"); | ||
| 261 | } | 246 | } |
| 262 | if (krph_val == 0) { | 247 | if (krph_val == 0) { |
| 263 | handler_errors++; | 248 | handler_errors++; |
| 264 | printk(KERN_ERR "Kprobe smoke test failed: " | 249 | pr_err("call to kretprobe entry handler failed\n"); |
| 265 | "call to kretprobe entry handler failed\n"); | ||
| 266 | } | 250 | } |
| 267 | 251 | ||
| 268 | krph_val = rand1; | 252 | krph_val = rand1; |
| @@ -281,16 +265,14 @@ static int test_kretprobe(void) | |||
| 281 | 265 | ||
| 282 | ret = register_kretprobe(&rp); | 266 | ret = register_kretprobe(&rp); |
| 283 | if (ret < 0) { | 267 | if (ret < 0) { |
| 284 | printk(KERN_ERR "Kprobe smoke test failed: " | 268 | pr_err("register_kretprobe returned %d\n", ret); |
| 285 | "register_kretprobe returned %d\n", ret); | ||
| 286 | return ret; | 269 | return ret; |
| 287 | } | 270 | } |
| 288 | 271 | ||
| 289 | ret = target(rand1); | 272 | ret = target(rand1); |
| 290 | unregister_kretprobe(&rp); | 273 | unregister_kretprobe(&rp); |
| 291 | if (krph_val != rand1) { | 274 | if (krph_val != rand1) { |
| 292 | printk(KERN_ERR "Kprobe smoke test failed: " | 275 | pr_err("kretprobe handler not called\n"); |
| 293 | "kretprobe handler not called\n"); | ||
| 294 | handler_errors++; | 276 | handler_errors++; |
| 295 | } | 277 | } |
| 296 | 278 | ||
| @@ -303,13 +285,11 @@ static int return_handler2(struct kretprobe_instance *ri, struct pt_regs *regs) | |||
| 303 | 285 | ||
| 304 | if (ret != (rand1 / div_factor) + 1) { | 286 | if (ret != (rand1 / div_factor) + 1) { |
| 305 | handler_errors++; | 287 | handler_errors++; |
| 306 | printk(KERN_ERR "Kprobe smoke test failed: " | 288 | pr_err("incorrect value in kretprobe handler2\n"); |
| 307 | "incorrect value in kretprobe handler2\n"); | ||
| 308 | } | 289 | } |
| 309 | if (krph_val == 0) { | 290 | if (krph_val == 0) { |
| 310 | handler_errors++; | 291 | handler_errors++; |
| 311 | printk(KERN_ERR "Kprobe smoke test failed: " | 292 | pr_err("call to kretprobe entry handler failed\n"); |
| 312 | "call to kretprobe entry handler failed\n"); | ||
| 313 | } | 293 | } |
| 314 | 294 | ||
| 315 | krph_val = rand1; | 295 | krph_val = rand1; |
| @@ -332,24 +312,21 @@ static int test_kretprobes(void) | |||
| 332 | rp.kp.flags = 0; | 312 | rp.kp.flags = 0; |
| 333 | ret = register_kretprobes(rps, 2); | 313 | ret = register_kretprobes(rps, 2); |
| 334 | if (ret < 0) { | 314 | if (ret < 0) { |
| 335 | printk(KERN_ERR "Kprobe smoke test failed: " | 315 | pr_err("register_kretprobe returned %d\n", ret); |
| 336 | "register_kretprobe returned %d\n", ret); | ||
| 337 | return ret; | 316 | return ret; |
| 338 | } | 317 | } |
| 339 | 318 | ||
| 340 | krph_val = 0; | 319 | krph_val = 0; |
| 341 | ret = target(rand1); | 320 | ret = target(rand1); |
| 342 | if (krph_val != rand1) { | 321 | if (krph_val != rand1) { |
| 343 | printk(KERN_ERR "Kprobe smoke test failed: " | 322 | pr_err("kretprobe handler not called\n"); |
| 344 | "kretprobe handler not called\n"); | ||
| 345 | handler_errors++; | 323 | handler_errors++; |
| 346 | } | 324 | } |
| 347 | 325 | ||
| 348 | krph_val = 0; | 326 | krph_val = 0; |
| 349 | ret = target2(rand1); | 327 | ret = target2(rand1); |
| 350 | if (krph_val != rand1) { | 328 | if (krph_val != rand1) { |
| 351 | printk(KERN_ERR "Kprobe smoke test failed: " | 329 | pr_err("kretprobe handler2 not called\n"); |
| 352 | "kretprobe handler2 not called\n"); | ||
| 353 | handler_errors++; | 330 | handler_errors++; |
| 354 | } | 331 | } |
| 355 | unregister_kretprobes(rps, 2); | 332 | unregister_kretprobes(rps, 2); |
| @@ -368,7 +345,7 @@ int init_test_probes(void) | |||
| 368 | rand1 = prandom_u32(); | 345 | rand1 = prandom_u32(); |
| 369 | } while (rand1 <= div_factor); | 346 | } while (rand1 <= div_factor); |
| 370 | 347 | ||
| 371 | printk(KERN_INFO "Kprobe smoke test started\n"); | 348 | pr_info("started\n"); |
| 372 | num_tests++; | 349 | num_tests++; |
| 373 | ret = test_kprobe(); | 350 | ret = test_kprobe(); |
| 374 | if (ret < 0) | 351 | if (ret < 0) |
| @@ -402,13 +379,11 @@ int init_test_probes(void) | |||
| 402 | #endif /* CONFIG_KRETPROBES */ | 379 | #endif /* CONFIG_KRETPROBES */ |
| 403 | 380 | ||
| 404 | if (errors) | 381 | if (errors) |
| 405 | printk(KERN_ERR "BUG: Kprobe smoke test: %d out of " | 382 | pr_err("BUG: %d out of %d tests failed\n", errors, num_tests); |
| 406 | "%d tests failed\n", errors, num_tests); | ||
| 407 | else if (handler_errors) | 383 | else if (handler_errors) |
| 408 | printk(KERN_ERR "BUG: Kprobe smoke test: %d error(s) " | 384 | pr_err("BUG: %d error(s) running handlers\n", handler_errors); |
| 409 | "running handlers\n", handler_errors); | ||
| 410 | else | 385 | else |
| 411 | printk(KERN_INFO "Kprobe smoke test passed successfully\n"); | 386 | pr_info("passed successfully\n"); |
| 412 | 387 | ||
| 413 | return 0; | 388 | return 0; |
| 414 | } | 389 | } |
