[DTrace-devel] [PATCH 7/8] test: improve kernel read and subroutine coverage

Kris Van Hees kris.van.hees at oracle.com
Mon Sep 28 18:02:07 UTC 2026


Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 .../codegen/tst.kernel_read_deref_struct.d    |  1 +
 .../codegen/tst.kernel_read_deref_struct.r.p  | 25 +++++++++++++++++++
 test/unittest/funcs/tst.subr.d                | 17 ++++++++++---
 test/unittest/funcs/tst.subr.r                | 13 ++++++++++
 4 files changed, 52 insertions(+), 4 deletions(-)
 create mode 100755 test/unittest/codegen/tst.kernel_read_deref_struct.r.p
 create mode 100644 test/unittest/funcs/tst.subr.r

diff --git a/test/unittest/codegen/tst.kernel_read_deref_struct.d b/test/unittest/codegen/tst.kernel_read_deref_struct.d
index c8ad5d3d..ca6b83cb 100644
--- a/test/unittest/codegen/tst.kernel_read_deref_struct.d
+++ b/test/unittest/codegen/tst.kernel_read_deref_struct.d
@@ -9,6 +9,7 @@
 
 BEGIN
 {
+	trace(sizeof(struct pid));
 	trace(*(struct pid *)`cad_pid);
 	exit(0);
 }
diff --git a/test/unittest/codegen/tst.kernel_read_deref_struct.r.p b/test/unittest/codegen/tst.kernel_read_deref_struct.r.p
new file mode 100755
index 00000000..d45aefe4
--- /dev/null
+++ b/test/unittest/codegen/tst.kernel_read_deref_struct.r.p
@@ -0,0 +1,25 @@
+#!/usr/bin/gawk -f
+
+NR == 1 {
+	expected = int($1);
+	print "Expect " expected " bytes";
+	next;
+}
+
+$1 ~ /^[0-9][0-9]*:$/ {
+	sub(/  .{16}$/, "");
+	got += NF - 1;
+
+	for (i = 2; i <= NF; i++)
+		not0 += ($i != "00");
+}
+
+END {
+	print "Got " got " bytes";
+	if (not0 == 0)
+		print "All zeros - read failure?";
+	else if (expected != got)
+		print "Data size mismatch";
+	else if (not0 < got / 4)
+		print "Too many zeros - check data?";
+}
diff --git a/test/unittest/funcs/tst.subr.d b/test/unittest/funcs/tst.subr.d
index d97a0780..1b9a6263 100644
--- a/test/unittest/funcs/tst.subr.d
+++ b/test/unittest/funcs/tst.subr.d
@@ -14,8 +14,17 @@
 	BEGIN				\
 	/*DSTYLED*/			\
 	{				\
+		this->ival = (long)(x);	\
 		subr++;			\
-		@[(long)x] = sum(1);	\
+	/*DSTYLED*/			\
+	}
+
+#define AINTFUNC(x)			\
+	BEGIN				\
+	/*DSTYLED*/			\
+	{				\
+		subr++;			\
+		this->aval = (long)(x);	\
 	/*DSTYLED*/			\
 	}
 
@@ -24,7 +33,7 @@
 	/*DSTYLED*/			\
 	{				\
 		subr++;			\
-		@str[x] = sum(1);	\
+		this->sval = (x);	\
 	/*DSTYLED*/			\
 	}
 
@@ -55,14 +64,14 @@ INTFUNC(mutex_type_spin((struct mutex *)&`bpf_verifier_lock))
 INTFUNC(rw_read_held((rwlock_t *)&`tasklist_lock))
 INTFUNC(rw_write_held((rwlock_t *)&`tasklist_lock))
 INTFUNC(rw_iswriter((rwlock_t *)&`tasklist_lock))
-INTFUNC(copyin(0, 1))
+AINTFUNC(copyin(0, 1))
 STRFUNC(copyinstr(0, 1))
 INTFUNC(speculation())
 INTFUNC(progenyof($pid))
 INTFUNC(strlen("fooey"))
 VOIDFUNC(copyout)
 VOIDFUNC(copyoutstr)
-INTFUNC(alloca(10))
+AINTFUNC(alloca(10))
 VOIDFUNC(bcopy)
 VOIDFUNC(copyinto)
 /* Not implemented.
diff --git a/test/unittest/funcs/tst.subr.r b/test/unittest/funcs/tst.subr.r
new file mode 100644
index 00000000..9dfa4b0e
--- /dev/null
+++ b/test/unittest/funcs/tst.subr.r
@@ -0,0 +1,13 @@
+                   FUNCTION:NAME
+                          :BEGIN 
+
+
+                1
+
+              libdtrace.so.2.0.0`BEGIN_probe
+              {ptr}
+                1
+-- @@stderr --
+dtrace: script 'test/unittest/funcs/tst.subr.d' matched 43 probes
+dtrace: error in dt_clause_8 for probe ID 1 (dtrace:::BEGIN): invalid address ({ptr}) at BPF pc NNN
+dtrace: error in dt_clause_9 for probe ID 1 (dtrace:::BEGIN): invalid address ({ptr}) at BPF pc NNN
-- 
2.52.0




More information about the DTrace-devel mailing list