4 # Copyright (c) 2009 Peter Holm
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 # Test calls with random arguments, in reverse order
32 # Variation of the syscall test program.
34 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
40 sed '1,/^EOF/d' < $odir/$0 > syscall2.c
41 cc -o syscall2 -Wall -I $odir/../include -L $odir/../lib syscall2.c -lstress -lutil
44 #kldstat -v | grep -q aio || kldload aio
45 #kldstat -v | grep -q mqueuefs || kldload mqueuefs
47 syscall=`grep SYS_MAXSYSCALL /usr/include/sys/syscall.h | awk '{print $NF}'`
52 rm -f /tmp/syscall2.log
53 while [ $n -gt 0 ]; do
54 echo "`date '+%T'` syscall $n" | tee /dev/tty >> /tmp/syscall2.log
56 su ${testuser} -c "sh -c \"/tmp/syscall2 -t 30s -i 100 -h -l 100 -k $n\""
66 /* Call random system calls with random arguments */
73 #include <sys/syscall.h>
74 #include <sys/resource.h>
79 static char path[128];
81 static int starting_dir = 0;
84 static int ignore[] = {
88 11, /* 11 is obsolete execv */
92 109, /* 109 is old sigblock */
93 111, /* 111 is old sigsuspend */
110 sprintf(path,"%s.%05d", getprogname(), getpid());
111 (void)mkdir(path, 0770);
112 if (chdir(path) == -1)
113 err(1, "chdir(%s), %s:%d", path, __FILE__, __LINE__);
114 if ((starting_dir = open(".", 0)) < 0)
118 num = atoi(op->argv[0]);
119 for (i = 0; i < sizeof(ignore) / sizeof(ignore[0]); i++)
120 if (num == ignore[i]) {
121 printf("syscall %d is marked a no test!\n", num);
127 num = random_int(0, SYS_MAXSYSCALL);
128 for (i = 0; i < sizeof(ignore) / sizeof(ignore[0]); i++)
129 if (num == ignore[i]) {
136 printf("Testing syscall #%d, pid %d\n", num, getpid());
138 /* Multiple parallel core dump may panic the kernel with:
139 panic: kmem_malloc(184320): kmem_map too small: 84426752 total allocated
141 rl.rlim_max = rl.rlim_cur = 0;
142 if (setrlimit(RLIMIT_CORE, &rl) == -1)
145 setproctitle("#%d", num);
153 if (starting_dir != 0) {
154 if (fchdir(starting_dir) == -1)
156 (void)system("find . -type d -exec chmod 777 {} \\;");
157 (void)system("find . -type f -exec chmod 666 {} \\;");
158 (void)system("find . -delete");
160 if (chdir("..") == -1)
162 if (rmdir(path) == -1)
163 err(1, "rmdir(%s), %s:%d", path, __FILE__, __LINE__);
173 for (i = 0; i < 7; i++) {
174 for (j = 0; j < 10; j++) {
175 if (arc4random() % 100 > 20)
176 rb[i][j] = arc4random();
178 rb[i][j] = (uint32_t) &rb[i][j];
192 r = (uint32_t) &rb[i][0];
201 unsigned int arg1, arg2, arg3, arg4, arg5, arg6, arg7;
203 for (i = 0; i < 128; i++) {
214 printf("%2d : syscall(%3d, %x, %x, %x, %x, %x, %x, %x)\n",
215 i, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
216 syscall(num, arg1, arg2, arg3, arg4, arg5, arg6, arg7);