1#!/bin/sh 2 3# 4# Copyright (c) 2009 Peter Holm 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 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. 15# 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 26# SUCH DAMAGE. 27# 28# $FreeBSD$ 29# 30 31# Test calls with random arguments, in reverse order 32# Variation of the syscall test program. 33 34[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 35 36. ../default.cfg 37 38odir=`pwd` 39cd /tmp 40sed '1,/^EOF/d' < $odir/$0 > syscall2.c 41cc -o syscall2 -Wall -I $odir/../include -L $odir/../lib syscall2.c -lstress -lutil 42rm -f syscall2.c 43 44kldstat -v | grep -q sysvmsg || kldload sysvmsg 45kldstat -v | grep -q sysvsem || kldload sysvsem 46kldstat -v | grep -q sysvshm || kldload sysvshm 47 48kldstat -v | grep -q aio || kldload aio 49kldstat -v | grep -q mqueuefs || kldload mqueuefs 50 51syscall=`grep SYS_MAXSYSCALL /usr/include/sys/syscall.h | awk '{print $NF}'` 52 53n=$syscall 54[ $# -eq 1 ] && n=$1 55 56rm -f /tmp/syscall2.log 57while [ $n -gt 0 ]; do 58 echo "`date '+%T'` syscall $n" | tee /dev/tty >> /tmp/syscall2.log 59 for i in `jot 5`; do 60 su ${testuser} -c "sh -c \"/tmp/syscall2 -t 30s -i 100 -h -l 100 -k $n\"" 61 done 62 chflags -R 0 $RUNDIR 63 rm -rf $RUNDIR 64 n=$((n - 1)) 65done 66rm -f /tmp/syscall2 67exit 68EOF 69 70/* Call random system calls with random arguments */ 71 72#include <stdio.h> 73#include <stdlib.h> 74#include <unistd.h> 75#include <fcntl.h> 76#include <sys/stat.h> 77#include <sys/syscall.h> 78#include <sys/resource.h> 79#include <err.h> 80 81#include "stress.h" 82 83static char path[128]; 84static int num; 85static int starting_dir = 0; 86uint32_t rb[7][10]; 87 88static int ignore[] = { 89 SYS_syscall, 90 SYS_exit, 91 SYS_fork, 92 11, /* 11 is obsolete execv */ 93 SYS_unmount, 94 SYS_reboot, 95 SYS_vfork, 96 109, /* 109 is old sigblock */ 97 111, /* 111 is old sigsuspend */ 98 SYS_shutdown, 99 SYS___syscall, 100 SYS_rfork, 101 SYS_sigsuspend, 102 SYS_mac_syscall, 103 SYS_sigtimedwait, 104 SYS_sigwaitinfo, 105}; 106 107int 108setup(int nb) 109{ 110 int i; 111 struct rlimit rl; 112 113 umask(0); 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) 119 err(1, "."); 120 121 if (op->argc == 1) { 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); 126 exit(1); 127 } 128 } else { 129 num = 0; 130 while (num == 0) { 131 num = random_int(0, SYS_MAXSYSCALL); 132 for (i = 0; i < sizeof(ignore) / sizeof(ignore[0]); i++) 133 if (num == ignore[i]) { 134 num = 0; 135 break; 136 } 137 } 138 } 139 if (op->verbose > 1) 140 printf("Testing syscall #%d, pid %d\n", num, getpid()); 141 142 /* Multiple parallel core dump may panic the kernel with: 143 panic: kmem_malloc(184320): kmem_map too small: 84426752 total allocated 144 */ 145 rl.rlim_max = rl.rlim_cur = 0; 146 if (setrlimit(RLIMIT_CORE, &rl) == -1) 147 warn("setrlimit"); 148 149 setproctitle("#%d", num); 150 151 return (0); 152} 153 154void 155cleanup(void) 156{ 157 if (starting_dir != 0) { 158 if (fchdir(starting_dir) == -1) 159 err(1, "fchdir()"); 160 (void)system("find . -type d -exec chmod 777 {} \\;"); 161 (void)system("find . -type f -exec chmod 666 {} \\;"); 162 (void)system("find . -delete"); 163 164 if (chdir("..") == -1) 165 err(1, "chdir(..)"); 166 if (rmdir(path) == -1) 167 err(1, "rmdir(%s), %s:%d", path, __FILE__, __LINE__); 168 } 169 starting_dir = 0; 170} 171 172void 173rainit(void) 174{ 175 int i, j; 176 177 for (i = 0; i < 7; i++) { 178 for (j = 0; j < 10; j++) { 179 if (arc4random() % 100 > 20) 180 rb[i][j] = arc4random(); 181 else 182 rb[i][j] = (uint32_t) &rb[i][j]; 183 } 184 } 185} 186 187uint32_t 188ra(int i) 189{ 190 uint32_t r; 191 192 r = arc4random(); 193 if ((r & 1) == 0) 194 r = arc4random(); 195 else 196 r = (uint32_t) &rb[i][0]; 197 198 return (r); 199} 200 201int 202test(void) 203{ 204 int i; 205 unsigned int arg1, arg2, arg3, arg4, arg5, arg6, arg7; 206 207 for (i = 0; i < 128; i++) { 208 rainit(); 209 arg1 = ra(0); 210 arg2 = ra(1); 211 arg3 = ra(2); 212 arg4 = ra(3); 213 arg5 = ra(4); 214 arg6 = ra(5); 215 arg7 = ra(6); 216 217 if (op->verbose > 3) 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); 221 } 222 223 return (0); 224} 225