Skip to contentSkip to conversation

ftrace: Add a ftrace test collection

RFC PATCH Superseded Masami Hiramatsu 3 participants 14 messages Sep 2, 2014 – Sep 17, 2014

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover ftrace: Add a ftrace test collection

Hi,

Here is the collection of testcases for ftrace version 3. This is just some updates and fixes according to the discussion at previous version.
https://lkml.org/lkml/2014/8/26/304

The major updates are:
- Fix some expressions to work on dash (Thanks Luis!)
- Support UNRESOLVED/UNTESTED/UNSUPPORTED results for testcase. Those are POSIX 1003.3 standard.
(see http://www.gnu.org/software/dejagnu/manual/x47.html for
more details)
- Fix to show error logs.

ftracetest is a small dash script for testing ftrace features. It will be required to add a unit test for each new feature after this is merged, because of preventing feature regressions.

This version still be out of the selftest. However, at the kernel summit, I talked with Shuah about that. And since the kselftest will be the standard kernel unit test framework, I agreed to move this under the selftest. But I also would like to ask Steven and Namhyung to agree with it before moving.

Actually, since we've already has similar shell-script base testcase under kselftest, we can easily move this under selftests.

Thank you,

---

Masami Hiramatsu (4):
ftracetest: Initial commit for ftracetest
ftracetest: Add ftrace basic testcases
ftracetest: Add kprobe basic testcases
ftracetest: Add XFAIL/XPASS and POSIX.3 std. result codes

 tools/testing/ftrace/README                        |   78 +++++++
 tools/testing/ftrace/ftracetest                    |  217 ++++++++++++++++++++
 tools/testing/ftrace/test.d/basic1.tc              |    7 +
 tools/testing/ftrace/test.d/basic2.tc              |    8 +
 tools/testing/ftrace/test.d/basic3.tc              |    9 +
 .../testing/ftrace/test.d/kprobe/add_and_remove.tc |   12 +
 tools/testing/ftrace/test.d/kprobe/busy_check.tc   |   14 +
 tools/testing/ftrace/test.d/template               |   10 +
 8 files changed, 355 insertions(+)
 create mode 100644 tools/testing/ftrace/README
 create mode 100755 tools/testing/ftrace/ftracetest
 create mode 100644 tools/testing/ftrace/test.d/basic1.tc
 create mode 100644 tools/testing/ftrace/test.d/basic2.tc
 create mode 100644 tools/testing/ftrace/test.d/basic3.tc
 create mode 100644 tools/testing/ftrace/test.d/kprobe/add_and_remove.tc
 create mode 100644 tools/testing/ftrace/test.d/kprobe/busy_check.tc
 create mode 100644 tools/testing/ftrace/test.d/template

--

#1 lore raw

RFC PATCH v3 1/4 ftracetest: Initial commit for ftracetest

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.

Changes in v3:
- Use "." instead of "source".
- Don't use -e option for echo since dash doesn't support it.

Changes in v2:
- Remove unneeded 'function' keyword.
- Add abspath and find_testcases.
- Make OPT_TEST_CASES a local var.
- Ensure given testcase ended with .tc.
- Accept a directory option which has multiple testcases.
- Change [PASSED]/[FAILED] to [PASS]/[FAIL]
- Change the basic shell to sh (dash).

---
 tools/testing/ftrace/README          |   45 ++++++++++
 tools/testing/ftrace/ftracetest      |  152 ++++++++++++++++++++++++++++++++++
 tools/testing/ftrace/test.d/template |    4 +
 3 files changed, 201 insertions(+)
 create mode 100644 tools/testing/ftrace/README
 create mode 100755 tools/testing/ftrace/ftracetest
 create mode 100644 tools/testing/ftrace/test.d/template
tools/testing/ftrace/README new file +45 -0
new file mode 100644
index 0000000..5d5de16
@@ -0,0 +1,45 @@
+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 has *.tc extension)
+and rewrite test description line.
+
+ * The working directory of the script is <debugfs>/tracing/.
+
+ * Take care about the side effect, because that is run with root privilege.
+
+ * Don't take too long. It's a kind of unit test.
+
+ * 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.
+
+TODO
+====
+
+ * Fancy colored output :)
+
+ * Integrate with selftest?
tools/testing/ftrace/ftracetest new file +152 -0

