2a3abc bench: renames, env: setenv(0,..) test

Authored and Committed by nsz 13 years ago
    bench: renames, env: setenv(0,..) test
    
        
file modified
+12 -14
common/bench.c CHANGED
@@ -19,18 +19,16 @@ void error__(const char *n, int l, const char *s, ...) {
19
19
20
20
int N;
21
21
static unsigned long long start;
22
- static unsigned long long ns;
22
+ static unsigned long long dt;
23
23
//static unsigned long long bytes;
24
24
25
25
#define SEC 1000000000ULL
26
26
#define MAXN 1000000000
27
27
28
- static unsigned long long nsclock() {
28
+ static unsigned long long tic() {
29
29
struct timespec ts;
30
- int r;
31
30
32
- r = clock_gettime(CLOCK_MONOTONIC, &ts);
31
+ if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) {
33
- if (r < 0) {
34
32
fprintf(stderr, "bench: clock_gettime failed: %s\n", strerror(errno));
35
33
return 0;
36
34
}
@@ -39,23 +37,23 @@ static unsigned long long nsclock() {
39
37
40
38
void start_timer() {
41
39
if (!start)
42
- start = nsclock();
40
+ start = tic();
43
41
}
44
42
45
43
void stop_timer() {
46
44
if (start)
47
- ns += nsclock() - start;
45
+ dt += tic() - start;
48
46
start = 0;
49
47
}
50
48
51
49
void reset_timer() {
52
50
if (start)
53
- start = nsclock();
54
- ns = 0;
51
+ start = tic();
52
+ dt = 0;
55
53
}
56
54
57
55
static int nextN() {
58
- unsigned long long n = ns/N;
56
+ unsigned long long n = dt/N;
59
57
60
58
if (n)
61
59
n = SEC/n;
@@ -79,17 +77,17 @@ static void run(const char *name, void (*f)()) {
79
77
f();
80
78
stop_timer();
81
79
// fprintf(stderr, "%10d%12llu\n", N, ns);
82
- if (ns > SEC || N >= MAXN)
80
+ if (dt >= SEC || N >= MAXN)
83
81
break;
84
82
if (N <= 0) {
85
83
fprintf(stderr, "bench: fatal: N <= 0\n");
86
84
return;
87
85
}
88
86
}
89
- if (ns/N > 100)
90
- fprintf(stderr, "%10d%10llu ns/op\n", N, ns/N);
87
+ if (dt/N > 100)
88
+ fprintf(stderr, "%10d%10llu ns/op\n", N, dt/N);
91
89
else
92
- fprintf(stderr, "%10d%13.2f ns/op\n", N, (double)ns/N);
90
+ fprintf(stderr, "%10d%13.2f ns/op\n", N, (double)dt/N);
93
91
}
94
92
95
93
int main() {
file modified
+4 -1
src/env/env.c CHANGED
@@ -40,6 +40,9 @@ void test_env() {
40
40
error("setenv: %s\n", strerror(errno));
41
41
if (strcmp(s=getenv("TEST"),"3") != 0)
42
42
error("getenv(\"TEST\"): \"%s\", wanted \"3\"\n", s);
43
+ /* test failures */
43
44
if ((r=setenv("","",0)) != -1 || errno != EINVAL)
44
- error("setenv(\"\",\"\"): %d, errno: %d (%s), wanted -1, %d (EINVAL)\n", r, errno, strerror(errno), EINVAL);
45
+ error("setenv(\"\",\"\",0): %d, errno: %d (%s), wanted -1, %d (EINVAL)\n", r, errno, strerror(errno), EINVAL);
46
+ if ((r=setenv(0,"",0)) != -1 || errno != EINVAL)
47
+ error("setenv(0,\"\",0): %d, errno: %d (%s), wanted -1, %d (EINVAL)\n", r, errno, strerror(errno), EINVAL);
45
48
}