[DTrace-devel] [PATCH v2] tests: Use distinct trigger for copyin* tests

Kris Van Hees kris.van.hees at oracle.com
Thu Feb 16 07:39:13 UTC 2023


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

On Sat, Jan 14, 2023 at 02:39:05PM -0500, eugene.loh--- via DTrace-devel wrote:
> From: Eugene Loh <eugene.loh at oracle.com>
> 
> Many copyin* tests implement a trigger by running system("echo foo")
> in the BEGIN probe.  This requires a destructive action, which is okay
> but does make these "unit tests" rely on features unrelated to the tests.
> 
> The main problem, however, is that the check that the corresponding
> write:entry probe has fired on the correct process becomes very weak
> -- e.g., just checking that a particular char is '-'.  And in the case
> of copyinto, this check is unnecessarily complicated.  Finally, if
> such a process is not found, the test would hang.
> 
> Use @@trigger.  E.g., delaydie will quickly terminate, emiting a simple
> message, which is all we need for these tests.
> 
> The existing predicates check being able to:
> - cast the return value of copyin() to string
> - use indexing on the cast value
> - use indexing on the return value of copyinstr()
> Each such predicate is replaced with a conditionalized printf.
> 
> Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
> ---
>  test/unittest/funcs/copyin/tst.copyin.d       | 12 ++++--------
>  test/unittest/funcs/copyin/tst.copyin.r       |  7 ++++---
>  .../copyinstr/tst.copyinstr-low-maxsize.d     | 12 ++++--------
>  .../copyinstr/tst.copyinstr-low-maxsize.r     |  6 ++++--
>  .../copyinstr/tst.copyinstr-no-maxsize.d      | 12 ++++--------
>  .../copyinstr/tst.copyinstr-no-maxsize.r      |  6 ++++--
>  test/unittest/funcs/copyinstr/tst.copyinstr.d | 12 ++++--------
>  test/unittest/funcs/copyinstr/tst.copyinstr.r |  7 ++++---
>  test/unittest/funcs/copyinto/tst.copyinto.d   | 19 ++++---------------
>  test/unittest/funcs/copyinto/tst.copyinto.r   |  7 ++++---
>  10 files changed, 40 insertions(+), 60 deletions(-)
> 
> diff --git a/test/unittest/funcs/copyin/tst.copyin.d b/test/unittest/funcs/copyin/tst.copyin.d
> index 11d52a5a..f40ab1a7 100644
> --- a/test/unittest/funcs/copyin/tst.copyin.d
> +++ b/test/unittest/funcs/copyin/tst.copyin.d
> @@ -1,6 +1,6 @@
>  /*
>   * Oracle Linux DTrace.
> - * Copyright (c) 2006, 2022, Oracle and/or its affiliates. All rights reserved.
> + * Copyright (c) 2006, 2023, 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.
>   */
> @@ -11,18 +11,14 @@
>   * SECTION: Actions and Subroutines/copyin()
>   *	    User Process Tracing/copyin() and copyinstr() Subroutines
>   */
> +/* @@trigger: delaydie */
>  
>  #pragma D option quiet
> -#pragma D option destructive
> -
> -BEGIN
> -{
> -	system("echo dtrace-copyin-test");
> -}
>  
>  syscall::write:entry
> -/(s = (string)copyin(arg1, 32))[6] == '-'/
> +/pid == $target/
>  {
> +	printf("%s char match\n", (s = (string)copyin(arg1, 32))[4] == 'y' ? "good" : "BAD");
>  	printf("'%s'", s);
>  	exit(0);
>  }
> diff --git a/test/unittest/funcs/copyin/tst.copyin.r b/test/unittest/funcs/copyin/tst.copyin.r
> index 05d2c96c..41e7b43d 100644
> --- a/test/unittest/funcs/copyin/tst.copyin.r
> +++ b/test/unittest/funcs/copyin/tst.copyin.r
> @@ -1,3 +1,4 @@
> -dtrace-copyin-test
> -'dtrace-copyin-test
> -'
> +good char match
> +'Delay in ns needed in delay env '
> +-- @@stderr --
> +Delay in ns needed in delay env var.
> diff --git a/test/unittest/funcs/copyinstr/tst.copyinstr-low-maxsize.d b/test/unittest/funcs/copyinstr/tst.copyinstr-low-maxsize.d
> index b7502c27..62cc1482 100644
> --- a/test/unittest/funcs/copyinstr/tst.copyinstr-low-maxsize.d
> +++ b/test/unittest/funcs/copyinstr/tst.copyinstr-low-maxsize.d
> @@ -1,6 +1,6 @@
>  /*
>   * Oracle Linux DTrace.
> - * Copyright (c) 2006, 2022, Oracle and/or its affiliates. All rights reserved.
> + * Copyright (c) 2006, 2023, 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.
>   */
> @@ -11,18 +11,14 @@
>   * SECTION: Actions and Subroutines/copyinstr()
>   *	    User Process Tracing/copyin() and copyinstr() Subroutines
>   */
> +/* @@trigger: delaydie */
>  
>  #pragma D option quiet
> -#pragma D option destructive
> -
> -BEGIN
> -{
> -	system("echo dtrace-copyinstr-test");
> -}
>  
>  syscall::write:entry
> -/(s = copyinstr(arg1, 8))[6] == '-'/
> +/pid == $target/
>  {
> +	printf("%s char match\n", (s = copyinstr(arg1, 8))[4] == 'y' ? "good" : "BAD");
>  	printf("'%s'", s);
>  	exit(0);
>  }
> diff --git a/test/unittest/funcs/copyinstr/tst.copyinstr-low-maxsize.r b/test/unittest/funcs/copyinstr/tst.copyinstr-low-maxsize.r
> index 45ca768e..29b53983 100644
> --- a/test/unittest/funcs/copyinstr/tst.copyinstr-low-maxsize.r
> +++ b/test/unittest/funcs/copyinstr/tst.copyinstr-low-maxsize.r
> @@ -1,2 +1,4 @@
> -dtrace-copyinstr-test
> -'dtrace-'
> +good char match
> +'Delay i'
> +-- @@stderr --
> +Delay in ns needed in delay env var.
> diff --git a/test/unittest/funcs/copyinstr/tst.copyinstr-no-maxsize.d b/test/unittest/funcs/copyinstr/tst.copyinstr-no-maxsize.d
> index 448fa7c5..f9094a40 100644
> --- a/test/unittest/funcs/copyinstr/tst.copyinstr-no-maxsize.d
> +++ b/test/unittest/funcs/copyinstr/tst.copyinstr-no-maxsize.d
> @@ -1,6 +1,6 @@
>  /*
>   * Oracle Linux DTrace.
> - * Copyright (c) 2006, 2022, Oracle and/or its affiliates. All rights reserved.
> + * Copyright (c) 2006, 2023, 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.
>   */
> @@ -11,18 +11,14 @@
>   * SECTION: Actions and Subroutines/copyinstr()
>   *	    User Process Tracing/copyin() and copyinstr() Subroutines
>   */
> +/* @@trigger: delaydie */
>  
>  #pragma D option quiet
> -#pragma D option destructive
> -
> -BEGIN
> -{
> -	system("echo dtrace-copyinstr-test");
> -}
>  
>  syscall::write:entry
> -/(s = copyinstr(arg1))[6] == '-'/
> +/pid == $target/
>  {
> +	printf("%s char match\n", (s = copyinstr(arg1))[4] == 'y' ? "good" : "BAD");
>  	printf("'%s'", s);
>  	exit(0);
>  }
> diff --git a/test/unittest/funcs/copyinstr/tst.copyinstr-no-maxsize.r b/test/unittest/funcs/copyinstr/tst.copyinstr-no-maxsize.r
> index 2be678ab..51713be3 100644
> --- a/test/unittest/funcs/copyinstr/tst.copyinstr-no-maxsize.r
> +++ b/test/unittest/funcs/copyinstr/tst.copyinstr-no-maxsize.r
> @@ -1,3 +1,5 @@
> -dtrace-copyinstr-test
> -'dtrace-copyinstr-test
> +good char match
> +'Delay in ns needed in delay env var.
>  '
> +-- @@stderr --
> +Delay in ns needed in delay env var.
> diff --git a/test/unittest/funcs/copyinstr/tst.copyinstr.d b/test/unittest/funcs/copyinstr/tst.copyinstr.d
> index 09f382b3..f518e861 100644
> --- a/test/unittest/funcs/copyinstr/tst.copyinstr.d
> +++ b/test/unittest/funcs/copyinstr/tst.copyinstr.d
> @@ -1,6 +1,6 @@
>  /*
>   * Oracle Linux DTrace.
> - * Copyright (c) 2006, 2022, Oracle and/or its affiliates. All rights reserved.
> + * Copyright (c) 2006, 2023, 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.
>   */
> @@ -11,18 +11,14 @@
>   * SECTION: Actions and Subroutines/copyinstr()
>   *	    User Process Tracing/copyin() and copyinstr() Subroutines
>   */
> +/* @@trigger: delaydie */
>  
>  #pragma D option quiet
> -#pragma D option destructive
> -
> -BEGIN
> -{
> -	system("echo dtrace-copyinstr-test");
> -}
>  
>  syscall::write:entry
> -/(s = copyinstr(arg1, 32))[6] == '-'/
> +/pid == $target/
>  {
> +	printf("%s char match\n", (s = copyinstr(arg1, 32))[4] == 'y' ? "good" : "BAD");
>  	printf("'%s'", s);
>  	exit(0);
>  }
> diff --git a/test/unittest/funcs/copyinstr/tst.copyinstr.r b/test/unittest/funcs/copyinstr/tst.copyinstr.r
> index 2be678ab..2155df09 100644
> --- a/test/unittest/funcs/copyinstr/tst.copyinstr.r
> +++ b/test/unittest/funcs/copyinstr/tst.copyinstr.r
> @@ -1,3 +1,4 @@
> -dtrace-copyinstr-test
> -'dtrace-copyinstr-test
> -'
> +good char match
> +'Delay in ns needed in delay env'
> +-- @@stderr --
> +Delay in ns needed in delay env var.
> diff --git a/test/unittest/funcs/copyinto/tst.copyinto.d b/test/unittest/funcs/copyinto/tst.copyinto.d
> index b0ec658b..a4c5f770 100644
> --- a/test/unittest/funcs/copyinto/tst.copyinto.d
> +++ b/test/unittest/funcs/copyinto/tst.copyinto.d
> @@ -1,6 +1,6 @@
>  /*
>   * Oracle Linux DTrace.
> - * Copyright (c) 2006, 2022, Oracle and/or its affiliates. All rights reserved.
> + * Copyright (c) 2006, 2023, 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.
>   */
> @@ -10,27 +10,16 @@
>   *
>   * SECTION: Actions and Subroutines/copyinto()
>   */
> +/* @@trigger: delaydie */
>  
>  #pragma D option quiet
> -#pragma D option destructive
> -
> -BEGIN
> -{
> -	system("echo dtrace-copyinto-test");
> -}
> -
> -syscall::write:entry
> -{
> -	ptr = (char *)alloca(32);
> -	copyinto(arg1, 32, ptr);
> -	ok = ptr[6] == '-';
> -}
>  
>  syscall::write:entry
> -/ok/
> +/pid == $target/
>  {
>  	ptr = (char *)alloca(32);
>  	copyinto(arg1, 32, ptr);
> +	printf("%s char match\n", ptr[4] == 'y' ? "good" : "BAD");
>  	printf("'%s'", stringof(ptr));
>  	exit(0);
>  }
> diff --git a/test/unittest/funcs/copyinto/tst.copyinto.r b/test/unittest/funcs/copyinto/tst.copyinto.r
> index 44dd1c87..41e7b43d 100644
> --- a/test/unittest/funcs/copyinto/tst.copyinto.r
> +++ b/test/unittest/funcs/copyinto/tst.copyinto.r
> @@ -1,3 +1,4 @@
> -dtrace-copyinto-test
> -'dtrace-copyinto-test
> -'
> +good char match
> +'Delay in ns needed in delay env '
> +-- @@stderr --
> +Delay in ns needed in delay env var.
> -- 
> 2.18.4
> 
> 
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel



More information about the DTrace-devel mailing list