git » nmdb » commit 3037f97

Add test number 3.

author Alberto Bertogli
2007-06-12 03:04:33 UTC
committer Alberto Bertogli
2007-06-12 03:04:33 UTC
parent 9e6762d25e19ec6986e1c185f2ce4879c63e3203

Add test number 3.

It performs the following loop:

for i in range(times):
  key = val = i
  set(key, val)
  val = get(key)
  del(key)

tests/3.c +91 -0
tests/build.sh +2 -1

diff --git a/tests/3.c b/tests/3.c
new file mode 100644
index 0000000..35771bd
--- /dev/null
+++ b/tests/3.c
@@ -0,0 +1,91 @@
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <stdlib.h>
+
+#include <nmdb.h>
+#include "timer.h"
+#include "prototypes.h"
+
+
+int main(int argc, char **argv)
+{
+	int i, r, times;
+	unsigned char *key, *val;
+	size_t ksize, vsize, bsize;
+	unsigned long elapsed, misses = 0;
+	nmdb_t *db;
+
+	if (argc != 4) {
+		printf("Usage: test3 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(70 * 1024);
+	bsize = 70 * 1024;
+	memset(val, 0, bsize);
+
+	if (key == NULL || val == NULL) {
+		perror("Error: malloc()");
+		return 1;
+	}
+
+	db = nmdb_init();
+	if (db == NULL) {
+		perror("nmdb_init() failed");
+		return 1;
+	}
+
+	NADDSRV(db);
+
+	timer_start();
+	for (i = 0; i < times; i++) {
+		* (int *) key = i;
+		* (int *) val = i;
+		r = NSET(db, key, ksize, val, vsize);
+		if (r < 0) {
+			perror("Set");
+			return 1;
+		}
+
+		* (int *) key = i;
+		r = NGET(db, key, ksize, val, bsize);
+		if (r < 0) {
+			perror("Get");
+			return 1;
+		} else if (r == 0) {
+			misses++;
+		}
+
+		* (int *) key = i;
+		r = NDEL(db, key, ksize);
+		if (r < 0) {
+			perror("Del");
+			return 1;
+		}
+	}
+	elapsed = timer_stop();
+	printf("%lu %lu\n", elapsed, misses);
+
+	free(key);
+	nmdb_free(db);
+
+	return 0;
+}
+
diff --git a/tests/build.sh b/tests/build.sh
index 2d8570b..cec62b8 100755
--- a/tests/build.sh
+++ b/tests/build.sh
@@ -39,11 +39,12 @@ for p in TIPC TCP UDP MULT; do
 		CF="-DUSE_$p=1 -DUSE_$v=1"
 
 		if [ "$CLEAN" == 1 ]; then
-			rm -vf 1-$OP 2-$OP
+			rm -vf 1-$OP 2-$OP 3-$OP
 		else
 			echo " * $OP"
 			cc -lnmdb $CF -o 1-$OP 1.c
 			cc -lnmdb $CF -o 2-$OP 2.c
+			cc -lnmdb $CF -o 3-$OP 3.c
 		fi
 	done
 done