[PATCH v10 8/8] selftests/ftrace: Add funcgraph-retval test case
Donglin Peng
pengdonglin at sangfor.com.cn
Sun Apr 2 22:01:30 PDT 2023
On 2023/4/3 10:33, Donglin Peng wrote:
> On 2023/4/2 6:04, Masami Hiramatsu (Google) wrote:
>> On Fri, 31 Mar 2023 05:47:44 -0700
>> Donglin Peng <pengdonglin at sangfor.com.cn> wrote:
>>
>>> Add a test case for the funcgraph-retval and funcgraph-retval-hex
>>> trace options.
>>>
>>> Signed-off-by: Donglin Peng <pengdonglin at sangfor.com.cn>
>>> ---
>>> v10:
>>> - Fix issues in selftest
>>>
>>> v8:
>>> - Fix issues in selftest
>>> ---
>>> .../ftrace/test.d/ftrace/fgraph-retval.tc | 43 +++++++++++++++++++
>>> 1 file changed, 43 insertions(+)
>>> create mode 100644
>>> tools/testing/selftests/ftrace/test.d/ftrace/fgraph-retval.tc
>>>
>>> diff --git
>>> a/tools/testing/selftests/ftrace/test.d/ftrace/fgraph-retval.tc
>>> b/tools/testing/selftests/ftrace/test.d/ftrace/fgraph-retval.tc
>>> new file mode 100644
>>> index 000000000000..5819aa2dd6ad
>>> --- /dev/null
>>> +++ b/tools/testing/selftests/ftrace/test.d/ftrace/fgraph-retval.tc
>>> @@ -0,0 +1,43 @@
>>> +#!/bin/sh
>>> +# SPDX-License-Identifier: GPL-2.0
>>> +# description: ftrace - function graph print function return value
>>> +# requires: options/funcgraph-retval options/funcgraph-retval-hex
>>> function_graph:tracer
>>> +
>>> +# Make sure that funcgraph-retval works
>>> +
>>> +fail() { # msg
>>> + echo $1
>>> + exit_fail
>>> +}
>>> +
>>> +disable_tracing
>>> +clear_trace
>>> +
>>> +read PID _ < /proc/self/stat
>>
>> You can use "$$" for self pid.
>
> Yeah, I will fix it.
I found that ftracetest used () to launch a new child process for
executing a .tc script file, however the $$ value remains unchanged,
so we can not use $$ here, because it is PPID. Therefore I think we
have to get PID from /proc/self/stat.
Here is the code from ftracetest that launches a child shell for
executing the .tc file.
__run_test() { # testfile
# setup PID and PPID, $$ is *not* updated.
(cd $TRACING_DIR; read PID _ < /proc/self/stat; set -e; set -x;
checkreq $1; initialize_ftrace; . $1)
[ $? -ne 0 ] && kill -s $SIG_FAIL $SIG_PID
}
>
>>
>>> +[ -f set_ftrace_pid ] && echo ${PID} > set_ftrace_pid
>>> +[ -f set_ftrace_filter ] && echo proc_reg_write > set_ftrace_filter
>>> +[ -f set_graph_function ] && echo proc_reg_write > set_graph_function
>>
>> You should set the required files for this test, so that the test result
>> is always same. BTW, you need to set either 'set_ftrace_filter' or
>> 'set_graph_function'.
>
> Yes, but I discovered that set_ftrace_filter and set_graph_function rely
> on the CONFIG_DYNAMIC_FTRACE configuration, which means that these two
> files are not present when CONFIG_DYNAMIC_FTRACE is disabled, even if
> CONFIG_FUNCTION_GRAPH_RETVAL is enabled. Therefore, I think that these
> two trace files are not necessary for this test.
>
> I will modify the above like this:
>
> [ -f set_ftrace_pid ] && echo $$ > set_ftrace_pid
> [ -f set_ftrace_filter ] && echo proc_reg_write > set_ftrace_filter
>
>>
>>> +echo function_graph > current_tracer
>>> +echo funcgraph-retval > trace_options
>>> +
>>> +set +e
>>> +enable_tracing
>>> +echo > /proc/interrupts
>>> +disable_tracing
>>> +set -e
>>> +
>>> +: "Test printing the error code in signed decimal format"
>>> +echo nofuncgraph-retval-hex > trace_options
>>
>> echo 0 > options/funcgraph-retval-hex
>>
>> If you require 'options/funcgraph-retval-hex' file, you can use the
>> file to set it or clear it.
>
> Yeah.
>
>>
>>> +count=`cat trace | grep 'proc_reg_write' | grep '= -5' | wc -l`
>>> +if [ $count -eq 0 ]; then
>>> + fail "Return value can not be printed in signed decimal format"
>>> +fi
>>> +
>>> +: "Test printing the error code in hexadecimal format"
>>> +echo funcgraph-retval-hex > trace_options
>>
>> Ditto.
>
> Thanks.
>
>>
>> Thanks,
>>
>>> +count=`cat trace | grep 'proc_reg_write' | grep 'fffffffb' | wc -l`
>>> +if [ $count -eq 0 ]; then
>>> + fail "Return value can not be printed in hexadecimal format"
>>> +fi
>>> +
>>> +exit 0
>>> --
>>> 2.25.1
>>>
>>
>>
>
More information about the linux-riscv
mailing list