diff mbox series

[v2,8/9] selftests/ftrace: Add BTF fields access testcases

Message ID 168960747750.34107.6104527579648222887.stgit@devnote2 (mailing list archive)
State Superseded
Headers show
Series tracing: Improbe BTF support on probe events | expand

Commit Message

Masami Hiramatsu (Google) July 17, 2023, 3:24 p.m. UTC
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Add test cases for accessing the data structure fields using BTF info.
This includes the field access from parameters and retval, and accessing
string information.

Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
Changes in v2:
 - Use '$retval' instead of 'retval'.
 - Add a test that use both '$retval' and '$arg1' for fprobe.
---
 .../ftrace/test.d/dynevent/add_remove_btfarg.tc    |   11 +++++++++++
 .../ftrace/test.d/dynevent/fprobe_syntax_errors.tc |    4 ++++
 2 files changed, 15 insertions(+)

Comments

Alan Maguire July 20, 2023, 11 p.m. UTC | #1
On 17/07/2023 16:24, Masami Hiramatsu (Google) wrote:
> From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> 
> Add test cases for accessing the data structure fields using BTF info.
> This includes the field access from parameters and retval, and accessing
> string information.
> 
> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

One suggestion below, but

Reviewed-by: Alan Maguire <alan.maguire@oracle.com>

> ---
> Changes in v2:
>  - Use '$retval' instead of 'retval'.
>  - Add a test that use both '$retval' and '$arg1' for fprobe.
> ---
>  .../ftrace/test.d/dynevent/add_remove_btfarg.tc    |   11 +++++++++++
>  .../ftrace/test.d/dynevent/fprobe_syntax_errors.tc |    4 ++++
>  2 files changed, 15 insertions(+)
> 
> diff --git a/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_btfarg.tc b/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_btfarg.tc
> index b89de1771655..93b94468967b 100644
> --- a/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_btfarg.tc
> +++ b/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_btfarg.tc
> @@ -21,6 +21,8 @@ echo 0 > events/enable
>  echo > dynamic_events
>  
>  TP=kfree
> +TP2=kmem_cache_alloc
> +TP3=getname_flags
>  
>  if [ "$FPROBES" ] ; then
>  echo "f:fpevent $TP object" >> dynamic_events
> @@ -33,6 +35,7 @@ echo > dynamic_events
>  
>  echo "f:fpevent $TP "'$arg1' >> dynamic_events
>  grep -q "fpevent.*object=object" dynamic_events
> +
>  echo > dynamic_events
>  
>  echo "f:fpevent $TP "'$arg*' >> dynamic_events
> @@ -45,6 +48,14 @@ fi
>  
>  echo > dynamic_events
>  
> +echo "t:tpevent $TP2 name=s->name:string" >> dynamic_events
> +echo "f:fpevent ${TP3}%return path=\$retval->name:string" >> dynamic_events
> +

could we test a numeric value like kmem_cache_alloc object size?
also if combos of -> and . are allowed, would be good to test one of
those too.

> +grep -q "tpevent.*name=s->name:string" dynamic_events
> +grep -q "fpevent.*path=\$retval->name:string" dynamic_events
> +
> +echo > dynamic_events
> +
>  if [ "$KPROBES" ] ; then
>  echo "p:kpevent $TP object" >> dynamic_events
>  grep -q "kpevent.*object=object" dynamic_events
> diff --git a/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc b/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc
> index 72563b2e0812..49758f77c923 100644
> --- a/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc
> +++ b/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc
> @@ -103,6 +103,10 @@ check_error 'f vfs_read%return ^$arg*'		# NOFENTRY_ARGS
>  check_error 'f vfs_read ^hoge'			# NO_BTFARG
>  check_error 'f kfree ^$arg10'			# NO_BTFARG (exceed the number of parameters)
>  check_error 'f kfree%return ^$retval'		# NO_RETVAL
> +check_error 'f vfs_read%return $retval->^foo'	# NO_PTR_STRCT
> +check_error 'f vfs_read file->^foo'		# NO_BTF_FIELD
> +check_error 'f vfs_read file^-.foo'		# BAD_HYPHEN
> +check_error 'f vfs_read ^file:string'		# BAD_TYPE4STR
>  else
>  check_error 'f vfs_read ^$arg*'			# NOSUP_BTFARG
>  check_error 't kfree ^$arg*'			# NOSUP_BTFARG
> 
>
Masami Hiramatsu (Google) July 21, 2023, 1:42 a.m. UTC | #2
On Fri, 21 Jul 2023 00:00:32 +0100
Alan Maguire <alan.maguire@oracle.com> wrote:

> 
> On 17/07/2023 16:24, Masami Hiramatsu (Google) wrote:
> > From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> > 
> > Add test cases for accessing the data structure fields using BTF info.
> > This includes the field access from parameters and retval, and accessing
> > string information.
> > 
> > Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> 
> One suggestion below, but
> 
> Reviewed-by: Alan Maguire <alan.maguire@oracle.com>

Thanks

