author | Alberto Bertogli
<albertito@gmail.com> 2007-06-04 04:08:47 UTC |
committer | Alberto Bertogli
<albertito@gmail.com> 2007-06-04 04:08:47 UTC |
parent | 24892c56dc8545759c80245a8340623c24aa4ae8 |
tests/{test1d.c => 1.c} | +7 | -5 |
tests/{test2d.c => 2.c} | +7 | -5 |
tests/Makefile | +0 | -52 |
tests/build.sh | +50 | -0 |
tests/prototypes.h | +38 | -0 |
tests/test1c.c | +0 | -85 |
tests/test2c.c | +0 | -100 |
tests/test2cm.c | +0 | -114 |
tests/test2dm.c | +0 | -106 |
diff --git a/tests/test1d.c b/tests/1.c similarity index 88% rename from tests/test1d.c rename to tests/1.c index a303741..388a48b 100644 --- a/tests/test1d.c +++ b/tests/1.c @@ -5,8 +5,9 @@ #include <sys/time.h> #include <stdlib.h> -#include "nmdb.h" +#include <nmdb.h> #include "timer.h" +#include "prototypes.h" int main(int argc, char **argv) @@ -33,12 +34,13 @@ int main(int argc, char **argv) perror("nmdb_init() failed"); return 1; } - nmdb_add_tipc_server(db, -1); + + NADDSRV(db); printf("set... "); timer_start(); for (i = 0; i < times; i++) { - r = nmdb_set(db, key, ksize, val, vsize); + r = NSET(db, key, ksize, val, vsize); if (r < 0) { perror("Set"); return 1; @@ -51,7 +53,7 @@ int main(int argc, char **argv) printf("get... "); timer_start(); for (i = 0; i < times; i++) { - r = nmdb_get(db, key, ksize, gval, vsize); + r = NGET(db, key, ksize, gval, vsize); if (r < 0) { perror("Get"); return 1; @@ -68,7 +70,7 @@ int main(int argc, char **argv) printf("del... "); timer_start(); for (i = 0; i < times; i++) { - r = nmdb_del(db, key, ksize); + r = NDEL(db, key, ksize); if (r < 0) { perror("Del"); return 1; diff --git a/tests/test2d.c b/tests/2.c similarity index 90% rename from tests/test2d.c rename to tests/2.c index d6cf2c7..2063418 100644 --- a/tests/test2d.c +++ b/tests/2.c @@ -5,8 +5,9 @@ #include <sys/time.h> #include <stdlib.h> -#include "nmdb.h" +#include <nmdb.h> #include "timer.h" +#include "prototypes.h" int main(int argc, char **argv) @@ -49,13 +50,14 @@ int main(int argc, char **argv) perror("nmdb_init() failed"); return 1; } - nmdb_add_tipc_server(db, -1); + + NADDSRV(db); timer_start(); for (i = 0; i < times; i++) { * (int *) key = i; * (int *) val = i; - r = nmdb_set(db, key, ksize, val, vsize); + r = NSET(db, key, ksize, val, vsize); if (r < 0) { perror("Set"); return 1; @@ -69,7 +71,7 @@ int main(int argc, char **argv) timer_start(); for (i = 0; i < times; i++) { * (int *) key = i; - r = nmdb_get(db, key, ksize, val, vsize); + r = NGET(db, key, ksize, val, vsize); if (r < 0) { perror("Get"); return 1; @@ -83,7 +85,7 @@ int main(int argc, char **argv) timer_start(); for (i = 0; i < times; i++) { * (int *) key = i; - r = nmdb_del(db, key, ksize); + r = NDEL(db, key, ksize); if (r < 0) { perror("Del"); return 1; diff --git a/tests/Makefile b/tests/Makefile deleted file mode 100644 index 561b580..0000000 --- a/tests/Makefile +++ /dev/null @@ -1,52 +0,0 @@ - -CFLAGS += -std=c99 -Wall -O3 -ALL_CFLAGS = -D_XOPEN_SOURCE=500 -fPIC $(CFLAGS) - -ifdef DEBUG -ALL_CFLAGS += -g -pg -fprofile-arcs -ftest-coverage -endif - -ifdef STRICT -ALL_CFLAGS += -ansi -pedantic -endif - - -OBJS = test1c.o test1d.o test2c.o test2cm.o test2d.o test2dm.o - - -default: all - -all: tests - -tests: test1c test1d test2c test2cm test2d test2dm - -test1c: test1c.o - $(CC) $(ALL_CFLAGS) test1c.o -lnmdb -o test1c - -test1d: test1d.o - $(CC) $(ALL_CFLAGS) test1d.o -lnmdb -o test1d - -test2c: test2c.o - $(CC) $(ALL_CFLAGS) test2c.o -lnmdb -o test2c - -test2cm: test2cm.o - $(CC) $(ALL_CFLAGS) test2cm.o -lnmdb -o test2cm - -test2d: test2d.o - $(CC) $(ALL_CFLAGS) test2d.o -lnmdb -o test2d - -test2dm: test2dm.o - $(CC) $(ALL_CFLAGS) test2dm.o -lnmdb -o test2dm - - -.c.o: - $(CC) $(ALL_CFLAGS) -c $< -o $@ - -clean: - rm -f $(OBJS) - rm -f test1c test1d test2c test2cm test2d test2dm - rm -f *.bb *.bbg *.da *.gcov *.gcda *.gcno gmon.out - -.PHONY: default all tests clean - - diff --git a/tests/build.sh b/tests/build.sh new file mode 100755 index 0000000..f8a96b0 --- /dev/null +++ b/tests/build.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +set -e + +USAGE="\ +Use: build.sh [build|debug_build|strict_build|profile_build|clean] +" + + +CF="-std=c99 -Wall -O3" +ALLCF="-D_XOPEN_SOURCE=500 -fPIC $CF" + +case "$1" in + "build" ) + # defaults are just fine for build + ;; + "debug_build" ) + ALLCF="-g $CF" + ;; + "strict_build" ) + ALLCF="-ansi -pedantic $CF" + ;; + "profile_build" ) + ALLCF="-g -pg -fprofile-arcs -ftest-coverage $CF" + ;; + "clean" ) + CLEAN=1 + ;; + "help" | "--help" | "-h" | "" ) + echo $USAGE + exit 1 + ;; +esac; + + +for p in TIPC TCP MULT; do + for v in NORMAL CACHE SYNC; do + OP=`echo $p-$v | tr '[A-Z]' '[a-z]'` + CF="-DUSE_$p=1 -DUSE_$v=1" + + if [ "$CLEAN" == 1 ]; then + rm -vf 1-$OP 2-$OP + else + echo " * $OP" + cc -lnmdb $CF -o 1-$OP 1.c + cc -lnmdb $CF -o 2-$OP 2.c + fi + done +done + diff --git a/tests/prototypes.h b/tests/prototypes.h new file mode 100644 index 0000000..af5f2eb --- /dev/null +++ b/tests/prototypes.h @@ -0,0 +1,38 @@ + +#ifndef _TEST_PROTOTYPES_H +#define _TEST_PROTOTYPES_H + + +#if USE_NORMAL + #define NGET(...) nmdb_get(__VA_ARGS__) + #define NSET(...) nmdb_set(__VA_ARGS__) + #define NDEL(...) nmdb_del(__VA_ARGS__) + #define NCAS(...) nmdb_cas(__VA_ARGS__) +#elif USE_CACHE + #define NGET(...) nmdb_cache_get(__VA_ARGS__) + #define NSET(...) nmdb_cache_set(__VA_ARGS__) + #define NDEL(...) nmdb_cache_del(__VA_ARGS__) + #define NCAS(...) nmdb_cache_cas(__VA_ARGS__) +#elif USE_SYNC + #define NGET(...) nmdb_get(__VA_ARGS__) + #define NSET(...) nmdb_set_sync(__VA_ARGS__) + #define NDEL(...) nmdb_del_sync(__VA_ARGS__) + #define NCAS(...) nmdb_cas(__VA_ARGS__) +#endif + + +#if USE_TCP + #define NADDSRV(db) nmdb_add_tcp_server(db, "localhost", -1) +#elif USE_TIPC + #define NADDSRV(db) nmdb_add_tipc_server(db, -1) +#elif USE_MULT + #define NADDSRV(db) \ + do { \ + nmdb_add_tipc_server(db, -1); \ + nmdb_add_tcp_server(db, "localhost", -1); \ + } while (0) +#endif + + +#endif + diff --git a/tests/test1c.c b/tests/test1c.c deleted file mode 100644 index d7fc06f..0000000 --- a/tests/test1c.c +++ /dev/null @@ -1,85 +0,0 @@ - -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/time.h> -#include <stdlib.h> - -#include "nmdb.h" -#include "timer.h" - - -int main(int argc, char **argv) -{ - int i, r, times; - unsigned char *key, *val, *gval; - size_t ksize, vsize; - unsigned long elapsed, misses = 0; - nmdb_t *db; - - if (argc != 4) { - printf("Usage: test1 TIMES KEY VAL\n"); - return 1; - } - - times = atoi(argv[1]); - key = (unsigned char *) argv[2]; - ksize = strlen((char *) key); - val = (unsigned char *) argv[3]; - vsize = strlen((char *) val); - - db = nmdb_init(); - if (db == NULL) { - perror("nmdb_init() failed"); - return 1; - } - nmdb_add_tipc_server(db, -1); - - printf("set... "); - timer_start(); - for (i = 0; i < times; i++) { - r = nmdb_cache_set(db, key, ksize, val, vsize); - if (r < 0) { - perror("Set"); - return 1; - } - } - elapsed = timer_stop(); - printf("%lu\n", elapsed); - - gval = malloc(70 * 1024); - printf("get... "); - timer_start(); - for (i = 0; i < times; i++) { - r = nmdb_cache_get(db, key, ksize, gval, vsize); - if (r < 0) { - perror("Get"); - return 1; - } else if (r == 0) { - misses++; - } - } - elapsed = timer_stop(); - printf("%lu\n", elapsed); - free(gval); - - printf("get misses: %ld\n", misses); - - printf("del... "); - timer_start(); - for (i = 0; i < times; i++) { - r = nmdb_cache_del(db, key, ksize); - if (r < 0) { - perror("Del"); - return 1; - } - } - elapsed = timer_stop(); - printf("%lu\n", elapsed); - - - nmdb_free(db); - - return 0; -} - diff --git a/tests/test2c.c b/tests/test2c.c deleted file mode 100644 index bf8624b..0000000 --- a/tests/test2c.c +++ /dev/null @@ -1,100 +0,0 @@ - -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/time.h> -#include <stdlib.h> - -#include "nmdb.h" -#include "timer.h" - - -int main(int argc, char **argv) -{ - int i, r, times; - unsigned char *key, *val; - size_t ksize, vsize; - unsigned long s_elapsed, g_elapsed, d_elapsed, misses = 0; - nmdb_t *db; - - if (argc != 4) { - printf("Usage: test2 TIMES KSIZE VSIZE\n"); - return 1; - } - - times = atoi(argv[1]); - ksize = atoi(argv[2]); - vsize = atoi(argv[3]); - if (times < 1) { - printf("Error: TIMES must be >= 1\n"); - return 1; - } - if (ksize < sizeof(int) || vsize < sizeof(int)) { - printf("Error: KSIZE and VSIZE must be >= sizeof(int)\n"); - return 1; - } - - key = malloc(ksize); - memset(key, 0, ksize); - val = malloc(vsize); - memset(val, 0, vsize); - - if (key == NULL || val == NULL) { - perror("Error: malloc()"); - return 1; - } - - db = nmdb_init(); - if (db == NULL) { - perror("nmdb_init() failed"); - return 1; - } - nmdb_add_tipc_server(db, -1); - - timer_start(); - for (i = 0; i < times; i++) { - * (int *) key = i; - * (int *) val = i; - r = nmdb_cache_set(db, key, ksize, val, vsize); - if (r < 0) { - perror("Set"); - return 1; - } - } - s_elapsed = timer_stop(); - - memset(key, 0, ksize); - free(val); - val = malloc(70 * 1024); - timer_start(); - for (i = 0; i < times; i++) { - * (int *) key = i; - r = nmdb_cache_get(db, key, ksize, val, vsize); - if (r < 0) { - perror("Get"); - return 1; - } else if (r == 0) { - misses++; - } - } - g_elapsed = timer_stop(); - free(val); - - timer_start(); - for (i = 0; i < times; i++) { - * (int *) key = i; - r = nmdb_cache_del(db, key, ksize); - if (r < 0) { - perror("Del"); - return 1; - } - } - d_elapsed = timer_stop(); - printf("%lu %lu %lu %lu\n", s_elapsed, g_elapsed, d_elapsed, misses); - - free(key); - nmdb_free(db); - - return 0; -} - diff --git a/tests/test2cm.c b/tests/test2cm.c deleted file mode 100644 index efc3a45..0000000 --- a/tests/test2cm.c +++ /dev/null @@ -1,114 +0,0 @@ - -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/time.h> -#include <stdlib.h> - -#include "nmdb.h" -#include "timer.h" - - -int main(int argc, char **argv) -{ - int i, r, times; - unsigned char *key, *val, *gval; - size_t ksize, vsize; - unsigned long s_elapsed, g_elapsed, d_elapsed, misses = 0; - nmdb_t *db; - - if (argc != 4) { - printf("Usage: test2 TIMES KSIZE VSIZE\n"); - return 1; - } - - times = atoi(argv[1]); - ksize = atoi(argv[2]); - vsize = atoi(argv[3]); - if (times < 1) { - printf("Error: TIMES must be >= 1\n"); - return 1; - } - if (ksize < sizeof(int) || vsize < sizeof(int)) { - printf("Error: KSIZE and VSIZE must be >= sizeof(int)\n"); - return 1; - } - - key = malloc(ksize); - memset(key, 0, ksize); - val = malloc(vsize); - memset(val, 0, vsize); - - if (key == NULL || val == NULL) { - perror("Error: malloc()"); - return 1; - } - - db = nmdb_init(); - if (db == NULL) { - perror("nmdb_init() failed"); - return 1; - } - - if (!nmdb_add_tipc_server(db, 11) || - !nmdb_add_tipc_server(db, 12) || - !nmdb_add_tipc_server(db, 13)) { - perror("nmdb_add_tipc_server() failed"); - return 1; - } - - timer_start(); - for (i = 0; i < times; i++) { - * (int *) key = i; - * (int *) val = i; - r = nmdb_cache_set(db, key, ksize, val, vsize); - if (r < 0) { - perror("Set"); - return 1; - } - } - s_elapsed = timer_stop(); - - memset(key, 0, ksize); - gval = malloc(70 * 1024); - timer_start(); - for (i = 0; i < times; i++) { - * (int *) key = i; - r = nmdb_cache_get(db, key, ksize, gval, vsize); - if (r < 0) { - perror("Get"); - return 1; - } else if (r == 0) { - misses++; - continue; - } - * (int *) val = i; - if (memcmp((void *) val, (void *) gval, vsize) != 0) { - printf("Values differ for key %s: %s - %s\n", - key, val, gval); - printf("i: %d\n", i); - return 1; - } - } - g_elapsed = timer_stop(); - free(gval); - free(val); - - timer_start(); - for (i = 0; i < times; i++) { - * (int *) key = i; - r = nmdb_cache_del(db, key, ksize); - if (r < 0) { - perror("Del"); - return 1; - } - } - d_elapsed = timer_stop(); - printf("%lu %lu %lu %lu\n", s_elapsed, g_elapsed, d_elapsed, misses); - - free(key); - nmdb_free(db); - - return 0; -} - diff --git a/tests/test2dm.c b/tests/test2dm.c deleted file mode 100644 index c417096..0000000 --- a/tests/test2dm.c +++ /dev/null @@ -1,106 +0,0 @@ - -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/time.h> -#include <stdlib.h> - -#include "nmdb.h" -#include "timer.h" - - -int main(int argc, char **argv) -{ - int i, r, times; - unsigned char *key, *val; - size_t ksize, vsize; - unsigned long s_elapsed, g_elapsed, d_elapsed, misses = 0; - nmdb_t *db; - - if (argc != 4) { - printf("Usage: test2 TIMES KSIZE VSIZE\n"); - return 1; - } - - times = atoi(argv[1]); - ksize = atoi(argv[2]); - vsize = atoi(argv[3]); - if (times < 1) { - printf("Error: TIMES must be >= 1\n"); - return 1; - } - if (ksize < sizeof(int) || vsize < sizeof(int)) { - printf("Error: KSIZE and VSIZE must be >= sizeof(int)\n"); - return 1; - } - - key = malloc(ksize); - memset(key, 0, ksize); - val = malloc(vsize); - memset(val, 0, vsize); - - if (key == NULL || val == NULL) { - perror("Error: malloc()"); - return 1; - } - - db = nmdb_init(); - if (db == NULL) { - perror("nmdb_init() failed"); - return 1; - } - - if (!nmdb_add_tipc_server(db, 11) || - !nmdb_add_tipc_server(db, 12) || - !nmdb_add_tipc_server(db, 13)) { - perror("nmdb_add_tipc_server() failed"); - return 1; - } - - timer_start(); - for (i = 0; i < times; i++) { - * (int *) key = i; - * (int *) val = i; - r = nmdb_set(db, key, ksize, val, vsize); - if (r < 0) { - perror("Set"); - return 1; - } - } - s_elapsed = timer_stop(); - - memset(key, 0, ksize); - free(val); - val = malloc(70 * 1024); - timer_start(); - for (i = 0; i < times; i++) { - * (int *) key = i; - r = nmdb_get(db, key, ksize, val, vsize); - if (r < 0) { - perror("Get"); - return 1; - } else if (r == 0) { - misses++; - } - } - g_elapsed = timer_stop(); - free(val); - - timer_start(); - for (i = 0; i < times; i++) { - * (int *) key = i; - r = nmdb_del(db, key, ksize); - if (r < 0) { - perror("Del"); - return 1; - } - } - d_elapsed = timer_stop(); - printf("%lu %lu %lu %lu\n", s_elapsed, g_elapsed, d_elapsed, misses); - - free(key); - nmdb_free(db); - - return 0; -} -