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 # The combination of ualarm() firing before and after the select(2) timeout
30 # triggers select() to return EINTR a number of times.
31 # Problem only seen on i386.
33 # Test scenario suggestion by kib@
35 # "FAIL n = 2389" seen on r302369, no debug build.
43 sed '1,/^EOF/d' < $odir/$0 > $dir/select.c
44 mycc -o select -Wall -Wextra -O0 -g select.c -lpthread || exit 1
54 #include <sys/param.h>
70 static pthread_barrier_t barr;
71 static sig_atomic_t alarms;
75 #define N 2000 /* also seen fail with N = 20.000 */
76 #define PARALLEL 16 /* Fails seen with 1 - 16 */
77 #define RUNTIME (10 * 60)
80 handler(int i __unused) {
90 r = pthread_barrier_wait(&barr);
91 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
92 errc(1, r, "pthread_barrier_wait");
94 signal(SIGALRM, handler);
96 for (i = 0; i < lines; i++) {
98 if (arc4random() % 100 < 50)
106 r = select(1, NULL, NULL, NULL, &tv);
108 } while (r == -1 && errno == EINTR);
113 fprintf(stderr, "FAIL n = %d, tv = %ld.%06ld\n",
114 n, (long)tv.tv_sec, tv.tv_usec);
119 fprintf(stderr, "FAIL alarms = %d\n", (int)alarms);
132 pthread_barrierattr_t attr;
134 int e, i, j, pids[PARALLEL], r, status;
136 lines = LINES / PARALLEL;
140 if ((r = pthread_barrierattr_init(&attr)) != 0)
141 errc(1, r, "pthread_barrierattr_init");
142 if ((r = pthread_barrierattr_setpshared(&attr,
143 PTHREAD_PROCESS_SHARED)) != 0)
144 errc(1, r, "pthread_barrierattr_setpshared");
145 if ((r = pthread_barrier_init(&barr, &attr, PARALLEL)) != 0)
146 errc(1, r, "pthread_barrier_init");
149 while ((time(NULL) - start) < RUNTIME && e == 0) {
150 for (i = 0; i < PARALLEL; i++) {
151 if ((pids[i] = fork()) == 0)
154 for (i = 0; i < PARALLEL; i++) {
155 waitpid(pids[i], &status, 0);
156 e += status == 0 ? 0 : 1;
158 for (j = i + 1; j < PARALLEL; j++)
159 kill(pids[j], SIGINT);
164 if ((r = pthread_barrier_destroy(&barr)) > 0)
165 errc(1, r, "pthread_barrier_destroy");