From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
Theodore Tso <tytso@mit.edu>,
Alexei Starovoitov <ast@plumgrid.com>
Subject: [PATCH 3/3] ftracetests: Add test to test event filter logic
Date: Tue, 02 Dec 2014 22:13:37 -0500 [thread overview]
Message-ID: <20141203032106.156623189@goodmis.org> (raw)
In-Reply-To: 20141203031334.174087814@goodmis.org
[-- Attachment #1: 0003-ftracetests-Add-test-to-test-event-filter-logic.patch --]
[-- Type: text/plain, Size: 5411 bytes --]
From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>
Add a test to test the event filter logic. It currently tests the
following filters against sched:sched_switch event.
( prev_pid != 0 )
( prev_pid == 0 )
( prev_pid < 100 )
( prev_pid <= $$ )
( prev_pid > 100 )
( prev_pid >= $$ )
! ( prev_pid != 0 )
! ( prev_pid == 0 )
! ( prev_pid < 100 )
! ( prev_pid <= $$ )
! ( prev_pid > 100 )
! ( prev_pid >= $$ )
( prev_pid != 0 && next_pid > 10 )
( prev_pid != 0 || next_pid > 10 )
! ( prev_pid != 0 && next_pid > 10 )
! ( prev_pid != 0 || next_pid > 10 )
( prev_pid & 1 )
( prev_pid & 2 )
( prev_pid & 4 )
( prev_pid & 8 )
( prev_pid & 16 )
! ( prev_pid & 1 )
! ( prev_pid & 2 )
! ( prev_pid & 4 )
! ( prev_pid & 8 )
! ( prev_pid & 16 )
( next_comm ~ "ftrace-test-fil" )
( next_comm != "ftrace-test-fil" )
! ( next_comm ~ "ftrace-test-fil" )
! ( next_comm != "ftrace-test-fil" )
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
.../selftests/ftrace/test.d/ftrace/filter.tc | 200 +++++++++++++++++++++
1 file changed, 200 insertions(+)
create mode 100644 tools/testing/selftests/ftrace/test.d/ftrace/filter.tc
diff --git a/tools/testing/selftests/ftrace/test.d/ftrace/filter.tc b/tools/testing/selftests/ftrace/test.d/ftrace/filter.tc
new file mode 100644
index 000000000000..de4c5ce57099
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/ftrace/filter.tc
@@ -0,0 +1,200 @@
+#!/bin/sh
+# description: ftrace - test filter logic
+
+EVENT=events/sched/sched_switch
+FILTER=$EVENT/filter
+ENABLE=$EVENT/enable
+
+FIELD1=prev_pid
+FIELD2=next_pid
+FIELD3=next_comm
+
+ITER=100
+
+enable_event() {
+ echo 1 > $ENABLE
+}
+
+disable_event() {
+ echo 0 > $ENABLE
+}
+
+clear_filter() {
+ echo 0 > $FILTER
+}
+
+do_reset() {
+ enable_tracing
+ disable_event
+ clear_filter
+ clear_trace
+}
+
+fail() { # msg
+ do_reset
+ echo $1
+ exit -1
+}
+
+run_code() {
+ # make lots of pids to filter on
+ for i in `seq $ITER`; do
+ ls /usr > /dev/null
+ done
+}
+
+run_event() {
+ enable_event
+ run_code
+ disable_event
+}
+
+disable_tracing
+clear_trace
+enable_tracing
+
+test_cmp() {
+ cmp=$1
+ rval=$2
+ filter=$3
+ not=$4
+
+ echo "$not ( $FIELD1 $filter )"
+ echo "$not ( $FIELD1 $filter )" > $FILTER
+
+ run_event
+
+ cat trace | sed -ne "s/.*$FIELD1=\([^ ]*\).*/\1/p" |
+ while read pid; do
+ if [ "$pid" $cmp $rval ]; then
+ if [ "$not" == '!' ]; then
+ fail "$pid matched filter: $filter; but should not not have for $not"
+ fi
+ elif [ "$not" != '!' ]; then
+ fail "$pid does not match filter: $filter"
+ fi
+ done
+ clear_trace
+}
+
+test_cmp2() {
+ cmp1=$1
+ rval1=$2
+ conj=$3
+ cmp2=$4
+ rval2=$5
+ filter1=$6
+ filter2=$7
+ fconj=$8
+ not=$9
+
+ echo "$not ( $FIELD1 $filter1 $fconj $FIELD2 $filter2 )"
+ echo "$not ( $FIELD1 $filter1 $fconj $FIELD2 $filter2 )" > $FILTER
+
+ run_event
+
+ cat trace | sed -ne "s/.*$FIELD1=\([^ ]*\).*$FIELD2=\([^ ]*\).*/\1 \2/p" |
+ while read pid1 pid2; do
+ if [ "$pid1" $cmp1 $rval1 $conj "$pid2" $cmp2 $rval2 ]; then
+ if [ "$not" == '!' ]; then
+ fail "$pid1 and $pid2 match not filter: $filter1 $fconj $filter2"
+ fi
+ elif [ "$not" != '!' ]; then
+ fail "$pid1 and $pid2 does not match filter: $filter1 $fconj $filter2"
+ fi
+ done
+ clear_trace
+}
+
+# first simple compares
+test_cmp -ne 0 "!= 0" ""
+test_cmp -eq 0 "== 0" ""
+test_cmp -lt 100 "< 100" ""
+test_cmp -le $$ "<= $$" ""
+test_cmp -gt 100 "> 100" ""
+test_cmp -ge $$ ">= $$" ""
+
+# Now test the not case
+test_cmp -ne 0 "!= 0" '!'
+test_cmp -eq 0 "== 0" '!'
+test_cmp -lt 100 "< 100" '!'
+test_cmp -le $$ "<= $$" '!'
+test_cmp -gt 100 "> 100" '!'
+test_cmp -ge $$ ">= $$" '!'
+
+# Test more complex compares (&& and !!)
+test_cmp2 -ne 0 -a -gt 10 "!= 0" "> 10" "&&" ''
+test_cmp2 -ne 0 -o -gt 10 "!= 0" "> 10" "||" ''
+
+test_cmp2 -ne 0 -a -gt 10 "!= 0" "> 10" "&&" '!'
+test_cmp2 -ne 0 -o -gt 10 "!= 0" "> 10" "||" '!'
+
+# test bitmask
+
+bit_test() {
+ not=$1
+
+ let x=1
+ for i in `seq 5`; do
+ echo "$not ( $FIELD1 & $x )"
+ echo "$not ( $FIELD1 & $x )" > $FILTER
+ run_event
+
+ cat trace | sed -ne "s/.*$FIELD1=\([^ ]*\).*/\1/p" |
+ while read pid; do
+
+ # do not exit if val becomes zero
+ set +e
+ let val="$pid & $x"
+ set -e
+
+ if [ $val -eq 0 ]; then
+ if [ "$not" != '!' ]; then
+ fail "$pid did not match bitmask $x"
+ fi
+ elif [ "$not" == '!' ]; then
+ fail "$pid did not match not bitmask $x"
+ fi
+ done
+ clear_trace
+ let x="$x << 1"
+ done
+}
+
+bit_test ''
+bit_test '!'
+
+test_string() {
+ cmp=$1
+ filter=$2
+ not=$3
+
+ comm=`cat /proc/$$/comm`
+
+ echo "$not ( $FIELD3 $filter \"$comm\" )"
+ echo "$not ( $FIELD3 $filter \"$comm\" )" > $FILTER
+
+ run_event
+
+ cat trace | sed -ne "s/.*$FIELD3=\([^ ]*\).*/\1/p" |
+ while read com; do
+ if [ "$com" $cmp "$comm" ]; then
+ if [ "$not" == '!' ]; then
+ fail "$com matched filter: $filter; but should not not have for $not"
+ fi
+ elif [ "$not" != '!' ]; then
+ fail "$com does not match filter: $filter"
+ fi
+ done
+ clear_trace
+}
+
+test_string "==" "~" ''
+test_string "!=" "!=" ''
+
+test_string "==" "~" '!'
+test_string "!=" "!=" '!'
+
+do_reset
+
+exit 0
--
2.1.3
next prev parent reply other threads:[~2014-12-03 3:21 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-03 3:13 [PATCH 0/3] tracing: Add event filter logic for !(...) Steven Rostedt
2014-12-03 3:13 ` [PATCH 1/3] tracing: Add NOT to filtering logic Steven Rostedt
2014-12-03 3:13 ` [PATCH 2/3] tracing: Allow NOT to filter AND and OR clauses Steven Rostedt
2014-12-03 3:13 ` Steven Rostedt [this message]
2014-12-03 6:22 ` [PATCH 3/3] ftracetests: Add test to test event filter logic Alexei Starovoitov
2014-12-03 8:40 ` Steven Rostedt
2014-12-03 17:53 ` Alexei Starovoitov
2014-12-03 18:01 ` Steven Rostedt
2014-12-03 9:26 ` Masami Hiramatsu
2014-12-03 9:34 ` Steven Rostedt
2014-12-03 16:20 ` Steven Rostedt
2014-12-04 8:12 ` Masami Hiramatsu
2014-12-03 23:14 ` Masami Hiramatsu
2014-12-03 23:29 ` Steven Rostedt
2014-12-04 3:18 ` [PATCH v2] " Steven Rostedt
2014-12-04 10:06 ` Masami Hiramatsu
2014-12-04 12:04 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141203032106.156623189@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=ast@plumgrid.com \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox