Skip to content

Commit

Permalink
test: Switch kernel pointer in tracemem() test
Browse files Browse the repository at this point in the history
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@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
euloh authored and kvanhees committed May 25, 2023
1 parent 32711a7 commit d51a52b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 85 deletions.
58 changes: 12 additions & 46 deletions test/unittest/tracemem/tst.tracemem.d
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (char *)`linux_banner; /* first 14 chars are "Linux version " */

/* try tracemem() with various sizes */

tracemem(p, 14); /* "Linux version ": 14 bytes */
tracemem(p, 14, -1); /* "Linux version ": 14 bytes (arg2 < 0) */
tracemem(p, 14, 0); /* 0 bytes */
tracemem(p, 14, 2); /* "Li" : 2 bytes */
tracemem(p, 14, 7); /* "Linux v" : 7 bytes */
tracemem(p, 14, 12); /* "Linux versio" : 12 bytes */
tracemem(p, 14, 14); /* "Linux version ": 14 bytes */
tracemem(p, 14, 15); /* "Linux version ": 14 bytes (arg1 <= arg2) */

exit(0);
}
31 changes: 22 additions & 9 deletions test/unittest/tracemem/tst.tracemem.r
Original file line number Diff line number Diff line change
@@ -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

30 changes: 0 additions & 30 deletions test/unittest/tracemem/tst.tracemem.r.p

This file was deleted.

0 comments on commit d51a52b

Please sign in to comment.