ftrace: add unit test for removing trace function
v2 cover ftrace: add unit test for removing trace function
Hi,
This patch adds a basic startup self-test for removing a traced function.
Being kallsyms_lookup_name made unexported there is no easy use of ftrace_set_filter_ip from kernel modules, leaving with ftrace_set_filter as the way to set trace functions. The ftrace_set_filter API is not explicit on how to remove trace functions, and there is no such use case either in the kernel source-tree for which I decided to add an example of it use as a self-test.
Changes since v1:
- Added changelog and sign-off line.
Carles Pey (1):
ftrace: add unit test for removing trace function
kernel/trace/trace_selftest.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
Signature · 1 line
2.26.3
PATCH v2 1/1 ftrace: add unit test for removing trace function
A self test is provided for the trace function removal functionality.
--- kernel/trace/trace_selftest.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
kernel/trace/trace_selftest.c +34 -0
@@ -287,6 +287,40 @@ static int trace_selftest_ops(struct trace_array *tr, int cnt)if (trace_selftest_test_probe3_cnt !=4 ) goto out_free; +/* Remove trace function from probe 3 */ + func1_name ="!" __stringify(DYN_FTRACE_TEST_NAME ); + len1 =strlen (func1_name); + +ftrace_set_filter (&test_probe3, func1_name, len1,0 ); + +DYN_FTRACE_TEST_NAME (); + +print_counts (); + +if (trace_selftest_test_probe1_cnt !=3 ) + goto out_free; +if (trace_selftest_test_probe2_cnt !=2 ) + goto out_free; +if (trace_selftest_test_probe3_cnt !=4 ) + goto out_free; +if (cnt >1 ) { +if (trace_selftest_test_global_cnt ==0 ) + goto out_free; + } +if (trace_selftest_test_dyn_cnt ==0 ) + goto out_free; + +DYN_FTRACE_TEST_NAME2 (); + +print_counts (); + +if (trace_selftest_test_probe1_cnt !=3 ) + goto out_free; +if (trace_selftest_test_probe2_cnt !=3 ) + goto out_free; +if (trace_selftest_test_probe3_cnt !=5 ) + goto out_free; + ret =0 ; out_free:unregister_ftrace_function (dyn_ops);
Signature · 1 line
2.26.3
Steven Rostedt
maintainerQuoted 1 line · On Sat, 18 Sep 2021 19:30:43 +0400 Carles Pey <[email protected]> wrote:
A self test is provided for the trace function removal functionality.
Thanks, I added it to my queue to be tested.
-- Steve
Quoted 2 lines
Signed-off-by Carles Pey <[email protected]>
Steven Rostedt
maintainerQuoted 4 lines · On Sat, 18 Sep 2021 19:30:42 +0400 Carles Pey <[email protected]> wrote:
Hi,
This patch adds a basic startup self-test for removing a traced function.
Thanks for the patch, but note, because I'm highly involved in the organization of Linux Plumbers that is taking place next week, I may not have time to look at it for a couple of weeks.
-- Steve