Re: [DTrace-devel] [PATCH v2] test: stack_fbt

Kris Van Hees
2024-11-20T19:23:33Z

On Thu, Nov 07, 2024 at 06:28:41PM -0500, eugene.loh--- via DTrace-devel wrote:
> From: Eugene Loh <eugene.loh@oracle.com>
>
> The test was being skipped on UEKR7 systems because __vfs_write
> was no longer traceable. The expected stack on UEKR6 x86_64 was
> out of date.
>
> Switch to fbt::vfs_write:entry. Convert to a .sh test, so that
> different stacks can be expected depending both on machine type
> and release number.
>
> Signed-off-by: Eugene Loh <eugene.loh@oracle.com>

Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>

... with small changes as shown below.

> ---
> test/unittest/stack/tst.stack3_fbt.aarch64.r | 11 --
> test/unittest/stack/tst.stack3_fbt.d | 25 ----
> test/unittest/stack/tst.stack3_fbt.x | 1 -
> test/unittest/stack/tst.stack3_fbt.x86_64.r | 11 --
> test/unittest/stack/tst.stack_fbt.aarch64.r | 14 ---
> test/unittest/stack/tst.stack_fbt.d | 25 ----
> test/unittest/stack/tst.stack_fbt.sh | 122 +++++++++++++++++++
> test/unittest/stack/tst.stack_fbt.x | 10 --
> test/unittest/stack/tst.stack_fbt.x86_64.r | 13 --
> 9 files changed, 122 insertions(+), 110 deletions(-)
> delete mode 100644 test/unittest/stack/tst.stack3_fbt.aarch64.r
> delete mode 100644 test/unittest/stack/tst.stack3_fbt.d
> delete mode 120000 test/unittest/stack/tst.stack3_fbt.x
> delete mode 100644 test/unittest/stack/tst.stack3_fbt.x86_64.r
> delete mode 100644 test/unittest/stack/tst.stack_fbt.aarch64.r
> delete mode 100644 test/unittest/stack/tst.stack_fbt.d
> create mode 100755 test/unittest/stack/tst.stack_fbt.sh
> delete mode 100755 test/unittest/stack/tst.stack_fbt.x
> delete mode 100644 test/unittest/stack/tst.stack_fbt.x86_64.r
>
> diff --git a/test/unittest/stack/tst.stack3_fbt.aarch64.r b/test/unittest/stack/tst.stack3_fbt.aarch64.r
> deleted file mode 100644
> index 5c8bfaed2..000000000
> --- a/test/unittest/stack/tst.stack3_fbt.aarch64.r
> +++ /dev/null
> @@ -1,11 +0,0 @@
> - FUNCTION:NAME
> - :BEGIN
> - __vfs_write:entry
> - vmlinux`__vfs_write
> - vmlinux`ksys_write+{ptr}
> - vmlinux`__arm64_sys_write+{ptr}
> -
> -
> --- @@stderr --
> -dtrace: script 'test/unittest/stack/tst.stack3_fbt.d' matched 2 probes
> -dtrace: allowing destructive actions
> diff --git a/test/unittest/stack/tst.stack3_fbt.d b/test/unittest/stack/tst.stack3_fbt.d
> deleted file mode 100644
> index 1a2eaf582..000000000
> --- a/test/unittest/stack/tst.stack3_fbt.d
> +++ /dev/null
> @@ -1,25 +0,0 @@
> -/*
> - * Oracle Linux DTrace.
> - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
> - * Licensed under the Universal Permissive License v 1.0 as shown at
> - * http://oss.oracle.com/licenses/upl.
> - */
> -
> -/*
> - * ASSERTION: Test the stack action with depth 3.
> - *
> - * SECTION: Output Formatting/printf()
> - */
> -
> -#pragma D option destructive
> -
> -BEGIN
> -{
> - system("echo write something > /dev/null");
> -}
> -
> -fbt::__vfs_write:entry
> -{
> - stack(3);
> - exit(0);
> -}
> diff --git a/test/unittest/stack/tst.stack3_fbt.x b/test/unittest/stack/tst.stack3_fbt.x
> deleted file mode 120000
> index fe0d493c5..000000000
> --- a/test/unittest/stack/tst.stack3_fbt.x
> +++ /dev/null
> @@ -1 +0,0 @@
> -tst.stack_fbt.x
> \ No newline at end of file
> diff --git a/test/unittest/stack/tst.stack3_fbt.x86_64.r b/test/unittest/stack/tst.stack3_fbt.x86_64.r
> deleted file mode 100644
> index f24c8cba5..000000000
> --- a/test/unittest/stack/tst.stack3_fbt.x86_64.r
> +++ /dev/null
> @@ -1,11 +0,0 @@
> - FUNCTION:NAME
> - :BEGIN
> - __vfs_write:entry
> - vmlinux`__vfs_write+{ptr}
> - vmlinux`ksys_write+{ptr}
> - vmlinux`__x64_sys_write+{ptr}
> -
> -
> --- @@stderr --
> -dtrace: script 'test/unittest/stack/tst.stack3_fbt.d' matched 2 probes
> -dtrace: allowing destructive actions
> diff --git a/test/unittest/stack/tst.stack_fbt.aarch64.r b/test/unittest/stack/tst.stack_fbt.aarch64.r
> deleted file mode 100644
> index 3a2896c48..000000000
> --- a/test/unittest/stack/tst.stack_fbt.aarch64.r
> +++ /dev/null
> @@ -1,14 +0,0 @@
> - FUNCTION:NAME
> - :BEGIN
> - __vfs_write:entry
> - vmlinux`__vfs_write
> - vmlinux`ksys_write+{ptr}
> - vmlinux`__arm64_sys_write+{ptr}
> - vmlinux`el0_svc_common+{ptr}
> - vmlinux`el0_svc_handler+{ptr}
> - vmlinux`el0_svc+{ptr}
> -
> -
> --- @@stderr --
> -dtrace: script 'test/unittest/stack/tst.stack_fbt.d' matched 2 probes
> -dtrace: allowing destructive actions
> diff --git a/test/unittest/stack/tst.stack_fbt.d b/test/unittest/stack/tst.stack_fbt.d
> deleted file mode 100644
> index 27db21164..000000000
> --- a/test/unittest/stack/tst.stack_fbt.d
> +++ /dev/null
> @@ -1,25 +0,0 @@
> -/*
> - * Oracle Linux DTrace.
> - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
> - * Licensed under the Universal Permissive License v 1.0 as shown at
> - * http://oss.oracle.com/licenses/upl.
> - */
> -
> -/*
> - * ASSERTION: Test the stack action with the default stack depth.
> - *
> - * SECTION: Output Formatting/printf()
> - */
> -
> -#pragma D option destructive
> -
> -BEGIN
> -{
> - system("echo write something > /dev/null");
> -}
> -
> -fbt::__vfs_write:entry
> -{
> - stack();
> - exit(0);
> -}
> diff --git a/test/unittest/stack/tst.stack_fbt.sh b/test/unittest/stack/tst.stack_fbt.sh
> new file mode 100755
> index 000000000..e60c519c8
> --- /dev/null
> +++ b/test/unittest/stack/tst.stack_fbt.sh
> @@ -0,0 +1,122 @@
> +#!/bin/bash
> +#
> +# Oracle Linux DTrace.
> +# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
> +# Licensed under the Universal Permissive License v 1.0 as shown at
> +# http://oss.oracle.com/licenses/upl.
> +#
> +# This test verifies the nusdtprobes option.

