Commit 0a13028a authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

More test cases

git-svn-id: file:///svn/tokudb@30 c7de825b-a66e-492c-adef-691d508d4ae1
parent 762601f0
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char *argv[]) {
int i;
for (i=0; i<1000; i++) {
printf("%d\t%d\n", random(), random());
}
return 0;
}
......@@ -1526,9 +1526,9 @@ int brt_c_get (BRT_CURSOR cursor, DBT *kbt, DBT *vbt, int flags) {
int do_rmw=0;
int r;
CACHEKEY *rootp;
dump_brt(cursor->brt);
fprintf(stderr, "%s:%d in brt_c_get(...)\n", __FILE__, __LINE__);
//dump_brt(cursor->brt);
//fprintf(stderr, "%s:%d in brt_c_get(...)\n", __FILE__, __LINE__);
if ((r = read_and_pin_brt_header(cursor->brt->cf, &cursor->brt->h))) {
if (0) { died0: unpin_brt_header(cursor->brt); }
return r;
......@@ -1562,7 +1562,7 @@ int brt_c_get (BRT_CURSOR cursor, DBT *kbt, DBT *vbt, int flags) {
fprintf(stderr, "%s:%d c_get(...,%d) not ready\n", __FILE__, __LINE__, flags);
abort();
}
printf("%s:%d unpinning header\n", __FILE__, __LINE__);
//printf("%s:%d unpinning header\n", __FILE__, __LINE__);
if ((r = unpin_brt_header(cursor->brt))!=0) return r;
return 0;
}
......@@ -25,3 +25,7 @@ void test_keycompare (void) {
assert(keycompare("aaaaa",5, "aaaba",5)<0);
assert(keycompare("aaaaa",3, "aaaba",3)==0);
}
int default_compare_fun (DB *db __attribute__((__unused__)), DBT *a, DBT*b) {
return keycompare(a->data, a->size, b->data, b->size);
}
......@@ -3,3 +3,4 @@
int keycompare (bytevec key1, ITEMLEN key1len, bytevec key2, ITEMLEN key2len);
void test_keycompare (void) ;
int default_compare_fun (DB *, DBT *, DBT*);
......@@ -5,7 +5,7 @@
#include <errno.h>
#include <stdio.h>
int memory_check=1;
int memory_check=0;
#define WHEN_MEM_DEBUG(x) ({if (memory_check) ({x});})
......@@ -22,7 +22,7 @@ void note_did_malloc (void *p, long size) {
WHEN_MEM_DEBUG(
if (n_items_malloced<items_limit) { items[n_items_malloced]=p; sizes[n_items_malloced]=size; }
else overflowed=1;
printf("%s:%d %p=malloc(%ld)\n", __FILE__, __LINE__, p, size);
//printf("%s:%d %p=malloc(%ld)\n", __FILE__, __LINE__, p, size);
);
n_items_malloced++;
}
......@@ -44,7 +44,7 @@ void note_did_free(void *p) {
abort();
ok:;
}
printf("%s:%d free(%p)\n", __FILE__, __LINE__, p);
//printf("%s:%d free(%p)\n", __FILE__, __LINE__, p);
);
n_items_malloced--;
}
......@@ -136,13 +136,13 @@ void *toku_malloc(long size) {
void * r;
errno=0;
r=actual_malloc(size);
printf("%s:%d malloc(%ld)->%p\n", __FILE__, __LINE__, size,r);
//printf("%s:%d malloc(%ld)->%p\n", __FILE__, __LINE__, size,r);
note_did_malloc(r, size);
//if ((long)r==0x80523f8) { printf("%s:%d %p size=%ld\n", __FILE__, __LINE__, r, size); }
return r;
}
void *tagmalloc(unsigned long size, int typtag) {
printf("%s:%d tagmalloc\n", __FILE__, __LINE__);
//printf("%s:%d tagmalloc\n", __FILE__, __LINE__);
void *r = toku_malloc(size);
assert(size>sizeof(int));
((int*)r)[0] = typtag;
......
......@@ -27,6 +27,7 @@ struct pma {
* Regions of size 128 are 60% full. Regions of size 256 are 50% full.
* The densitystep is 0.10. */
PMA_CURSOR cursors_head, cursors_tail;
int (*compare_fun)(DB*,DBT*,DBT*);
};
int pmainternal_count_region (struct pair *pairs, int lo, int hi);
......
......@@ -9,7 +9,7 @@
static void test_make_space_at (void) {
PMA pma;
int r=pma_create(&pma);
int r=pma_create(&pma, default_compare_fun);
assert(r==0);
assert(pma_n_entries(pma)==0);
r=pmainternal_make_space_at(pma, 2);
......@@ -200,7 +200,7 @@ static void test_count_region (void) {
static void test_pma_random_pick (void) {
PMA pma;
int r = pma_create(&pma);
int r = pma_create(&pma, default_compare_fun);
bytevec key,val;
ITEMLEN keylen,vallen;
assert(r==0);
......@@ -260,7 +260,7 @@ static void test_find_insert (void) {
int r;
bytevec dv;
ITEMLEN dl;
pma_create(&pma);
pma_create(&pma, default_compare_fun);
r=pma_lookup(pma, "aaa", 3, &dv, &dl);
assert(r==DB_NOTFOUND);
......@@ -291,7 +291,7 @@ static void test_find_insert (void) {
assert((unsigned long)pma->pairs[pma_index_limit(pma)].key==0xdeadbeefL);
r=pma_free(&pma); assert(r==0); assert(pma==0);
pma_create(&pma); assert(pma!=0);
pma_create(&pma, default_compare_fun); assert(pma!=0);
{
int i;
......@@ -327,7 +327,7 @@ static void test_pma_iterate_internal (PMA pma, int expected_k, int expected_v)
static void test_pma_iterate (void) {
PMA pma;
int r;
pma_create(&pma);
pma_create(&pma, default_compare_fun);
r=pma_insert(pma, "42", 3, "-19", 4);
assert(r==BRT_OK);
test_pma_iterate_internal(pma, 42, -19);
......@@ -343,8 +343,8 @@ static void test_pma_iterate2 (void) {
int r;
int sum=0;
int n_items=0;
r=pma_create(&pma0); assert(r==0);
r=pma_create(&pma1); assert(r==0);
r=pma_create(&pma0, default_compare_fun); assert(r==0);
r=pma_create(&pma1, default_compare_fun); assert(r==0);
pma_insert(pma0, "a", 2, "aval", 5);
pma_insert(pma0, "b", 2, "bval", 5);
pma_insert(pma1, "x", 2, "xval", 5);
......@@ -361,7 +361,7 @@ void test_pma_cursor_0 (void) {
PMA pma;
PMA_CURSOR c=0;
int r;
r=pma_create(&pma); assert(r==0);
r=pma_create(&pma, default_compare_fun); assert(r==0);
r=pma_cursor(pma, &c); assert(r==0); assert(c!=0);
printf("%s:%d\n", __FILE__, __LINE__);
r=pma_free(&pma); assert(r!=0); /* didn't deallocate the cursor. */
......@@ -379,7 +379,7 @@ void test_pma_cursor_1 (void) {
int r;
int order;
for (order=0; order<6; order++) {
r=pma_create(&pma); assert(r==0);
r=pma_create(&pma, default_compare_fun); assert(r==0);
r=pma_cursor(pma, &c0); assert(r==0); assert(c0!=0);
r=pma_cursor(pma, &c1); assert(r==0); assert(c1!=0);
r=pma_cursor(pma, &c2); assert(r==0); assert(c2!=0);
......@@ -410,7 +410,7 @@ void test_pma_cursor_2 (void) {
DBT key,val;
ybt_init(&key); key.flags=DB_DBT_REALLOC;
ybt_init(&val); val.flags=DB_DBT_REALLOC;
r=pma_create(&pma); assert(r==0);
r=pma_create(&pma, default_compare_fun); assert(r==0);
r=pma_cursor(pma, &c); assert(r==0); assert(c!=0);
r=pma_cursor_set_position_last(c); assert(r==DB_NOTFOUND);
r=pma_cursor_free(&c); assert(r==0);
......@@ -422,7 +422,7 @@ void test_pma_cursor_3 (void) {
PMA_CURSOR c=0;
int r;
DBT key,val;
r=pma_create(&pma); assert(r==0);
r=pma_create(&pma, default_compare_fun); assert(r==0);
r=pma_insert(pma, "x", 2, "xx", 3); assert(r==BRT_OK);
r=pma_insert(pma, "m", 2, "mm", 3); assert(r==BRT_OK);
r=pma_insert(pma, "aa", 3, "a", 2); assert(r==BRT_OK);
......@@ -470,9 +470,67 @@ void test_pma_cursor (void) {
test_pma_cursor_3();
}
int wrong_endian_compare_fun (DB *ignore __attribute__((__unused__)),
DBT *a, DBT *b) {
unsigned int i;
unsigned char *ad=a->data;
unsigned char *bd=b->data;
int siz = a->size;
assert(a->size==b->size); // This function requires that the keys be the same size.
abort();
for (i=0; i<a->size; i++) {
if (ad[siz-1-i]<bd[siz-1-i]) return -1;
if (ad[siz-1-i]>bd[siz-1-i]) return +1;
}
return 0;
}
void test_pma_compare_fun (int wrong_endian_p) {
PMA pma;
PMA_CURSOR c = 0;
DBT key,val;
int r;
char *wrong_endian_expected_keys[] = {"00", "10", "01", "11"}; /* Sorry for being judgemental. But it's wrong. */
char *right_endian_expected_keys[] = {"00", "01", "10", "11"};
char **expected_keys = wrong_endian_p ? wrong_endian_expected_keys : right_endian_expected_keys;
int i;
r = pma_create(&pma, wrong_endian_p ? wrong_endian_compare_fun : default_compare_fun); assert(r==0);
r = pma_insert(pma, "10", 3, "10v", 4); assert(r==BRT_OK);
r = pma_insert(pma, "00", 3, "00v", 4); assert(r==BRT_OK);
r = pma_insert(pma, "01", 3, "01v", 4); assert(r==BRT_OK);
r = pma_insert(pma, "11", 3, "11v", 4); assert(r==BRT_OK);
ybt_init(&key); key.flags=DB_DBT_REALLOC;
ybt_init(&val); val.flags=DB_DBT_REALLOC;
r=pma_cursor(pma, &c); assert(r==0); assert(c!=0);
for (i=0; i<4; i++) {
if (i==0) {
r=pma_cursor_set_position_first(c); assert(r==0);
} else {
r=pma_cursor_set_position_next(c); assert(r==0);
}
r=pma_cget_current(c, &key, &val); assert(r==0);
//printf("Got %s, expect %s\n", (char*)key.data, expected_keys[i]);
assert(key.size=3); assert(memcmp(key.data,expected_keys[i],3)==0);
assert(val.size=4); assert(memcmp(val.data,expected_keys[i],2)==0);
assert(memcmp(2+(char*)val.data,"v",2)==0);
}
r=pma_cursor_set_position_next(c); assert(r==DB_NOTFOUND);
toku_free(key.data);
toku_free(val.data);
r=pma_cursor_free(&c); assert(r==0);
r=pma_free(&pma); assert(r==0);
}
void pma_tests (void) {
memory_check=1;
test_pma_iterate(); memory_check_all_free();
test_pma_compare_fun(0); memory_check_all_free();
test_pma_compare_fun(1); memory_check_all_free();
test_pma_iterate();
test_pma_iterate2(); memory_check_all_free();
test_make_space_at(); memory_check_all_free();
test_smooth_region(); memory_check_all_free();
......
......@@ -261,7 +261,7 @@ int pmainternal_count_region (struct pair *pairs, int lo, int hi) {
return n;
}
int pma_create (PMA *pma) {
int pma_create (PMA *pma, int (*compare_fun)(DB*,DBT*,DBT*)) {
TAGMALLOC(PMA, result);
int i;
if (result==0) return -1;
......@@ -282,6 +282,7 @@ int pma_create (PMA *pma) {
}
pmainternal_calculate_parameters(result);
result->cursors_head = result->cursors_tail = 0;
result->compare_fun = compare_fun;
*pma = result;
assert((unsigned long)result->pairs[result->N].key==0xdeadbeefL);
return 0;
......@@ -557,5 +558,3 @@ void pma_iterate (PMA pma, void(*f)(bytevec,ITEMLEN,bytevec,ITEMLEN, void*), voi
}
}
}
......@@ -12,7 +12,7 @@ typedef struct pma *PMA;
typedef struct pma_cursor *PMA_CURSOR;
/* All functions return 0 on success. */
int pma_create (PMA *);
int pma_create (PMA *, int (*compare_fun)(DB*,DBT*,DBT*));
/* returns 0 if OK.
* You must have freed all the cursors, otherwise returns nonzero and does nothing. */
......
......@@ -36,8 +36,8 @@ C_OBJS= mut_pthread.lo \
txn_region.lo txn_stat.lo txn_util.lo xa.lo xa_db.lo xa_map.lo
MAYBENOTICECALL = noticecall.lo
#install: libdb.so
# cp libdb.so ../src/
install: libdb.so
cp libdb.so ../lib/
libdb.so: ydb.lo bdbw.lo $(MAYBENOTICECALL)
echo cc ydb.lo bdbw.lo BDB-OBJS -shared -fPIC -o libdb.so $(CFLAGS)
@cc ydb.lo bdbw.lo $(MAYBENOTICECALL) $(patsubst %,/home/bradley/mysql/build-bdb-with-uniquename/bdb/build_unix/%,$(C_OBJS)) -shared -fPIC -o libdb.so $(CFLAGS)
......
......@@ -409,11 +409,26 @@ int yobi_dbc_c_get (DBC_ydb *dbc, DBT_ydb *a, DBT_ydb *b, u_int32_t flags) {
tracef(" &a, &b, ");
tracef(" %s);\n", flagstring);
if (r==0) {
unsigned int i;
tracef(" assert(r==%d);\n", r);
tracef(" assert(a.size==%d);\n", da.size);
//tracef(" assert(memcmp(a.address, ");
tracef(" assert(b.size==%d);\n", db.size);
tracef(" { unsigned char adata[%d] = {", da.size);
for (i=0; i<da.size; i++) {
if (i>0) tracef(", ");
tracef("%u", ((unsigned char*)(da.data))[i]);
}
tracef("};\n unsigned char bdata[%d] = {", db.size);
for (i=0; i<db.size; i++) {
if (i>0) tracef(", ");
tracef("%u", ((unsigned char*)(db.data))[i]);
}
tracef("};\n");
tracef(" assert(memcmp(a.data, adata, sizeof(adata))==0);\n");
tracef(" assert(memcmp(b.data, bdata, sizeof(bdata))==0);\n");
a->size = da.size;
tracef(" }\n");
a->data = da.data;
b->size = db.size;
b->data = db.data;
......@@ -503,10 +518,11 @@ static int bdbw_db_open (DB_ydb *db, DB_TXN_ydb *txn, const char *fname, const
static int bdbw_bt_compare (DB *db, const DBT *a, const DBT *b) {
DB_ydb *ydb = db->app_private;
DBT_ydb a_y, b_y;
note();
//note();
assert(ydb);
a_y.data = a->data;
a_y.size = a->size;
a_y.app_private = a->app_private; /* mysql uses app_private for key compares. */
b_y.data = b->data;
b_y.size = b->size;
return ydb->i->bt_compare(ydb, &a_y, &b_y);
......@@ -551,6 +567,7 @@ int bdbw_db_put (DB_ydb *db, DB_TXN_ydb *txn, DBT_ydb *dbta, DBT_ydb *dbtb, u_i
a.flags = 0; b.flags = 0;
a.ulen = 0; b.ulen = 0;
a.size = dbta->size; b.size = dbtb->size;
a.app_private = dbta->app_private; /* mysql uses app_private to inform bt_compare of the key structure, so comparisons can be done properly. This is needed because mysql does not write the keys to disk in a format that memcmp() could be used. */
r=db->i->db->put(db->i->db, txn ? txn->i->txn : 0, &a, &b, flags);
assert(r==0);
tracef(" r=dbobj(%lld)->put(dbobj(%lld), txnobj(%lld), &a, &b, %s); assert(r==%d);\n}\n",
......@@ -593,7 +610,7 @@ static int bdbw_db_set_bt_compare (DB_ydb *db, int (*bt_compare)(DB_ydb *, cons
if (bt_compare==berkeley_cmp_hidden_key) {
fun_name = "berkeley_cmp_hidden_key";
} else if (bt_compare==berkeley_cmp_packed_key) {
fun_name = "berkeley_cmp_hidden_key";
fun_name = "berkeley_cmp_packed_key";
} else {
fun_name = "Unknown_function";
barf();
......
#include <db.h>
#include <pthread.h>
#include <stdlib.h>
#define MANAGER_BERKELEY_LOG_CLEANUP (1L << 0)
......@@ -33,3 +34,10 @@ berkeley_cmp_hidden_key(DB* file, const DBT *new_key, const DBT *saved_key)
unsigned long long b=uint5korr((char*) saved_key->data);
return a < b ? -1 : (a > b ? 1 : 0);
}
int
berkeley_cmp_packed_key(DB* file, const DBT *new_key, const DBT *saved_key)
{
printf("Whoops\n");
abort();
}
......@@ -370,7 +370,7 @@ int yobi_db_open (DB *db, DB_TXN *txn, const char *fname, const char *dbname, D
}
int yobi_db_put (DB *db, DB_TXN *txn, DBT *dbta, DBT *dbtb, u_int32_t flags) {
int r = brt_insert(db->i->brt, dbta->data, dbta->size, dbtb->data, dbtb->size);
printf("%s:%d %d=yobi_db_put(...)\n", __FILE__, __LINE__, r);
//printf("%s:%d %d=yobi_db_put(...)\n", __FILE__, __LINE__, r);
return r;
}
int yobi_db_remove (DB *db, const char *fname, const char *dbname, u_int32_t flags) {
......
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