[PATCH v2 tracing 5/6] selftests/ftrace: add test coverage for filter predicates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



add tests verifying filter predicates work for 1/2/4/8/16 byte values,
IPv4, IPv6, MAC addresses and strings; use predicats at event and
subsystem level.

Signed-off-by: Alan Maguire <alan.maguire@xxxxxxxxxx>
---
 .../selftests/ftrace/test.d/event/filter.tc   | 91 +++++++++++++++++++
 1 file changed, 91 insertions(+)
 create mode 100644 tools/testing/selftests/ftrace/test.d/event/filter.tc

diff --git a/tools/testing/selftests/ftrace/test.d/event/filter.tc b/tools/testing/selftests/ftrace/test.d/event/filter.tc
new file mode 100644
index 000000000000..21d4715e2176
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/event/filter.tc
@@ -0,0 +1,91 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: event tracing - enable filter predicates
+# requires: set_event events/sched
+# flags:
+
+do_reset() {
+    echo 0 > ${event}/enable
+    echo 0 > ${event}/filter
+    clear_trace
+}
+
+fail() { #msg
+    echo $1
+    exit_fail
+}
+
+test_filter() { # event filter cmd
+    event=$1
+    filter="$2"
+    cmd=$3
+    findevent=`basename $event`
+    echo "$filter" > ${event}/filter
+    echo 1 > ${event}/enable
+    $cmd
+    count=`grep $findevent trace |wc -l`
+    if [ $count -lt 1 ]; then
+        fail "at least one $event should be recorded for '$filter'"
+    fi
+    do_reset
+}
+
+# verify filter predicates at trace event/subsys level for
+# - string (prev_comm)
+# - 1-byte value (common_flags)
+# - 2-byte value (common_type)
+# - 4-byte value (next_pid)
+# - 8-byte value (prev_state)
+
+for event in events/sched/sched_switch events/sched
+do
+    for filter in	"prev_comm == 'ftracetest'"	\
+			"common_flags != 0"		\
+			"common_type >= 0"		\
+			"next_pid > 0"			\
+			"prev_state != 0"
+    do
+        test_filter "$event" "$filter" "yield"
+    done
+done
+
+# verify '==', '!=' filter predicates for IPv4 addresses at event/subsys
+# level
+for event in events/fib/fib_table_lookup events/fib ; do
+    for filter in "dst == 127.0.0.1" \
+	          "src != 127.0.0.1"
+    do
+        test_filter "$event" "$filter" "ping -c 1 127.0.0.1"
+    done
+done
+
+# verify '==', '!=' filter predicates for IPv6 addresses/16-byte arrays
+# at event/subsys level
+for event in events/fib6/fib6_table_lookup events/fib6 ; do
+    for filter in "dst == 0x00000000000000000000000000000001" \
+	          "src != 0x00000000000000000000000000000001" \
+		  "dst == ::1" \
+		  "src != ::1" \
+		  "dst == 0:0:0:0:0:0:0:1" \
+		  "dst == 0000:0000:0000:0000:0000:0000:0000:00001"
+    do
+       test_filter "$event" "$filter" "ping -c 1 -6 ::1"
+    done
+done
+
+set +e
+modprobe cfg80211
+set -e
+
+if [[ -d events/cfg80211/rdev_get_key ]]; then
+    for event in events/cfg80211/rdev_get_key ; do
+       for filter in "mac_addr == de:ad:be:ef:de:ad" \
+		     "mac_addr != AB:CD:EF:01:23:45"
+       do
+          echo "$filter" > events/cfg80211/rdev_get_key/filter
+          echo 0 > events/cfg80211/rdev_get_key/filter
+       done
+     done
+fi
+
+exit 0
-- 
2.31.1




[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux