12 #define T(f) void f();
17 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() {
76 fprintf(stderr, "FAIL:%d (all: %d)\n", nfailed, count);
78 fprintf(stderr, "PASS (all: %d)\n", count);
83 fprintf(stderr, "usage: ./t [-vs]\n");
87 int main(int argc, char *argv[]) {
90 while((c = getopt(argc, argv, "vs")) != -1)
104 #define T(t) run(#t, t);