Surely this is a copy'n'paste error and should be removed? Or rather, it
should be replaced with a message that actually states what this test
exercises/verifies?

Shall I make it:

Test the stack action with default stack depth and depth 3.

> +
> +dtrace=$1
> +
> +# Set up test directory.
> +
> +DIRNAME=$tmpdir/stack_fbt.$$.$RANDOM
> +mkdir -p $DIRNAME
> +cd $DIRNAME
> +
> +# Use DTrace to capture stack() at vfs_write:entry.
> +
> +$dtrace $dt_flags $nusdt -wqn '

I assume $nusdt should not be used here.

> +BEGIN
> +{
> + system("echo write something > /dev/null");
> +}
> +
> +fbt::vfs_write:entry
> +{
> + stack();
> + printf("first 3 frames\n");
> + stack(3);
> + exit(0);
> +}' >& dtrace.out
> +
> +if [ $? -ne 0 ]; then
> + echo ERROR: dtrace failed
> + cat dtrace.out
> + exit 1
> +fi
> +
> +# Strip out blank lines and pointer values.
> +
> +awk 'NF != 0 { sub(/+0x[0-9a-f]*$/, "+{ptr}"); print }' dtrace.out > dtrace.post
> +if [ $? -ne 0 ]; then
> + echo ERROR: awk failed
> + cat dtrace.out
> + exit 1
> +fi
> +
> +# Figure out what stack to expect.
> +
> +read MAJOR MINOR <<< `uname -r | grep -Eo '^[0-9]+\.[0-9]+' | tr '.' ' '`
> +
> +if [ $MAJOR -eq 5 -a $MINOR -lt 8 ]; then
> + # up to 5.8
> + KERVER="A"
> +else
> + # starting at 5.8
> + KERVER="B"
> +fi
> +
> +if [ $(uname -m) == "x86_64" -a $KERVER == "A" ]; then
> +cat << EOF > dtrace.cmp
> + vmlinux\`vfs_write+{ptr}
> + vmlinux\`__x64_sys_write+{ptr}
> + vmlinux\`x64_sys_call+{ptr}
> + vmlinux\`do_syscall_64+{ptr}
> + vmlinux\`entry_SYSCALL_64+{ptr}
> +EOF
> +elif [ $(uname -m) == "aarch64" -a $KERVER == "A" ]; then
> +cat << EOF > dtrace.cmp
> + vmlinux\`vfs_write
> + vmlinux\`__arm64_sys_write+{ptr}
> + vmlinux\`el0_svc_common+{ptr}
> + vmlinux\`el0_svc_handler+{ptr}
> + vmlinux\`el0_svc+{ptr}
> +EOF
> +elif [ $(uname -m) == "x86_64" -a $KERVER == "B" ]; then
> +cat << EOF > dtrace.cmp
> + vmlinux\`vfs_write+{ptr}
> + vmlinux\`ksys_write+{ptr}
> + vmlinux\`do_syscall_64+{ptr}
> + vmlinux\`entry_SYSCALL_64+{ptr}
> +EOF
> +elif [ $(uname -m) == "aarch64" -a $KERVER == "B" ]; then
> +cat << EOF > dtrace.cmp
> + vmlinux\`vfs_write
> + vmlinux\`__arm64_sys_write+{ptr}
> + vmlinux\`invoke_syscall+{ptr}
> + vmlinux\`el0_svc_common+{ptr}
> + vmlinux\`do_el0_svc+{ptr}
> + vmlinux\`el0_svc+{ptr}
> + vmlinux\`el0t_64_sync_handler+{ptr}
> + vmlinux\`el0t_64_sync+{ptr}
> +EOF
> +else
> + echo ERROR: unrecognized platform
> + uname -r
> + uname -m
> + exit 1
> +fi
> +
> +# Add the first 3 frames a second time.
> +
> +head -3 dtrace.cmp > dtrace.tmp
> +echo first 3 frames >> dtrace.cmp
> +cat dtrace.tmp >> dtrace.cmp
> +
> +# Compare results.
> +
> +if ! diff -q dtrace.cmp dtrace.post; then
> + echo ERROR: results do not match
> + diff dtrace.cmp dtrace.post
> + echo "==== expect"
> + cat dtrace.cmp
> + echo "==== actual"
> + cat dtrace.out
> + exit 1
> +fi
> +
> +echo success
> +
> +exit 0
> diff --git a/test/unittest/stack/tst.stack_fbt.x b/test/unittest/stack/tst.stack_fbt.x
> deleted file mode 100755
> index 4561df8bb..000000000
> --- a/test/unittest/stack/tst.stack_fbt.x
> +++ /dev/null
> @@ -1,10 +0,0 @@
> -#!/bin/bash
> -
> -read MAJOR MINOR <<< `uname -r | grep -Eo '^[0-9]+\.[0-9]+' | tr '.' ' '`
> -
> -if [ $MAJOR -eq 5 -a $MINOR -lt 8 ]; then
> - exit 0
> -else
> - echo "Function __vfs_write no longer exists starting in 5.8"
> - exit 2
> -fi
> diff --git a/test/unittest/stack/tst.stack_fbt.x86_64.r b/test/unittest/stack/tst.stack_fbt.x86_64.r
> deleted file mode 100644
> index 792ce80ad..000000000
> --- a/test/unittest/stack/tst.stack_fbt.x86_64.r
> +++ /dev/null
> @@ -1,13 +0,0 @@
> - FUNCTION:NAME
> - :BEGIN
> - __vfs_write:entry
> - vmlinux`__vfs_write+{ptr}
> - vmlinux`ksys_write+{ptr}
> - vmlinux`__x64_sys_write+{ptr}
> - vmlinux`do_syscall_64+{ptr}
> - vmlinux`entry_SYSCALL_64+{ptr}
> -
> -
> --- @@stderr --
> -dtrace: script 'test/unittest/stack/tst.stack_fbt.d' matched 2 probes
> -dtrace: allowing destructive actions
> --
> 2.43.5
>
>
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel@oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel