Skip to contentSkip to conversation

test: improve kernel read and subroutine coverage

PATCH In review Kris Van Hees 2 participants 2 messages Sep 28 – Oct 3

lore
Share & tools
lore
#0 lore raw

PATCH 7/8 test: improve kernel read and subroutine coverage

---
 .../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
test/unittest/codegen/tst.kernel_read_deref_struct.d +1 -0
index c8ad5d3d..ca6b83cb 100644
@@ -9,6 +9,7 @@
 
 BEGIN
 {
+	trace(sizeof(struct pid));
 	trace(*(struct pid *)`cad_pid);
 	exit(0);
 }
test/unittest/codegen/tst.kernel_read_deref_struct.r.p new file +25 -0
new file mode 100755
index 00000000..d45aefe4
@@ -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?";
+}
test/unittest/funcs/tst.subr.d +13 -4
index d97a0780..1b9a6263 100644
@@ -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.
test/unittest/funcs/tst.subr.r new file +13 -0
new file mode 100644
index 00000000..9dfa4b0e
@@ -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
Signature · 1 line
2.52.0
Reviewed-by on v1 7/8
#1 lore raw
Quoted 130 lines · Kris Van Hees via DTrace-devel
---
 .../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
test/unittest/codegen/tst.kernel_read_deref_struct.d +1 -0
index c8ad5d3d..ca6b83cb 100644
@@ -9,6 +9,7 @@
 
 BEGIN
 {
+	trace(sizeof(struct pid));
 	trace(*(struct pid *)`cad_pid);
 	exit(0);
 }
test/unittest/codegen/tst.kernel_read_deref_struct.r.p new file +25 -0
new file mode 100755
index 00000000..d45aefe4
@@ -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?";
+}
test/unittest/funcs/tst.subr.d +13 -4
index d97a0780..1b9a6263 100644
@@ -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.
test/unittest/funcs/tst.subr.r new file +13 -0
new file mode 100644
index 00000000..9dfa4b0e
@@ -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
Signature · 7 lines
2.52.0


_______________________________________________
DTrace-devel mailing list
[email protected]
https://oss.oracle.com/mailman/listinfo/dtrace-devel