Commit 4878b14b authored by Fabian Frederick's avatar Fabian Frederick Committed by Linus Torvalds

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: default avatarFabian 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 4dfe694f
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
* the GNU General Public License for more details. * the GNU General Public License for more details.
*/ */
#define pr_fmt(fmt) "Kprobe smoke test: " fmt
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/kprobes.h> #include <linux/kprobes.h>
#include <linux/random.h> #include <linux/random.h>
...@@ -41,8 +43,7 @@ static void kp_post_handler(struct kprobe *p, struct pt_regs *regs, ...@@ -41,8 +43,7 @@ static void kp_post_handler(struct kprobe *p, struct pt_regs *regs,
{ {
if (preh_val != (rand1 / div_factor)) { if (preh_val != (rand1 / div_factor)) {
handler_errors++; handler_errors++;
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("incorrect value in post_handler\n");
"incorrect value in post_handler\n");
} }
posth_val = preh_val + div_factor; posth_val = preh_val + div_factor;
} }
...@@ -59,8 +60,7 @@ static int test_kprobe(void) ...@@ -59,8 +60,7 @@ static int test_kprobe(void)
ret = register_kprobe(&kp); ret = register_kprobe(&kp);
if (ret < 0) { if (ret < 0) {
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("register_kprobe returned %d\n", ret);
"register_kprobe returned %d\n", ret);
return ret; return ret;
} }
...@@ -68,14 +68,12 @@ static int test_kprobe(void) ...@@ -68,14 +68,12 @@ static int test_kprobe(void)
unregister_kprobe(&kp); unregister_kprobe(&kp);
if (preh_val == 0) { if (preh_val == 0) {
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("kprobe pre_handler not called\n");
"kprobe pre_handler not called\n");
handler_errors++; handler_errors++;
} }
if (posth_val == 0) { if (posth_val == 0) {
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("kprobe post_handler not called\n");
"kprobe post_handler not called\n");
handler_errors++; handler_errors++;
} }
...@@ -98,8 +96,7 @@ static void kp_post_handler2(struct kprobe *p, struct pt_regs *regs, ...@@ -98,8 +96,7 @@ static void kp_post_handler2(struct kprobe *p, struct pt_regs *regs,
{ {
if (preh_val != (rand1 / div_factor) + 1) { if (preh_val != (rand1 / div_factor) + 1) {
handler_errors++; handler_errors++;
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("incorrect value in post_handler2\n");
"incorrect value in post_handler2\n");
} }
posth_val = preh_val + div_factor; posth_val = preh_val + div_factor;
} }
...@@ -120,8 +117,7 @@ static int test_kprobes(void) ...@@ -120,8 +117,7 @@ static int test_kprobes(void)
kp.flags = 0; kp.flags = 0;
ret = register_kprobes(kps, 2); ret = register_kprobes(kps, 2);
if (ret < 0) { if (ret < 0) {
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("register_kprobes returned %d\n", ret);
"register_kprobes returned %d\n", ret);
return ret; return ret;
} }
...@@ -130,14 +126,12 @@ static int test_kprobes(void) ...@@ -130,14 +126,12 @@ static int test_kprobes(void)
ret = target(rand1); ret = target(rand1);
if (preh_val == 0) { if (preh_val == 0) {
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("kprobe pre_handler not called\n");
"kprobe pre_handler not called\n");
handler_errors++; handler_errors++;
} }
if (posth_val == 0) { if (posth_val == 0) {
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("kprobe post_handler not called\n");
"kprobe post_handler not called\n");
handler_errors++; handler_errors++;
} }
...@@ -146,14 +140,12 @@ static int test_kprobes(void) ...@@ -146,14 +140,12 @@ static int test_kprobes(void)
ret = target2(rand1); ret = target2(rand1);
if (preh_val == 0) { if (preh_val == 0) {
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("kprobe pre_handler2 not called\n");
"kprobe pre_handler2 not called\n");
handler_errors++; handler_errors++;
} }
if (posth_val == 0) { if (posth_val == 0) {
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("kprobe post_handler2 not called\n");
"kprobe post_handler2 not called\n");
handler_errors++; handler_errors++;
} }
...@@ -166,8 +158,7 @@ static u32 j_kprobe_target(u32 value) ...@@ -166,8 +158,7 @@ static u32 j_kprobe_target(u32 value)
{ {
if (value != rand1) { if (value != rand1) {
handler_errors++; handler_errors++;
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("incorrect value in jprobe handler\n");
"incorrect value in jprobe handler\n");
} }
jph_val = rand1; jph_val = rand1;
...@@ -186,16 +177,14 @@ static int test_jprobe(void) ...@@ -186,16 +177,14 @@ static int test_jprobe(void)
ret = register_jprobe(&jp); ret = register_jprobe(&jp);
if (ret < 0) { if (ret < 0) {
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("register_jprobe returned %d\n", ret);
"register_jprobe returned %d\n", ret);
return ret; return ret;
} }
ret = target(rand1); ret = target(rand1);
unregister_jprobe(&jp); unregister_jprobe(&jp);
if (jph_val == 0) { if (jph_val == 0) {
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("jprobe handler not called\n");
"jprobe handler not called\n");
handler_errors++; handler_errors++;
} }
...@@ -217,24 +206,21 @@ static int test_jprobes(void) ...@@ -217,24 +206,21 @@ static int test_jprobes(void)
jp.kp.flags = 0; jp.kp.flags = 0;
ret = register_jprobes(jps, 2); ret = register_jprobes(jps, 2);
if (ret < 0) { if (ret < 0) {
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("register_jprobes returned %d\n", ret);
"register_jprobes returned %d\n", ret);
return ret; return ret;
} }
jph_val = 0; jph_val = 0;
ret = target(rand1); ret = target(rand1);
if (jph_val == 0) { if (jph_val == 0) {
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("jprobe handler not called\n");
"jprobe handler not called\n");
handler_errors++; handler_errors++;
} }
jph_val = 0; jph_val = 0;
ret = target2(rand1); ret = target2(rand1);
if (jph_val == 0) { if (jph_val == 0) {
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("jprobe handler2 not called\n");
"jprobe handler2 not called\n");
handler_errors++; handler_errors++;
} }
unregister_jprobes(jps, 2); unregister_jprobes(jps, 2);
...@@ -256,13 +242,11 @@ static int return_handler(struct kretprobe_instance *ri, struct pt_regs *regs) ...@@ -256,13 +242,11 @@ static int return_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
if (ret != (rand1 / div_factor)) { if (ret != (rand1 / div_factor)) {
handler_errors++; handler_errors++;
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("incorrect value in kretprobe handler\n");
"incorrect value in kretprobe handler\n");
} }
if (krph_val == 0) { if (krph_val == 0) {
handler_errors++; handler_errors++;
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("call to kretprobe entry handler failed\n");
"call to kretprobe entry handler failed\n");
} }
krph_val = rand1; krph_val = rand1;
...@@ -281,16 +265,14 @@ static int test_kretprobe(void) ...@@ -281,16 +265,14 @@ static int test_kretprobe(void)
ret = register_kretprobe(&rp); ret = register_kretprobe(&rp);
if (ret < 0) { if (ret < 0) {
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("register_kretprobe returned %d\n", ret);
"register_kretprobe returned %d\n", ret);
return ret; return ret;
} }
ret = target(rand1); ret = target(rand1);
unregister_kretprobe(&rp); unregister_kretprobe(&rp);
if (krph_val != rand1) { if (krph_val != rand1) {
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("kretprobe handler not called\n");
"kretprobe handler not called\n");
handler_errors++; handler_errors++;
} }
...@@ -303,13 +285,11 @@ static int return_handler2(struct kretprobe_instance *ri, struct pt_regs *regs) ...@@ -303,13 +285,11 @@ static int return_handler2(struct kretprobe_instance *ri, struct pt_regs *regs)
if (ret != (rand1 / div_factor) + 1) { if (ret != (rand1 / div_factor) + 1) {
handler_errors++; handler_errors++;
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("incorrect value in kretprobe handler2\n");
"incorrect value in kretprobe handler2\n");
} }
if (krph_val == 0) { if (krph_val == 0) {
handler_errors++; handler_errors++;
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("call to kretprobe entry handler failed\n");
"call to kretprobe entry handler failed\n");
} }
krph_val = rand1; krph_val = rand1;
...@@ -332,24 +312,21 @@ static int test_kretprobes(void) ...@@ -332,24 +312,21 @@ static int test_kretprobes(void)
rp.kp.flags = 0; rp.kp.flags = 0;
ret = register_kretprobes(rps, 2); ret = register_kretprobes(rps, 2);
if (ret < 0) { if (ret < 0) {
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("register_kretprobe returned %d\n", ret);
"register_kretprobe returned %d\n", ret);
return ret; return ret;
} }
krph_val = 0; krph_val = 0;
ret = target(rand1); ret = target(rand1);
if (krph_val != rand1) { if (krph_val != rand1) {
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("kretprobe handler not called\n");
"kretprobe handler not called\n");
handler_errors++; handler_errors++;
} }
krph_val = 0; krph_val = 0;
ret = target2(rand1); ret = target2(rand1);
if (krph_val != rand1) { if (krph_val != rand1) {
printk(KERN_ERR "Kprobe smoke test failed: " pr_err("kretprobe handler2 not called\n");
"kretprobe handler2 not called\n");
handler_errors++; handler_errors++;
} }
unregister_kretprobes(rps, 2); unregister_kretprobes(rps, 2);
...@@ -368,7 +345,7 @@ int init_test_probes(void) ...@@ -368,7 +345,7 @@ int init_test_probes(void)
rand1 = prandom_u32(); rand1 = prandom_u32();
} while (rand1 <= div_factor); } while (rand1 <= div_factor);
printk(KERN_INFO "Kprobe smoke test started\n"); pr_info("started\n");
num_tests++; num_tests++;
ret = test_kprobe(); ret = test_kprobe();
if (ret < 0) if (ret < 0)
...@@ -402,13 +379,11 @@ int init_test_probes(void) ...@@ -402,13 +379,11 @@ int init_test_probes(void)
#endif /* CONFIG_KRETPROBES */ #endif /* CONFIG_KRETPROBES */
if (errors) if (errors)
printk(KERN_ERR "BUG: Kprobe smoke test: %d out of " pr_err("BUG: %d out of %d tests failed\n", errors, num_tests);
"%d tests failed\n", errors, num_tests);
else if (handler_errors) else if (handler_errors)
printk(KERN_ERR "BUG: Kprobe smoke test: %d error(s) " pr_err("BUG: %d error(s) running handlers\n", handler_errors);
"running handlers\n", handler_errors);
else else
printk(KERN_INFO "Kprobe smoke test passed successfully\n"); pr_info("passed successfully\n");
return 0; return 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment