[DTrace-devel] [PATCH] test: Use kernel pointer for nonDPTR tests

eugene.loh at oracle.com eugene.loh at oracle.com
Mon Feb 27 02:32:00 UTC 2023


From: Eugene Loh <eugene.loh at oracle.com>

The nonDPTR tests need to use non-DTrace pointers to be meaningful.
They were using pointers in user space, but technically speaking such
pointers should first be copied (e.g., with copyin or copyinstr) first.
But that makes them DTrace pointers, bypassing the whole point!

Use a kernel pointer like `linux_banner.  Use short strsize so that .r
results files will check consistent "Linux version " strings.

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 .../funcs/strjoin/tst.strjoin_nonDPTR.d       | 16 +++++---------
 .../funcs/strjoin/tst.strjoin_nonDPTR.r       |  2 +-
 .../funcs/strtok/tst.strtok_nonDPTR.d         | 22 ++++++++-----------
 .../funcs/strtok/tst.strtok_nonDPTR.r         |  8 +++----
 .../funcs/substr/tst.substr_nonDPTR.d         | 18 ++++++---------
 .../funcs/substr/tst.substr_nonDPTR.r         |  4 ++--
 test/unittest/funcs/tst.basename_nonDPTR.d    | 16 +++++---------
 test/unittest/funcs/tst.basename_nonDPTR.r    |  2 +-
 test/unittest/funcs/tst.dirname_nonDPTR.d     | 16 +++++---------
 test/unittest/funcs/tst.dirname_nonDPTR.r     |  2 +-
 test/unittest/funcs/tst.index_nonDPTR.d       | 16 +++++---------
 test/unittest/funcs/tst.inet_ntoa_nonDPTR.d   | 16 ++++++--------
 test/unittest/funcs/tst.inet_ntoa_nonDPTR.r   |  2 +-
 test/unittest/funcs/tst.rindex_nonDPTR.d      | 16 +++++---------
 test/unittest/funcs/tst.strchr_nonDPTR.d      | 18 ++++++---------
 test/unittest/funcs/tst.strchr_nonDPTR.r      |  4 ++--
 16 files changed, 72 insertions(+), 106 deletions(-)

diff --git a/test/unittest/funcs/strjoin/tst.strjoin_nonDPTR.d b/test/unittest/funcs/strjoin/tst.strjoin_nonDPTR.d
index 433ceeb9..bbd79d1c 100644
--- a/test/unittest/funcs/strjoin/tst.strjoin_nonDPTR.d
+++ b/test/unittest/funcs/strjoin/tst.strjoin_nonDPTR.d
@@ -1,24 +1,20 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 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.
  */
 
 #pragma D option quiet
-#pragma D option destructive
+#pragma D option strsize=14
 
 BEGIN
 {
-	/* "abcdef" */
-	system("printf '\x61\x62\x63\x64\x65\x66' > /dev/null 2>&1");
+	printf("|%s|\n", strjoin(`linux_banner, `linux_banner));
+	exit(0);
 }
 
-syscall::write:entry
-/ppid == $pid/
+ERROR
 {
-	printf("|%s|\n", strjoin((void *)arg1, (void *)arg1));
-	exit(0);
+	exit(1);
 }
-
-ERROR { exit(1); }
diff --git a/test/unittest/funcs/strjoin/tst.strjoin_nonDPTR.r b/test/unittest/funcs/strjoin/tst.strjoin_nonDPTR.r
index 89fb09b7..6d3a19ef 100644
--- a/test/unittest/funcs/strjoin/tst.strjoin_nonDPTR.r
+++ b/test/unittest/funcs/strjoin/tst.strjoin_nonDPTR.r
@@ -1,2 +1,2 @@
-|abcdefabcdef|
+|Linux version |
 
diff --git a/test/unittest/funcs/strtok/tst.strtok_nonDPTR.d b/test/unittest/funcs/strtok/tst.strtok_nonDPTR.d
index 54da5650..00753e59 100644
--- a/test/unittest/funcs/strtok/tst.strtok_nonDPTR.d
+++ b/test/unittest/funcs/strtok/tst.strtok_nonDPTR.d
@@ -1,27 +1,23 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 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.
  */
 
 #pragma D option quiet
-#pragma D option destructive
+#pragma D option strsize=14
 
 BEGIN
 {
-	/* "abcdef" */
-	system("printf '\x61\x62\x63\x64\x65\x66' > /dev/null 2>&1");
+	printf("|%s|\n", strtok(`linux_banner, " "));
+	printf("|%s|\n", strtok(NULL, " "));
+	printf("|%s|\n", strtok("@@@@@ !!!!!", `linux_banner));
+	printf("|%s|\n", strtok(NULL, `linux_banner));
+	exit(0);
 }
 
-syscall::write:entry
-/ppid == $pid/
+ERROR
 {
-	printf("|%s|\n", strtok((void *)arg1, "defghidEFGHI"));
-	printf("|%s|\n", strtok(NULL, "fF"));
-	printf("|%s|\n", strtok("nmlkjihgfFOOBARedcba", (void *)arg1));
-	printf("|%s|\n", strtok(NULL, (void *)arg1));
-	exit(0);
+	exit(1);
 }
-
-ERROR { exit(1); }
diff --git a/test/unittest/funcs/strtok/tst.strtok_nonDPTR.r b/test/unittest/funcs/strtok/tst.strtok_nonDPTR.r
index cbfb0b38..cbe08303 100644
--- a/test/unittest/funcs/strtok/tst.strtok_nonDPTR.r
+++ b/test/unittest/funcs/strtok/tst.strtok_nonDPTR.r
@@ -1,5 +1,5 @@
-|abc|
-|de|
-|nmlkjihg|
-|FOOBAR|
+|Linux|
+|version|
+|@@@@@|
+|!!!!!|
 
diff --git a/test/unittest/funcs/substr/tst.substr_nonDPTR.d b/test/unittest/funcs/substr/tst.substr_nonDPTR.d
index 726f20a8..d85800f3 100644
--- a/test/unittest/funcs/substr/tst.substr_nonDPTR.d
+++ b/test/unittest/funcs/substr/tst.substr_nonDPTR.d
@@ -1,25 +1,21 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 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.
  */
 
 #pragma D option quiet
-#pragma D option destructive
+#pragma D option strsize=13
 
 BEGIN
 {
-	/* "abcdef" */
-	system("printf '\x61\x62\x63\x64\x65\x66' > /dev/null 2>&1");
+	printf("|%s|\n", substr(`linux_banner, 1));
+	printf("|%s|\n", substr(`linux_banner, 1, 4));
+	exit(0);
 }
 
-syscall::write:entry
-/ppid == $pid/
+ERROR
 {
-	printf("|%s|\n", substr((void *)arg1, 1));
-	printf("|%s|\n", substr((void *)arg1, 1, 4));
-	exit(0);
+	exit(1);
 }
-
-ERROR { exit(1); }
diff --git a/test/unittest/funcs/substr/tst.substr_nonDPTR.r b/test/unittest/funcs/substr/tst.substr_nonDPTR.r
index a862e3ce..45303c90 100644
--- a/test/unittest/funcs/substr/tst.substr_nonDPTR.r
+++ b/test/unittest/funcs/substr/tst.substr_nonDPTR.r
@@ -1,3 +1,3 @@
-|bcdef|
-|bcde|
+|inux version |
+|inux|
 
diff --git a/test/unittest/funcs/tst.basename_nonDPTR.d b/test/unittest/funcs/tst.basename_nonDPTR.d
index 12f6436c..3e00ceeb 100644
--- a/test/unittest/funcs/tst.basename_nonDPTR.d
+++ b/test/unittest/funcs/tst.basename_nonDPTR.d
@@ -1,24 +1,20 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 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.
  */
 
 #pragma D option quiet
