1 #define _POSIX_C_SOURCE 200809L
13 #define T(t) void t();
18 static const char *name;
24 static void errtimer() { error("use *_timer in benchmarks only\n"); }
26 void start_timer() { errtimer(); }
27 void stop_timer() { errtimer(); }
28 void reset_timer() { errtimer(); }
30 void error__(const char *n, int l, const char *s, ...) {
34 fprintf(stderr, "- ERROR %s at %s:%d: ", name, n, l);
36 vfprintf(stderr, s, ap);
40 static void run(const char *n, void (*f)()) {
48 fprintf(stderr, "running %s:\n", name);
52 /* run test in a child process */
58 error("fork failed: %s\n", strerror(errno));
60 if (waitpid(pid, &s, 0) == -1)
61 error("waitpid failed: %s\n", strerror(errno));
62 else if (!WIFEXITED(s))
63 error("abnormal exit: %s\n", WIFSIGNALED(s) ? strsignal(WTERMSIG(s)) : "(unknown)");
65 failed = !!WEXITSTATUS(s);
70 fprintf(stderr, "FAILED %s\n", name);
72 fprintf(stderr, "PASSED %s\n", name);
75 static int summary() {
76 fprintf(stderr, "PASS:%d FAIL:%d\n", count-nfailed, nfailed);
81 #define T(t) run(#t, t);