all: t b
clean:
- rm -f $(OBJS) t t.o main.h b b.o tests.a
+ rm -f $(OBJS) t t.o b b.o tests.a tests.h
.c.o:
$(CC) $(CFLAGS) $(INC) -c -o $@ $<
$(OBJS): $(ROOTDIR)/common/test.h $(ROOTDIR)/Makefile.conf
-main.h: $(OBJS)
+tests.h: $(OBJS)
nm -f posix $+ |awk ' \
/^test/ && $$2=="T"{print "T(" $$1 ")"} \
/^bench/ && $$2=="T"{print "B(" $$1 ")"} \
- ' >main.h
+ ' >tests.h
tests.a: $(OBJS)
$(AR) rc $@ $+
$(RANLIB) $@
-t.o: $(ROOTDIR)/common/t.c $(ROOTDIR)/common/test.h main.h
+t.o: $(ROOTDIR)/common/t.c $(ROOTDIR)/common/test.h tests.h
$(CC) $(CFLAGS) $(INC) -I. -c -o $@ $<
t: t.o tests.a
$(CC) $+ $(LDFLAGS) -o $@
-b.o: $(ROOTDIR)/common/b.c $(ROOTDIR)/common/test.h main.h
+b.o: $(ROOTDIR)/common/b.c $(ROOTDIR)/common/test.h tests.h
$(CC) $(CFLAGS) $(INC) -I. -c -o $@ $<
b: b.o tests.a
simple libc tests based on the libc-testsuit
and libc-bench of dalias
see http://git.etalabs.net/cgi-bin/gitweb.cgi
+see http://www.etalabs.net/libc-bench.html
build tests:
cp Makefile.conf.def Makefile.conf
run benchmarks:
./b
-about the framework:
+framework:
the only hook in the test framework is error(...) which
prints a formatted message and sets the test to failed
see common/test.h
-benchmark functions are repeatedly called with increasing
-N until runing time is long enough, then time/N is printed
-
-in the root dir make builds an executable with all tests
-in a src/* dir make builds only local tests
+in the root directory make builds an executable with all tests
+in a src/* directory make builds only local tests
see Makefile.inc
a test function looks like
test functions
see Makefile.inc
-edit the generated main.h to exclude certain tests
+a benchmark function looks like
+ void bench_foo(int N) {
+ for (i = 0; i < N; i++)
+ foo();
+ }
+benchmark functions are repeatedly called with an increasing
+N until the runing time is long enough, then time/N is printed
+
+edit the generated tests.h to exclude certain tests
see common/t.c for tests
see common/b.c for benchmarks
#include <unistd.h>
#include "test.h"
-#define T(t)
-#define B(t) void t();
-#include "main.h"
+#define T(f)
+#define B(f) void f(int);
+#include "tests.h"
#undef B
static int verbose = 1;
fprintf(stderr, "use error in tests only\n");
}
-int N;
+static int N;
static unsigned long long start;
static unsigned long long dt;
//static unsigned long long bytes;
static int nextN() {
unsigned long long n = dt/N;
+ unsigned long long i;
if (n)
n = SEC/2/n;
n = N+1;
if (n > MAXN)
n = MAXN;
- return n;
+
+ /* round up to a nice number */
+ for (i = 1; i < n; i *= 10);
+ if (i/2 >= n)
+ i /= 2;
+ if (i/2 >= n)
+ i /= 2;
+ return i;
}
void vmstats() {
fputc('\n', stderr);
}
-static void run(const char *name, void (*f)()) {
+static void run(const char *name, void (*f)(int)) {
int p = fork();
if (p) {
int s;
}
fprintf(stderr, "%-32s", name);
for (N=1; ; N=nextN()) {
+ // TODO: fork at each iteration and pass N,dt..?
reset_timer();
start_timer();
- f();
+ f(N);
stop_timer();
// fprintf(stderr, "%10d%12llu next: %d\n", N, dt, nextN());
if (dt >= SEC/2 || N >= MAXN) {
int main() {
#define B(t) run(#t, t);
-#include "main.h"
+#include "tests.h"
return 0;
}
#include <unistd.h>
#include "test.h"
-#define B(t)
-#define T(t) void t();
-#include "main.h"
+#define B(f)
+#define T(f) void f();
+#include "tests.h"
#undef T
static int failed;
static int nfailed;
static void errtimer() { error("use *_timer in benchmarks only\n"); }
-int N = 0;
void start_timer() { errtimer(); }
void stop_timer() { errtimer(); }
void reset_timer() { errtimer(); }
int main() {
#define T(t) run(#t, t);
-#include "main.h"
+#include "tests.h"
return summary();
}
void error__(const char *n, int l, const char *s, ...);
/* use it in bench_ functions */
-extern int N;
void start_timer(void);
void stop_timer(void);
void reset_timer(void);
return n;
}
-void bench_foo() {
+void bench_foo(int N) {
int i;
for (i = 0; i < N; i++)
#include <pthread.h>
#include "test.h"
-void bench_malloc_sparse() {
+void bench_malloc_sparse(int N) {
void *p[N];
size_t i;
for (i=0; i<sizeof p/sizeof *p; i++) {
if (i%150) free(p[i]);
}
-void bench_malloc_bubble() {
+void bench_malloc_bubble(int N) {
void *p[N];
size_t i;
for (i=0; i<sizeof p/sizeof *p; i++) {
free(p[i]);
}
-void bench_malloc_tiny1() {
+void bench_malloc_tiny1(int N) {
void **p = malloc(N * sizeof *p);
size_t i;
for (i=0; i<N; i++) {
free(p);
}
-void bench_malloc_tiny2() {
+void bench_malloc_tiny2(int N) {
void **p = malloc(N * sizeof *p);
size_t i;
for (i=0; i<N; i++) {
free(p);
}
-void bench_malloc_big1() {
+void bench_malloc_big1(int N) {
void *p[N];
size_t i;
for (i=0; i<sizeof p/sizeof *p; i++) {
}
}
-void bench_malloc_big2() {
+void bench_malloc_big2(int N) {
void *p[N];
size_t i;
for (i=0; i<sizeof p/sizeof *p; i++) {
return *r = *r * 1103515245 + 12345;
}
+static int N;
static void *stress(void *arg)
{
return 0;
}
-void bench_malloc_thread_stress() {
+void bench_malloc_thread_stress(int n) {
struct foo foo[SH_COUNT] = {{0}};
pthread_t td1, td2;
void *res;
+ N = n;
pthread_create(&td1, 0, stress, foo);
pthread_create(&td2, 0, stress, foo);
pthread_join(td1, &res);
pthread_join(td2, &res);
}
-void bench_malloc_thread_local() {
+void bench_malloc_thread_local(int n) {
struct foo foo1[SH_COUNT] = {{0}};
struct foo foo2[SH_COUNT] = {{0}};
pthread_t td1, td2;
void *res;
+ N = n;
pthread_create(&td1, 0, stress, foo1);
pthread_create(&td2, 0, stress, foo2);
pthread_join(td1, &res);
pthread_join(td2, &res);
}
-
#include <string.h>
#include "test.h"
-void bench_stdio_putcgetc() {
+void bench_stdio_putcgetc(int N) {
FILE *f = tmpfile();
size_t i;
size_t cs = 0;
abort();
}
-void bench_stdio_putcgetc_unlocked() {
+void bench_stdio_putcgetc_unlocked(int N) {
FILE *f = tmpfile();
size_t i;
size_t cs = 0;