diff --git a/Makefile b/Makefile index dc0b6f2..13ed2cb 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ B:=src SRCS:=$(sort $(wildcard src/*/*.c)) OBJS:=$(SRCS:src/%.c=$(B)/%.o) +LOBJS:=$(SRCS:src/%.c=$(B)/%.lo) DIRS:=$(patsubst src/%/,%,$(sort $(dir $(SRCS)))) BDIRS:=$(DIRS:%=$(B)/%) NAMES:=$(SRCS:src/%.c=%) @@ -8,7 +9,7 @@ CFLAGS:=-Isrc/common -I$(B)/common LDLIBS:=$(B)/common/libtest.a AR = $(CROSS_COMPILE)ar RANLIB = $(CROSS_COMPILE)ranlib -RUN_TEST = $(RUN_WRAP) $(B)/common/runtest +RUN_TEST = $(RUN_WRAP) $(B)/common/runtest -w '$(RUN_WRAP)' all: %.mk: @@ -78,7 +79,7 @@ $(B)/$(1)/run: $(B)/$(1)/cleanerr $(B)/$(1)/REPORT $(B)/$(1)/cleanerr: rm -f $$(filter-out $(B)/$(1)/%-static.err,$$($(1).ERRS)) $(B)/$(1)/clean: - rm -f $$(filter $(B)/$(1)/%,$$(OBJS) $$(BINS) $$(LIBS)) $(B)/$(1)/*.err + rm -f $$(filter $(B)/$(1)/%,$$(OBJS) $$(LOBJS) $$(BINS) $$(LIBS)) $(B)/$(1)/*.err $(B)/$(1)/REPORT: $$($(1).ERRS) cat $(B)/$(1)/*.err >$$@ run: $(B)/$(1)/run @@ -92,6 +93,8 @@ $(B)/common/libtest.a: $(common.OBJS) $(AR) rc $@ $^ $(RANLIB) $@ +$(B)/common/all: $(B)/common/runtest + $(ERRS): $(B)/common/runtest | $(BDIRS) $(BINS) $(LIBS): $(B)/common/libtest.a $(OBJS): src/common/test.h | $(BDIRS) diff --git a/src/common/runtest.c b/src/common/runtest.c index 95e615e..28504c4 100644 --- a/src/common/runtest.c +++ b/src/common/runtest.c @@ -14,44 +14,66 @@ static void handler(int s) { } -static int start(char *argv[]) +static int start(char *wrap, char *argv[]) { int pid; pid = fork(); if (pid == 0) { t_setrlim(RLIMIT_STACK, 100*1024); - t_setrlim(RLIMIT_CPU, 2); - execv(argv[0], argv); + if (*wrap) { + argv--; + argv[0] = wrap; + } + execvp(argv[0], argv); t_error("%s exec failed: %s\n", argv[0], strerror(errno)); exit(1); } - if (pid == -1) { - t_error("%s fork failed: %s\n", argv[0], strerror(errno)); - exit(-1); - } return pid; } +static void usage(char *argv[]) +{ + t_error("usage: %s [-t timeoutsec] [-w wrapcmd] cmd [args..]\n", argv[0]); + exit(-1); +} + int main(int argc, char *argv[]) { + char *wrap = ""; + int timeoutsec = 5; + int timeout = 0; int status; sigset_t set; - int timeout = 0; - int sig = 0; + int opt; int pid; - if (argc < 2) { - t_error("usage: ./runtest cmd [args..]\n"); - return -1; + while ((opt = getopt(argc, argv, "w:t:")) != -1) { + switch (opt) { + case 'w': + wrap = optarg; + break; + case 't': + timeoutsec = atoi(optarg); + break; + default: + usage(argv); + } } - argv++; + if (optind >= argc) + usage(argv); + argv += optind; sigemptyset(&set); sigaddset(&set, SIGCHLD); sigprocmask(SIG_BLOCK, &set, 0); signal(SIGCHLD, handler); - pid = start(argv); - if (sigtimedwait(&set, 0, &(struct timespec){5,0}) == -1) { + pid = start(wrap, argv); + if (pid == -1) { + t_error("%s fork failed: %s\n", argv[0], strerror(errno)); + t_printf("FAIL %s [internal]\n", argv[0]); + return -1; + } + if (sigtimedwait(&set, 0, &(struct timespec){timeoutsec,0}) == -1) { if (errno == EAGAIN) timeout = 1; if (kill(pid, SIGKILL) == -1) @@ -59,6 +81,7 @@ int main(int argc, char *argv[]) } if (waitpid(pid, &status, 0) != pid) { t_error("%s waitpid failed: %s\n", argv[0], strerror(errno)); + t_printf("FAIL %s [internal]\n", argv[0]); return -1; } if (WIFEXITED(status)) {