linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Tom Zanussi <zanussi@kernel.org>, Steven Rostedt <rostedt@goodmis.org>
Cc: tglx@linutronix.de, mhiramat@kernel.org, namhyung@kernel.org,
	bigeasy@linutronix.de, joel@joelfernandes.org,
	linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org
Subject: [RFC PATCH 7/7] selftests/ftrace: Add error_log testcase for kprobe errors
Date: Wed, 13 Mar 2019 21:28:41 +0900	[thread overview]
Message-ID: <155248012180.10815.9684996376860674672.stgit@devnote2> (raw)
In-Reply-To: <155248005229.10815.334731901778152247.stgit@devnote2>

Add error_log testcase for error logs on kprobe events.
This tests most of error cases and checks the error position
is correct.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 .../ftrace/test.d/kprobe/kprobe_syntax_errors.tc   |   91 ++++++++++++++++++++
 1 file changed, 91 insertions(+)
 create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc

diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc
new file mode 100644
index 000000000000..5796e258747c
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc
@@ -0,0 +1,91 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: Kprobe event parser error log check
+
+[ -f kprobe_events ] || exit_unsupported # this is configurable
+
+[ -f error_log ] || exit_unsupported
+
+check_error() { # command expected_pos
+echo "$1"
+(! echo "$1" > kprobe_events ) >& /dev/null
+grep "trace_kprobe: error:" -A 3 error_log
+N=$(tail -n 1 error_log | wc -c)
+# "  Command: " and "^" => 12
+test $(expr 12 + $2) -eq $N
+echo > error_log
+}
+
+if grep -q 'r\[maxactive\]' README; then
+check_error 'p100 vfs_read' 2		# MAXACT_NO_KPROBE
+check_error 'r1a111 vfs_read' 2		# BAD_MAXACT
+check_error 'r100000 vfs_read' 2	# MAXACT_TOO_BIG
+fi
+
+check_error 'p non_exist_func' 3	# BAD_PROBE_ADDR (enoent)
+check_error 'p hoge-fuga' 3		# BAD_PROBE_ADDR (bad syntax)
+check_error 'p hoge+1000-1000' 3	# BAD_PROBE_ADDR (bad syntax)
+check_error 'r vfs_read+10' 3		# BAD_RETPROBE
+check_error 'p:/bar vfs_read' 3		# NO_GROUP_NAME
+check_error 'p:12345678901234567890123456789012345678901234567890123456789012345/bar vfs_read' 3	# GROUP_TOO_LONG
+
+check_error 'p:foo.1/bar vfs_read' 3	# BAD_GROUP_NAME
+check_error 'p:foo/ vfs_read' 7		# NO_EVENT_NAME
+check_error 'p:foo/12345678901234567890123456789012345678901234567890123456789012345 vfs_read' 7	# EVENT_TOO_LONG
+check_error 'p:foo/bar.1 vfs_read' 7	# BAD_EVENT_NAME
+
+check_error 'p vfs_read $retval' 12	# RETVAL_ON_PROBE
+check_error 'p vfs_read $stack10000' 12	# BAD_STACK_NUM
+
+if grep -q '$arg<N>' README; then
+check_error 'p vfs_read $arg10000' 12	# BAD_ARG_NUM
+fi
+
+check_error 'p vfs_read $none_var' 12	# BAD_VAR
+
+check_error 'p vfs_read %none_reg' 12	# BAD_REG_NAME
+check_error 'p vfs_read @12345678abcde' 12	# BAD_MEM_ADDR
+check_error 'p vfs_read @+10' 12	# FILE_ON_KPROBE
+
+check_error 'p vfs_read +0@0)' 12	# DEREF_NEED_BRACE
+check_error 'p vfs_read +0ab1(@0)' 12	# BAD_DEREF_OFFS
+check_error 'p vfs_read +0(+0(@0)' 17	# DEREF_OPEN_BRACE
+
+if grep -A1 "fetcharg:" README | grep -q '\$comm' ; then
+check_error 'p vfs_read +0($comm)' 15	# COMM_CANT_DEREF
+fi
+
+check_error 'p vfs_read &1' 12		# BAD_FETCH_ARG
+
+
+# We've introduced this limitation with array support
+if grep -q ' <type>\\\[<array-size>\\\]' README; then
+check_error 'p vfs_read +0(+0(+0(+0(+0(+0(+0(+0(+0(+0(+0(+0(+0(+0(@0))))))))))))))' 15	# TOO_MANY_OPS?
+check_error 'p vfs_read +0(@11):u8[10' 22	# ARRAY_NO_CLOSE
+check_error 'p vfs_read +0(@11):u8[10]a' 26	# BAD_ARRAY_SUFFIX
+check_error 'p vfs_read +0(@11):u8[10a]' 23	# BAD_ARRAY_NUM
+check_error 'p vfs_read +0(@11):u8[256]' 23	# ARRAY_TOO_BIG
+fi
+
+check_error 'p vfs_read @11:unknown_type' 16	# BAD_TYPE
+check_error 'p vfs_read $stack0:string' 20	# BAD_STRING
+check_error 'p vfs_read @11:b10@a/16' 16	# BAD_BITFIELD
+
+check_error 'p vfs_read arg123456789012345678901234567890=@11' 12	# ARG_NAME_TOO_LOG
+check_error 'p vfs_read =@11' 12		# NO_ARG_NAME
+check_error 'p vfs_read var.1=@11' 12		# BAD_ARG_NAME
+check_error 'p vfs_read var1=@11 var1=@12' 21	# USED_ARG_NAME
+check_error 'p vfs_read +1234567(+1234567(+1234567(+1234567(+1234567(+1234567(@1234))))))' 12	# ARG_TOO_LONG
+check_error 'p vfs_read arg1=' 17		# NO_ARG_BODY
+
+# instruction boundary check is valid on x86 (at this moment)
+case $(uname -m) in
+  x86_64|i[3456]86)
+    echo 'p vfs_read' > kprobe_events
+    if grep -q FTRACE ../kprobes/list ; then
+	check_error 'p vfs_read+3' 3		# BAD_INSN_BNDRY (only if function-tracer is enabled)
+    fi
+    ;;
+esac
+
+exit 0


  parent reply	other threads:[~2019-03-13 12:28 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-13 12:27 [RFC PATCH 0/7] tracing: Use common error_log with probe events Masami Hiramatsu
2019-03-13 12:27 ` [RFC PATCH 1/7] tracing/probe: Check maxactive error cases Masami Hiramatsu
2019-03-13 13:20   ` Steven Rostedt
2019-03-13 14:37     ` Masami Hiramatsu
2019-03-13 14:51       ` Steven Rostedt
2019-03-13 22:43         ` Masami Hiramatsu
2019-03-13 12:27 ` [RFC PATCH 2/7] tracing/probe: Check event name length correctly Masami Hiramatsu
2019-03-13 12:28 ` [RFC PATCH 3/7] tracing/probe: Check the size of argument name and body Masami Hiramatsu
2019-03-13 12:28 ` [RFC PATCH 4/7] tracing/probe: Check event/group naming rule at parsing Masami Hiramatsu
2019-03-13 13:23   ` Steven Rostedt
2019-03-13 15:04     ` Masami Hiramatsu
2019-03-13 15:23       ` Steven Rostedt
2019-03-13 22:47         ` Masami Hiramatsu
2019-03-13 12:28 ` [RFC PATCH 5/7] tracing/probe: Verify alloc_trace_*probe() result Masami Hiramatsu
2019-03-13 12:28 ` [RFC PATCH 6/7] tracing: Use tracing error_log with probe events Masami Hiramatsu
2019-03-13 12:28 ` Masami Hiramatsu [this message]
2019-03-13 20:15 ` [RFC PATCH 0/7] tracing: Use common " Tom Zanussi

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=155248012180.10815.9684996376860674672.stgit@devnote2 \
    --to=mhiramat@kernel.org \
    --cc=bigeasy@linutronix.de \
    --cc=joel@joelfernandes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=namhyung@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=zanussi@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).