Skip to contentSkip to conversation

ftracetest/tools/selftests: Self tests to test ftrace

GIT PULL New Steven Rostedt 1 participant 6 messages Oct 8, 2014

Subsystems (2)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

Linus,

This patch series starts a new selftests section in the tools/testing/selftest directory called "ftrace" that holds tests aimed at testing ftrace and subsystems that use ftrace (like kprobes).

So far only a few tests were written (by Masami Hiramatsu), but more will be added in the near future (3.19).

Please pull the latest ftracetest-3.18 tree, which can be found at:

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
ftracetest-3.18

Tag SHA1: 82533f8d106661960f4675f5f3248c00e9157f49 Head SHA1: 89c5497d1f933af56dac617f0fd86150942a7fb6

Masami Hiramatsu (5):
ftracetest: Initial commit for ftracetest
ftracetest: Add ftrace basic testcases
ftracetest: Add kprobe basic testcases
ftracetest: Add POSIX.3 standard and XFAIL result codes tracing/kprobes: Add selftest scripts testing kprobe-tracer as startup test

----

 MAINTAINERS                                        |   1 +
 tools/testing/selftests/Makefile                   |   1 +
 tools/testing/selftests/ftrace/Makefile            |   7 +
 tools/testing/selftests/ftrace/README              |  82 +++++++
 tools/testing/selftests/ftrace/ftracetest          | 253 +++++++++++++++++++++
 tools/testing/selftests/ftrace/samples/fail.tc     |   4 +
 tools/testing/selftests/ftrace/samples/pass.tc     |   3 +
 .../testing/selftests/ftrace/samples/unresolved.tc |   4 +
 .../selftests/ftrace/samples/unsupported.tc        |   3 +
 tools/testing/selftests/ftrace/samples/untested.tc |   3 +
 tools/testing/selftests/ftrace/samples/xfail.tc    |   3 +
 .../selftests/ftrace/test.d/00basic/basic1.tc      |   3 +
 .../selftests/ftrace/test.d/00basic/basic2.tc      |   7 +
 .../selftests/ftrace/test.d/00basic/basic3.tc      |   8 +
 .../ftrace/test.d/kprobe/add_and_remove.tc         |  11 +
 .../selftests/ftrace/test.d/kprobe/busy_check.tc   |  13 ++
 .../selftests/ftrace/test.d/kprobe/kprobe_args.tc  |  16 ++
 .../ftrace/test.d/kprobe/kretprobe_args.tc         |  15 ++
 tools/testing/selftests/ftrace/test.d/template     |   9 +
 19 files changed, 446 insertions(+)
author maintainer
#1 lore raw

PATCH 1/5 ftracetest: Initial commit for ftracetest

From: Masami Hiramatsu <[email protected]>

ftracetest is a collection of testcase shell-scripts for ftrace. To avoid regressions of ftrace, these testcases check correct ftrace behaviors. If someone would like to add any features on ftrace, the patch series should have at least one testcase for checking the new behavior.

---
 MAINTAINERS                                    |   1 +
 tools/testing/selftests/Makefile               |   1 +
 tools/testing/selftests/ftrace/Makefile        |   7 ++
 tools/testing/selftests/ftrace/README          |  45 +++++++
 tools/testing/selftests/ftrace/ftracetest      | 159 +++++++++++++++++++++++++
 tools/testing/selftests/ftrace/test.d/template |   4 +
 6 files changed, 217 insertions(+)
 create mode 100644 tools/testing/selftests/ftrace/Makefile
 create mode 100644 tools/testing/selftests/ftrace/README
 create mode 100755 tools/testing/selftests/ftrace/ftracetest
 create mode 100644 tools/testing/selftests/ftrace/test.d/template