152 lines not on this page · raw message

tools/testing/ftrace/test.d/template new file +4 -0
new file mode 100644
index 0000000..ce5f735
@@ -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
#2 lore raw

Re: [RFC PATCH v3 1/4] ftracetest: Initial commit for ftracetest

Hi Masami,

Just a nit..

Quoted 5 lines · Masami Hiramatsu

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.

[SNIP]

tools/testing/ftrace/ftracetest line 133

Quoted 7 lines
tools/testing/ftrace/ftracetest new file +7 -0
+# Run one test case
+run_test() { # testfile
+  local testname=`basename $1`
+  local testlog=`mktemp --tmpdir=$LOG_DIR ${testname}-XXXXXX.log`
+  testcase $1
+  echo "execute: "$1 > $testlog
+  (cd $TRACING_DIR; set -x ; . $t) >> $testlog 2>&1

s/$t/$1/ ?

Thanks,
Namhyung

Quoted 29 lines
tools/testing/ftrace/ftracetest new file +19 -0
+  ret=$?
+  if [ $ret -ne 0 ]; then
+    failed
+    catlog $testlog
+  else
+    passed
+    [ $KEEP_LOG -eq 0 ] && rm $testlog
+  fi
+}
+
+# Main loop
+for t in $TEST_CASES; do
+  run_test $t
+done
+prlog ""
+prlog "# of passed: " `echo $PASSED_CASES | wc -w`
+prlog "# of failed: " `echo $FAILED_CASES | wc -w`
+
+test -z "$FAILED_CASES" # if no error, return 0
tools/testing/ftrace/test.d/template new file +4 -0
new file mode 100644
index 0000000..ce5f735
@@ -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
#3 lore raw

Re: [RFC PATCH v3 1/4] ftracetest: Initial commit for ftracetest

Quoted 14 lines · Namhyung Kim

Hi Masami,

Just a nit..

Quoted 5 lines · Masami Hiramatsu

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.

[SNIP]

Quoted 9 lines

tools/testing/ftrace/ftracetest line 133

Quoted 7 lines
tools/testing/ftrace/ftracetest new file +7 -0
+# Run one test case
+run_test() { # testfile
+  local testname=`basename $1`
+  local testlog=`mktemp --tmpdir=$LOG_DIR ${testname}-XXXXXX.log`
+  testcase $1
+  echo "execute: "$1 > $testlog
+  (cd $TRACING_DIR; set -x ; . $t) >> $testlog 2>&1

s/$t/$1/ ?

Oops, right! I missed that. Since the $1 is same as $t, the test itself works, but it should be fixed.

Thank you!

Quoted 35 lines

Thanks,
Namhyung

Quoted 29 lines
tools/testing/ftrace/ftracetest new file +19 -0
+  ret=$?
+  if [ $ret -ne 0 ]; then
+    failed
+    catlog $testlog
+  else
+    passed
+    [ $KEEP_LOG -eq 0 ] && rm $testlog
+  fi
+}
+
+# Main loop
+for t in $TEST_CASES; do
+  run_test $t
+done
+prlog ""
+prlog "# of passed: " `echo $PASSED_CASES | wc -w`
+prlog "# of failed: " `echo $FAILED_CASES | wc -w`
+
+test -z "$FAILED_CASES" # if no error, return 0
tools/testing/ftrace/test.d/template new file +4 -0
new file mode 100644
index 0000000..ce5f735
@@ -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 · 4 lines
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]
#4 lore raw

Re: [RFC PATCH v3 1/4] ftracetest: Initial commit for ftracetest

In reply to Masami Hiramatsu
Quoted 23 lines
tools/testing/ftrace/README new file +16 -0
new file mode 100644
index 0000000..5d5de16
@@ -0,0 +1,45 @@
+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:
+

tools/testing/ftrace/README line 26

Quoted 10 lines
tools/testing/ftrace/README new file +10 -0
+  # ./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 has *.tc extension)

"whose filename must have *.tc extension"

tools/testing/ftrace/README line 27

Quoted 1 line
tools/testing/ftrace/README new file +1 -0
+and rewrite test description line.

"and rewrite the test description line"

tools/testing/ftrace/README line 31

