tracing/kprobe: Integrate test warnings into WARN_ONCE

Cleanup the redundant WARN_ON_ONCE(cond) + pr_warn(msg) into
WARN_ONCE(cond, msg). Also add some WARN_ONCE() for hitcount check.
These WARN_ONCE() errors makes it easy to handle errors from ktest.

Link: https://lore.kernel.org/all/171811264685.85078.8068819097047430463.stgit@devnote2/Suggested-by: default avatarSteven Rostedt <rostedt@goodmis.org>
Signed-off-by: default avatarMasami Hiramatsu (Google) <mhiramat@kernel.org>
Reviewed-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
parent 30addd1d
...@@ -2023,19 +2023,16 @@ static __init int kprobe_trace_self_tests_init(void) ...@@ -2023,19 +2023,16 @@ static __init int kprobe_trace_self_tests_init(void)
pr_info("Testing kprobe tracing: "); pr_info("Testing kprobe tracing: ");
ret = create_or_delete_trace_kprobe("p:testprobe kprobe_trace_selftest_target $stack $stack0 +0($stack)"); ret = create_or_delete_trace_kprobe("p:testprobe kprobe_trace_selftest_target $stack $stack0 +0($stack)");
if (WARN_ON_ONCE(ret)) { if (WARN_ONCE(ret, "error on probing function entry.")) {
pr_warn("error on probing function entry.\n");
warn++; warn++;
} else { } else {
/* Enable trace point */ /* Enable trace point */
tk = find_trace_kprobe("testprobe", KPROBE_EVENT_SYSTEM); tk = find_trace_kprobe("testprobe", KPROBE_EVENT_SYSTEM);
if (WARN_ON_ONCE(tk == NULL)) { if (WARN_ONCE(tk == NULL, "error on probing function entry.")) {
pr_warn("error on getting new probe.\n");
warn++; warn++;
} else { } else {
file = find_trace_probe_file(tk, top_trace_array()); file = find_trace_probe_file(tk, top_trace_array());
if (WARN_ON_ONCE(file == NULL)) { if (WARN_ONCE(file == NULL, "error on getting probe file.")) {
pr_warn("error on getting probe file.\n");
warn++; warn++;
} else } else
enable_trace_kprobe( enable_trace_kprobe(
...@@ -2044,19 +2041,16 @@ static __init int kprobe_trace_self_tests_init(void) ...@@ -2044,19 +2041,16 @@ static __init int kprobe_trace_self_tests_init(void)
} }
ret = create_or_delete_trace_kprobe("r:testprobe2 kprobe_trace_selftest_target $retval"); ret = create_or_delete_trace_kprobe("r:testprobe2 kprobe_trace_selftest_target $retval");
if (WARN_ON_ONCE(ret)) { if (WARN_ONCE(ret, "error on probing function return.")) {
pr_warn("error on probing function return.\n");
warn++; warn++;
} else { } else {
/* Enable trace point */ /* Enable trace point */
tk = find_trace_kprobe("testprobe2", KPROBE_EVENT_SYSTEM); tk = find_trace_kprobe("testprobe2", KPROBE_EVENT_SYSTEM);
if (WARN_ON_ONCE(tk == NULL)) { if (WARN_ONCE(tk == NULL, "error on getting 2nd new probe.")) {
pr_warn("error on getting 2nd new probe.\n");
warn++; warn++;
} else { } else {
file = find_trace_probe_file(tk, top_trace_array()); file = find_trace_probe_file(tk, top_trace_array());
if (WARN_ON_ONCE(file == NULL)) { if (WARN_ONCE(file == NULL, "error on getting probe file.")) {
pr_warn("error on getting probe file.\n");
warn++; warn++;
} else } else
enable_trace_kprobe( enable_trace_kprobe(
...@@ -2079,18 +2073,15 @@ static __init int kprobe_trace_self_tests_init(void) ...@@ -2079,18 +2073,15 @@ static __init int kprobe_trace_self_tests_init(void)
/* Disable trace points before removing it */ /* Disable trace points before removing it */
tk = find_trace_kprobe("testprobe", KPROBE_EVENT_SYSTEM); tk = find_trace_kprobe("testprobe", KPROBE_EVENT_SYSTEM);
if (WARN_ON_ONCE(tk == NULL)) { if (WARN_ONCE(tk == NULL, "error on getting test probe.")) {
pr_warn("error on getting test probe.\n");
warn++; warn++;
} else { } else {
if (trace_kprobe_nhit(tk) != 1) { if (WARN_ONCE(trace_kprobe_nhit(tk) != 1,
pr_warn("incorrect number of testprobe hits\n"); "incorrect number of testprobe hits."))
warn++; warn++;
}
file = find_trace_probe_file(tk, top_trace_array()); file = find_trace_probe_file(tk, top_trace_array());
if (WARN_ON_ONCE(file == NULL)) { if (WARN_ONCE(file == NULL, "error on getting probe file.")) {
pr_warn("error on getting probe file.\n");
warn++; warn++;
} else } else
disable_trace_kprobe( disable_trace_kprobe(
...@@ -2098,18 +2089,15 @@ static __init int kprobe_trace_self_tests_init(void) ...@@ -2098,18 +2089,15 @@ static __init int kprobe_trace_self_tests_init(void)
} }
tk = find_trace_kprobe("testprobe2", KPROBE_EVENT_SYSTEM); tk = find_trace_kprobe("testprobe2", KPROBE_EVENT_SYSTEM);
if (WARN_ON_ONCE(tk == NULL)) { if (WARN_ONCE(tk == NULL, "error on getting 2nd test probe.")) {
pr_warn("error on getting 2nd test probe.\n");
warn++; warn++;
} else { } else {
if (trace_kprobe_nhit(tk) != 1) { if (WARN_ONCE(trace_kprobe_nhit(tk) != 1,
pr_warn("incorrect number of testprobe2 hits\n"); "incorrect number of testprobe2 hits."))
warn++; warn++;
}
file = find_trace_probe_file(tk, top_trace_array()); file = find_trace_probe_file(tk, top_trace_array());
if (WARN_ON_ONCE(file == NULL)) { if (WARN_ONCE(file == NULL, "error on getting probe file.")) {
pr_warn("error on getting probe file.\n");
warn++; warn++;
} else } else
disable_trace_kprobe( disable_trace_kprobe(
...@@ -2117,23 +2105,19 @@ static __init int kprobe_trace_self_tests_init(void) ...@@ -2117,23 +2105,19 @@ static __init int kprobe_trace_self_tests_init(void)
} }
ret = create_or_delete_trace_kprobe("-:testprobe"); ret = create_or_delete_trace_kprobe("-:testprobe");
if (WARN_ON_ONCE(ret)) { if (WARN_ONCE(ret, "error on deleting a probe."))
pr_warn("error on deleting a probe.\n");
warn++; warn++;
}
ret = create_or_delete_trace_kprobe("-:testprobe2"); ret = create_or_delete_trace_kprobe("-:testprobe2");
if (WARN_ON_ONCE(ret)) { if (WARN_ONCE(ret, "error on deleting a probe."))
pr_warn("error on deleting a probe.\n");
warn++; warn++;
}
end: end:
ret = dyn_events_release_all(&trace_kprobe_ops); ret = dyn_events_release_all(&trace_kprobe_ops);
if (WARN_ON_ONCE(ret)) { if (WARN_ONCE(ret, "error on cleaning up probes."))
pr_warn("error on cleaning up probes.\n");
warn++; warn++;
}
/* /*
* Wait for the optimizer work to finish. Otherwise it might fiddle * Wait for the optimizer work to finish. Otherwise it might fiddle
* with probes in already freed __init text. * with probes in already freed __init text.
......
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