$(foreach n,$(NAMES),$(eval $(call template,$(n))))
BINS:=$(foreach n,$(NAMES),$($(n).BINS)) $(B)/api/main
-LIBS:=$(foreach n,$(NAMES),$($(n).LIBS)) $(B)/common/run
+LIBS:=$(foreach n,$(NAMES),$($(n).LIBS)) $(B)/common/runtest
ERRS:=$(BINS:%=%.err)
debug:
define target_template
$(1).ERRS:=$$(filter $(B)/$(1)/%,$$(ERRS))
$(B)/$(1)/all: $(B)/$(1)/REPORT
-# TODO: $(B)/common/run collides with the run binary target
$(B)/$(1)/run: $(B)/$(1)/cleanerr $(B)/$(1)/REPORT
$(B)/$(1)/cleanerr:
rm -f $$(filter-out $(B)/$(1)/%-static.err,$$($(1).ERRS))
$(AR) rc $@ $^
$(RANLIB) $@
-$(ERRS): $(B)/common/run | $(BDIRS)
+$(ERRS): $(B)/common/runtest | $(BDIRS)
$(BINS) $(LIBS): $(B)/common/libtest.a
$(OBJS): src/common/test.h | $(BDIRS)
$(BDIRS):
all:$(B)/REPORT
run:$(B)/REPORT
clean:
- rm -f $(OBJS) $(BINS) $(LIBS) $(B)/common/libtest.a $(B)/common/run $(B)/*/*.err
+ rm -f $(OBJS) $(BINS) $(LIBS) $(B)/common/libtest.a $(B)/common/runtest $(B)/*/*.err
cleanall: clean
rm -f $(B)/REPORT $(B)/*/REPORT
$(B)/REPORT:
%.ld.err: %
touch $@
%.err: %
- $(B)/common/run ./$< 2>/dev/null >$@ || true
+ $(B)/common/runtest ./$< >$@ || true
.PHONY: all run clean cleanall
#define T2(f,w) (result=(f), result==(w) || (t_error("%s failed: got %s, want %s\n", #f, result, w),0))
binaries should be possible to run from arbitrary directory.
-the build system runs the tests using the src/common/run tool which
+the build system runs the tests using the src/common/runtest tool which
kills the test process after a timeout and reports the exit status
in case of failure
+++ /dev/null
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <signal.h>
-#include <time.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-#include <unistd.h>
-#include "test.h"
-
-static void handler(int s)
-{
-}
-
-static int start(char *argv[])
-{
- int pid;
-
- pid = fork();
- if (pid == 0) {
- t_setrlim(RLIMIT_STACK, 100*1024);
- t_setrlim(RLIMIT_CPU, 2);
- execv(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;
-}
-
-int main(int argc, char *argv[])
-{
- int status;
- sigset_t set;
- int timeout = 0;
- int sig = 0;
- int pid;
-
- if (argc < 2) {
- t_error("usage: ./run cmd [args..]\n");
- return -1;
- }
- argv++;
- 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) {
- if (errno == EAGAIN)
- timeout = 1;
- if (kill(pid, SIGKILL) == -1)
- t_error("%s kill failed: %s\n", argv[0], strerror(errno));
- }
- if (waitpid(pid, &status, 0) != pid) {
- t_error("%s waitpid failed: %s\n", argv[0], strerror(errno));
- return -1;
- }
- if (WIFEXITED(status)) {
- if (WEXITSTATUS(status) == 0)
- return 0;
- t_printf("FAIL %s [status %d]\n", argv[0], WEXITSTATUS(status));
- } else if (timeout) {
- t_printf("FAIL %s [timed out]\n", argv[0]);
- } else if (WIFSIGNALED(status)) {
- t_printf("FAIL %s [signal %s]\n", argv[0], strsignal(WTERMSIG(status)));
- } else
- t_printf("FAIL %s [unknown]\n", argv[0]);
- return 1;
-}
--- /dev/null
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <signal.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <unistd.h>
+#include "test.h"
+
+static void handler(int s)
+{
+}
+
+static int start(char *argv[])
+{
+ int pid;
+
+ pid = fork();
+ if (pid == 0) {
+ t_setrlim(RLIMIT_STACK, 100*1024);
+ t_setrlim(RLIMIT_CPU, 2);
+ execv(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;
+}
+
+int main(int argc, char *argv[])
+{
+ int status;
+ sigset_t set;
+ int timeout = 0;
+ int sig = 0;
+ int pid;
+
+ if (argc < 2) {
+ t_error("usage: ./runtest cmd [args..]\n");
+ return -1;
+ }
+ argv++;
+ 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) {
+ if (errno == EAGAIN)
+ timeout = 1;
+ if (kill(pid, SIGKILL) == -1)
+ t_error("%s kill failed: %s\n", argv[0], strerror(errno));
+ }
+ if (waitpid(pid, &status, 0) != pid) {
+ t_error("%s waitpid failed: %s\n", argv[0], strerror(errno));
+ return -1;
+ }
+ if (WIFEXITED(status)) {
+ if (WEXITSTATUS(status) == 0)
+ return t_status;
+ t_printf("FAIL %s [status %d]\n", argv[0], WEXITSTATUS(status));
+ } else if (timeout) {
+ t_printf("FAIL %s [timed out]\n", argv[0]);
+ } else if (WIFSIGNALED(status)) {
+ t_printf("FAIL %s [signal %s]\n", argv[0], strsignal(WTERMSIG(status)));
+ } else
+ t_printf("FAIL %s [unknown]\n", argv[0]);
+ return 1;
+}