Quoted 4 lines
tools/testing/ftrace/README new file +4 -0
+
+ * The working directory of the script is <debugfs>/tracing/.
+
+ * Take care about the side effect, because that is run with root privilege.

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

tools/testing/ftrace/README line 33

Quoted 2 lines
tools/testing/ftrace/README new file +2 -0
+
+ * Don't take too long. It's a kind of unit test.

"The tests should not run for a long period of time. These are to be unit tests"

We should probably specify what the time should be. Is 20 minutes too long?

Quoted 18 lines
tools/testing/ftrace/README new file +12 -0
+
+ * 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.
+
+TODO
+====
+
+ * Fancy colored output :)
+
+ * Integrate with selftest?
tools/testing/ftrace/ftracetest new file +0 -0
new file mode 100755
index 0000000..8d92e74

tools/testing/ftrace/ftracetest line 3

Quoted 3 lines
tools/testing/ftrace/ftracetest new file +3 -0
@@ -0,0 +1,152 @@
+#!/bin/sh
+# ftracetest - Ftrace test shell scripts
+# Written by Masami Hiramatsu <[email protected]>

Maybe add your copyright here, with year?

Also, we should probably state that this is under the GPL v2?

-- Steve

Quoted 10 lines
tools/testing/ftrace/ftracetest new file +10 -0
+
+usage() { # errno [message]
+[ "$2" ] && echo $2
+echo "Usage: ftracetest [options] [testcase(s)] [testcase-directory(s)]"
+echo " Options:"
+echo "		-h|--help  Show help message"
+echo "		-k|--keep  Keep passed test logs"
+echo "		-d|--debug Debug mode (trace all shell commands)"
+exit $1
+}
#5 lore raw

Re: [RFC PATCH v3 1/4] ftracetest: Initial commit for ftracetest

Hi Steve,

Thank you for your comments.

Quoted 36 lines · Steven Rostedt
Quoted 23 lines
tools/testing/ftrace/README new file +16 -0
new file mode 100644
index 0000000..5d5de16
@@ -0,0 +1,45 @@
+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:
+

tools/testing/ftrace/README line 26

Quoted 10 lines
tools/testing/ftrace/README new file +10 -0
+  # ./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 has *.tc extension)

"whose filename must have *.tc extension"

Quoted 3 lines

tools/testing/ftrace/README line 27

Quoted 1 line
tools/testing/ftrace/README new file +1 -0
+and rewrite test description line.

"and rewrite the test description line"

Thanks, I'll update it.

Quoted 8 lines

tools/testing/ftrace/README line 31

Quoted 5 lines
tools/testing/ftrace/README new file +4 -0
+
+ * The working directory of the script is <debugfs>/tracing/.
+
+ * Take care about the side effect, because that is run with root privilege.

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

Quoted 8 lines

tools/testing/ftrace/README line 33

Quoted 2 lines
tools/testing/ftrace/README new file +2 -0
+
+ * Don't take too long. It's a kind of unit test.

"The tests should not run for a long period of time. These are to be unit tests"

We should probably specify what the time should be. Is 20 minutes too long?

I guess more than 1 minute is enough long to doubt something goes wrong. What unit test could be so long?
I think we need something like progress bar for such long tests.

Quoted 15 lines
Quoted 15 lines
tools/testing/ftrace/README new file +12 -0
+
+ * 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.
+
+TODO
+====
+
+ * Fancy colored output :)
+
+ * Integrate with selftest?
tools/testing/ftrace/ftracetest new file +0 -0
new file mode 100755
index 0000000..8d92e74
Quoted 8 lines

tools/testing/ftrace/ftracetest line 3

Quoted 6 lines
tools/testing/ftrace/ftracetest new file +3 -0
@@ -0,0 +1,152 @@
+#!/bin/sh
+# ftracetest - Ftrace test shell scripts
+# Written by Masami Hiramatsu <[email protected]>

Maybe add your copyright here, with year?

Ah, right.

Quoted 2 lines

Also, we should probably state that this is under the GPL v2?

OK, I'll add it. :)

Thank you,

Quoted 14 lines

-- Steve

