1 /* Repeatedly run a program. */
4 * Copyright (C) 2003-2006 IBM
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 #include <sys/types.h>
33 static char *progname
;
34 static pid_t test_pgrp
;
37 static void int_func(int signum
) {
38 pounder_fprintf(tty_fp
, "%s: Killed by interrupt. Last exit code = %d.\n",
40 kill(-test_pgrp
, SIGTERM
);
44 int main(int argc
, char *argv
[]) {
48 unsigned int revs
= 0;
51 printf("Usage: %s command [args]\n", argv
[0]);
55 tty_fp
= fdopen(3, "w+");
57 tty_fp
= fopen("/dev/tty", "w+");
64 progname
= rindex(argv
[1], '/');
65 if (progname
== NULL
) {
72 memset(&zig
, 0x00, sizeof(zig
));
73 zig
.sa_handler
= int_func
;
74 sigaction(SIGINT
, &zig
, NULL
);
75 sigaction(SIGTERM
, &zig
, NULL
);
77 /* set up process groups so that we can kill the
78 * loop test and descendants easily */
81 pounder_fprintf(tty_fp
, "%s: %s loop #%d.\n", progname
, start_msg
, revs
++);
90 stat
= execvp(argv
[1], &argv
[1]);
92 stat
= execvp(argv
[1], &argv
[1]);
100 /* save the pgrp of the spawned process */
103 // wait for it to be done
104 if (waitpid(pid
, &stat
, 0) != pid
) {
110 if (WIFSIGNALED(stat
)) {
111 pounder_fprintf(tty_fp
, "%s: %s on signal %d.\n",
112 progname
, fail_msg
, WTERMSIG(stat
));
115 res
= WEXITSTATUS(stat
);
117 pounder_fprintf(tty_fp
, "%s: %s.\n", progname
, pass_msg
);
118 } else if (res
< 0 || res
== 255) {
119 pounder_fprintf(tty_fp
, "%s: %s with code %d.\n",
120 progname
, abort_msg
, res
);
122 // FIXME: add test to blacklist
124 pounder_fprintf(tty_fp
, "%s: %s with code %d.\n",
125 progname
, fail_msg
, res
);