linux-stable/tools/testing/selftests/ftrace
Masami Hiramatsu (Google) 25f00e40ce tracing/probes: Support $argN in return probe (kprobe and fprobe)
Support accessing $argN in the return probe events. This will help users to
record entry data in function return (exit) event for simplfing the function
entry/exit information in one event, and record the result values (e.g.
allocated object/initialized object) at function exit.

For example, if we have a function `int init_foo(struct foo *obj, int param)`
sometimes we want to check how `obj` is initialized. In such case, we can
define a new return event like below;

 # echo 'r init_foo retval=$retval param=$arg2 field1=+0($arg1)' >> kprobe_events

Thus it records the function parameter `param` and its result `obj->field1`
(the dereference will be done in the function exit timing) value at once.

This also support fprobe, BTF args and'$arg*'. So if CONFIG_DEBUG_INFO_BTF
is enabled, we can trace both function parameters and the return value
by following command.

 # echo 'f target_function%return $arg* $retval' >> dynamic_events

Link: https://lore.kernel.org/all/170952365552.229804.224112990211602895.stgit@devnote2/

Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
2024-03-07 00:27:34 +09:00
..
samples ftracetest: Add POSIX.3 standard and XFAIL result codes 2014-10-03 16:44:02 -04:00
test.d tracing/probes: Support $argN in return probe (kprobe and fprobe) 2024-03-07 00:27:34 +09:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
Makefile selftests/ftrace: Improve integration with kselftest runner 2023-05-08 11:10:13 -06:00
README ftracetest: Add POSIX.3 standard and XFAIL result codes 2014-10-03 16:44:02 -04:00
config selftests/ftrace: Add CONFIG_SAMPLE_FTRACE_DIRECT=m kconfig 2020-04-14 10:00:29 -06:00
ftracetest selftests: tracing: Fix to unmount tracefs for recovering environment 2023-09-12 09:34:20 -06:00
ftracetest-ktap selftests/ftrace: Improve integration with kselftest runner 2023-05-08 11:10:13 -06:00
settings tracing/selftests: Turn off timeout setting 2019-11-14 13:15:11 -05:00

README

Linux Ftrace Testcases

This is a collection of testcases for ftrace tracing feature in the Linux
kernel. Since ftrace exports interfaces via the debugfs, we just need
shell scripts for testing. Feel free to add new test cases.

Running the ftrace testcases
============================

At first, you need to be the root user to run this script.
To run all testcases:

  $ sudo ./ftracetest

To run specific testcases:

  # ./ftracetest test.d/basic3.tc

Or you can also run testcases under given directory:

  # ./ftracetest test.d/kprobe/

Contributing new testcases
==========================

Copy test.d/template to your testcase (whose filename must have *.tc
extension) and rewrite the test description line.

 * The working directory of the script is <debugfs>/tracing/.

 * Take care with side effects as the tests are run with root privilege.

 * The tests should not run for a long period of time (more than 1 min.)
   These are to be unit tests.

 * You can add a directory for your testcases under test.d/ if needed.

 * The test cases should run on dash (busybox shell) for testing on
   minimal cross-build environments.

 * Note that the tests are run with "set -e" (errexit) option. If any
   command fails, the test will be terminated immediately.

 * The tests can return some result codes instead of pass or fail by
   using exit_unresolved, exit_untested, exit_unsupported and exit_xfail.

Result code
===========

Ftracetest supports following result codes.

 * PASS: The test succeeded as expected. The test which exits with 0 is
         counted as passed test.

 * FAIL: The test failed, but was expected to succeed. The test which exits
         with !0 is counted as failed test.

 * UNRESOLVED: The test produced unclear or intermidiate results.
             for example, the test was interrupted
                       or the test depends on a previous test, which failed.
                       or the test was set up incorrectly
             The test which is in above situation, must call exit_unresolved.

 * UNTESTED: The test was not run, currently just a placeholder.
             In this case, the test must call exit_untested.

 * UNSUPPORTED: The test failed because of lack of feature.
               In this case, the test must call exit_unsupported.

 * XFAIL: The test failed, and was expected to fail.
          To return XFAIL, call exit_xfail from the test.

There are some sample test scripts for result code under samples/.
You can also run samples as below:

  # ./ftracetest samples/

TODO
====

 * Fancy colored output :)