Quoted 10 lines
tools/testing/ftrace/ftracetest new file +10 -0
+
+usage() { # errno [message]
+[ "$2" ] && echo $2
+echo "Usage: ftracetest [options] [testcase(s)] [testcase-directory(s)]"
+echo " Options:"
+echo "		-h|--help  Show help message"
+echo "		-k|--keep  Keep passed test logs"
+echo "		-d|--debug Debug mode (trace all shell commands)"
+exit $1
+}
Signature · 4 lines
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]
#6 lore raw

RFC PATCH v3 2/4 ftracetest: Add ftrace basic testcases

In reply to Masami Hiramatsu

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

Changes in v2:
- Change shell to sh instead of bash.

---
 tools/testing/ftrace/test.d/basic1.tc |    3 +++
 tools/testing/ftrace/test.d/basic2.tc |    6 ++++++
 tools/testing/ftrace/test.d/basic3.tc |    8 ++++++++
 3 files changed, 17 insertions(+)
 create mode 100644 tools/testing/ftrace/test.d/basic1.tc
 create mode 100644 tools/testing/ftrace/test.d/basic2.tc
 create mode 100644 tools/testing/ftrace/test.d/basic3.tc
tools/testing/ftrace/test.d/basic1.tc new file +3 -0
new file mode 100644
index 0000000..9980ff1
@@ -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/ftrace/test.d/basic2.tc new file +6 -0
new file mode 100644
index 0000000..b04f30d
@@ -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/ftrace/test.d/basic3.tc new file +8 -0
new file mode 100644
index 0000000..0c1a3a2
@@ -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
#7 lore raw

RFC PATCH v3 3/4 ftracetest: Add kprobe basic testcases

In reply to Masami Hiramatsu

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

Changes in v2:
- Change shell to sh instead of bash.

---
 .../testing/ftrace/test.d/kprobe/add_and_remove.tc |   11 +++++++++++
 tools/testing/ftrace/test.d/kprobe/busy_check.tc   |   14 ++++++++++++++
 2 files changed, 25 insertions(+)
 create mode 100644 tools/testing/ftrace/test.d/kprobe/add_and_remove.tc
 create mode 100644 tools/testing/ftrace/test.d/kprobe/busy_check.tc
tools/testing/ftrace/test.d/kprobe/add_and_remove.tc new file +11 -0
new file mode 100644
index 0000000..5ddfb47
@@ -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/ftrace/test.d/kprobe/busy_check.tc new file +14 -0
new file mode 100644
index 0000000..588fde97
@@ -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
+
#8 lore raw

RFC PATCH v3 4/4 ftracetest: Add XFAIL/XPASS and POSIX.3 std. result codes

In reply to Masami Hiramatsu

Add XFAIL, XPASS and POSIX 1003.3 std. codes (UNRESOLVED/ UNTESTED/UNSUPPORTED) as a result code. These are used for the results that test case is expected to fail or unsupported feature (by config).
This also introduces PASS/FAIL/XFAIL/XPASS/UNSUP/UNTST/UNRES result codes for each testcase. Since the results are not binary, each testcase must use these codes to return the test result.

Changes in v3:
- Add UNRESOLVED/UNTESTED codes.
- Fix to handle undefined codes.
- Add a document about return codes.
- Fix to show failure logs.
- Don't use -e option for echo since dash doesn't support it.

---
 tools/testing/ftrace/README                        |   33 +++++++
 tools/testing/ftrace/ftracetest                    |   95 +++++++++++++++++---
 tools/testing/ftrace/test.d/basic1.tc              |    6 +
 tools/testing/ftrace/test.d/basic2.tc              |    6 +
 tools/testing/ftrace/test.d/basic3.tc              |    9 +-
 .../testing/ftrace/test.d/kprobe/add_and_remove.tc |   15 ++-
 tools/testing/ftrace/test.d/kprobe/busy_check.tc   |   20 ++--
 tools/testing/ftrace/test.d/template               |    8 +-
 8 files changed, 152 insertions(+), 40 deletions(-)
tools/testing/ftrace/README +33 -0
index 5d5de16..758c0c6 100644
@@ -37,6 +37,39 @@ and rewrite test description line.
  * The test cases should run on dash (busybox shell) for testing on
    minimal cross-build environments.
 
