The random syscall generator has a bug on x86-64 where it only generates
random bits for the upper 32 bits of the syscall argument, and then
truncates the upper 32 bits anyway! This patch replaces the rand()
weirdness with a function that generates N bytes of random data instead.
It also adds a -z flag in case one *wants* the zero-arguments behavior;
Max Asbock and Russ Weight requested it because zero is a quick way to
find kernel code paths that don't check userland pointers.
--
Signed-off-by: Darrick J. Wong <djwong@...>
diff -Naurp -x '*CVS*' ltp/testcases/pounder21/CHANGELOG ltpounder/testcases/pounder21/CHANGELOG
--- ltp/testcases/pounder21/CHANGELOG 2006-01-26 14:16:41.000000000 -0800
+++ ltpounder/testcases/pounder21/CHANGELOG 2006-11-07 10:51:14.000000000 -0800
@@ -1,5 +1,20 @@
This is a log of changes to pounder21.
+pounder21-2006-11-07:
+- Fix a bug in randasys on x86-64 where we had insufficient random bits and
+ would truncate whatever we got, leading to all 0 arguments by simply
+ generating enough random bytes to fill an unsigned long. Also add a -z
+ switch to enable this zero-only mode because it found some bugs. :)
+
+pounder21-2006-10-12:
+- Include /sysfs contents in the hw inventory
+- Put 'lspci' into the PCI inventory for easy finding.
+
+pounder21-2006-09-23:
+- Various time test fixes from jstultz.
+- IPMI tests from James Simshaw/Carol Hebert.
+- Update kernel from 2.6.15 to 2.6.18.
+
pounder21-2006-01-24:
- Establish all files in the tarball as originating from IBM LTC.
- License all files under the GNU Public License (GPL) v2.
diff -Naurp -x '*CVS*' ltp/testcases/pounder21/run.c ltpounder/testcases/pounder21/run.c
--- ltp/testcases/pounder21/run.c 2006-06-23 09:27:47.000000000 -0700
+++ ltpounder/testcases/pounder21/run.c 2006-10-20 13:26:32.000000000 -0700
@@ -152,6 +152,7 @@ int main(int argc, char *argv[]) {
/* Set up signals */
memset(&zig, 0x00, sizeof(zig));
zig.sa_handler = jump_out;
+ sigaction(SIGHUP, &zig, NULL);
sigaction(SIGINT, &zig, NULL);
sigaction(SIGTERM, &zig, NULL);
diff -Naurp -x '*CVS*' ltp/testcases/pounder21/src/randasyscall/randasys.c ltpounder/testcases/pounder21/src/randasyscall/randasys.c
--- ltp/testcases/pounder21/src/randasyscall/randasys.c 2006-06-23 09:27:50.000000000 -0700
+++ ltpounder/testcases/pounder21/src/randasyscall/randasys.c 2006-10-12 15:46:41.000000000 -0700
@@ -30,9 +30,10 @@
#include <string.h>
#include <stdio.h>
#include <syscall.h>
+#include <stdint.h>
#include <stdlib.h>
-int callnum, args[6];
+unsigned long callnum, args[6];
int seed_random(void) {
int fp;
@@ -55,6 +56,15 @@ int seed_random(void) {
return 1;
}
+void get_big_randnum(void *buf, unsigned int size) {
+ uint32_t *x = buf;
+ int i;
+
+ for (i = 0; i < size; i += 4, x++) {
+ *x = (unsigned long)((float)UINT_MAX * (rand() / (RAND_MAX + 1.0)));
+ }
+}
+
unsigned long get_randnum(unsigned long min, unsigned long max) {
return min + (unsigned long)((float)max * (rand() / (RAND_MAX + 1.0)));
}
@@ -168,7 +178,7 @@ badcall:
}
void bogus_signal_handler(int signum) {
- fprintf(stderr, " Signal %d on syscall(%d, %d, %d, %d, %d, %d, %d).\n",
+ fprintf(stderr, " Signal %d on syscall(%lu, 0x%lX, 0x%lX, 0x%lX, 0x%lX, 0x%lX, 0x%lX).\n",
signum, callnum, args[0], args[1], args[2], args[3],
args[4], args[5]);
}
@@ -193,43 +203,39 @@ void install_signal_handlers(void) {
}
int main(int argc, char *argv[]) {
- int debug = 0;
+ int i;
+ int debug = 0, zero_mode = 0;
if (!seed_random()) {
return 1;
}
- if (argc > 1 && strcmp(argv[1], "-d") == 0) {
- debug = 1;
+ for (i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "-d"))
+ debug = 1;
+ else if(!strcmp(argv[i], "-z"))
+ zero_mode = 1;
}
- /*
- FILE *fp = fopen("/dev/tty", "w");
- fprintf(fp, "randasys process group is %d\n", getpgrp());
- fclose(fp);
- */
+ memset(args, 0, sizeof(unsigned long) * 6);
install_signal_handlers();
while(1) {
callnum = find_syscall();
- args[0] = get_randnum(0, ULONG_MAX);
- args[1] = get_randnum(0, ULONG_MAX);
- args[2] = get_randnum(0, ULONG_MAX);
- args[3] = get_randnum(0, ULONG_MAX);
- args[4] = get_randnum(0, ULONG_MAX);
- args[5] = get_randnum(0, ULONG_MAX);
+ if (!zero_mode)
+ get_big_randnum(&args[0], sizeof(unsigned long) * 6);
if (debug) {
- printf("syscall(%d, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X); \r",
- callnum, args[0], args[1], args[2], args[3], args[4],
- args[5]);
+ printf("syscall(%lu, 0x%lX, 0x%lX, 0x%lX, 0x%lX, "
+ "0x%lX, 0x%lX); \n",
+ callnum, args[0], args[1], args[2], args[3],
+ args[4], args[5]);
fflush(stdout);
}
syscall(callnum, args[0], args[1], args[2],
args[3], args[4], args[5]);
-
}
return 0;
diff -Naurp -x '*CVS*' ltp/testcases/pounder21/test_scripts/random_syscall ltpounder/testcases/pounder21/test_scripts/random_syscall
--- ltp/testcases/pounder21/test_scripts/random_syscall 2006-01-26 14:16:42.000000000 -0800
+++ ltpounder/testcases/pounder21/test_scripts/random_syscall 2006-10-12 15:48:54.000000000 -0700
@@ -50,6 +50,7 @@ dmesg > "$POUNDER_TMPDIR/randasys-before
for ((k=0; k < $NR_CPUS; k++))
do
"$POUNDER_HOME/fancy_timed_loop" 900 $RANDASYS_UID $RANDASYS_GID 9 "$PROGRAM" &
+ "$POUNDER_HOME/fancy_timed_loop" 900 $RANDASYS_UID $RANDASYS_GID 9 "$PROGRAM" -z &
done
# Wait for this to finish (it won't)
|