1b83d1 use dprintf(1,..) instead of buffered stderr

Authored and Committed by nsz 13 years ago
    use dprintf(1,..) instead of buffered stderr
    
        
file modified
+5 -5
Makefile CHANGED
@@ -1,10 +1,10 @@
1
1
DIRS = $(sort $(wildcard src/*))
2
2
3
3
all:
4
- for i in $(DIRS); do echo $$i; make -s -C $$i; done
5
- t: all
6
- # for i in $(DIRS); do echo $$i; $$i/t; done
7
- b: all
8
- for i in $(DIRS); do echo $$i; $$i/b; done
4
+ for i in $(DIRS); do printf "%-20s" $$i; make -s -C $$i; done
5
+ t:
6
+ @for i in $(DIRS); do printf "%-20s" $$i; make -s -C $$i 2>/dev/null; done
7
+ b: t
8
+ @for i in $(DIRS); do echo $$i; $$i/b; done
9
9
clean:
10
10
for i in $(DIRS); do make -s -C $$i clean; done
file modified
+1 -1
Makefile.inc CHANGED
@@ -9,7 +9,7 @@ OBJS = $(SRCS:.c=.o)
9
9
AR=ar
10
10
RANLIB=ranlib
11
11
12
- CFLAGS += -g -D_POSIX_C_SOURCE=200809L -std=c99 -pipe -Wall
12
+ CFLAGS += -g -D_POSIX_C_SOURCE=200809L -std=c99 -pipe -Wall -Wno-unused-function
13
13
LDFLAGS += -g -lpthread -lrt -lm
14
14
15
15
-include $(TROOT)/config.mak
file modified
+11 -11
common/b.c CHANGED
@@ -16,7 +16,7 @@
16
16
static int verbose = 1;
17
17
18
18
void error__(const char *n, int l, const char *s, ...) {
19
- fprintf(stderr, "use error in tests only\n");
19
+ dprintf(1, "use error in tests only\n");
20
20
}
21
21
22
22
static int N;
@@ -32,7 +32,7 @@ static unsigned long long tic() {
32
32
struct timespec ts;
33
33
34
34
if (clock_gettime(CLOCK_REALTIME, &ts) < 0) {
35
- fprintf(stderr, "bench: clock_gettime failed: %s\n", strerror(errno));
35
+ dprintf(1, "bench: clock_gettime failed: %s\n", strerror(errno));
36
36
return 0;
37
37
}
38
38
return ts.tv_sec*SEC + ts.tv_nsec;
@@ -98,17 +98,17 @@ void vmstats() {
98
98
}
99
99
}
100
100
if (f) fclose(f);
101
- fprintf(stderr, " %7zu virt %7zu res %7zu dirty", vm_size, vm_rss, vm_priv_dirty);
101
+ dprintf(1, " %7zu virt %7zu res %7zu dirty", vm_size, vm_rss, vm_priv_dirty);
102
102
}
103
103
104
104
void stats() {
105
- if (dt/N > 100)
106
- fprintf(stderr, "%10d N %10llu ns/op ", N, dt/N);
105
+ if (dt/N >= 100)
106
+ dprintf(1, "%10d N %10llu ns/op ", N, dt/N);
107
107
else
108
- fprintf(stderr, "%10d N %13.2f ns/op", N, (double)dt/N);
108
+ dprintf(1, "%10d N %13.2f ns/op", N, (double)dt/N);
109
109
if (verbose)
110
110
vmstats();
111
- fputc('\n', stderr);
111
+ dprintf(1, "\n");
112
112
}
113
113
114
114
static void run(const char *name, void (*f)(int)) {
@@ -116,23 +116,23 @@ static void run(const char *name, void (*f)(int)) {
116
116
if (p) {
117
117
int s;
118
118
if (p<0 || wait(&s)<0 || !WIFEXITED(s) || WEXITSTATUS(s))
119
- fprintf(stderr, "benchmark %s failed\n", name);
119
+ dprintf(1, "benchmark %s failed\n", name);
120
120
return;
121
121
}
122
- fprintf(stderr, "%-32s", name);
122
+ dprintf(1, "%-32s", name);
123
123
for (N=1; ; N=nextN()) {
124
124
// TODO: fork at each iteration and pass N,dt..?
125
125
reset_timer();
126
126
start_timer();
127
127
f(N);
128
128
stop_timer();
129
- // fprintf(stderr, "%10d%12llu next: %d\n", N, dt, nextN());
129
+ // dprintf(1, "%10d%12llu next: %d\n", N, dt, nextN());
130
130
if (dt >= SEC/2 || N >= MAXN) {
131
131
stats();
132
132
exit(0);
133
133
}
134
134
if (N <= 0) {
135
- fprintf(stderr, "bench: fatal: N <= 0\n");
135
+ dprintf(1, "bench: fatal: N <= 0\n");
136
136
exit(1);
137
137
}
138
138
}
file modified
+10 -8
common/t.c CHANGED
@@ -29,10 +29,12 @@ void reset_timer() { errtimer(); }
29
29
void error__(const char *n, int l, const char *s, ...) {
30
30
va_list ap;
31
31
32
+ if (failed == 0 && nfailed == 0)
33
+ dprintf(1, "FAIL\n", n);
32
34
failed = 1;
33
- fprintf(stderr, " ERROR %s %s:%d: ", name, n, l);
35
+ dprintf(1, " ERROR %s %s:%d: ", name, n, l);
34
36
va_start(ap, s);
35
- vfprintf(stderr, s, ap);
37
+ vdprintf(1, s, ap);
36
38
va_end(ap);
37
39
}
38
40
@@ -44,7 +46,7 @@ static void run(const char *n, void (*f)()) {
44
46
failed = 0;
45
47
name = n;
46
48
if (verbose)
47
- fprintf(stderr, "running %s:\n", name);
49
+ dprintf(1, "running %s:\n", name);
48
50
49
51
pid = fork();
50
52
if (pid == 0) {
@@ -66,21 +68,21 @@ static void run(const char *n, void (*f)()) {
66
68
67
69
if (failed) {
68
70
nfailed++;
69
- fprintf(stderr, "FAILED %s\n", name);
71
+ dprintf(1, "FAILED %s\n", name);
70
72
} else if (verbose)
71
- fprintf(stderr, "PASSED %s\n", name);
73
+ dprintf(1, "PASSED %s\n", name);
72
74
}
73
75
74
76
static int summary() {
75
77
if (nfailed)
76
- fprintf(stderr, "FAIL:%d (all: %d)\n", nfailed, count);
78
+ dprintf(1, "FAIL (%d out of %d tests)\n", nfailed, count);
77
79
else
78
- fprintf(stderr, "PASS (all: %d)\n", count);
80
+ dprintf(1, "ok (%d tests)\n", count);
79
81
return !!nfailed;
80
82
}
81
83
82
84
static void usage() {
83
- fprintf(stderr, "usage: ./t [-vs]\n");
85
+ dprintf(1, "usage: ./t [-vs]\n");
84
86
exit(1);
85
87
}
86
88
file modified
+2 -2
src/udiv/udiv.c CHANGED
@@ -166,7 +166,7 @@ void test_udiv()
166
166
}
167
167
}
168
168
169
- void bench_div(int N)
169
+ void bench_udiv(int N)
170
170
{
171
171
int i;
172
172
volatile uint64_t r = 0;
@@ -176,7 +176,7 @@ void bench_div(int N)
176
176
r += ((uint64_t)i<<32) / d;
177
177
}
178
178
179
- void bench_mod(int N)
179
+ void bench_umod(int N)
180
180
{
181
181
int i;
182
182
volatile uint64_t r = 0;