+ * The test cases must return one of result codes described below.
+
+Return codes
+============
+
+Ftracetest supports following return codes, which are defined as shell
+variables (do not overwrite them.)
+
+ * PASS: The test succeeded as expected.
+
+ * FAIL: The test failed, but was expected to succeed.
+
+ * 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
+
+ * UNTESTED: The test was not run, currently just a placeholder.
+
+ * UNSUPPORTED: The test failed because of lack of feature.
+
+ * XFAIL: The test failed, and was expected to fail.
+
+ * XPASS: The test succeeded, but was expected to fail.
+
+Below shortened valiables are also available.
+
+ * UNRES: means UNRESOLVED.
+
+ * UNTST: means UNTESTED.
+
+ * UNSUP: means UNSUPPORTED.
+
 TODO
 ====
 
tools/testing/ftrace/ftracetest +80 -15

122 lines not on this page · raw message

tools/testing/ftrace/test.d/basic1.tc +5 -1
index 9980ff1..1e95209 100644
@@ -1,3 +1,7 @@
 #!/bin/sh
 # description: Basic trace file check
-test -f README -a -f trace -a -f tracing_on -a -f trace_pipe
+if test -f README -a -f trace -a -f tracing_on -a -f trace_pipe; then
+  exit $PASS
+else
+  exit $FAIL
+fi
tools/testing/ftrace/test.d/basic2.tc +4 -2
index b04f30d..44949e9 100644
@@ -1,6 +1,8 @@
 #!/bin/sh
 # description: Basic test for tracers
+test -f available_tracers || exit $FAIL # this is basic feature, must be there.
 for t in `cat available_tracers`; do
-  echo $t > current_tracer || exit 1
+  echo $t > current_tracer || exit $FAIL
 done
-echo nop > current_tracer
+echo nop > current_tracer || exit $FAIL
+exit $PASS
tools/testing/ftrace/test.d/basic3.tc +5 -4
index 0c1a3a2..7bc5a53 100644
@@ -1,8 +1,9 @@
 #!/bin/sh
 # description: Basic trace clock test
-[ -f trace_clock ] || exit 1
+[ -f trace_clock ] || exit $FAIL # this is basic feature, must be there
 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 || exit $FAIL
+  grep '\['$c'\]' trace_clock || exit $FAIL
 done
-echo local > trace_clock
+echo local > trace_clock || exit $FAIL
+exit $PASS
tools/testing/ftrace/test.d/kprobe/add_and_remove.tc +8 -7
index 5ddfb47..fa3034b 100644
@@ -1,11 +1,12 @@
 #!/bin/sh
 # description: Kprobe dynamic event - adding and removing
 
-[ -f kprobe_events ] || exit 1
+[ -f kprobe_events ] || exit $UNSUP # 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 > kprobe_events
+echo 0 > events/enable || exit $FAIL
+echo > kprobe_events || exit $FAIL
+echo p:myevent do_fork > kprobe_events || exit $FAIL
+grep myevent kprobe_events || exit $FAIL
+[ -d events/kprobes/myevent ] || exit $FAIL
+echo > kprobe_events || exit $FAIL
+exit $PASS
tools/testing/ftrace/test.d/kprobe/busy_check.tc +10 -10
index 588fde97..6f47784 100644
@@ -1,14 +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
+[ -f kprobe_events ] || exit $UNSUP
 
+echo 0 > events/enable || exit $FAIL
+echo > kprobe_events || exit $FAIL
+echo p:myevent do_fork > kprobe_events || exit $FAIL
+[ -d events/kprobes/myevent ] || exit $FAIL
+echo 1 > events/kprobes/myevent/enable || exit $FAIL
+echo > kprobe_events && exit $FAIL # this must fail
+echo 0 > events/kprobes/myevent/enable || exit $FAIL
+echo > kprobe_events || exit $FAIL # this must succeed
+exit $PASS
tools/testing/ftrace/test.d/template +7 -1
index ce5f735..02b97af 100644
@@ -1,4 +1,10 @@
 #!/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
+exit $PASS # Return $PASS if the test succeeded.
+# If the test failed, return $FAIL.
+# If the test failed as expected, return $XFAIL.
+# If the test passed, but it was expected to fail, return $XPASS.
+# If the test could not run because of lack of feature, return $UNSUPPORTED
+# If the test returned unclear results, return $UNRESOLVED
+# If the test is a dummy, or a placeholder, return $UNTESTED
#9 lore raw