-#pragma D option destructive
+#pragma D option strsize=14
 
 BEGIN
 {
-	/* "/foo/bar/baz/.//" */
-	system("printf '\x2f\x66\x6f\x6f\x2f\x62\x61\x72\x2f\x62\x61\x7a\x2f\x2e\x2f\x2f' > /dev/null 2>&1");
+	printf("|%s|\n", basename(`linux_banner));
+	exit(0);
 }
 
-syscall::write:entry
-/ppid == $pid/
+ERROR
 {
-	printf("|%s|\n", basename((void *)arg1));
-	exit(0);
+	exit(1);
 }
-
-ERROR { exit(1); }
diff --git a/test/unittest/funcs/tst.basename_nonDPTR.r b/test/unittest/funcs/tst.basename_nonDPTR.r
index 3e52321d..6d3a19ef 100644
--- a/test/unittest/funcs/tst.basename_nonDPTR.r
+++ b/test/unittest/funcs/tst.basename_nonDPTR.r
@@ -1,2 +1,2 @@
-|.|
+|Linux version |
 
diff --git a/test/unittest/funcs/tst.dirname_nonDPTR.d b/test/unittest/funcs/tst.dirname_nonDPTR.d
index dab80655..8d19eb5a 100644
--- a/test/unittest/funcs/tst.dirname_nonDPTR.d
+++ b/test/unittest/funcs/tst.dirname_nonDPTR.d
@@ -1,24 +1,20 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 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.
  */
 
 #pragma D option quiet
-#pragma D option destructive
+#pragma D option strsize=14
 
 BEGIN
 {
-	/* "/foo/bar///baz/" */
-	system("printf '\x2f\x66\x6f\x6f\x2f\x62\x61\x72\x2f\x2f\x2f\x62\x61\x7a\x2f' > /dev/null 2>&1");
+	printf("|%s|\n", dirname(`linux_banner));
+	exit(0);
 }
 
-syscall::write:entry
-/ppid == $pid/
+ERROR
 {
-	printf("|%s|\n", dirname((void *)arg1));
-	exit(0);
+	exit(1);
 }
-
-ERROR { exit(1); }
diff --git a/test/unittest/funcs/tst.dirname_nonDPTR.r b/test/unittest/funcs/tst.dirname_nonDPTR.r
index bb8afc9d..3e52321d 100644
--- a/test/unittest/funcs/tst.dirname_nonDPTR.r
+++ b/test/unittest/funcs/tst.dirname_nonDPTR.r
@@ -1,2 +1,2 @@
-|/foo/bar|
+|.|
 
diff --git a/test/unittest/funcs/tst.index_nonDPTR.d b/test/unittest/funcs/tst.index_nonDPTR.d
index 44a9d6df..b3a08266 100644
--- a/test/unittest/funcs/tst.index_nonDPTR.d
+++ b/test/unittest/funcs/tst.index_nonDPTR.d
@@ -1,24 +1,20 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 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.
  */
 
 #pragma D option quiet
-#pragma D option destructive
+#pragma D option strsize=14
 
 BEGIN
 {
-	/* "abcdef" */
-	system("printf '\x61\x62\x63\x64\x65\x66' > /dev/null 2>&1");
+	printf("index is %d, should be 0\n", index(`linux_banner, `linux_banner));
+	exit(0);
 }
 
-syscall::write:entry
-/ppid == $pid/
+ERROR
 {
-	printf("index is %d, should be 0\n", index((void *)arg1, (void *)arg1));
-	exit(0);
+	exit(1);
 }
-
-ERROR { exit(1); }
diff --git a/test/unittest/funcs/tst.inet_ntoa_nonDPTR.d b/test/unittest/funcs/tst.inet_ntoa_nonDPTR.d
index 3622787d..c6eb29e9 100644
--- a/test/unittest/funcs/tst.inet_ntoa_nonDPTR.d
+++ b/test/unittest/funcs/tst.inet_ntoa_nonDPTR.d
@@ -1,23 +1,21 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 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.
  */
 
 #pragma D option quiet
