diff --git a/tools/test/stress2/misc/exlock2.sh b/tools/test/stress2/misc/exlock2.sh index 58a49919d86a..e1760cc52a4d 100755 --- a/tools/test/stress2/misc/exlock2.sh +++ b/tools/test/stress2/misc/exlock2.sh @@ -1,210 +1,205 @@ #!/bin/sh # # SPDX-License-Identifier: BSD-2-Clause # # Copyright (c) 2021 Peter Holm # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # O_CREAT|O_EXCL|O_EXLOCK atomic implementation test. # Lots of input from kib@ [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/exlock2.c mycc -o exlock2 -Wall -Wextra -O0 -g exlock2.c || exit 1 rm -f exlock2.c cd $odir $dir/exlock2 s=$? [ -f exlock2.core -a $s -eq 0 ] && { ls -l exlock2.core; mv exlock2.core $dir; s=1; } cd $odir rm -f $dir/exlock2 /tmp/exlock2.*.file exit $s EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include static _Atomic(int) *share; +static int debug; /* Set to "1" for debug output */ static int quit; static char file[80]; #define RUNTIME (2 * 60) #define SYNC 0 static void handler(int s __unused) { quit = 1; } static void test1(void) { time_t start; int fd, n; signal(SIGHUP, handler); n = 0; start = time(NULL); while (time(NULL) - start < RUNTIME && quit == 0) { n++; if ((fd = open(file, O_RDWR|O_CREAT|O_EXCL|O_EXLOCK, DEFFILEMODE)) == -1) err(1, "open(%s) creat", file); unlink(file); if (write(fd, "test", 5) != 5) err(1, "write()"); while (share[SYNC] == 1) ; /* wait for test2 to signal "done" */ close(fd); } -#if defined(DEBUG) - fprintf(stderr, "%s: n = %d\n", __func__, n); -#endif + if (debug != 0) + fprintf(stderr, "%s: n = %d\n", __func__, n); _exit(0); } static void test2(void) { struct flock fl; struct stat st; time_t start; - int e, fd, n; + int e, fd; e = 0; fd = 0; - n = 0; start = time(NULL); while (time(NULL) - start < RUNTIME) { share[SYNC] = 1; if ((fd = open(file, O_RDWR)) == -1) goto out; - n++; memset(&fl, 0, sizeof(fl)); fl.l_start = 0; fl.l_len = 0; fl.l_type = F_WRLCK; fl.l_whence = SEEK_SET; if (fcntl(fd, F_SETLK, &fl) < 0) { if (errno != EAGAIN) err(1, "fcntl(F_SETFL)"); goto out; } /* test1 must have dropped the lock */ fprintf(stderr, "%s got the lock.\n", __func__); if (fstat(fd, &st) == -1) err(1, "stat(%s)", file); /* As test1 has opened the file exclusivly, this should not happen */ if (st.st_size == 0) fprintf(stderr, "%s has size 0\n", file); e = 1; break; out: if (fd != -1) close(fd); share[SYNC] = 0; usleep(100); } -#if defined(DEBUG) - if (e != 0) { + if (debug != 0 && e != 0) system("ps -Uroot | grep -v grep | grep /tmp/exlock2 | "\ "awk '{print $1}' | xargs procstat -f"); - } -#endif share[SYNC] = 0; _exit(e); } int main(void) { pid_t pid1, pid2; size_t len; int e, status; e = 0; len = PAGE_SIZE; if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) err(1, "mmap"); snprintf(file, sizeof(file), "/tmp/exlock2.%d.file", getpid()); if ((pid1 = fork()) == 0) test1(); if (pid1 == -1) err(1, "fork()"); if ((pid2 = fork()) == 0) test2(); if (pid2 == -1) err(1, "fork()"); if (waitpid(pid2, &status, 0) != pid2) err(1, "waitpid(%d)", pid2); if (status != 0) { if (WIFSIGNALED(status)) fprintf(stderr, "pid %d exit signal %d\n", pid2, WTERMSIG(status)); } e += status == 0 ? 0 : 1; kill(pid1, SIGHUP); if (waitpid(pid1, &status, 0) != pid1) err(1, "waitpid(%d)", pid1); if (status != 0) { if (WIFSIGNALED(status)) fprintf(stderr, "pid %d exit signal %d\n", pid1, WTERMSIG(status)); } e += status == 0 ? 0 : 1; return (e); } diff --git a/tools/test/stress2/misc/fcntl2.sh b/tools/test/stress2/misc/fcntl2.sh index 80be1bd05e5a..acb161fd0523 100755 --- a/tools/test/stress2/misc/fcntl2.sh +++ b/tools/test/stress2/misc/fcntl2.sh @@ -1,188 +1,190 @@ #!/bin/sh # # SPDX-License-Identifier: BSD-2-Clause # # Copyright (c) 2019 Dell EMC Isilon # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # fcntl(2) fuzz # "umount: unmount of /mnt failed: Device busy" seen: # https://people.freebsd.org/~pho/stress/log/fcntl2.txt . ../default.cfg [ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/fcntl2.c mycc -o fcntl2 -Wall -Wextra -O0 -g fcntl2.c || exit 1 rm -f fcntl2.c cd $odir set -e mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint [ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart newfs $newfs_flags md$mdstart > /dev/null mount /dev/md$mdstart $mntpoint set +e (cd $odir/../testcases/swap; ./swap -t 3m -i 20) & cd $mntpoint limits -n 10000 $dir/fcntl2 s=$? [ -f fcntl2.core -a $s -eq 0 ] && { ls -l fcntl2.core; mv fcntl2.core $dir; s=1; } cd $odir while pkill swap; do :; done for i in `jot 6`; do mount | grep -q "on $mntpoint " || break umount $mntpoint && break || sleep 10 [ $i -eq 6 ] && { echo FATAL; fstat -mf $mntpoint; exit 1; } done mdconfig -d -u $mdstart rm -rf $dir/fcntl2 exit $s EOF #include #include #include #include #include #include #include #include #include #include #include #include static volatile u_int *share; #define PARALLEL 64 #define RUNTIME (3 * 60) #define SYNC 0 #define N (128 * 1024 / (int)sizeof(u_int32_t)) static u_int32_t r[N]; static unsigned long makearg(void) { unsigned long val; unsigned int i; val = arc4random(); i = arc4random() % 100; if (i < 20) val = val & 0xff; if (i >= 20 && i < 40) val = val & 0xffff; if (i >= 40 && i < 60) val = (unsigned long)(r) | (val & 0xffff); #if defined(__LP64__) if (i >= 60) { val = (val << 32) | arc4random(); if (i > 80) val = val & 0x00007fffffffffffUL; } #endif return (val); } static void test(void) { time_t start; unsigned long arg3; int cmd, fd, i, n, success; char file[80]; atomic_add_int(&share[SYNC], 1); while (share[SYNC] != PARALLEL) ; success = 0; snprintf(file, sizeof(file), "file.%d", getpid()); if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE)) == -1) err(1, "open(%s)", file); n = arc4random() % 100 + 1; for (i = 0; i < n; i++) if (write(fd, file, sizeof(file)) != sizeof(file)) err(1, "write()"); start = time(NULL); while (time(NULL) - start < 60) { cmd = arc4random() % 20; arg3 = makearg(); alarm(20); if (fcntl(fd, cmd, arg3) != -1) success++; alarm(0); } close(fd); unlink(file); + if (success == 0) + fprintf(stderr, "No calls to fcntl() succeeded.\n"); _exit(0); } int main(void) { pid_t pids[PARALLEL]; size_t len; time_t start; int i, status; len = PAGE_SIZE; if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) err(1, "mmap"); start = time(NULL); while ((time(NULL) - start) < RUNTIME) { for (i = 0; i < N; i++) r[i] = arc4random(); share[SYNC] = 0; for (i = 0; i < PARALLEL; i++) { if ((pids[i] = fork()) == 0) test(); if (pids[i] == -1) err(1, "fork()"); } for (i = 0; i < PARALLEL; i++) { if (waitpid(pids[i], &status, 0) == -1) err(1, "waitpid(%d)", pids[i]); } } return (0); } diff --git a/tools/test/stress2/misc/fifo2.sh b/tools/test/stress2/misc/fifo2.sh index 9e4a7e632e9d..4a7b986931d9 100755 --- a/tools/test/stress2/misc/fifo2.sh +++ b/tools/test/stress2/misc/fifo2.sh @@ -1,204 +1,204 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Page fault seen # http://people.freebsd.org/~pho/stress/log/kostik654.txt # Fixed by r259521. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > fifo2.c rm -f /tmp/fifo2 mycc -o fifo2 -Wall -Wextra -O2 -g fifo2.c -lpthread || exit 1 rm -f fifo2.c mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart || exit 1 newfs $newfs_flags md$mdstart > /dev/null mount /dev/md$mdstart $mntpoint chmod 777 $mntpoint mkfifo $mntpoint/f chmod 777 $mntpoint/f sleeptime=12 st=`date '+%s'` while [ $((`date '+%s'` - st)) -lt $((10 * sleeptime)) ]; do (cd $mntpoint; /tmp/fifo2) & start=`date '+%s'` while [ $((`date '+%s'` - start)) -lt $sleeptime ]; do pgrep -q fifo2 || break sleep .5 done while pkill -9 fifo2; do :; done wait done for i in `jot 10`; do mount | grep -q md$mdstart && \ umount $mntpoint > /dev/null 2>&1 && mdconfig -d -u $mdstart && break sleep 10 done s=0 mount | grep -q md$mdstart && { echo "umount $mntpoint failed"; s=1; } rm -f /tmp/fifo2 exit $s EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define N (128 * 1024 / (int)sizeof(u_int32_t)) +static int debug; /* Set to 1 for debug output */ u_int32_t r[N]; static void hand(int i __unused) { /* handler */ _exit(1); } static unsigned long makearg(void) { unsigned int i; unsigned long val; val = arc4random(); i = arc4random() % 100; if (i < 20) val = val & 0xff; if (i >= 20 && i < 40) val = val & 0xffff; if (i >= 40 && i < 60) val = (unsigned long)(r) | (val & 0xffff); #if defined(__LP64__) if (i >= 60) { val = (val << 32) | arc4random(); if (i > 80) val = val & 0x00007fffffffffffUL; } #endif return(val); } static void * calls(void *arg __unused) { unsigned long arg1, arg2, arg3, arg4, arg5, arg6, arg7; int i; for (i = 0;; i++) { arg1 = (unsigned long)(void *)"f"; arg2 = makearg(); arg3 = makearg(); arg4 = makearg(); arg5 = makearg(); arg6 = makearg(); arg7 = makearg(); -#if 0 - fprintf(stderr, "%2d : syscall(%3d, %lx, %lx, %lx, %lx, %lx, %lx, %lx)\n", - i, SYS_open, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + if (debug != 0) + fprintf(stderr, "%2d : syscall(%3d, %lx, %lx, %lx, %lx, %lx, %lx, %lx)\n", + i, SYS_open, arg1, arg2, arg3, arg4, arg5, arg6, arg7); usleep(100000); -#endif alarm(1); syscall(SYS_open, arg1, arg2, arg3, arg4, arg5, arg6, arg7); } return (0); } int main(void) { struct passwd *pw; struct rlimit limit; pthread_t cp[50]; time_t start; int e, j; if ((pw = getpwnam("nobody")) == NULL) err(1, "no such user: nobody"); if (setgroups(1, &pw->pw_gid) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); limit.rlim_cur = limit.rlim_max = 1000; if (setrlimit(RLIMIT_NPTS, &limit) < 0) err(1, "setrlimit"); signal(SIGALRM, hand); signal(SIGILL, hand); signal(SIGFPE, hand); signal(SIGSEGV, hand); signal(SIGBUS, hand); signal(SIGURG, hand); signal(SIGSYS, hand); signal(SIGTRAP, hand); start = time(NULL); while ((time(NULL) - start) < 120) { if (fork() == 0) { for (j = 0; j < 1; j++) if ((e = pthread_create(&cp[j], NULL, calls, NULL)) != 0) errc(1, e,"pthread_create"); for (j = 0; j < 1; j++) pthread_join(cp[j], NULL); _exit(0); } wait(NULL); } return (0); } diff --git a/tools/test/stress2/misc/mmap18.sh b/tools/test/stress2/misc/mmap18.sh index 065b5bb7df6c..f2b19c07fe60 100755 --- a/tools/test/stress2/misc/mmap18.sh +++ b/tools/test/stress2/misc/mmap18.sh @@ -1,308 +1,303 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Copy of mmap10.sh with core dump disabled. # http://people.freebsd.org/~pho/stress/log/kostik711.txt # panic: vm_fault_copy_entry: main object missing page # http://people.freebsd.org/~pho/stress/log/mmap18.txt # Fixed by: r316689 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > mmap18.c mycc -o mmap18 -Wall -Wextra -O2 mmap18.c -lpthread || exit 1 rm -f mmap18.c s=0 wire=$((`sysctl -n vm.max_user_wired` - \ `sysctl -n vm.stats.vm.v_user_wire_count`)) /tmp/mmap18 $wire & start=`date +%s` while true; do e=$((`date +%s` - start)) pgrep -q mmap18 || break if [ $e -gt 900 ]; then pgrep mmap18 | xargs ps -lHp pkill mmap18 break; fi sleep 10 done wait $!; s=$? rm -f /tmp/mmap18 /tmp/mmap18.core exit $s EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define LOOPS 50 #define N (128 * 1024 / (int)sizeof(u_int32_t)) #define PARALLEL 50 static u_int32_t r[N]; static void *p; +static int debug; /* set to 1 for debug output */ static unsigned long makearg(void) { unsigned long val; unsigned int i; val = arc4random(); i = arc4random() % 100; if (i < 20) val = val & 0xff; if (i >= 20 && i < 40) val = val & 0xffff; if (i >= 40 && i < 60) val = (unsigned long)(r) | (val & 0xffff); #if defined(__LP64__) if (i >= 60) { val = (val << 32) | arc4random(); if (i > 80) val = val & 0x00007fffffffffffUL; } #endif return (val); } static void * makeptr(void) { unsigned long val; if (p != MAP_FAILED && p != NULL) val = (unsigned long)p + arc4random(); else val = makearg(); val = trunc_page(val); return ((void *)val); } static void * tmmap(void *arg __unused) { size_t len; int i, fd; pthread_set_name_np(pthread_self(), __func__); len = 1LL * 1024 * 1024 * 1024; for (i = 0; i < 100; i++) { if ((fd = open("/dev/zero", O_RDWR)) == -1) err(1,"open()"); if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0)) != MAP_FAILED) { usleep(100); munmap(p, len); } if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0)) != MAP_FAILED) { usleep(100); munmap(p, len); } close(fd); } return (NULL); } static void * tmlock(void *arg __unused) { int i, n; size_t len; pthread_set_name_np(pthread_self(), __func__); n = 0; for (i = 0; i < 200; i++) { len = trunc_page(makearg()); if (mlock(makeptr(), len) == 0) n++; len = trunc_page(makearg()); if (arc4random() % 100 < 50) if (munlock(makeptr(), len) == 0) n++; } -#if defined(DEBUG) - if (n < 10) + if (debug != 0 && n < 10) fprintf(stderr, "Note: tmlock() only succeeded %d " "times.\n", n); -#endif return (NULL); } static void * tmprotect(void *arg __unused) { void *addr; size_t len; int i, n, prot; pthread_set_name_np(pthread_self(), __func__); n = 0; for (i = 0; i < 200; i++) { addr = makeptr(); len = trunc_page(makearg()); prot = makearg(); if (mprotect(addr, len, prot) == 0) n++; usleep(1000); } -#if defined(DEBUG) - if (n < 10) + if (debug != 0 && n < 10) fprintf(stderr, "Note: tmprotect() only succeeded %d " "times.\n", n); -#endif return (NULL); } static void * tmlockall(void *arg __unused) { int flags, i, n; pthread_set_name_np(pthread_self(), __func__); n = 0; for (i = 0; i < 200; i++) { flags = makearg(); if (mlockall(flags) == 0) n++; usleep(100); munlockall(); usleep(1000); } -#if defined(DEBUG) - if (n < 10) + if (debug != 0 && n < 10) fprintf(stderr, "Note: tmlockall() only succeeded %d " "times.\n", n); -#endif return (NULL); } static void test(void) { pthread_t tid[4]; int i, rc; if ((rc = pthread_create(&tid[0], NULL, tmmap, NULL)) != 0) errc(1, rc, "tmmap()"); if ((rc = pthread_create(&tid[1], NULL, tmlock, NULL)) != 0) errc(1, rc, "tmlock()"); if ((rc = pthread_create(&tid[2], NULL, tmprotect, NULL)) != 0) errc(1, rc, "tmprotect()"); if ((rc = pthread_create(&tid[3], NULL, tmlockall, NULL)) != 0) errc(1, rc, "tmlockall()"); for (i = 0; i < 100; i++) { if (fork() == 0) { usleep(10000); _exit(0); } wait(NULL); } for (i = 0; i < 4; i++) if ((rc = pthread_join(tid[i], NULL)) != 0) errc(1, rc, "pthread_join(%d)", i); _exit(0); } int main(int argc, char *argv[]) { struct rlimit rl; rlim_t maxlock; int i, j; if (argc != 2) { fprintf(stderr, "Usage:%s \n", argv[0]); exit(1); } rl.rlim_max = rl.rlim_cur = 0; if (setrlimit(RLIMIT_CORE, &rl) == -1) warn("setrlimit"); if (getrlimit(RLIMIT_MEMLOCK, &rl) == -1) warn("getrlimit"); maxlock = atol(argv[1]); if (maxlock <= 0) errx(1, "Bad argument %jd", maxlock); maxlock = (maxlock / 10 * 8) / PARALLEL * PAGE_SIZE; if (maxlock < rl.rlim_cur) { rl.rlim_max = rl.rlim_cur = maxlock; if (setrlimit(RLIMIT_MEMLOCK, &rl) == -1) warn("setrlimit"); } for (i = 0; i < N; i++) r[i] = arc4random(); for (i = 0; i < LOOPS; i++) { for (j = 0; j < PARALLEL; j++) { if (fork() == 0) test(); } for (j = 0; j < PARALLEL; j++) wait(NULL); } return (0); } diff --git a/tools/test/stress2/misc/mmap32.sh b/tools/test/stress2/misc/mmap32.sh index a775b756084e..334327a85989 100755 --- a/tools/test/stress2/misc/mmap32.sh +++ b/tools/test/stress2/misc/mmap32.sh @@ -1,202 +1,201 @@ #!/bin/sh # # Copyright (c) 2017 Dell EMC Isilon # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Bug 223732 - mmap(2) causes unkillable denial of service with specific # flags # Test scenario inspired by: Arto Pekkanen # Fixed by r326098. . ../default.cfg dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/mmap32.c mycc -o mmap32 -Wall -Wextra -O0 -g mmap32.c || exit 1 rm -f mmap32.c $dir/mmap32 s=$? [ -f mmap32.core -a $s -eq 0 ] && { ls -l mmap32.core; mv mmap32.core /tmp; s=1; } rm -rf $dir/mmap32 exit $s EOF #include #include #include #include #include #include #include #include #include #define N 4096 +static int debug; /* set to 1 for debug output */ static uint32_t r[N]; static unsigned long makearg(void) { unsigned int i; unsigned long val; val = arc4random(); i = arc4random() % 100; if (i < 20) val = val & 0xff; if (i >= 20 && i < 40) val = val & 0xffff; if (i >= 40 && i < 60) val = (unsigned long)(r) | (val & 0xffff); #if defined(__LP64__) if (i >= 60) { val = (val << 32) | arc4random(); if (i > 80) val = val & 0x00007fffffffffffUL; } #endif return(val); } static void fuzz(int arg, void *addr, size_t len, int prot, int flags, int fd, off_t offset) { time_t start; void *vp; int n; setproctitle("arg%d", arg); n = 0; start = time(NULL); while (time(NULL) - start < 10) { switch (arg) { case 1: addr = (void *)makearg(); break; case 2: len = makearg(); break; case 3: prot = makearg(); break; case 4: flags = makearg(); break; case 5: fd = makearg(); break; case 6: offset = makearg() & 0xffff; break; case 34: prot = makearg(); flags = makearg(); break; default: errx(1, "Bad argument %d to %s", arg, __func__); } vp = mmap(addr, len, prot, flags, fd, offset); if (vp != MAP_FAILED) { munmap(vp, len); n++; } } -#if defined(DEBUG) - if (n == 0 && arg != 5) + if (debug != 0 &&n == 0 && arg != 5) fprintf(stderr, "%s(%d) failed\n", __func__, arg); -#endif exit(0); } int main(void) { off_t offset; pid_t pid; size_t len; struct rlimit rl; time_t start; void *addr, *vp; int e, flags, fd, i, prot, status; e = 0; rl.rlim_max = rl.rlim_cur = 0; if (setrlimit(RLIMIT_CORE, &rl) == -1) warn("setrlimit"); addr = 0; len = PAGE_SIZE; prot = PROT_READ | PROT_WRITE; flags = MAP_ANON | MAP_SHARED; fd = -1; offset = 0; vp = mmap(addr, len, prot, flags, fd, offset); if (vp == MAP_FAILED) err(1, "initail mmap"); munmap(vp, len); start = time(NULL); while (time(NULL) - start < 120) { for (i = 0; i < N; i++) r[i] = arc4random(); for (i = 0; i < 6; i++) { if ((pid = fork()) == 0) fuzz(i + 1, addr, len, prot, flags, fd, offset); if (waitpid(pid, &status, 0) != pid) err(1, "waitpid %d", pid); if (status != 0) { if (WIFSIGNALED(status)) fprintf(stderr, "pid %d exit signal %d\n", pid, WTERMSIG(status)); } e += status == 0 ? 0 : 1; } if ((pid = fork()) == 0) fuzz(34, addr, len, prot, flags, fd, offset); if (waitpid(pid, &status, 0) != pid) err(1, "waitpid %d", pid); if (status != 0) { if (WIFSIGNALED(status)) fprintf(stderr, "pid %d exit signal %d\n", pid, WTERMSIG(status)); } e += status == 0 ? 0 : 1; } return (e); } diff --git a/tools/test/stress2/misc/poll2.sh b/tools/test/stress2/misc/poll2.sh index 7c0aff9c78ca..aa5ad5f995dd 100755 --- a/tools/test/stress2/misc/poll2.sh +++ b/tools/test/stress2/misc/poll2.sh @@ -1,212 +1,212 @@ #!/bin/sh # # SPDX-License-Identifier: BSD-2-Clause # # Copyright (c) 2019 Dell EMC Isilon # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Test of pipe_poll() # https://reviews.freebsd.org/D21333 # No problems seen. # markj@ write: # A simplified reproducible might be tricky to come up with. I think this # would do it: # # - Thread W writes 8KB (PIPE_MINDIRECT) of data to a pipe at a time. # - Thread P poll()s the pipe for POLLIN. # - Thread R reads 8KB of data from the pipe at a time. # # Thread P uses non-blocking poll() (timeout == 0). When thread P does # not see POLLIN, it signals the reader and the writer and continues # polling in a loop. When thread P sees POLLIN it signals the reader and # sleeps until the reader returns and wakes it up. After threads R and W # finish their respective system calls, they always wait for another # signal from P before doing anything. # # Basically, if all three threads are executing their respective system # calls, and the reader has drained the writer's data and awoken the # writer, there is a window where poll() will return POLLIN even though # all data has been read. If the reader then attempts to read() from the # pipe again, it will block and the application appears to be hung. . ../default.cfg dir=/tmp odir=`pwd` cd $dir rm -f $dir/poll2.c || exit 1 sed '1,/^EOF/d' < $odir/$0 > $dir/poll2.c mycc -o poll2 -Wall -Wextra -O0 -g poll2.c -lpthread || exit 1 cpuset -l 0 $dir/poll2 s=$? pkill swap wait rm -rf poll2 poll2.c poll2.core exit $s EOF #include #include #include #include #include #include #include #include #include #include #include static volatile int done, frd, fwr, fpl; static int fds[2]; static char b1[8192], b2[8192]; #define RUNTIME (2 * 60) #define LOOP 400000 static void * wr(void *data __unused) { int i; for (i = 0; i < LOOP; i++) { pthread_set_name_np(pthread_self(), "wr-idle"); while (fwr == 0) usleep(5); pthread_set_name_np(pthread_self(), "wr-act"); fpl = 1; if (write(fds[1], b1, sizeof(b1)) != sizeof(b1)) err(1, "write"); fpl = 1; fwr = 0; } return (NULL); } static void * rd(void *data __unused) { int i; for (i = 0; i < LOOP; i++) { fpl = 1; pthread_set_name_np(pthread_self(), "rd-idle"); while (frd == 0) usleep(5); pthread_set_name_np(pthread_self(), "rd-act"); if (read(fds[0], b2, sizeof(b2)) != sizeof(b2)) err(1, "read"); frd = 0; fpl = 1; } done = 1; return (NULL); } static void * pl(void *data __unused) { struct pollfd pfd; - int i, r; + int r; pfd.fd = fds[0]; pfd.events = POLLIN; - for (i = 0; done == 0; i++) { + while (done == 0) { pfd.fd = fds[0]; pfd.events = POLLIN; pthread_set_name_np(pthread_self(), "pl-idle"); pthread_set_name_np(pthread_self(), "pl-act"); while (fpl == 0) usleep(5); again: if ((r = poll(&pfd, 1, 0)) == -1) err(1, "poll"); if (done == 1) return (NULL); if (r == 0) { frd = fwr = 1; goto again; } else { fpl = 0; frd = fwr = 1; } } return (NULL); } void test(void) { pthread_t tid[3]; int rc; if (pipe(fds) == -1) err(1, "pipe"); done = 0; fpl = 0; frd = 0; fwr = 0; if ((rc = pthread_create(&tid[0], NULL, rd, NULL)) != 0) errc(1, rc, "pthread_create"); if ((rc = pthread_create(&tid[1], NULL, wr, NULL)) != 0) errc(1, rc, "pthread_create"); if ((rc = pthread_create(&tid[2], NULL, pl, NULL)) != 0) errc(1, rc, "pthread_create"); frd = 1; fwr = 1; if ((rc = pthread_join(tid[0], NULL)) != 0) errc(1, rc, "pthread_join"); if ((rc = pthread_join(tid[1], NULL)) != 0) errc(1, rc, "pthread_join"); if ((rc = pthread_join(tid[2], NULL)) != 0) errc(1, rc, "pthread_join"); close(fds[0]); close(fds[1]); } int main(void) { time_t start; alarm(600); start = time(NULL); while ((time(NULL) - start) < RUNTIME) { test(); } return (0); } diff --git a/tools/test/stress2/misc/procfs4.sh b/tools/test/stress2/misc/procfs4.sh index ffa812a7f73d..18e5c0a6f803 100755 --- a/tools/test/stress2/misc/procfs4.sh +++ b/tools/test/stress2/misc/procfs4.sh @@ -1,156 +1,155 @@ #!/bin/sh # # Copyright (c) 2012 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Test scenario idea by kib@ # "panic: double fault" seen due to recursion [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg mount | grep -q procfs || mount -t procfs procfs /proc here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > procfs4.c mycc -o procfs4 -Wall -Wextra -O2 procfs4.c || exit 1 rm -f procfs4.c cd $here su $testuser -c /tmp/procfs4 e=$? rm -f /tmp/procfs4 exit $e EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define LOOPS 1000 #define MAXRUN 1200 #define PARALLEL 10 +static int debug; /* Set to 1 for debug output */ char *files[] = { "cmdline", "ctl", "dbregs", "etype", "file", "fpregs", "map", "mem", "note", "notepg", "osrel", "regs", "rlimit", "status" }; void test(void) { pid_t p; int fd, i, j, n, opens; char path[128]; for (i = 0; i < 64; i++) { if ((p = fork()) == 0) { setproctitle("Sleeper"); usleep(20000); usleep(arc4random() % 200); for (j = 0; j < 10000; j++) getpid(); _exit(0); } opens = 0; setproctitle("load"); for (j = 0; j < 14; j++) { snprintf(path, sizeof(path), "/proc/%d/%s", p, files[j]); if ((fd = open(path, O_RDWR)) == -1) if ((fd = open(path, O_RDONLY)) == -1) continue; ioctl(fd, FIONREAD, &n); if (ioctl(fd, FIONBIO, &n) != -1) opens++; close(fd); } kill(p, SIGHUP); -#if 0 - if (opens < 1) - fprintf(stderr, "Warn %d open(s) for pid %d\n", opens, getpid()); -#endif + if (debug != 0 && opens == 0) + fprintf(stderr, "No ioctl() calls succeeded.\n"); } for (i = 0; i < 64; i++) wait(NULL); _exit(0); } int main(void) { time_t start; int e, i, j; e = 0; start = time(NULL); for (i = 0; i < LOOPS; i++) { for (j = 0; j < PARALLEL; j++) { if (fork() == 0) test(); } for (j = 0; j < PARALLEL; j++) wait(NULL); usleep(10000); if (time(NULL) - start > MAXRUN) { fprintf(stderr, "FAIL Timeout\n"); e = 1; break; } } return (e); } diff --git a/tools/test/stress2/misc/sendfile25.sh b/tools/test/stress2/misc/sendfile25.sh index fa2e2b8687cd..ae755bf1d4df 100755 --- a/tools/test/stress2/misc/sendfile25.sh +++ b/tools/test/stress2/misc/sendfile25.sh @@ -1,237 +1,235 @@ #!/bin/sh # # SPDX-License-Identifier: BSD-2-Clause # # Copyright (c) 2020 Peter Holm # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # sendfile(2) test with disk read errors # "panic: vm_page_readahead_finish: 0xfffffe000d88d758 is invalid" seen: # https://people.freebsd.org/~pho/stress/log/sendfile25.txt # Test scenario suggestion by chs@ # Fixed by [ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 kldstat | grep -q geom_nop || { gnop load 2>/dev/null || exit 0 && notloaded=1; } gnop status || exit 1 . ../default.cfg dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/sendfile25.c mycc -o sendfile25 -Wall -Wextra -O0 -g sendfile25.c || exit 1 cd $odir set -e mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint [ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart gnop create /dev/md$mdstart newfs $newfs_flags -n -b $((32 * 1024)) /dev/md$mdstart.nop > /dev/null mount /dev/md$mdstart.nop $mntpoint chmod 777 $mntpoint set +e dd if=/dev/zero of=$mntpoint/file bs=416k count=1 status=none start=`date +%s` echo 'Expect: sendfile25: sendfile: sendfile25: read(), sendfile25.c:61: Broken pipe Connection reset by peer' while [ $((`date +%s` - start)) -lt 10 ]; do umount $mntpoint mount /dev/md$mdstart.nop $mntpoint ls -l $mntpoint > /dev/null gnop configure -e 5 -r 1 /dev/md$mdstart.nop /tmp/sendfile25 $mntpoint/file /dev/null 12345 gnop configure -e 5 -r 0 /dev/md$mdstart.nop done umount $mntpoint gnop destroy /dev/md$mdstart.nop mdconfig -d -u $mdstart [ $notloaded ] && gnop unload rm -f /tmp/sendfile25 /tmp/sendfile25.c exit 0 EOF #include #include #include #include #include #include #include #include #include #include #include #include int port; char *inputFile; char *outputFile; int bufsize = 4096; static void reader(void) { int tcpsock, msgsock; int on; socklen_t len; struct sockaddr_in inetaddr, inetpeer; - int n, t, *buf, fd; + int n, *buf, fd; on = 1; if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) err(1, "socket(), %s:%d", __FILE__, __LINE__); if (setsockopt(tcpsock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) err(1, "setsockopt(), %s:%d", __FILE__, __LINE__); inetaddr.sin_family = AF_INET; inetaddr.sin_addr.s_addr = INADDR_ANY; inetaddr.sin_port = htons(port); inetaddr.sin_len = sizeof(inetaddr); if (bind(tcpsock, (struct sockaddr *)&inetaddr, sizeof (inetaddr)) < 0) err(1, "bind(), %s:%d", __FILE__, __LINE__); if (listen(tcpsock, 5) < 0) err(1, "listen(), %s:%d", __FILE__, __LINE__); len = sizeof(inetpeer); if ((msgsock = accept(tcpsock, (struct sockaddr *)&inetpeer, &len)) < 0) err(1, "accept(), %s:%d", __FILE__, __LINE__); - t = 0; if ((buf = malloc(bufsize)) == NULL) err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__); if ((fd = open(outputFile, O_RDWR | O_CREAT | O_TRUNC, 0640)) == -1) err(1, "open(%s)", outputFile); for (;;) { if ((n = read(msgsock, buf, bufsize)) < 0) err(1, "read(), %s:%d", __FILE__, __LINE__); - t += n; if (n == 0) break; if ((write(fd, buf, n)) != n) err(1, "write"); } close(msgsock); close(fd); return; } static void writer(void) { int tcpsock, on; struct sockaddr_in inetaddr; struct hostent *hostent; struct stat statb; off_t off = 0; size_t size; int i, r, fd; on = 1; for (i = 1; i < 5; i++) { if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) err(1, "socket(), %s:%d", __FILE__, __LINE__); if (setsockopt(tcpsock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) err(1, "setsockopt(), %s:%d", __FILE__, __LINE__); size = getpagesize() -4; if (setsockopt(tcpsock, SOL_SOCKET, SO_SNDBUF, (void *)&size, sizeof(size)) < 0) err(1, "setsockopt(SO_SNDBUF), %s:%d", __FILE__, __LINE__); hostent = gethostbyname ("localhost"); memcpy (&inetaddr.sin_addr.s_addr, hostent->h_addr, sizeof (struct in_addr)); inetaddr.sin_family = AF_INET; inetaddr.sin_port = htons(port); inetaddr.sin_len = sizeof(inetaddr); r = connect(tcpsock, (struct sockaddr *) &inetaddr, sizeof(inetaddr)); if (r == 0) break; sleep(1); close(tcpsock); } if (r < 0) err(1, "connect(), %s:%d", __FILE__, __LINE__); if (stat(inputFile, &statb) != 0) err(1, "stat(%s)", inputFile); if ((fd = open(inputFile, O_RDONLY)) == -1) err(1, "open(%s)", inputFile); off = 12 * 32 * 1024; if (sendfile(fd, tcpsock, 0, statb.st_size, NULL, &off, 0) == -1) err(1, "sendfile"); return; } int main(int argc, char **argv) { pid_t pid; if (argc != 4) { fprintf(stderr, "Usage: %s 0) { reader(); kill(pid, SIGINT); } else err(1, "fork(), %s:%d", __FILE__, __LINE__); return (0); } diff --git a/tools/test/stress2/misc/setsockopt2.sh b/tools/test/stress2/misc/setsockopt2.sh index 44ed98320404..13cc3175cce3 100755 --- a/tools/test/stress2/misc/setsockopt2.sh +++ b/tools/test/stress2/misc/setsockopt2.sh @@ -1,208 +1,211 @@ #!/bin/sh # # SPDX-License-Identifier: BSD-2-Clause # # Copyright (c) 2019 Dell EMC Isilon # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # "panic: Assertion in_epoch(net_epoch_preempt) failed at raw_ip6.c:742" # https://people.freebsd.org/~pho/stress/log/setsockopt2.txt . ../default.cfg [ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/setsockopt2.c mycc -o setsockopt2 -Wall -Wextra -O0 -g setsockopt2.c || exit 1 rm -f setsockopt2.c cd $odir set -e mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint [ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart newfs $newfs_flags md$mdstart > /dev/null mount /dev/md$mdstart $mntpoint set +e (cd ../testcases/swap; ./swap -t 5m -i 20) & cd $mntpoint $dir/setsockopt2 s=$? [ -f setsockopt2.core -a $s -eq 0 ] && { ls -l setsockopt2.core; mv setsockopt2.core $dir; s=1; } cd $odir while pkill swap; do :; done wait for i in `jot 6`; do mount | grep -q "on $mntpoint " || break umount $mntpoint && break || sleep 10 [ $i -eq 6 ] && { echo FATAL; fstat -mf $mntpoint; exit 1; } done mdconfig -d -u $mdstart rm -rf $dir/setsockopt2 exit $s EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include +static int debug; /* set to 1 for debug output */ static volatile u_int *share; #define PARALLEL 128 #define RUNTIME (2 * 60) #define SYNC 0 static void test(void) { struct sockaddr_un sun; pid_t pid; time_t start; char file[80]; int domain, fd, i, one, prot, success, typ; success = 0; snprintf(file, sizeof(file), "setsockopt2.socket.%d", getpid()); memset(&sun, 0, sizeof(sun)); sun.sun_family = AF_LOCAL; sun.sun_len = sizeof(sun); snprintf(sun.sun_path, sizeof(sun.sun_path), "%s", file); unlink(file); start = time(NULL); while (time(NULL) - start < 30) { share[SYNC] = 0; fd = -1; while (fd == -1) { domain = arc4random() % 256; typ = arc4random() % 10; if (arc4random() % 100 < 20) prot = arc4random() % 10; else prot = 0; if ((fd = socket(domain, typ, prot)) == -1) continue; close(fd); } pid = fork(); if (pid < 0) err(1, "fork"); if (pid == 0) { // listen fd = socket(domain, typ, prot); if (fd < 0) _exit(0); one = 1; if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0) err(1, "setsockopt"); if (bind(fd, (struct sockaddr *)&sun, sizeof(sun)) < 0) _exit(0); if (listen(fd, 10) == 0) { share[SYNC] = 1; usleep(random() % 10000); } (void)close(fd); (void)unlink(file); _exit(0); } fd = socket(domain, typ, prot); if (fd == -1) goto bad; setsockopt(fd, 0xffff, 0x80, 0x0, 0x0); sun.sun_len = arc4random() % 128; sun.sun_family = arc4random() % 10; setsockopt(fd, 0x6, 0x401, &sun, 0x14); for (i = 0; share[SYNC] == 0 && i < 10; i++) usleep(100); if (connect(fd, (struct sockaddr *)&sun, sizeof(sun)) != -1) success++; usleep(random() % 100); bad: (void)close(fd); if (waitpid(pid, NULL, 0) != pid) err(1, "waitpid(%d)", pid); } + if (debug != 0 && success == 0) + fprintf(stderr, "No calls to connect() succeded.\n"); _exit(0); } int main(void) { pid_t pids[PARALLEL]; size_t len; time_t start; int e, i, status; e = 0; len = PAGE_SIZE; if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) err(1, "mmap"); start = time(NULL); while ((time(NULL) - start) < RUNTIME) { for (i = 0; i < PARALLEL; i++) { if ((pids[i] = fork()) == 0) test(); if (pids[i] == -1) err(1, "fork()"); } for (i = 0; i < PARALLEL; i++) { if (waitpid(pids[i], &status, 0) == -1) err(1, "waitpid(%d)", pids[i]); if (status != 0) { if (WIFSIGNALED(status)) fprintf(stderr, "pid %d exit signal %d\n", pids[i], WTERMSIG(status)); } e += status == 0 ? 0 : 1; } } return (e); }