use dprintf(1,..) instead of buffered stderr
authornsz <nsz@port70.net>
Tue, 27 Mar 2012 11:53:36 +0000 (13:53 +0200)
committernsz <nsz@port70.net>
Tue, 27 Mar 2012 11:53:36 +0000 (13:53 +0200)
Makefile
Makefile.inc
common/b.c
common/t.c
src/udiv/udiv.c

index dc5c6fd..ad17b56 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,10 @@
 DIRS = $(sort $(wildcard src/*))
 
 all:
 DIRS = $(sort $(wildcard src/*))
 
 all:
-       for i in $(DIRS); do echo $$i; make -s -C $$i; done
-t: all
-#      for i in $(DIRS); do echo $$i; $$i/t; done
-b: all
-       for i in $(DIRS); do echo $$i; $$i/b; done
+       for i in $(DIRS); do printf "%-20s" $$i; make -s -C $$i; done
+t:
+       @for i in $(DIRS); do printf "%-20s" $$i; make -s -C $$i 2>/dev/null; done
+b: t
+       @for i in $(DIRS); do echo $$i; $$i/b; done
 clean:
        for i in $(DIRS); do make -s -C $$i clean; done
 clean:
        for i in $(DIRS); do make -s -C $$i clean; done
index 4613e08..f0ebc00 100644 (file)
@@ -9,7 +9,7 @@ OBJS = $(SRCS:.c=.o)
 AR=ar
 RANLIB=ranlib
 
 AR=ar
 RANLIB=ranlib
 
-CFLAGS += -g -D_POSIX_C_SOURCE=200809L -std=c99 -pipe -Wall
+CFLAGS += -g -D_POSIX_C_SOURCE=200809L -std=c99 -pipe -Wall -Wno-unused-function
 LDFLAGS += -g -lpthread -lrt -lm
 
 -include $(TROOT)/config.mak
 LDFLAGS += -g -lpthread -lrt -lm
 
 -include $(TROOT)/config.mak
index 91f137e..07b299c 100644 (file)
@@ -16,7 +16,7 @@
 static int verbose = 1;
 
 void error__(const char *n, int l, const char *s, ...) {
 static int verbose = 1;
 
 void error__(const char *n, int l, const char *s, ...) {
-       fprintf(stderr, "use error in tests only\n");
+       dprintf(1, "use error in tests only\n");
 }
 
 static int N;
 }
 
 static int N;
@@ -32,7 +32,7 @@ static unsigned long long tic() {
        struct timespec ts;
 
        if (clock_gettime(CLOCK_REALTIME, &ts) < 0) {
        struct timespec ts;
 
        if (clock_gettime(CLOCK_REALTIME, &ts) < 0) {
-               fprintf(stderr, "bench: clock_gettime failed: %s\n", strerror(errno));
+               dprintf(1, "bench: clock_gettime failed: %s\n", strerror(errno));
                return 0;
        }
        return ts.tv_sec*SEC + ts.tv_nsec;
                return 0;
        }
        return ts.tv_sec*SEC + ts.tv_nsec;
@@ -98,17 +98,17 @@ void vmstats() {
                }
        }
        if (f) fclose(f);
                }
        }
        if (f) fclose(f);
-       fprintf(stderr, " %7zu virt %7zu res %7zu dirty", vm_size, vm_rss, vm_priv_dirty);
+       dprintf(1, " %7zu virt %7zu res %7zu dirty", vm_size, vm_rss, vm_priv_dirty);
 }
 
 void stats() {
 }
 
 void stats() {
-       if (dt/N > 100)
-               fprintf(stderr, "%10d N %10llu ns/op   ", N, dt/N);
+       if (dt/N >= 100)
+               dprintf(1, "%10d N %10llu ns/op   ", N, dt/N);
        else
        else
-               fprintf(stderr, "%10d N %13.2f ns/op", N, (double)dt/N);
+               dprintf(1, "%10d N %13.2f ns/op", N, (double)dt/N);
        if (verbose)
                vmstats();
        if (verbose)
                vmstats();
-       fputc('\n', stderr);
+       dprintf(1, "\n");
 }
 
 static void run(const char *name, void (*f)(int)) {
 }
 
 static void run(const char *name, void (*f)(int)) {
@@ -116,23 +116,23 @@ static void run(const char *name, void (*f)(int)) {
        if (p) {
                int s;
                if (p<0 || wait(&s)<0 || !WIFEXITED(s) || WEXITSTATUS(s))
        if (p) {
                int s;
                if (p<0 || wait(&s)<0 || !WIFEXITED(s) || WEXITSTATUS(s))
-                       fprintf(stderr, "benchmark %s failed\n", name);
+                       dprintf(1, "benchmark %s failed\n", name);
                return;
        }
                return;
        }
-       fprintf(stderr, "%-32s", name);
+       dprintf(1, "%-32s", name);
        for (N=1; ; N=nextN()) {
                // TODO: fork at each iteration and pass N,dt..?
                reset_timer();
                start_timer();
                f(N);
                stop_timer();
        for (N=1; ; N=nextN()) {
                // TODO: fork at each iteration and pass N,dt..?
                reset_timer();
                start_timer();
                f(N);
                stop_timer();
-//             fprintf(stderr, "%10d%12llu next: %d\n", N, dt, nextN());
+//             dprintf(1, "%10d%12llu next: %d\n", N, dt, nextN());
                if (dt >= SEC/2 || N >= MAXN) {
                        stats();
                        exit(0);
                }
                if (N <= 0) {
                if (dt >= SEC/2 || N >= MAXN) {
                        stats();
                        exit(0);
                }
                if (N <= 0) {
-                       fprintf(stderr, "bench: fatal: N <= 0\n");
+                       dprintf(1, "bench: fatal: N <= 0\n");
                        exit(1);
                }
        }
                        exit(1);
                }
        }
index ecaaf7f..2373b09 100644 (file)
@@ -29,10 +29,12 @@ void reset_timer() { errtimer(); }
 void error__(const char *n, int l, const char *s, ...) {
        va_list ap;
 
 void error__(const char *n, int l, const char *s, ...) {
        va_list ap;
 
+       if (failed == 0 && nfailed == 0)
+               dprintf(1, "FAIL\n", n);
        failed = 1;
        failed = 1;
-       fprintf(stderr, " ERROR %s %s:%d: ", name, n, l);
+       dprintf(1, " ERROR %s %s:%d: ", name, n, l);
        va_start(ap, s);
        va_start(ap, s);
-       vfprintf(stderr, s, ap);
+       vdprintf(1, s, ap);
        va_end(ap);
 }
 
        va_end(ap);
 }
 
@@ -44,7 +46,7 @@ static void run(const char *n, void (*f)()) {
        failed = 0;
        name = n;
        if (verbose)
        failed = 0;
        name = n;
        if (verbose)
-               fprintf(stderr, "running %s:\n", name);
+               dprintf(1, "running %s:\n", name);
 
        pid = fork();
        if (pid == 0) {
 
        pid = fork();
        if (pid == 0) {
@@ -66,21 +68,21 @@ static void run(const char *n, void (*f)()) {
 
        if (failed) {
                nfailed++;
 
        if (failed) {
                nfailed++;
-               fprintf(stderr, "FAILED %s\n", name);
+               dprintf(1, "FAILED %s\n", name);
        } else if (verbose)
        } else if (verbose)
-               fprintf(stderr, "PASSED %s\n", name);
+               dprintf(1, "PASSED %s\n", name);
 }
 
 static int summary() {
        if (nfailed)
 }
 
 static int summary() {
        if (nfailed)
-               fprintf(stderr, "FAIL:%d (all: %d)\n", nfailed, count);
+               dprintf(1, "FAIL (%d out of %d tests)\n", nfailed, count);
        else
        else
-               fprintf(stderr, "PASS (all: %d)\n", count);
+               dprintf(1, "ok (%d tests)\n", count);
        return !!nfailed;
 }
 
 static void usage() {
        return !!nfailed;
 }
 
 static void usage() {
-       fprintf(stderr, "usage: ./t [-vs]\n");
+       dprintf(1, "usage: ./t [-vs]\n");
        exit(1);
 }
 
        exit(1);
 }
 
index 945e144..42010ee 100644 (file)
@@ -166,7 +166,7 @@ void test_udiv()
        }
 }
 
        }
 }
 
-void bench_div(int N)
+void bench_udiv(int N)
 {
        int i;
        volatile uint64_t r = 0;
 {
        int i;
        volatile uint64_t r = 0;
@@ -176,7 +176,7 @@ void bench_div(int N)
                r += ((uint64_t)i<<32) / d;
 }
 
                r += ((uint64_t)i<<32) / d;
 }
 
-void bench_mod(int N)
+void bench_umod(int N)
 {
        int i;
        volatile uint64_t r = 0;
 {
        int i;
        volatile uint64_t r = 0;