Linux-libre 5.7.5-gnu
[librecmc/linux-libre.git] / tools / testing / selftests / ftrace / test.d / ftrace / func_profiler.tc
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0
3 # description: ftrace - function profiler with function tracing
4
5 # There was a bug after a rewrite of the ftrace infrastructure that
6 # caused the function_profiler not to be able to run with the function
7 # tracer, because the function_profiler used the function_graph tracer
8 # and it was assumed the two could not run simultaneously.
9 #
10 # There was another related bug where the solution to the first bug
11 # broke the way filtering of the function tracer worked.
12 #
13 # This test triggers those bugs on those kernels.
14 #
15 # We need function_graph and profiling to to run this test
16 if ! grep -q function_graph available_tracers; then
17     echo "no function graph tracer configured"
18     exit_unsupported;
19 fi
20
21 check_filter_file set_ftrace_filter
22
23 if [ ! -f function_profile_enabled ]; then
24     echo "function_profile_enabled not found, function profiling enabled?"
25     exit_unsupported
26 fi
27
28 fail() { # mesg
29     echo $1
30     exit_fail
31 }
32
33 echo "Testing function tracer with profiler:"
34 echo "enable function tracer"
35 echo function > current_tracer
36 echo "enable profiler"
37 echo 1 > function_profile_enabled
38
39 sleep 1
40
41 echo "Now filter on just schedule"
42 echo '*schedule' > set_ftrace_filter
43 clear_trace
44
45 echo "Now disable function profiler"
46 echo 0 > function_profile_enabled
47
48 sleep 1
49
50 # make sure only schedule functions exist
51
52 echo "testing if only schedule is being traced"
53 if grep -v -e '^#' -e 'schedule' trace; then
54         fail "more than schedule was found"
55 fi
56
57 echo "Make sure schedule was traced"
58 if ! grep -e 'schedule' trace > /dev/null; then
59         cat trace
60         fail "can not find schedule in trace"
61 fi
62
63 echo > set_ftrace_filter
64 clear_trace
65
66 sleep 1
67
68 echo "make sure something other than scheduler is being traced"
69 if ! grep -v -e '^#' -e 'schedule' trace > /dev/null; then
70         cat trace
71         fail "no other functions besides schedule was found"
72 fi
73
74 exit 0