9 #include <sys/resource.h>
14 #define T(f) void f();
19 static const char *name;
26 static void errtimer() { error("use *_timer in benchmarks only\n"); }
27 void start_timer() { errtimer(); }
28 void stop_timer() { errtimer(); }
29 void reset_timer() { errtimer(); }
31 void error__(const char *n, int l, const char *s, ...) {
34 if (failed == 0 && nfailed == 0)
37 dprintf(1, " ERROR %s %s:%d: ", name, n, l);
43 static void setrl(int r, long lim) {
46 if (getrlimit(r, &rl))
47 error("getrlimit %d: %s\n", r, strerror(errno));
49 if (setrlimit(r, &rl))
50 error("setrlimit %d: %s\n", r, strerror(errno));
53 static void run(const char *n, void (*f)()) {
61 dprintf(1, "running %s:\n", name);
65 /* run test in a child process */
66 setrl(RLIMIT_CORE, 1<<24);
67 setrl(RLIMIT_STACK, 1<<16);
74 error("fork failed: %s\n", strerror(errno));
76 if (waitpid(pid, &s, 0) == -1)
77 error("waitpid failed: %s\n", strerror(errno));
78 else if (!WIFEXITED(s))
79 error("abnormal exit: %s\n", WIFSIGNALED(s) ? strsignal(WTERMSIG(s)) : "(unknown)");
81 failed = !!WEXITSTATUS(s);
86 dprintf(1, "FAILED %s\n", name);
88 dprintf(1, "PASSED %s\n", name);
91 static int summary() {
93 dprintf(1, "FAIL (%d out of %d tests)\n", nfailed, count);
95 dprintf(1, "ok (%d tests)\n", count);
100 dprintf(1, "usage: ./t [-vs]\n");
104 int main(int argc, char *argv[]) {
107 while((c = getopt(argc, argv, "vs")) != -1)
121 #define T(t) run(#t, t);