Commit 9bd88bb0 authored by Rich Prohaska's avatar Rich Prohaska

add fifo-test addresses #249

git-svn-id: file:///svn/tokudb@1607 c7de825b-a66e-492c-adef-691d508d4ae1
parent 4b52108a
......@@ -51,7 +51,7 @@ REGRESSION_TESTS = \
brt-serialize-test \
cachetable-test \
cachetable-test2 \
hashtest \
fifo-test \
brt-test \
test_oexcl \
# This line intentially kept commented so I can have a \ on the end of the previous line
......@@ -87,7 +87,7 @@ CHECKS = \
cachetable-test \
cachetable-test2 \
brt-serialize-test \
brt-test hashtest \
brt-test fifo-test \
test_toku_malloc_plain_free
check: bins $(patsubst %,check_%,$(CHECKS)) check_benchmarktest_256
check_benchmarktest_256: benchmark-test
......@@ -123,7 +123,7 @@ brt.o: $(BRT_INTERNAL_H_INCLUDES) key.h log_header.h
fifo.o: fifo.h brttypes.h
memory.o: memory.h
primes.o: primes.h
hashtest: fifo.o memory.o primes.o
fifo-test: fifo.o memory.o
brt-serialize.o: $(BRT_INTERNAL_H_INCLUDES) key.h wbuf.h rbuf.h
brt-bigtest: memory.o ybt.o brt.o pma.o cachetable.o key.o fifo.o brt-serialize.o
brt-bigtest.o: brt.h ../include/db.h
......
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "memory.h"
#include "fifo.h"
int verbose;
void test_fifo_create() {
int r;
FIFO f;
f = 0;
r = toku_fifo_create(&f);
assert(r == 0); assert(f != 0);
toku_fifo_free(&f);
assert(f == 0);
}
void test_fifo_enq(int n) {
int r;
FIFO f;
f = 0;
r = toku_fifo_create(&f);
assert(r == 0); assert(f != 0);
char *thekey = 0; int thekeylen;
char *theval = 0; int thevallen;
void buildkey(int len) {
thekeylen = len;
thekey = realloc(thekey, thekeylen);
memset(thekey, len, thekeylen);
}
void buildval(int len) {
thevallen = len+1;
theval = realloc(theval, thevallen);
memset(theval, ~len, thevallen);
}
int i;
for (i=0; i<n; i++) {
buildkey(i);
buildval(i);
r = toku_fifo_enq(f, thekey, thekeylen, theval, thevallen, i); assert(r == 0);
}
void checkit(bytevec key, ITEMLEN keylen, bytevec val, ITEMLEN vallen, int type, void *arg) {
if (verbose) printf("checkit %d %d\n", i, type);
assert(arg == 0);
buildkey(i);
buildval(i);
assert((int) keylen == thekeylen); assert(memcmp(key, thekey, keylen) == 0);
assert((int) vallen == thevallen); assert(memcmp(val, theval, vallen) == 0);
assert(i % 256 == type);
i += 1;
}
i = 0;
toku_fifo_iterate(f, checkit, 0);
assert(i == n);
if (thekey) free(thekey);
if (theval) free(theval);
while (toku_fifo_deq(f) == 0)
;
toku_fifo_free(&f);
assert(f == 0);
}
int main(int argc, char *argv[]) {
int i;
for (i = 1; i < argc; i++) {
char *arg = argv[i];
if (0 == strcmp(arg, "-v") || 0 == strcmp(arg, "--verbose")) {
verbose = 1; continue;
}
}
test_fifo_create();
test_fifo_enq(512);
toku_malloc_cleanup();
return 0;
}
......@@ -11,6 +11,10 @@ static void fifo_init(struct fifo *fifo) {
fifo->n = 0;
}
static int fifo_entry_size(struct fifo_entry *entry) {
return sizeof (struct fifo_entry) + entry->keylen + entry->vallen;
}
static struct fifo_entry *fifo_peek(struct fifo *fifo) {
return fifo->head;
}
......@@ -40,7 +44,7 @@ static struct fifo_entry *fifo_deq(struct fifo *fifo) {
static void fifo_destroy(struct fifo *fifo) {
struct fifo_entry *entry;
while ((entry = fifo_deq(fifo)) != 0)
toku_free(entry);
toku_free_n(entry, fifo_entry_size(entry));
}
int toku_fifo_create(FIFO *ptr) {
......@@ -54,7 +58,7 @@ int toku_fifo_create(FIFO *ptr) {
void toku_fifo_free(FIFO *ptr) {
struct fifo *fifo = *ptr; *ptr = 0;
fifo_destroy(fifo);
toku_free(fifo);
toku_free_n(fifo, sizeof *fifo);
}
int toku_fifo_n_entries(FIFO fifo) {
......@@ -88,7 +92,7 @@ int toku_fifo_peek(FIFO fifo, bytevec *key, unsigned int *keylen, bytevec *data,
int toku_fifo_deq(FIFO fifo) {
struct fifo_entry *entry = fifo_deq(fifo);
if (entry == 0) return ENOMEM;
toku_free(entry);
toku_free_n(entry, fifo_entry_size(entry));
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment