2 * Copyright (c) 2008 Peter Holm <pho@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 /* Main program for all test programs */
43 static char const rcsid[] = "$Name: $ $FreeBSD$";
45 volatile int done_testing;
46 static int cleanupcalled = 0;
57 for (j = 0; j < op->incarnations; j++) {
59 printf("handler: kill -HUP %d\n", r[j]);
60 if (r[j] != 0 && kill(r[j], SIGHUP) == -1)
62 warn("kill(%d, SIGHUP), %s:%d", r[j], __FILE__, __LINE__);
66 /* test programs may have blocked for the SIGHUP, so try harder */
67 for (j = 0; j < op->incarnations; j++) {
69 printf("handler: kill -KILL %d\n", r[j]);
71 (void) kill(r[j], SIGKILL);
77 run_test_handler(int i)
93 if (cleanupcalled == 0)
103 signal(SIGHUP, run_test_handler);
104 signal(SIGINT, exit_handler);
107 if ((strcmp(getprogname(), "run") != 0) && (op->nodelay == 0))
108 sleep(random_int(1,10));
110 while (done_testing == 0 &&
111 (time(NULL) - start) < op->run_time) {
119 run_incarnations(void)
124 signal(SIGHUP, handler);
125 for (i = 0; i < op->incarnations && done_testing == 0; i++) {
126 if ((r[i] = fork()) == 0) {
130 warn("fork(), %s:%d", __FILE__, __LINE__);
135 for (i = 0; i < op->incarnations; i++)
136 if (r[i] != 0 && waitpid(r[i], &s, 0) == -1)
137 warn("waitpid(%d), %s:%d", r[i], __FILE__, __LINE__);
149 if (random_int(1,100) > op->load)
162 err(1, "fork() in %s:%d", __FILE__, __LINE__);
163 while (done_testing != 1 &&
164 (time(NULL) - start) < op->run_time)
166 if (kill(p, SIGHUP) == -1)
167 warn("kill(%d, SIGHUP), %s:%d", p, __FILE__, __LINE__);
169 if (waitpid(p, &status, 0) == -1)
170 err(1, "waitpid(%d), %s:%d", p, __FILE__, __LINE__);
176 main(int argc, char **argv)
184 if (stat(op->wd, &sb) == -1) {
185 if (mkdir(op->wd, 0770) == -1)
187 err(1, "mkdir(%s) %s:%d", op->wd, __FILE__, __LINE__);
189 if (stat(op->cd, &sb) == -1) {
190 if (mkdir(op->cd, 0770) == -1)
192 err(1, "mkdir(%s) %s:%d", op->cd, __FILE__, __LINE__);
194 if ((home = getcwd(NULL, 0)) == NULL)
195 err(1, "getcwd(), %s:%d", __FILE__, __LINE__);
196 if (chdir(op->wd) == -1)
197 err(1, "chdir(%s) %s:%d", op->wd, __FILE__, __LINE__);
199 r = (pid_t *)calloc(1, op->incarnations * sizeof(pid_t));