4 # Copyright (c) 2016 EMC Corp.
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
29 # Test effort to reproduce reported: "observed a hang in a multi-threaded
30 # process that had hit an assertion failure and was attempting to dump core".
33 # Most interesting load are:
34 # - coredumping of the multithreaded program with the current dir on NFS,
35 # which also accesses NFS files;
36 # - advisory locking tests on NFS files, while e.g. sending SIGSTOP/SIGCONT
37 # to the test programs.
39 # See also pthread9.sh
41 # https://people.freebsd.org/~pho/stress/log/kostik897.txt
44 # "panic: mutex sleepq chain not owned at subr_sleepqueue.c:1009" seen:
45 # https://people.freebsd.org/~pho/stress/log/kostik914.txt
48 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
52 [ -z "$nfs_export" ] && exit 0
53 ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 ||
59 sed '1,/^EOF/d' < $here/$0 > nfs15.c
60 mycc -o nfs15 -Wall -Wextra -O2 -g nfs15.c -lpthread || exit 1
64 mount | grep "on $mntpoint " | grep nfs > /dev/null && umount $mntpoint
66 mount -t nfs -o tcp -o retrycnt=3 -o intr,soft -o rw -o nolockd \
67 $nfs_export $mntpoint || exit 1
69 wd=$mntpoint/nfs15.dir
76 while mount | grep "on $mntpoint " | grep -q nfs; do
77 umount $mntpoint || sleep 1
84 #include <sys/param.h>
88 #include <machine/atomic.h>
104 volatile u_int *share;
107 t1(void *data __unused)
109 atomic_add_int(&share[SYNC], 1);
110 usleep(arc4random() % 8000);
117 t2(void *data __unused)
122 for (i = 0; i < 100; i++) {
123 atomic_add_int(&share[SYNC], 1);
124 snprintf(file, sizeof(file), "file.%06d", i);
125 if ((fd = open(file, O_WRONLY | O_CREAT | O_APPEND,
127 err(1, "open(%s)", file);
129 r = lockf(fd, F_LOCK, 0);
130 } while (r == -1 && errno == EDEADLK);
132 err(1, "lockf(%s, F_LOCK)", file);
134 if (lseek(fd, 0, SEEK_SET) == -1)
136 if (lockf(fd, F_ULOCK, 0) == -1)
137 err(1, "lockf(%s, F_ULOCK)", file);
150 for (i = 0; i < 10; i++) {
151 if ((rc = pthread_create(&tid[0], NULL, t2, NULL)) == -1)
152 errc(1, rc, "pthread_create");
153 if ((rc = pthread_create(&tid[1], NULL, t2, NULL)) == -1)
154 errc(1, rc, "pthread_create");
155 if ((rc = pthread_create(&tid[2], NULL, t1, NULL)) == -1)
156 errc(1, rc, "pthread_create");
158 if ((rc = pthread_join(tid[0], NULL)) == -1)
159 errc(1, rc, "pthread_join");
160 if ((rc = pthread_join(tid[1], NULL)) == -1)
161 errc(1, rc, "pthread_join");
162 if ((rc = pthread_join(tid[2], NULL)) == -1)
163 errc(1, rc, "pthread_join");
172 pid_t pids[PARALLEL];
178 if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE,
179 MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED)
183 while (time(NULL) - start < RUNTIME) {
184 for (i = 0; i < PARALLEL; i++) {
185 if ((pids[i] = fork()) == 0)
191 atomic_add_int(&share[SYNC], -1);
192 for (i = 0; i < PARALLEL; i++)
193 kill(pids[i], SIGSTOP);
194 usleep(100 + arc4random() % 1000);
195 for (i = 0; i < PARALLEL; i++)
196 kill(pids[i], SIGCONT);
197 usleep(100 + arc4random() % 400);
198 if (share[SYNC] == 0) { /* If all procs are done */
200 if (share[SYNC] == 0)
205 for (i = 0; i < PARALLEL; i++) {
206 if (waitpid(pids[i], &status, 0) != pids[i])