MAINTAINERS +1 -0
index 670b3dcce2de..bb455d0ae12a 100644
@@ -9310,6 +9310,7 @@ F:	include/*/ftrace.h
 F:	include/linux/trace*.h
 F:	include/trace/
 F:	kernel/trace/
+F:	tools/testing/selftests/ftrace/
 
 TRIVIAL PATCHES
 M:	Jiri Kosina <[email protected]>
tools/testing/selftests/Makefile +1 -0
index 36ff2e4c7b6f..45f145c6f843 100644
@@ -14,6 +14,7 @@ TARGETS += powerpc
 TARGETS += user
 TARGETS += sysctl
 TARGETS += firmware
+TARGETS += ftrace
 
 TARGETS_HOTPLUG = cpu-hotplug
 TARGETS_HOTPLUG += memory-hotplug
tools/testing/selftests/ftrace/Makefile new file +7 -0
new file mode 100644
index 000000000000..76cc9f156267
@@ -0,0 +1,7 @@
+all:
+
+run_tests:
+	@/bin/sh ./ftracetest || echo "ftrace selftests: [FAIL]"
+
+clean:
+	rm -rf logs/*
tools/testing/selftests/ftrace/README new file +45 -0

45 lines not on this page · raw message

tools/testing/selftests/ftrace/ftracetest new file +159 -0

159 lines not on this page · raw message

tools/testing/selftests/ftrace/test.d/template new file +4 -0
new file mode 100644
index 000000000000..ce5f735b2e65
@@ -0,0 +1,4 @@
+#!/bin/sh
+# description: %HERE DESCRIBE WHAT THIS DOES%
+# you have to add ".tc" extention for your testcase file
+exit 0 # Return 0 if the test is passed, otherwise return !0
Signature · 1 line
2.0.1
author maintainer
#2 lore raw

PATCH 2/5 ftracetest: Add ftrace basic testcases

In reply to Steven Rostedt

From: Masami Hiramatsu <[email protected]>

Add ftrace basic testcases. This just checks ftrace debugfs interface works as it is designed.

---
 tools/testing/selftests/ftrace/test.d/00basic/basic1.tc | 3 +++
 tools/testing/selftests/ftrace/test.d/00basic/basic2.tc | 6 ++++++
 tools/testing/selftests/ftrace/test.d/00basic/basic3.tc | 8 ++++++++
 3 files changed, 17 insertions(+)
 create mode 100644 tools/testing/selftests/ftrace/test.d/00basic/basic1.tc
 create mode 100644 tools/testing/selftests/ftrace/test.d/00basic/basic2.tc
 create mode 100644 tools/testing/selftests/ftrace/test.d/00basic/basic3.tc
tools/testing/selftests/ftrace/test.d/00basic/basic1.tc new file +3 -0
new file mode 100644
index 000000000000..9980ff14ae44
@@ -0,0 +1,3 @@
+#!/bin/sh
+# description: Basic trace file check
+test -f README -a -f trace -a -f tracing_on -a -f trace_pipe
tools/testing/selftests/ftrace/test.d/00basic/basic2.tc new file +6 -0
new file mode 100644
index 000000000000..b04f30df0db3
@@ -0,0 +1,6 @@
+#!/bin/sh
+# description: Basic test for tracers
+for t in `cat available_tracers`; do
+  echo $t > current_tracer || exit 1
+done
+echo nop > current_tracer
tools/testing/selftests/ftrace/test.d/00basic/basic3.tc new file +8 -0
new file mode 100644
index 000000000000..0c1a3a207636
@@ -0,0 +1,8 @@
+#!/bin/sh
+# description: Basic trace clock test
+[ -f trace_clock ] || exit 1
+for c in `cat trace_clock | tr  -d \[\]`; do
+  echo $c > trace_clock || exit 1
+  grep '\['$c'\]' trace_clock || exit 1
+done
+echo local > trace_clock
Signature · 1 line
2.0.1
author maintainer
#3 lore raw

PATCH 3/5 ftracetest: Add kprobe basic testcases

In reply to Steven Rostedt

From: Masami Hiramatsu <[email protected]>

Add basic testcases for kprobe dynamic events. This also shows that the ftracetest accepts sub-directory for new testcases.

---
 .../selftests/ftrace/test.d/kprobe/add_and_remove.tc       | 11 +++++++++++
 tools/testing/selftests/ftrace/test.d/kprobe/busy_check.tc | 14 ++++++++++++++
 2 files changed, 25 insertions(+)
 create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/add_and_remove.tc
 create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/busy_check.tc
tools/testing/selftests/ftrace/test.d/kprobe/add_and_remove.tc new file +11 -0
new file mode 100644
index 000000000000..5ddfb476eceb
@@ -0,0 +1,11 @@
+#!/bin/sh
+# description: Kprobe dynamic event - adding and removing
+
+[ -f kprobe_events ] || exit 1
+
+echo 0 > events/enable || exit 1
+echo > kprobe_events || exit 1
+echo p:myevent do_fork > kprobe_events || exit 1
+grep myevent kprobe_events || exit 1
+[ -d events/kprobes/myevent ] || exit 1
+echo > kprobe_events
tools/testing/selftests/ftrace/test.d/kprobe/busy_check.tc new file +14 -0
new file mode 100644
index 000000000000..588fde97e93f
@@ -0,0 +1,14 @@
+#!/bin/sh
+# description: Kprobe dynamic event - busy event check
+
+[ -f kprobe_events ] || exit 1
+
+echo 0 > events/enable || exit 1
+echo > kprobe_events || exit 1
+echo p:myevent do_fork > kprobe_events || exit 1
+[ -d events/kprobes/myevent ] || exit 1
+echo 1 > events/kprobes/myevent/enable || exit 1
+echo > kprobe_events && exit 1 # this must fail
+echo 0 > events/kprobes/myevent/enable || exit 1
+echo > kprobe_events # this must succeed
+
Signature · 1 line
2.0.1
author maintainer
#4 lore raw

PATCH 4/5 ftracetest: Add POSIX.3 standard and XFAIL result codes

In reply to Steven Rostedt

From: Masami Hiramatsu <[email protected]>

Add XFAIL and POSIX 1003.3 standard codes (UNRESOLVED/ UNTESTED/UNSUPPORTED) as result codes. These are used for the results that test case is expected to fail or unsupported feature (by config).

To return these result code, this introduces exit_unresolved, exit_untested, exit_unsupported and exit_xfail functions, which use real-time signals to notify the result code to ftracetest.

This also set "errexit" option for the testcases, so that the tests don't need to exit explicitly.

Note that if the test returns UNRESOLVED/UNSUPPORTED/FAIL, its test log including executed commands is shown on console and main logfile as below.

------

  # ./ftracetest samples/
  === Ftrace unit tests ===
  [1] failure-case example        [FAIL]
  execute: /home/fedora/ksrc/linux-3/tools/testing/selftests/ftrace/samples/fail.tc
  + . /home/fedora/ksrc/linux-3/tools/testing/selftests/ftrace/samples/fail.tc
  ++ cat non-exist-file
  cat: non-exist-file: No such file or directory
  [2] pass-case example   [PASS]
  [3] unresolved-case example     [UNRESOLVED]
  execute: /home/fedora/ksrc/linux-3/tools/testing/selftests/ftrace/samples/unresolved.tc
  + . /home/fedora/ksrc/linux-3/tools/testing/selftests/ftrace/samples/unresolved.tc
  ++ trap exit_unresolved INT
  ++ kill -INT 29324
  +++ exit_unresolved
  +++ kill -s 38 29265
  +++ exit 0
  [4] unsupported-case example    [UNSUPPORTED]
  execute: /home/fedora/ksrc/linux-3/tools/testing/selftests/ftrace/samples/unsupported.tc
  + . /home/fedora/ksrc/linux-3/tools/testing/selftests/ftrace/samples/unsupported.tc
  ++ exit_unsupported
  ++ kill -s 40 29265
  ++ exit 0
  [5] untested-case example       [UNTESTED]
  [6] xfail-case example  [XFAIL]
  # of passed:  1
  # of failed:  1
  # of unresolved:  1
  # of untested:  1
  # of unsupported:  1
  # of xfailed:  1
  # of undefined(test bug):  0
  ------
---
 tools/testing/selftests/ftrace/README              |  37 ++++++
 tools/testing/selftests/ftrace/ftracetest          | 124 ++++++++++++++++++---
 tools/testing/selftests/ftrace/samples/fail.tc     |   4 +
 tools/testing/selftests/ftrace/samples/pass.tc     |   3 +
 .../testing/selftests/ftrace/samples/unresolved.tc |   4 +
 .../selftests/ftrace/samples/unsupported.tc        |   3 +
 tools/testing/selftests/ftrace/samples/untested.tc |   3 +
 tools/testing/selftests/ftrace/samples/xfail.tc    |   3 +
 .../selftests/ftrace/test.d/00basic/basic2.tc      |   3 +-
 .../selftests/ftrace/test.d/00basic/basic3.tc      |   6 +-
 .../ftrace/test.d/kprobe/add_and_remove.tc         |  12 +-
 .../selftests/ftrace/test.d/kprobe/busy_check.tc   |  15 ++-
 tools/testing/selftests/ftrace/test.d/template     |   5 +
 13 files changed, 189 insertions(+), 33 deletions(-)
 create mode 100644 tools/testing/selftests/ftrace/samples/fail.tc
 create mode 100644 tools/testing/selftests/ftrace/samples/pass.tc
 create mode 100644 tools/testing/selftests/ftrace/samples/unresolved.tc
 create mode 100644 tools/testing/selftests/ftrace/samples/unsupported.tc
 create mode 100644 tools/testing/selftests/ftrace/samples/untested.tc
 create mode 100644 tools/testing/selftests/ftrace/samples/xfail.tc
tools/testing/selftests/ftrace/README +37 -0
index b8631f03e754..182e76fa4b82 100644
@@ -38,6 +38,43 @@ extension) and rewrite the test description line.
  * 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
 ====
 
tools/testing/selftests/ftrace/ftracetest +109 -15

153 lines not on this page · raw message

tools/testing/selftests/ftrace/samples/fail.tc new file +4 -0
new file mode 100644
index 000000000000..15e35b956e05
@@ -0,0 +1,4 @@
+#!/bin/sh
+# description: failure-case example
+cat non-exist-file
+echo "this is not executed"
tools/testing/selftests/ftrace/samples/pass.tc new file +3 -0
new file mode 100644
index 000000000000..d01549370041
@@ -0,0 +1,3 @@
+#!/bin/sh
+# description: pass-case example
+return 0
tools/testing/selftests/ftrace/samples/unresolved.tc new file +4 -0
new file mode 100644
index 000000000000..41e99d3358d1
@@ -0,0 +1,4 @@
+#!/bin/sh
+# description: unresolved-case example
+trap exit_unresolved INT
+kill -INT $PID
tools/testing/selftests/ftrace/samples/unsupported.tc new file +3 -0
new file mode 100644
index 000000000000..45910ff13328
@@ -0,0 +1,3 @@
+#!/bin/sh
+# description: unsupported-case example
+exit_unsupported
tools/testing/selftests/ftrace/samples/untested.tc new file +3 -0
new file mode 100644
index 000000000000..35a45946ec60
@@ -0,0 +1,3 @@
+#!/bin/sh
+# description: untested-case example
+exit_untested
tools/testing/selftests/ftrace/samples/xfail.tc new file +3 -0
new file mode 100644
index 000000000000..9dd395323259
@@ -0,0 +1,3 @@
+#!/bin/sh
+# description: xfail-case example
+cat non-exist-file || exit_xfail
tools/testing/selftests/ftrace/test.d/00basic/basic2.tc +2 -1
index b04f30df0db3..bf9a7b037924 100644
@@ -1,6 +1,7 @@
 #!/bin/sh
 # description: Basic test for tracers
+test -f available_tracers
 for t in `cat available_tracers`; do
-  echo $t > current_tracer || exit 1
+  echo $t > current_tracer
 done
 echo nop > current_tracer
tools/testing/selftests/ftrace/test.d/00basic/basic3.tc +3 -3
index 0c1a3a207636..bde6625d9785 100644
@@ -1,8 +1,8 @@
 #!/bin/sh
 # description: Basic trace clock test
-[ -f trace_clock ] || exit 1
+test -f trace_clock
 for c in `cat trace_clock | tr  -d \[\]`; do
-  echo $c > trace_clock || exit 1
-  grep '\['$c'\]' trace_clock || exit 1
+  echo $c > trace_clock
+  grep '\['$c'\]' trace_clock
 done
 echo local > trace_clock
tools/testing/selftests/ftrace/test.d/kprobe/add_and_remove.tc +6 -6
index 5ddfb476eceb..1b8b665ab2b3 100644
@@ -1,11 +1,11 @@
 #!/bin/sh
 # description: Kprobe dynamic event - adding and removing
 
-[ -f kprobe_events ] || exit 1
+[ -f kprobe_events ] || exit_unsupported # this is configurable
 
-echo 0 > events/enable || exit 1
-echo > kprobe_events || exit 1
-echo p:myevent do_fork > kprobe_events || exit 1
-grep myevent kprobe_events || exit 1
-[ -d events/kprobes/myevent ] || exit 1
+echo 0 > events/enable
+echo > kprobe_events
+echo p:myevent do_fork > kprobe_events
+grep myevent kprobe_events
+test -d events/kprobes/myevent
 echo > kprobe_events
tools/testing/selftests/ftrace/test.d/kprobe/busy_check.tc +7 -8
index 588fde97e93f..b55c84003587 100644
@@ -1,14 +1,13 @@
 #!/bin/sh
 # description: Kprobe dynamic event - busy event check
 
-[ -f kprobe_events ] || exit 1
+[ -f kprobe_events ] || exit_unsupported
 
-echo 0 > events/enable || exit 1
-echo > kprobe_events || exit 1
-echo p:myevent do_fork > kprobe_events || exit 1
-[ -d events/kprobes/myevent ] || exit 1
-echo 1 > events/kprobes/myevent/enable || exit 1
+echo 0 > events/enable
+echo > kprobe_events
+echo p:myevent do_fork > kprobe_events
+test -d events/kprobes/myevent
+echo 1 > events/kprobes/myevent/enable
 echo > kprobe_events && exit 1 # this must fail
-echo 0 > events/kprobes/myevent/enable || exit 1
+echo 0 > events/kprobes/myevent/enable
 echo > kprobe_events # this must succeed
-
tools/testing/selftests/ftrace/test.d/template +5 -0
index ce5f735b2e65..5448f7abad5f 100644
@@ -1,4 +1,9 @@
 #!/bin/sh
 # description: %HERE DESCRIBE WHAT THIS DOES%
 # you have to add ".tc" extention for your testcase file
+# Note that all tests are run with "errexit" option.
+
 exit 0 # Return 0 if the test is passed, otherwise return !0
+# If the test could not run because of lack of feature, call exit_unsupported
+# If the test returned unclear results, call exit_unresolved
+# If the test is a dummy, or a placeholder, call exit_untested
Signature · 1 line
2.0.1
author maintainer
#5 lore raw

PATCH 5/5 tracing/kprobes: Add selftest scripts testing kprobe-tracer as startup test

In reply to Steven Rostedt

From: Masami Hiramatsu <[email protected]>

Add two selftest scripts which tests kprobe-tracer as the startup selftest does.
These test cases are testing that the kprobe_event can accept a kprobe event with $stack related arguments and a kretprobe event with $retval argument.

---
 .../selftests/ftrace/test.d/kprobe/kprobe_args.tc        | 16 ++++++++++++++++
 .../selftests/ftrace/test.d/kprobe/kretprobe_args.tc     | 15 +++++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args.tc
 create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_args.tc
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args.tc new file +16 -0
new file mode 100644
index 000000000000..a603d3f8db7b
@@ -0,0 +1,16 @@
+#!/bin/sh
+# description: Kprobe dynamic event with arguments
+
+[ -f kprobe_events ] || exit_unsupported # this is configurable
+
+echo 0 > events/enable
+echo > kprobe_events
+echo 'p:testprobe do_fork $stack $stack0 +0($stack)' > kprobe_events
+grep testprobe kprobe_events
+test -d events/kprobes/testprobe
+echo 1 > events/kprobes/testprobe/enable
+( echo "forked")
+echo 0 > events/kprobes/testprobe/enable
+echo "-:testprobe" >> kprobe_events
+test -d events/kprobes/testprobe && exit 1 || exit 0
+
tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_args.tc new file +15 -0
new file mode 100644
index 000000000000..283c29e7f7c4
@@ -0,0 +1,15 @@
+#!/bin/sh
+# description: Kretprobe dynamic event with arguments
+
+[ -f kprobe_events ] || exit_unsupported # this is configurable
+
+echo 0 > events/enable
+echo > kprobe_events
+echo 'r:testprobe2 do_fork $retval' > kprobe_events
+grep testprobe2 kprobe_events
+test -d events/kprobes/testprobe2
+echo 1 > events/kprobes/testprobe2/enable
+( echo "forked")
+echo 0 > events/kprobes/testprobe2/enable
+echo '-:testprobe2' >> kprobe_events
+test -d events/kprobes/testprobe2 && exit 1 || exit 0
Signature · 1 line
2.0.1