[DTrace-devel] [PATCH] test: Switch kernel pointer in tracemem() test

eugene.loh at oracle.com eugene.loh at oracle.com
Mon Mar 6 21:14:20 UTC 2023


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

The tracemem() test dumped a portion of kernel memory, comparing
different tracemem() output for the same kernel memory for consistency.
Since it was looking at task_struct for the current thread, however,
the underlying data could conceivably change as the test ran, leading
to inconsistency and a false negative.

Change the kernel memory to be the first 14 bytes of 'linux_banner,
which should remain "Linux version ".

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 test/unittest/tracemem/tst.tracemem.d   | 58 +++++--------------------
 test/unittest/tracemem/tst.tracemem.r   | 31 +++++++++----
 test/unittest/tracemem/tst.tracemem.r.p | 30 -------------
 3 files changed, 34 insertions(+), 85 deletions(-)
 delete mode 100755 test/unittest/tracemem/tst.tracemem.r.p

diff --git a/test/unittest/tracemem/tst.tracemem.d b/test/unittest/tracemem/tst.tracemem.d
index 41440518..202fb514 100644
--- a/test/unittest/tracemem/tst.tracemem.d
+++ b/test/unittest/tracemem/tst.tracemem.d
@@ -13,53 +13,19 @@
 
 #pragma D option quiet
 
-long long *p;
-
 BEGIN {
-	/* pick some pointer to kernel memory */
-	p = (long long *) curthread;
-
-	/* dump memory at this pointer */
-	printf("%16.16x %16.16x\n", p[ 0], p[ 1]);
-	printf("%16.16x %16.16x\n", p[ 2], p[ 3]);
-	printf("%16.16x %16.16x\n", p[ 4], p[ 5]);
-	printf("%16.16x %16.16x\n", p[ 6], p[ 7]);
-	printf("%16.16x %16.16x\n", p[ 8], p[ 9]);
-	printf("%16.16x %16.16x\n", p[10], p[11]);
-	printf("%16.16x %16.16x\n", p[12], p[13]);
-	printf("%16.16x %16.16x\n", p[14], p[15]);
-	printf("%16.16x %16.16x\n", p[16], p[17]);
-	printf("%16.16x %16.16x\n", p[18], p[19]);
-	printf("%16.16x %16.16x\n", p[20], p[21]);
-	printf("%16.16x %16.16x\n", p[22], p[23]);
-	printf("%16.16x %16.16x\n", p[24], p[25]);
-	printf("%16.16x %16.16x\n", p[26], p[27]);
-	printf("%16.16x %16.16x\n", p[28], p[29]);
-	printf("%16.16x %16.16x\n", p[30], p[31]);
-
-	/* try tracemem() with this same pointer but various sizes */
-
-	tracemem(p, 256);	/* 256 bytes */
-
-	tracemem(p, 256,  -1);	/* 256 bytes (arg2 < 0) */
-
-	tracemem(p, 256,   0);	/*   0 bytes */
-
-	tracemem(p, 256,  32);	/*  32 bytes */
-
-	tracemem(p, 256,  64);	/*  64 bytes */
-
-	tracemem(p, 256, 128);	/* 128 bytes */
-
-	tracemem(p, 256, 256);	/* 256 bytes */
-
-	tracemem(p, 256, 320);	/* 256 bytes (arg1 <= arg2) */
-
-	tracemem(p, 256, (unsigned char) 0x80);
-				/* 128 bytes */
-
-	tracemem(p, 256, (signed char) 0x80);
-				/* 256 bytes (arg2 < 0) */
+	/* p = `linux_banner; */     /* first 14 chars are "Linux version " */
+
+	/* try tracemem() with various sizes */
+
+	tracemem(`linux_banner, 14);     /* "Linux version ": 14 bytes */
+	tracemem(`linux_banner, 14, -1); /* "Linux version ": 14 bytes (arg2 < 0) */
+	tracemem(`linux_banner, 14,  0); /*                    0 bytes */
+	tracemem(`linux_banner, 14,  2); /* "Li"            :  2 bytes */
+	tracemem(`linux_banner, 14,  7); /* "Linux v"       :  7 bytes */
+	tracemem(`linux_banner, 14, 12); /* "Linux versio"  : 12 bytes */
+	tracemem(`linux_banner, 14, 14); /* "Linux version ": 14 bytes */
+	tracemem(`linux_banner, 14, 15); /* "Linux version ": 14 bytes (arg1 <= arg2) */
 
 	exit(0);
 }
diff --git a/test/unittest/tracemem/tst.tracemem.r b/test/unittest/tracemem/tst.tracemem.r
index 1b24115f..2952158d 100644
--- a/test/unittest/tracemem/tst.tracemem.r
+++ b/test/unittest/tracemem/tst.tracemem.r
@@ -1,9 +1,22 @@
-256 bytes
-256 bytes
-32 bytes
-64 bytes
-128 bytes
-256 bytes
-256 bytes
-128 bytes
-256 bytes
+
+             0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
+         0: 4c 69 6e 75 78 20 76 65 72 73 69 6f 6e 20        Linux version 
+
+             0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
+         0: 4c 69 6e 75 78 20 76 65 72 73 69 6f 6e 20        Linux version 
+
+             0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
+         0: 4c 69                                            Li
+
+             0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
+         0: 4c 69 6e 75 78 20 76                             Linux v
+
+             0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
+         0: 4c 69 6e 75 78 20 76 65 72 73 69 6f              Linux versio
+
+             0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
+         0: 4c 69 6e 75 78 20 76 65 72 73 69 6f 6e 20        Linux version 
+
+             0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
+         0: 4c 69 6e 75 78 20 76 65 72 73 69 6f 6e 20        Linux version 
+
diff --git a/test/unittest/tracemem/tst.tracemem.r.p b/test/unittest/tracemem/tst.tracemem.r.p
deleted file mode 100755
index 3f34b26b..00000000
--- a/test/unittest/tracemem/tst.tracemem.r.p
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/usr/bin/gawk -f
-
-# read data against which we will check tracemem() results
-BEGIN {
-        n = 0;    # count check results
-        m = 0;    # count tracemem() results
-}
-NF == 2 {
-        check[n] = $1; n++;
-        check[n] = $2; n++;
-        next;
-}
-
-# if we have a blank line, report number of bytes compared, if any
-NF == 0 && m > 0 { print 8 * m, "bytes" }
-
-# restart counting tracemem() output
-NF == 0 { m = 0; next; }
-
-# comparison function
-function mycomp(expect, actual) {
-        if ( expect != actual )
-                print "ERROR: expect", expect, "actual", actual;
-}
-
-# tracemem output has two sets of 8 bytes each; reverse bytes for comparison
-/:/ {
-        mycomp( check[m++], $9$8$7$6$5$4$3$2);
-        mycomp( check[m++], $17$16$15$14$13$12$11$10);
-}
-- 
2.18.4




More information about the DTrace-devel mailing list