-#pragma D option destructive
+#pragma D option strsize=14
 
 BEGIN
 {
-	system("printf '\xc0\xa8\x01\x17' > /dev/null 2>&1");
+	/* "Linu" will be 76.105.110.117 */
+	printf("%s\n", inet_ntoa(`linux_banner));
+	exit(0);
 }
 
-syscall::write:entry
-/ppid == $pid/
+ERROR
 {
-	printf("%s\n", inet_ntoa((void *)arg1));
-	exit(0);
+	exit(1);
 }
-
-ERROR { exit(1); }
diff --git a/test/unittest/funcs/tst.inet_ntoa_nonDPTR.r b/test/unittest/funcs/tst.inet_ntoa_nonDPTR.r
index 7257e488..011ffbbf 100644
--- a/test/unittest/funcs/tst.inet_ntoa_nonDPTR.r
+++ b/test/unittest/funcs/tst.inet_ntoa_nonDPTR.r
@@ -1,2 +1,2 @@
-192.168.1.23
+76.105.110.117
 
diff --git a/test/unittest/funcs/tst.rindex_nonDPTR.d b/test/unittest/funcs/tst.rindex_nonDPTR.d
index 0b193eb0..974b35de 100644
--- a/test/unittest/funcs/tst.rindex_nonDPTR.d
+++ b/test/unittest/funcs/tst.rindex_nonDPTR.d
@@ -1,24 +1,20 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 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.
  */
 
 #pragma D option quiet
-#pragma D option destructive
+#pragma D option strsize=14
 
 BEGIN
 {
-	/* "abcdef" */
-	system("printf '\x61\x62\x63\x64\x65\x66' > /dev/null 2>&1");
+	printf("rindex is %d, should be 0\n", rindex(`linux_banner, `linux_banner));
+	exit(0);
 }
 
-syscall::write:entry
-/ppid == $pid/
+ERROR
 {
-	printf("rindex is %d, should be 0\n", rindex((void *)arg1, (void *)arg1));
-	exit(0);
+	exit(1);
 }
-
-ERROR { exit(1); }
diff --git a/test/unittest/funcs/tst.strchr_nonDPTR.d b/test/unittest/funcs/tst.strchr_nonDPTR.d
index 95cb08c2..726a1a3c 100644
--- a/test/unittest/funcs/tst.strchr_nonDPTR.d
+++ b/test/unittest/funcs/tst.strchr_nonDPTR.d
@@ -1,25 +1,21 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 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.
  */
 
 #pragma D option quiet
-#pragma D option destructive
+#pragma D option strsize=14
 
 BEGIN
 {
-	/* "abcdef" */
-	system("printf '\x61\x62\x63\x64\x65\x66' > /dev/null 2>&1");
+	printf("|%s|\n", strchr(`linux_banner, 'x'));
+	printf("|%s|\n", strrchr(`linux_banner, 'u'));
+	exit(0);
 }
 
-syscall::write:entry
-/ppid == $pid/
+ERROR
 {
-	printf("|%s|\n", strchr((void *)arg1, 'b'));
-	printf("|%s|\n", strrchr((void *)arg1, 'b'));
-	exit(0);
+	exit(1);
 }
-
-ERROR { exit(1); }
diff --git a/test/unittest/funcs/tst.strchr_nonDPTR.r b/test/unittest/funcs/tst.strchr_nonDPTR.r
index b1b10def..6bb00a3f 100644
--- a/test/unittest/funcs/tst.strchr_nonDPTR.r
+++ b/test/unittest/funcs/tst.strchr_nonDPTR.r
@@ -1,3 +1,3 @@
-|bcdef|
-|bcdef|
+|x version|
+|ux version|
 
-- 
2.18.4




More information about the DTrace-devel mailing list