2 * Copyright (C) 2010 Red Hat, Inc. All rights reserved.
4 * This file is part of LVM2.
6 * This copyrighted material is made available to anyone wishing to use,
7 * modify, copy, or redistribute it subject to the terms and conditions
8 * of the GNU General Public License v.2.
10 * You should have received a copy of the GNU General Public License
11 * along with this program; if not, write to the Free Software Foundation,
12 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #include <sys/socket.h>
39 int readbuf_sz = 0, readbuf_used = 0;
49 void handler( int s ) {
56 fwrite(readbuf, 1, readbuf_used, stdout);
67 sz = read(fds[1], buf, 2048);
72 if (readbuf_used + sz >= readbuf_sz) {
73 readbuf_sz = readbuf_sz ? 2 * readbuf_sz : 4096;
74 readbuf = realloc(readbuf, readbuf_sz);
78 memcpy(readbuf + readbuf_used, buf, sz);
80 readbuf[readbuf_used] = 0;
84 void passed(int i, char *f) {
85 if (strstr(readbuf, "TEST WARNING")) {
96 void skipped(int i, char *f) {
98 s.status[i] = SKIPPED;
102 void failed(int i, char *f, int st) {
104 s.status[i] = FAILED;
106 printf("interrupted.\n");
110 printf("-- FAILED %s ------------------------------------\n", f);
112 printf("-- FAILED %s (end) ------------------------------\n", f);
115 void run(int i, char *f) {
118 perror("Fork failed.");
120 } else if (pid == 0) {
124 execlp("bash", "bash", f, NULL);
130 snprintf(buf, 128, "%s ...", f);
132 printf("Running %-40s ", buf);
135 while ((w = waitpid(pid, &st, WNOHANG)) == 0) {
145 if (WEXITSTATUS(st) == 0) {
147 } else if (WEXITSTATUS(st) == 200) {
159 int main(int argc, char **argv) {
163 fprintf(stderr, "Sorry, my head exploded. Please increase MAX.\n");
167 s.nwarned = s.nfailed = s.npassed = s.nskipped = 0;
169 char *config = getenv("LVM_TEST_CONFIG"),
171 *be_verbose = getenv("VERBOSE");
172 if (be_verbose && atoi(be_verbose))
174 config = config ? config : "";
175 asprintf(&config_debug, "%s\n%s\n", config, "log { verbose=4 }");
177 if (socketpair(PF_UNIX, SOCK_STREAM, 0, fds)) {
178 perror("socketpair");
182 if ( fcntl( fds[1], F_SETFL, O_NONBLOCK ) == -1 ) {
183 perror("fcntl on socket");
187 /* set up signal handlers */
188 for (i = 0; i <= 32; ++i) {
189 if (i == SIGCHLD || i == SIGWINCH || i == SIGURG)
195 for (i = 1; i < argc; ++ i) {
201 printf("\n## %d tests: %d OK, %d warnings, %d failures; %d skipped\n",
202 s.nwarned + s.npassed + s.nfailed + s.nskipped,
203 s.npassed, s.nwarned, s.nfailed, s.nskipped);
205 /* print out a summary */
206 if (s.nfailed || s.nskipped) {
207 for (i = 1; i < argc; ++ i) {
208 switch (s.status[i]) {
210 printf("FAILED: %s\n", argv[i]);
213 printf("skipped: %s\n", argv[i]);
218 return s.nfailed > 0 || die;