Re: [RFC PATCH v3 4/4] ftracetest: Add XFAIL/XPASS and POSIX.3 std. result codes

Quoted 18 lines · Masami Hiramatsu

Add XFAIL, XPASS and POSIX 1003.3 std. codes (UNRESOLVED/ UNTESTED/UNSUPPORTED) as a result code. These are used for the results that test case is expected to fail or unsupported feature (by config).
This also introduces PASS/FAIL/XFAIL/XPASS/UNSUP/UNTST/UNRES result codes for each testcase. Since the results are not binary, each testcase must use these codes to return the test result.

Changes in v3:
- Add UNRESOLVED/UNTESTED codes.
- Fix to handle undefined codes.
- Add a document about return codes.
- Fix to show failure logs.
- Don't use -e option for echo since dash doesn't support it.

---

[SNIP]

Quoted 8 lines
tools/testing/ftrace/test.d/basic3.tc +0 -1
index 0c1a3a2..7bc5a53 100644
@@ -1,8 +1,9 @@
 #!/bin/sh
 # description: Basic trace clock test
-[ -f trace_clock ] || exit 1

tools/testing/ftrace/test.d/basic3.tc line 9

Quoted 10 lines
tools/testing/ftrace/test.d/basic3.tc +5 -3
+[ -f trace_clock ] || exit $FAIL # this is basic feature, must be there
 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 || exit $FAIL
+  grep '\['$c'\]' trace_clock || exit $FAIL
 done
-echo local > trace_clock
+echo local > trace_clock || exit $FAIL
+exit $PASS

IMHO it's a bit sad that we need to write every test in this way - adding '|| exit $FAIL' for every command. It'd be better if only exceptional cases require that explicitly and normal cases live in simple.

Can we do better - like using trap or something?

Thanks,
Namhyung

#10 lore raw

Re: Re: [RFC PATCH v3 4/4] ftracetest: Add XFAIL/XPASS and POSIX.3 std. result codes

Quoted 24 lines · Namhyung Kim
Quoted 8 lines
tools/testing/ftrace/test.d/basic3.tc +0 -1
index 0c1a3a2..7bc5a53 100644
@@ -1,8 +1,9 @@
 #!/bin/sh
 # description: Basic trace clock test
-[ -f trace_clock ] || exit 1

tools/testing/ftrace/test.d/basic3.tc line 9

Quoted 10 lines
tools/testing/ftrace/test.d/basic3.tc +5 -3
+[ -f trace_clock ] || exit $FAIL # this is basic feature, must be there
 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 || exit $FAIL
+  grep '\['$c'\]' trace_clock || exit $FAIL
 done
-echo local > trace_clock
+echo local > trace_clock || exit $FAIL
+exit $PASS

IMHO it's a bit sad that we need to write every test in this way - adding '|| exit $FAIL' for every command. It'd be better if only exceptional cases require that explicitly and normal cases live in simple.

Quoted 1 line

Can we do better - like using trap or something?

Hmm, no, trap is only for the signal trapping, and using signal means run "kill" command for special errors. That may not be what you want... :(

Perhaps, "set -e" may help you to simplify the script. But since it also returns various exit code, you can not control it. (I hope to have the "atexit" for dash...)

Anyway, IMHO, the test cases should express what happened clearly since the test is a kind of verification process.

Thank you,

Signature · 4 lines
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]
#11 lore raw

Re: Re: Re: [RFC PATCH v3 4/4] ftracetest: Add XFAIL/XPASS and POSIX.3 std. result codes

Quoted 25 lines · Masami Hiramatsu
Quoted 24 lines · Namhyung Kim
Quoted 8 lines
tools/testing/ftrace/test.d/basic3.tc +0 -1
index 0c1a3a2..7bc5a53 100644
@@ -1,8 +1,9 @@
 #!/bin/sh
 # description: Basic trace clock test
-[ -f trace_clock ] || exit 1

tools/testing/ftrace/test.d/basic3.tc line 9

Quoted 10 lines
tools/testing/ftrace/test.d/basic3.tc +5 -3
+[ -f trace_clock ] || exit $FAIL # this is basic feature, must be there
 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 || exit $FAIL
+  grep '\['$c'\]' trace_clock || exit $FAIL
 done
-echo local > trace_clock
+echo local > trace_clock || exit $FAIL
+exit $PASS

