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
32 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
37 sed '1,/^EOF/d' < $odir/$0 > $dir/pipe2.c
38 mycc -o pipe2 -Wall -Wextra -O0 -g pipe2.c || exit 1
41 daemon sh -c "(cd $odir/../testcases/swap; ./swap -t 10m -i 20)" > \
45 su $testuser -c /tmp/pipe2
48 while pgrep -q swap; do
56 #include <sys/param.h>
59 #include <machine/atomic.h>
69 volatile u_int *share, *share2;
71 #define R1 1 /* sync start */
72 #define R2 2 /* forks */
78 hand(int i __unused) { /* handler */
79 fprintf(stderr, "Timed out\n");
91 if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE,
92 MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED)
98 write(fds[1], &token, sizeof(token));
100 if (share[R2] >= PIPES)
102 if ((r = fork()) == 0) {
103 atomic_add_int(&share[R2], 1);
104 if (read(fds[0], &token, sizeof(token)) != sizeof(token))
110 if (write(fds[1], &token, sizeof(token)) != sizeof(token))
119 if (share[R2] == PIPES) {
121 if (read(fds[0], &token, sizeof(token)) != sizeof(token))
122 err(1, "final read");
123 fprintf(stderr, "FINAL read %d from %d\n", token, fds[0]);
125 atomic_add_int(&share2[R1], 1);
138 if ((share2 = mmap(NULL, len, PROT_READ | PROT_WRITE,
139 MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED)
142 sa.sa_handler = SIG_IGN;
143 sigemptyset(&sa.sa_mask);
145 if (sigaction(SIGCHLD, &sa, 0) == -1)
148 for (i = 0; i < PARALLEL; i++) {
153 signal(SIGALRM, hand);
155 while (share2[R1] != PARALLEL) {
158 fprintf(stderr, "share2 = %d\n", share2[R1]);