> 
> > ---
> > Changes in v2:
> >  - Use '$retval' instead of 'retval'.
> >  - Add a test that use both '$retval' and '$arg1' for fprobe.
> > ---
> >  .../ftrace/test.d/dynevent/add_remove_btfarg.tc    |   11 +++++++++++
> >  .../ftrace/test.d/dynevent/fprobe_syntax_errors.tc |    4 ++++
> >  2 files changed, 15 insertions(+)
> > 
> > diff --git a/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_btfarg.tc b/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_btfarg.tc
> > index b89de1771655..93b94468967b 100644
> > --- a/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_btfarg.tc
> > +++ b/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_btfarg.tc
> > @@ -21,6 +21,8 @@ echo 0 > events/enable
> >  echo > dynamic_events
> >  
> >  TP=kfree
> > +TP2=kmem_cache_alloc
> > +TP3=getname_flags
> >  
> >  if [ "$FPROBES" ] ; then
> >  echo "f:fpevent $TP object" >> dynamic_events
> > @@ -33,6 +35,7 @@ echo > dynamic_events
> >  
> >  echo "f:fpevent $TP "'$arg1' >> dynamic_events
> >  grep -q "fpevent.*object=object" dynamic_events
> > +
> >  echo > dynamic_events
> >  
> >  echo "f:fpevent $TP "'$arg*' >> dynamic_events
> > @@ -45,6 +48,14 @@ fi
> >  
> >  echo > dynamic_events
> >  
> > +echo "t:tpevent $TP2 name=s->name:string" >> dynamic_events
> > +echo "f:fpevent ${TP3}%return path=\$retval->name:string" >> dynamic_events
> > +
> 
> could we test a numeric value like kmem_cache_alloc object size?
> also if combos of -> and . are allowed, would be good to test one of
> those too.

OK, that's a good point! I'll add it.

> 
> > +grep -q "tpevent.*name=s->name:string" dynamic_events
> > +grep -q "fpevent.*path=\$retval->name:string" dynamic_events
> > +
> > +echo > dynamic_events
> > +
> >  if [ "$KPROBES" ] ; then
> >  echo "p:kpevent $TP object" >> dynamic_events
> >  grep -q "kpevent.*object=object" dynamic_events
> > diff --git a/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc b/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc
> > index 72563b2e0812..49758f77c923 100644
> > --- a/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc
> > +++ b/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc
> > @@ -103,6 +103,10 @@ check_error 'f vfs_read%return ^$arg*'		# NOFENTRY_ARGS
> >  check_error 'f vfs_read ^hoge'			# NO_BTFARG
> >  check_error 'f kfree ^$arg10'			# NO_BTFARG (exceed the number of parameters)
> >  check_error 'f kfree%return ^$retval'		# NO_RETVAL
> > +check_error 'f vfs_read%return $retval->^foo'	# NO_PTR_STRCT
> > +check_error 'f vfs_read file->^foo'		# NO_BTF_FIELD
> > +check_error 'f vfs_read file^-.foo'		# BAD_HYPHEN
> > +check_error 'f vfs_read ^file:string'		# BAD_TYPE4STR
> >  else
> >  check_error 'f vfs_read ^$arg*'			# NOSUP_BTFARG
> >  check_error 't kfree ^$arg*'			# NOSUP_BTFARG
> > 
> >
diff mbox series

Patch

diff --git a/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_btfarg.tc b/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_btfarg.tc
index b89de1771655..93b94468967b 100644
--- a/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_btfarg.tc
+++ b/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_btfarg.tc
@@ -21,6 +21,8 @@  echo 0 > events/enable
 echo > dynamic_events
 
 TP=kfree
+TP2=kmem_cache_alloc
+TP3=getname_flags
 
 if [ "$FPROBES" ] ; then
 echo "f:fpevent $TP object" >> dynamic_events
@@ -33,6 +35,7 @@  echo > dynamic_events
 
 echo "f:fpevent $TP "'$arg1' >> dynamic_events
 grep -q "fpevent.*object=object" dynamic_events
+
 echo > dynamic_events
 
 echo "f:fpevent $TP "'$arg*' >> dynamic_events
@@ -45,6 +48,14 @@  fi
 
 echo > dynamic_events
 
+echo "t:tpevent $TP2 name=s->name:string" >> dynamic_events
+echo "f:fpevent ${TP3}%return path=\$retval->name:string" >> dynamic_events
+
+grep -q "tpevent.*name=s->name:string" dynamic_events
+grep -q "fpevent.*path=\$retval->name:string" dynamic_events
+
+echo > dynamic_events
+
 if [ "$KPROBES" ] ; then
 echo "p:kpevent $TP object" >> dynamic_events
 grep -q "kpevent.*object=object" dynamic_events
diff --git a/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc b/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc
index 72563b2e0812..49758f77c923 100644
--- a/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc
+++ b/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc
@@ -103,6 +103,10 @@  check_error 'f vfs_read%return ^$arg*'		# NOFENTRY_ARGS
 check_error 'f vfs_read ^hoge'			# NO_BTFARG
 check_error 'f kfree ^$arg10'			# NO_BTFARG (exceed the number of parameters)
 check_error 'f kfree%return ^$retval'		# NO_RETVAL
+check_error 'f vfs_read%return $retval->^foo'	# NO_PTR_STRCT
+check_error 'f vfs_read file->^foo'		# NO_BTF_FIELD
+check_error 'f vfs_read file^-.foo'		# BAD_HYPHEN
+check_error 'f vfs_read ^file:string'		# BAD_TYPE4STR
 else
 check_error 'f vfs_read ^$arg*'			# NOSUP_BTFARG
 check_error 't kfree ^$arg*'			# NOSUP_BTFARG