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 sysvmsg || kldload sysvmsg
45 kldstat -v | grep -q sysvsem || kldload sysvsem
46 kldstat -v | grep -q sysvshm || kldload sysvshm
48 kldstat -v | grep -q aio || kldload aio
49 kldstat -v | grep -q mqueuefs || kldload mqueuefs
51 syscall=`grep SYS_MAXSYSCALL /usr/include/sys/syscall.h | awk '{print $NF}'`
56 rm -f /tmp/syscall2.log
57 while [ $n -gt 0 ]; do
58 echo "`date '+%T'` syscall $n" | tee /dev/tty >> /tmp/syscall2.log
60 su ${testuser} -c "sh -c \"/tmp/syscall2 -t 30s -i 100 -h -l 100 -k $n\""
70 /* Call random system calls with random arguments */
77 #include <sys/syscall.h>
78 #include <sys/resource.h>
83 static char path[128];
85 static int starting_dir = 0;
88 static int ignore[] = {
92 11, /* 11 is obsolete execv */
96 109, /* 109 is old sigblock */
97 111, /* 111 is old sigsuspend */
114 sprintf(path,"%s.%05d", getprogname(), getpid());
115 (void)mkdir(path, 0770);
116 if (chdir(path) == -1)
117 err(1, "chdir(%s), %s:%d", path, __FILE__, __LINE__);
118 if ((starting_dir = open(".", 0)) < 0)
122 num = atoi(op->argv[0]);
123 for (i = 0; i < sizeof(ignore) / sizeof(ignore[0]); i++)
124 if (num == ignore[i]) {
125 printf("syscall %d is marked a no test!\n", num);
131 num = random_int(0, SYS_MAXSYSCALL);
132 for (i = 0; i < sizeof(ignore) / sizeof(ignore[0]); i++)
133 if (num == ignore[i]) {
140 printf("Testing syscall #%d, pid %d\n", num, getpid());
142 /* Multiple parallel core dump may panic the kernel with:
143 panic: kmem_malloc(184320): kmem_map too small: 84426752 total allocated
145 rl.rlim_max = rl.rlim_cur = 0;
146 if (setrlimit(RLIMIT_CORE, &rl) == -1)
149 setproctitle("#%d", num);
157 if (starting_dir != 0) {
158 if (fchdir(starting_dir) == -1)
160 (void)system("find . -type d -exec chmod 777 {} \\;");
161 (void)system("find . -type f -exec chmod 666 {} \\;");
162 (void)system("find . -delete");
164 if (chdir("..") == -1)
166 if (rmdir(path) == -1)
167 err(1, "rmdir(%s), %s:%d", path, __FILE__, __LINE__);
177 for (i = 0; i < 7; i++) {
178 for (j = 0; j < 10; j++) {
179 if (arc4random() % 100 > 20)
180 rb[i][j] = arc4random();
182 rb[i][j] = (uint32_t) &rb[i][j];
196 r = (uint32_t) &rb[i][0];
205 unsigned int arg1, arg2, arg3, arg4, arg5, arg6, arg7;
207 for (i = 0; i < 128; i++) {
218 printf("%2d : syscall(%3d, %x, %x, %x, %x, %x, %x, %x)\n",
219 i, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
220 syscall(num, arg1, arg2, arg3, arg4, arg5, arg6, arg7);