1 #define _POSIX_C_SOURCE 200809L
13 #define T(f) void f();
18 static const char *name;
24 static void errtimer() { error("use *_timer in benchmarks only\n"); }
25 void start_timer() { errtimer(); }
26 void stop_timer() { errtimer(); }
27 void reset_timer() { errtimer(); }
29 void error__(const char *n, int l, const char *s, ...) {
33 fprintf(stderr, " ERROR %s %s:%d: ", name, n, l);
35 vfprintf(stderr, s, ap);
39 static void run(const char *n, void (*f)()) {
47 fprintf(stderr, "running %s:\n", name);
51 /* run test in a child process */
57 error("fork failed: %s\n", strerror(errno));
59 if (waitpid(pid, &s, 0) == -1)
60 error("waitpid failed: %s\n", strerror(errno));
61 else if (!WIFEXITED(s))
62 error("abnormal exit: %s\n", WIFSIGNALED(s) ? strsignal(WTERMSIG(s)) : "(unknown)");
64 failed = !!WEXITSTATUS(s);
69 fprintf(stderr, "FAILED %s\n", name);
71 fprintf(stderr, "PASSED %s\n", name);
74 static int summary() {
75 fprintf(stderr, "PASS:%d FAIL:%d\n", count-nfailed, nfailed);
80 #define T(t) run(#t, t);