test: improve kernel read and subroutine coverage
PATCH 7/8 test: improve kernel read and subroutine coverage
Signed-off-by Kris Van Hees <[email protected]>
--- .../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
@@ -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
@@ -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
@@ -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
@@ -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 Elena Zannoni <[email protected]>
Quoted 130 lines · Kris Van Hees via DTrace-devel
Signed-off-by Kris Van Hees <[email protected]>--- .../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.rtest/unittest/codegen/tst.kernel_read_deref_struct.d +1
-0@@ -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@@ -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@@ -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@@ -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 NNNSignature · 7 lines
2.52.0 _______________________________________________ DTrace-devel mailing list [email protected] https://oss.oracle.com/mailman/listinfo/dtrace-devel