IMHO it's a bit sad that we need to write every test in this way - adding '|| exit $FAIL' for every command. It'd be better if only exceptional cases require that explicitly and normal cases live in simple.

Quoted 5 lines
Quoted 1 line

Can we do better - like using trap or something?

Hmm, no, trap is only for the signal trapping, and using signal means run "kill" command for special errors. That may not be what you want... :(

I've changed my mind. I've checked that the possibility of simplification of the testcases with signal traps. :)
Here I've added the following functions,

-----
exit_unsupported () {
kill -s $SIG_UNSUPPORTED $SIG_PID
exit 0
}
trap_unsupported () {
SIG_RESULT=$UNSUPPORTED
}
trap trap_unsupported $SIG_UNSUPPORTED
-----

And add "set -e;"(errexit) for sub-shell testcases.

-----
#!/bin/sh
# description: Kprobe dynamic event - adding and removing

[ -f kprobe_events ] || exit_unsupported

# If we have any error, sub shell exits soon with error code. 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
exit 0
-----

So, we'll have no return code in the testcases.

Quoted 4 lines

Perhaps, "set -e" may help you to simplify the script. But since it also returns various exit code, you can not control it. (I hope to have the "atexit" for dash...)

I've found that trap with 0 can catch the exit of subshell, but it can not know the exit code...

BTW, I've found that $PPID and $$ in subshell doesn't updated automatically. PPID can be updated, but $$ cannnot. I'll pass $PID so that the testcases can use it instead of $$. Or, should I use $SHELL to run testcases?

Thank you,

Signature · 4 lines
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]
#12 lore raw
In reply to Masami Hiramatsu
Quoted 25 lines · Masami Hiramatsu

Hi,

Here is the collection of testcases for ftrace version 3. This is just some updates and fixes according to the discussion at previous version.
https://lkml.org/lkml/2014/8/26/304

The major updates are:
- Fix some expressions to work on dash (Thanks Luis!)
- Support UNRESOLVED/UNTESTED/UNSUPPORTED results for testcase. Those are POSIX 1003.3 standard.
(see http://www.gnu.org/software/dejagnu/manual/x47.html for
more details)
- Fix to show error logs.

ftracetest is a small dash script for testing ftrace features. It will be required to add a unit test for each new feature after this is merged, because of preventing feature regressions.

This version still be out of the selftest. However, at the kernel summit, I talked with Shuah about that. And since the kselftest will be the standard kernel unit test framework, I agreed to move this under the selftest. But I also would like to ask Steven and Namhyung to agree with it before moving.

Quoted 3 lines

Actually, since we've already has similar shell-script base testcase under kselftest, we can easily move this under selftests.

By [k]selftest, did you mean tools/testing/selftests/ ?

Anyway I have no objection to the move.

Thanks for your work!
Namhyung

#13 lore raw
Quoted 26 lines · Namhyung Kim
Quoted 25 lines · Masami Hiramatsu

Hi,

Here is the collection of testcases for ftrace version 3. This is just some updates and fixes according to the discussion at previous version.
https://lkml.org/lkml/2014/8/26/304

The major updates are:
- Fix some expressions to work on dash (Thanks Luis!)
- Support UNRESOLVED/UNTESTED/UNSUPPORTED results for testcase. Those are POSIX 1003.3 standard.
(see http://www.gnu.org/software/dejagnu/manual/x47.html for
more details)
- Fix to show error logs.

ftracetest is a small dash script for testing ftrace features. It will be required to add a unit test for each new feature after this is merged, because of preventing feature regressions.

This version still be out of the selftest. However, at the kernel summit, I talked with Shuah about that. And since the kselftest will be the standard kernel unit test framework, I agreed to move this under the selftest. But I also would like to ask Steven and Namhyung to agree with it before moving.

Quoted 5 lines
Quoted 3 lines

Actually, since we've already has similar shell-script base testcase under kselftest, we can easily move this under selftests.

By [k]selftest, did you mean tools/testing/selftests/ ?

Yes, and I will just move tools/testing/ftrace to tools/testing/selftests/ftrace and add a Makefile.

Quoted 1 line

Anyway I have no objection to the move.

Thank you!

Quoted 4 lines

Thanks for your work!
Namhyung

Signature · 4 lines
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]