2005-01-14 01:52:53 +00:00
|
|
|
/*---
|
|
|
|
This software is copyrighted by the Regents of the University of
|
|
|
|
California, and other parties. The following terms apply to all files
|
|
|
|
associated with the software unless explicitly disclaimed in
|
|
|
|
individual files.
|
|
|
|
|
|
|
|
The authors hereby grant permission to use, copy, modify, distribute,
|
|
|
|
and license this software and its documentation for any purpose,
|
|
|
|
provided that existing copyright notices are retained in all copies
|
|
|
|
and that this notice is included verbatim in any distributions. No
|
|
|
|
written agreement, license, or royalty fee is required for any of the
|
|
|
|
authorized uses. Modifications to this software may be copyrighted by
|
|
|
|
their authors and need not follow the licensing terms described here,
|
|
|
|
provided that the new terms are clearly indicated on the first page of
|
|
|
|
each file where they apply.
|
|
|
|
|
|
|
|
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
|
|
|
|
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
|
|
|
|
DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
|
|
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
|
|
|
NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND
|
|
|
|
THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
|
|
|
|
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
|
|
|
|
GOVERNMENT USE: If you are acquiring this software on behalf of the
|
|
|
|
U.S. government, the Government shall have only "Restricted Rights" in
|
|
|
|
the software and related documentation as defined in the Federal
|
|
|
|
Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you are
|
|
|
|
acquiring the software on behalf of the Department of Defense, the
|
|
|
|
software shall be classified as "Commercial Computer Software" and the
|
|
|
|
Government shall have only "Restricted Rights" as defined in Clause
|
|
|
|
252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the
|
|
|
|
authors grant the U.S. Government and others acting in its behalf
|
|
|
|
permission to use and distribute the software in accordance with the
|
|
|
|
terms specified in this license.
|
|
|
|
---*/
|
|
|
|
|
|
|
|
#include "../check_includes.h"
|
|
|
|
|
2007-06-11 21:36:57 +00:00
|
|
|
#include <stasis/transactional.h>
|
2005-01-14 01:52:53 +00:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <math.h>
|
2005-01-15 01:45:27 +00:00
|
|
|
#include <pthread.h>
|
2006-06-12 22:45:41 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2005-01-14 01:52:53 +00:00
|
|
|
#define LOG_NAME "check_linearHashNTA.log"
|
2008-09-28 03:11:24 +00:00
|
|
|
static const int NUM_ENTRIES = 100000;
|
2008-11-13 04:18:50 +00:00
|
|
|
|
|
|
|
#define ARRAY_SIZE (2 * 3 * (int)(PAGE_SIZE * 1.5))
|
|
|
|
static void arraySet(int * a, int mul) {
|
2009-04-14 20:21:05 +00:00
|
|
|
int i;
|
2008-11-13 04:18:50 +00:00
|
|
|
|
|
|
|
for ( i = 0 ; i < ARRAY_SIZE; i++) {
|
|
|
|
a[i]= mul*i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int arryCmp(int * a, int * b, int len) {
|
|
|
|
return memcmp(a,b,len);
|
|
|
|
}
|
|
|
|
|
2010-09-01 04:01:20 +00:00
|
|
|
START_TEST(linearHashNTAabortTest) {
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
int xid = Tbegin();
|
|
|
|
recordid rid = ThashCreate(xid, -1, -1);
|
|
|
|
assert(0 == ThashInsert(xid, rid, "foo", 4, "bar", 4));
|
|
|
|
char * ret;
|
|
|
|
int len = ThashLookup(xid, rid, "foo", 4, &ret);
|
|
|
|
assert(len == 4);
|
|
|
|
assert(!strcmp("bar", ret));
|
|
|
|
free(ret);
|
|
|
|
Tcommit(xid);
|
|
|
|
|
|
|
|
xid = Tbegin();
|
|
|
|
|
|
|
|
assert(1 == ThashInsert(xid, rid, "foo", 4, "baz", 4));
|
|
|
|
assert(0 == ThashInsert(xid, rid, "bar", 4, "bat", 4));
|
|
|
|
|
|
|
|
len = ThashLookup(xid, rid, "foo", 4, &ret);
|
|
|
|
assert(len == 4);
|
|
|
|
assert(!strcmp("baz", ret));
|
|
|
|
free(ret);
|
|
|
|
|
|
|
|
len = ThashLookup(xid, rid, "bar", 4, &ret);
|
|
|
|
assert(len == 4);
|
|
|
|
assert(!strcmp("bat", ret));
|
|
|
|
free(ret);
|
|
|
|
|
|
|
|
Tabort(xid);
|
|
|
|
|
|
|
|
len = ThashLookup(xid, rid, "foo", 4, &ret);
|
|
|
|
assert(len == 4);
|
|
|
|
assert(!strcmp("bar", ret));
|
|
|
|
free(ret);
|
|
|
|
|
|
|
|
/*
|
|
|
|
assert_equal(nil, Hash.lookup( -1, rid, "bar"))
|
|
|
|
assert_equal(0, Tdeinit)
|
|
|
|
assert_equal(0, Tinit)
|
|
|
|
assert_equal("bar", Hash.lookup( -1, rid, "foo"))
|
|
|
|
assert_equal(nil, Hash.lookup( -1, rid, "bar"))
|
|
|
|
assert_equal(0, Hash.insert(xid, rid, "bar", "bat"))
|
|
|
|
assert_equal("bat", Hash.lookup(xid,rid,"bar"))
|
|
|
|
assert_equal(0, Raw.Tdeinit)
|
|
|
|
*/
|
|
|
|
|
|
|
|
Tdeinit();
|
|
|
|
} END_TEST
|
|
|
|
|
2008-11-13 04:18:50 +00:00
|
|
|
/**
|
|
|
|
@test
|
2005-01-15 01:45:27 +00:00
|
|
|
*/
|
2005-01-14 01:52:53 +00:00
|
|
|
START_TEST(linearHashNTAtest)
|
|
|
|
{
|
|
|
|
Tinit();
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2005-01-14 01:52:53 +00:00
|
|
|
int xid = Tbegin();
|
|
|
|
recordid val;
|
|
|
|
recordid hashHeader = ThashCreate(xid, sizeof(int), sizeof(recordid));
|
|
|
|
recordid * val2;
|
2006-07-25 21:14:33 +00:00
|
|
|
recordid ** bval2 = &val2;
|
2005-01-14 01:52:53 +00:00
|
|
|
int i;
|
|
|
|
printf("\n"); fflush(stdout);
|
|
|
|
for(i = 0; i < NUM_ENTRIES; i++) {
|
|
|
|
if(!(i % (NUM_ENTRIES/10))) {
|
|
|
|
printf("."); fflush(stdout);
|
|
|
|
}
|
|
|
|
val.page = i * NUM_ENTRIES;
|
|
|
|
val.slot = val.page * NUM_ENTRIES;
|
|
|
|
val.size = val.slot * NUM_ENTRIES;
|
2006-07-25 21:14:33 +00:00
|
|
|
int found = ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)bval2);
|
2005-02-08 01:13:57 +00:00
|
|
|
assert(-1 == found);
|
2005-01-14 01:52:53 +00:00
|
|
|
ThashInsert(xid, hashHeader, (byte*)&i, sizeof(int), (byte*)&val, sizeof(recordid));
|
2006-07-25 21:14:33 +00:00
|
|
|
found = ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)bval2);
|
2005-02-08 01:13:57 +00:00
|
|
|
assert(sizeof(recordid) == found);
|
2008-09-28 03:11:24 +00:00
|
|
|
assert(val2->page == val.page);
|
|
|
|
assert(val2->slot == val.slot);
|
|
|
|
assert(val2->size == val.size);
|
2005-01-14 01:52:53 +00:00
|
|
|
free(val2);
|
|
|
|
}
|
|
|
|
Tcommit(xid);
|
|
|
|
printf("\n"); fflush(stdout);
|
|
|
|
|
|
|
|
xid = Tbegin();
|
|
|
|
for(i = 0; i < NUM_ENTRIES; i+=10){
|
|
|
|
if(!(i % (NUM_ENTRIES/10))) {
|
|
|
|
printf("-"); fflush(stdout);
|
|
|
|
}
|
2006-07-25 21:14:33 +00:00
|
|
|
int found = ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)bval2);
|
2005-02-08 01:13:57 +00:00
|
|
|
assert(sizeof(recordid) == found);
|
2005-01-14 01:52:53 +00:00
|
|
|
free(val2);
|
2009-04-14 20:21:05 +00:00
|
|
|
found = ThashRemove(xid, hashHeader, (byte*)&i, sizeof(int));
|
2005-02-08 01:13:57 +00:00
|
|
|
assert(found);
|
2006-07-25 21:14:33 +00:00
|
|
|
found = ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)bval2);
|
2005-02-08 01:13:57 +00:00
|
|
|
assert(-1==found);
|
|
|
|
found = ThashRemove(xid, hashHeader, (byte*)&i, sizeof(int));
|
|
|
|
assert(!found);
|
2005-01-14 01:52:53 +00:00
|
|
|
}
|
2009-06-02 18:25:35 +00:00
|
|
|
printf("\n"); fflush(stdout);
|
2005-01-14 01:52:53 +00:00
|
|
|
Tabort(xid);
|
|
|
|
xid = Tbegin();
|
|
|
|
for(i = 0; i < NUM_ENTRIES; i++) {
|
|
|
|
if(!(i % (NUM_ENTRIES/10))) {
|
|
|
|
printf("+"); fflush(stdout);
|
|
|
|
}
|
2006-07-25 21:14:33 +00:00
|
|
|
int found = ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)bval2);
|
2005-02-08 01:13:57 +00:00
|
|
|
assert(sizeof(recordid) == found);
|
2005-01-14 01:52:53 +00:00
|
|
|
assert(val2->page == i * NUM_ENTRIES);
|
2008-09-28 03:11:24 +00:00
|
|
|
assert(val2->slot == (slotid_t)val2->page * NUM_ENTRIES);
|
2005-01-14 01:52:53 +00:00
|
|
|
assert(val2->size == val2->slot * NUM_ENTRIES);
|
|
|
|
free(val2);
|
|
|
|
}
|
|
|
|
Tcommit(xid);
|
|
|
|
Tdeinit();
|
2009-06-02 18:25:35 +00:00
|
|
|
printf("\n"); fflush(stdout);
|
2005-01-14 01:52:53 +00:00
|
|
|
} END_TEST
|
2005-01-28 21:28:23 +00:00
|
|
|
|
|
|
|
/** @test
|
|
|
|
*/
|
|
|
|
START_TEST(linearHashNTAVariableSizetest)
|
|
|
|
{
|
2009-06-02 18:25:35 +00:00
|
|
|
fflush(stdout); printf("\n");
|
|
|
|
|
2005-01-28 21:28:23 +00:00
|
|
|
Tinit();
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2005-01-28 21:28:23 +00:00
|
|
|
int xid = Tbegin();
|
|
|
|
recordid val;
|
2008-03-01 19:35:16 +00:00
|
|
|
memset(&val,0,sizeof(val));
|
2005-01-28 21:28:23 +00:00
|
|
|
recordid hashHeader = ThashCreate(xid, VARIABLE_LENGTH, VARIABLE_LENGTH);
|
|
|
|
recordid * val2;
|
2006-07-25 21:14:33 +00:00
|
|
|
recordid ** bval2 = &val2;
|
2005-01-28 21:28:23 +00:00
|
|
|
int i;
|
|
|
|
for(i = 0; i < NUM_ENTRIES; i++) {
|
|
|
|
if(!(i % (NUM_ENTRIES/10))) {
|
|
|
|
printf("."); fflush(stdout);
|
|
|
|
}
|
|
|
|
val.page = i * NUM_ENTRIES;
|
|
|
|
val.slot = val.page * NUM_ENTRIES;
|
|
|
|
val.size = val.slot * NUM_ENTRIES;
|
2009-04-14 20:21:05 +00:00
|
|
|
val2 = 0;
|
2006-07-25 21:14:33 +00:00
|
|
|
int found = ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)bval2);
|
2005-02-08 01:13:57 +00:00
|
|
|
assert(-1 == found);
|
2005-01-28 21:28:23 +00:00
|
|
|
ThashInsert(xid, hashHeader, (byte*)&i, sizeof(int), (byte*)&val, sizeof(recordid));
|
2005-01-29 01:17:37 +00:00
|
|
|
val2 =0;
|
2006-07-25 21:14:33 +00:00
|
|
|
int ret = ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)bval2);
|
2006-07-21 01:07:09 +00:00
|
|
|
|
2005-01-29 01:17:37 +00:00
|
|
|
assert(sizeof(recordid) == ret);
|
2008-09-28 03:11:24 +00:00
|
|
|
assert(val2->page == val.page);
|
|
|
|
assert(val2->slot == val.slot);
|
|
|
|
assert(val2->size == val.size);
|
2005-01-28 21:28:23 +00:00
|
|
|
free(val2);
|
|
|
|
}
|
2006-07-21 01:07:09 +00:00
|
|
|
|
2005-01-28 21:28:23 +00:00
|
|
|
Tcommit(xid);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2006-10-04 04:34:23 +00:00
|
|
|
printf("\n");
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2005-01-28 21:28:23 +00:00
|
|
|
xid = Tbegin();
|
|
|
|
for(i = 0; i < NUM_ENTRIES; i+=10){
|
|
|
|
if(!(i % (NUM_ENTRIES/10))) {
|
|
|
|
printf("-"); fflush(stdout);
|
|
|
|
}
|
2006-07-25 21:14:33 +00:00
|
|
|
int found = ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)bval2);
|
2005-02-08 01:13:57 +00:00
|
|
|
assert(sizeof(recordid) == found);
|
2005-01-28 21:28:23 +00:00
|
|
|
free(val2);
|
2009-04-14 20:21:05 +00:00
|
|
|
found = ThashRemove(xid, hashHeader, (byte*)&i, sizeof(int));
|
2005-02-08 01:13:57 +00:00
|
|
|
assert(found);
|
2006-07-25 21:14:33 +00:00
|
|
|
found = ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)bval2);
|
2005-02-08 01:13:57 +00:00
|
|
|
assert(-1==found);
|
|
|
|
found = ThashRemove(xid, hashHeader, (byte*)&i, sizeof(int));
|
|
|
|
assert(!found);
|
2005-01-28 21:28:23 +00:00
|
|
|
}
|
2009-06-02 18:25:35 +00:00
|
|
|
printf("\n"); fflush(stdout);
|
2005-01-28 21:28:23 +00:00
|
|
|
Tabort(xid);
|
|
|
|
xid = Tbegin();
|
|
|
|
for(i = 0; i < NUM_ENTRIES; i++) {
|
|
|
|
if(!(i % (NUM_ENTRIES/10))) {
|
|
|
|
printf("+"); fflush(stdout);
|
|
|
|
}
|
2006-07-25 21:14:33 +00:00
|
|
|
int ret = ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)bval2);
|
2005-01-31 02:18:46 +00:00
|
|
|
assert(sizeof(recordid) == ret);
|
2005-01-28 21:28:23 +00:00
|
|
|
assert(val2->page == i * NUM_ENTRIES);
|
2008-09-28 03:11:24 +00:00
|
|
|
assert(val2->slot == (slotid_t)val2->page * NUM_ENTRIES);
|
2005-01-28 21:28:23 +00:00
|
|
|
assert(val2->size == val2->slot * NUM_ENTRIES);
|
|
|
|
free(val2);
|
|
|
|
}
|
2009-06-02 18:25:35 +00:00
|
|
|
printf("\n");
|
2005-01-28 21:28:23 +00:00
|
|
|
Tcommit(xid);
|
|
|
|
Tdeinit();
|
|
|
|
} END_TEST
|
|
|
|
|
|
|
|
|
2006-06-12 22:45:41 +00:00
|
|
|
#define DEFAULT_NUM_THREADS 100
|
|
|
|
|
|
|
|
#define DEFAULT_NUM_T_ENTRIES 500
|
|
|
|
|
|
|
|
int NUM_THREADS = DEFAULT_NUM_THREADS;
|
|
|
|
int NUM_T_ENTRIES = DEFAULT_NUM_T_ENTRIES;
|
2005-01-28 21:28:23 +00:00
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
typedef struct {
|
2005-01-15 01:45:27 +00:00
|
|
|
int thread;
|
|
|
|
recordid rid;
|
|
|
|
} linear_hash_worker_args;
|
|
|
|
recordid makekey(int thread, int i) {
|
|
|
|
recordid ret;
|
|
|
|
ret.page = thread * NUM_T_ENTRIES + i;
|
|
|
|
ret.slot = thread * NUM_T_ENTRIES + i * 2;
|
|
|
|
ret.size= thread * NUM_T_ENTRIES + i * 3;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
void * worker(void* arg) {
|
|
|
|
linear_hash_worker_args * args = arg;
|
|
|
|
int thread = args->thread;
|
|
|
|
recordid hash = args->rid;
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2005-01-15 01:45:27 +00:00
|
|
|
int xid = Tbegin();
|
|
|
|
|
|
|
|
int i;
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2005-01-15 01:45:27 +00:00
|
|
|
for(i = 0; i < NUM_T_ENTRIES; i++) {
|
|
|
|
int value = i + thread * NUM_T_ENTRIES;
|
|
|
|
recordid key = makekey(thread,i);
|
|
|
|
ThashInsert(xid, hash, (byte*)&key, sizeof(recordid), (byte*)&value, sizeof(int));
|
|
|
|
}
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2005-01-15 01:45:27 +00:00
|
|
|
Tcommit(xid);
|
|
|
|
xid = Tbegin();
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2006-07-25 21:14:33 +00:00
|
|
|
int * value;
|
|
|
|
int ** bvalue = &value;
|
2005-01-15 01:45:27 +00:00
|
|
|
for(i = 0; i < NUM_T_ENTRIES; i+=10) {
|
|
|
|
recordid key = makekey(thread,i);
|
2009-04-14 20:21:05 +00:00
|
|
|
int found = ThashRemove(xid, hash, (byte*)&key, sizeof(recordid));
|
2005-02-08 01:13:57 +00:00
|
|
|
assert(found);
|
2006-07-25 21:14:33 +00:00
|
|
|
found = ThashLookup(xid, hash, (byte*)&key, sizeof(recordid), (byte**)bvalue);
|
2005-02-08 01:13:57 +00:00
|
|
|
assert(-1==found);
|
|
|
|
found = ThashRemove(xid, hash, (byte*)&key, sizeof(recordid));
|
|
|
|
assert(!found);
|
2005-01-15 01:45:27 +00:00
|
|
|
}
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2005-01-15 01:45:27 +00:00
|
|
|
Tabort(xid);
|
|
|
|
xid = Tbegin();
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2005-01-15 01:45:27 +00:00
|
|
|
for(i = 0; i < NUM_T_ENTRIES; i+=10) {
|
|
|
|
recordid key = makekey(thread,i);
|
2006-07-25 21:14:33 +00:00
|
|
|
int found = ThashLookup(xid, hash, (byte*)&key, sizeof(recordid), (byte**)bvalue);
|
2009-04-14 20:21:05 +00:00
|
|
|
assert(sizeof(int) == found);
|
2005-01-15 01:45:27 +00:00
|
|
|
assert(*value == i + thread * NUM_T_ENTRIES);
|
|
|
|
free (value);
|
|
|
|
}
|
|
|
|
Tcommit(xid);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
START_TEST(linearHashNTAThreadedTest) {
|
|
|
|
Tinit();
|
|
|
|
int xid = Tbegin();
|
|
|
|
recordid rid = ThashCreate(xid, sizeof(recordid), sizeof(int));
|
|
|
|
int i;
|
|
|
|
Tcommit(xid);
|
|
|
|
pthread_t threads[NUM_THREADS];
|
|
|
|
for(i = 0; i < NUM_THREADS; i++) {
|
|
|
|
linear_hash_worker_args * args = malloc(sizeof(linear_hash_worker_args));
|
|
|
|
args->thread = i;
|
|
|
|
args->rid= rid;
|
|
|
|
pthread_create(&threads[i], NULL, &worker, args);
|
|
|
|
}
|
|
|
|
for(i = 0; i < NUM_THREADS; i++) {
|
|
|
|
void * ret;
|
2006-05-25 22:49:19 +00:00
|
|
|
pthread_join(threads[i], &ret);
|
2005-01-15 01:45:27 +00:00
|
|
|
}
|
|
|
|
Tdeinit();
|
|
|
|
} END_TEST
|
2006-06-12 22:51:14 +00:00
|
|
|
#ifdef LONG_TEST
|
2006-06-12 22:45:41 +00:00
|
|
|
START_TEST(linearHashNTAThreadedTestRandomized) {
|
|
|
|
Tinit();
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, 0);
|
|
|
|
|
|
|
|
srandom(tv.tv_sec * 1000000 + tv.tv_usec);
|
2006-09-26 20:22:20 +00:00
|
|
|
NUM_THREADS = (int)(((double)random()/(double)RAND_MAX)* ((double)DEFAULT_NUM_THREADS) * 2.0);
|
|
|
|
NUM_T_ENTRIES = (int)(((double)random()/(double)RAND_MAX) * ((double)DEFAULT_NUM_T_ENTRIES) * 1.0);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2006-06-12 22:45:41 +00:00
|
|
|
printf("\n%d threads, %d entries", NUM_THREADS, NUM_T_ENTRIES);
|
|
|
|
|
|
|
|
int xid = Tbegin();
|
|
|
|
recordid rid = ThashCreate(xid, sizeof(recordid), sizeof(int));
|
|
|
|
int i;
|
|
|
|
Tcommit(xid);
|
|
|
|
pthread_t threads[NUM_THREADS];
|
|
|
|
for(i = 0; i < NUM_THREADS; i++) {
|
|
|
|
linear_hash_worker_args * args = malloc(sizeof(linear_hash_worker_args));
|
|
|
|
args->thread = i;
|
|
|
|
args->rid= rid;
|
|
|
|
pthread_create(&threads[i], NULL, &worker, args);
|
2009-04-14 20:21:05 +00:00
|
|
|
if(!(i % 50)) {
|
2006-06-12 22:45:41 +00:00
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(i = 0; i < NUM_THREADS; i++) {
|
|
|
|
void * ret;
|
|
|
|
pthread_join(threads[i], &ret);
|
|
|
|
}
|
|
|
|
Tdeinit();
|
|
|
|
} END_TEST
|
2006-06-12 22:51:14 +00:00
|
|
|
#endif // LONG_TEST
|
2008-11-13 04:18:50 +00:00
|
|
|
/**
|
|
|
|
@test Test linear hash nta when the values it stores are larger
|
|
|
|
than a single page.
|
|
|
|
*/
|
|
|
|
START_TEST(linearHashNTABlobTest) {
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
int arry1[ARRAY_SIZE];
|
|
|
|
int arry2[ARRAY_SIZE];
|
|
|
|
int arry3[ARRAY_SIZE];
|
|
|
|
int arry4[ARRAY_SIZE];
|
|
|
|
int *scratch;
|
|
|
|
int alen=ARRAY_SIZE*sizeof(int);
|
|
|
|
int one, two, three, four;
|
|
|
|
int len1,len2,len3; // len4;
|
|
|
|
|
|
|
|
arraySet(arry1,1); one = 1;
|
|
|
|
arraySet(arry2,1); two = 2;
|
|
|
|
arraySet(arry3,1); three = 3;
|
|
|
|
arraySet(arry4,1); four = 4;
|
|
|
|
|
|
|
|
int xid = Tbegin();
|
|
|
|
recordid rid = ThashCreate(xid, VARIABLE_LENGTH, VARIABLE_LENGTH);
|
|
|
|
ThashInsert(xid,rid,(byte*)&one,sizeof(one),(byte*)arry1,alen);
|
|
|
|
len1 = ThashLookup(xid,rid,(byte*)&one,sizeof(one),(byte**)&scratch);
|
|
|
|
assert(len1==alen);
|
|
|
|
assert(!arryCmp(arry1,scratch,alen));
|
|
|
|
free(scratch);
|
|
|
|
Tcommit(xid);
|
|
|
|
xid = Tbegin();
|
|
|
|
ThashInsert(xid,rid,(byte*)&two, sizeof(two), (byte*)arry2,alen/2);
|
|
|
|
ThashInsert(xid,rid,(byte*)&three,sizeof(three),(byte*)arry3,alen/3);
|
|
|
|
|
|
|
|
len2 = ThashLookup(xid,rid,(byte*)&two, sizeof(two), (byte**)&scratch);
|
|
|
|
assert(len2 == alen/2);
|
|
|
|
assert(!arryCmp(scratch,arry2,alen/2));
|
|
|
|
free(scratch);
|
|
|
|
|
|
|
|
len3 = ThashLookup(xid,rid,(byte*)&three, sizeof(three), (byte**)&scratch);
|
|
|
|
assert(len3 == alen/3);
|
|
|
|
assert(!arryCmp(scratch,arry3,alen/3));
|
|
|
|
free(scratch);
|
|
|
|
|
|
|
|
Tabort(xid);
|
|
|
|
|
|
|
|
Tdeinit();
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
xid = Tbegin();
|
|
|
|
len1 = ThashLookup(xid,rid,(byte*)&one, sizeof(one), (byte**)&scratch);
|
|
|
|
assert(len1 == alen);
|
|
|
|
assert(!arryCmp(scratch,arry1,alen));
|
|
|
|
free(scratch);
|
|
|
|
|
|
|
|
len3 = ThashLookup(xid,rid,(byte*)&two, sizeof(two), (byte**)&scratch);
|
|
|
|
assert(len3 == -1);
|
|
|
|
Tcommit(xid);
|
|
|
|
|
|
|
|
Tdeinit();
|
|
|
|
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
Tdeinit();
|
|
|
|
} END_TEST
|
|
|
|
|
2009-03-15 02:14:03 +00:00
|
|
|
void iteratorTest(int variableLength) {
|
2005-01-15 01:45:27 +00:00
|
|
|
int seen[NUM_ENTRIES];
|
2009-03-15 02:14:03 +00:00
|
|
|
recordid hash;
|
|
|
|
{
|
|
|
|
Tinit();
|
|
|
|
int xid = Tbegin();
|
|
|
|
|
|
|
|
if(variableLength) {
|
|
|
|
hash = ThashCreate(xid, VARIABLE_LENGTH, VARIABLE_LENGTH);
|
|
|
|
} else {
|
|
|
|
hash = ThashCreate(xid, sizeof(int), sizeof(recordid));
|
|
|
|
}
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2009-03-15 02:14:03 +00:00
|
|
|
int i = 0;
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2009-03-15 02:14:03 +00:00
|
|
|
for(i = 0; i < NUM_ENTRIES; i++) {
|
|
|
|
recordid value = makekey(0, i);
|
|
|
|
int found = ThashInsert(xid, hash, (byte*)&i, sizeof(int), (byte*)&value, sizeof(recordid));
|
|
|
|
assert(!found);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < NUM_ENTRIES; i++) {
|
|
|
|
seen[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
lladd_hash_iterator * it = ThashIterator(xid, hash, sizeof(int), sizeof(recordid));
|
|
|
|
|
|
|
|
int * key;
|
|
|
|
int ** bkey = &key;
|
|
|
|
recordid * value;
|
|
|
|
recordid ** bvalue = &value;
|
2009-04-14 20:21:05 +00:00
|
|
|
int keySize;
|
2009-03-15 02:14:03 +00:00
|
|
|
int valueSize;
|
|
|
|
|
|
|
|
while(ThashNext(xid, it, (byte**)bkey, &keySize, (byte**)bvalue, &valueSize)) {
|
|
|
|
|
|
|
|
recordid check = makekey(0, *key);
|
|
|
|
assert(!memcmp(value, &check, sizeof(recordid)));
|
|
|
|
|
|
|
|
assert(!seen[*key]);
|
|
|
|
seen[*key]++;
|
|
|
|
|
|
|
|
free(key);
|
|
|
|
free(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0 ; i < NUM_ENTRIES; i++) {
|
|
|
|
assert(seen[i] == 1);
|
|
|
|
seen[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tcommit(xid);
|
|
|
|
Tdeinit();
|
2005-01-15 01:45:27 +00:00
|
|
|
}
|
2009-03-15 02:14:03 +00:00
|
|
|
{
|
|
|
|
Tinit();
|
|
|
|
int xid = Tbegin();
|
|
|
|
|
|
|
|
for(int i = 0; i < NUM_ENTRIES; i++) {
|
|
|
|
recordid value = makekey(0, i);
|
|
|
|
int found = ThashInsert(xid, hash, (byte*)&i, sizeof(int), (byte*)&value, sizeof(recordid));
|
|
|
|
assert(found);
|
|
|
|
}
|
|
|
|
|
|
|
|
lladd_hash_iterator * it = ThashIterator(xid, hash, sizeof(int), sizeof(recordid));
|
|
|
|
|
|
|
|
int * key;
|
|
|
|
int ** bkey = &key;
|
|
|
|
recordid * value;
|
|
|
|
recordid ** bvalue = &value;
|
2009-04-14 20:21:05 +00:00
|
|
|
int keySize;
|
2009-03-15 02:14:03 +00:00
|
|
|
int valueSize;
|
|
|
|
|
|
|
|
while(ThashNext(xid, it, (byte**)bkey, &keySize, (byte**)bvalue, &valueSize)) {
|
|
|
|
|
|
|
|
recordid check = makekey(0, *key);
|
|
|
|
assert(!memcmp(value, &check, sizeof(recordid)));
|
|
|
|
|
|
|
|
assert(!seen[*key]);
|
|
|
|
seen[*key]++;
|
|
|
|
|
|
|
|
free(key);
|
|
|
|
free(value);
|
|
|
|
}
|
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
for(int i = 0 ; i < NUM_ENTRIES; i++) {
|
2009-03-15 02:14:03 +00:00
|
|
|
assert(seen[i] == 1);
|
|
|
|
seen[i] = 0;
|
|
|
|
}
|
|
|
|
Tabort(xid);
|
|
|
|
Tdeinit();
|
2005-01-15 01:45:27 +00:00
|
|
|
}
|
2009-03-15 02:14:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(linearHashNTAFixedLengthIteratortest) {
|
|
|
|
iteratorTest(0);
|
|
|
|
} END_TEST
|
|
|
|
|
|
|
|
START_TEST(linearHashNTAVariableLengthIteratortest) {
|
|
|
|
iteratorTest(1);
|
2005-01-15 01:45:27 +00:00
|
|
|
} END_TEST
|
2005-01-14 01:52:53 +00:00
|
|
|
|
2005-03-01 07:32:02 +00:00
|
|
|
START_TEST(emptyHashIterator) {
|
|
|
|
Tinit();
|
|
|
|
int xid = Tbegin();
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2005-03-01 07:32:02 +00:00
|
|
|
recordid hash = ThashCreate(xid, sizeof(int), sizeof(recordid));
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2005-03-01 07:32:02 +00:00
|
|
|
lladd_hash_iterator * it = ThashIterator(xid, hash, sizeof(int), sizeof(recordid));
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2005-03-01 07:32:02 +00:00
|
|
|
byte * key;
|
|
|
|
byte * value;
|
|
|
|
int keySize;
|
|
|
|
int valueSize;
|
|
|
|
|
|
|
|
while(ThashNext(xid, it, &key, &keySize, &value, &valueSize)) {
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
Tabort(xid);
|
|
|
|
|
|
|
|
Tdeinit();
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2005-03-01 07:32:02 +00:00
|
|
|
|
|
|
|
} END_TEST
|
|
|
|
START_TEST(emptyHashIterator2) {
|
|
|
|
Tinit();
|
|
|
|
int xid = Tbegin();
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2005-03-01 07:32:02 +00:00
|
|
|
recordid hash = ThashCreate(xid, sizeof(int), VARIABLE_LENGTH);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2005-03-01 07:32:02 +00:00
|
|
|
lladd_hash_iterator * it = ThashIterator(xid, hash, sizeof(int), VARIABLE_LENGTH);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2005-03-01 07:32:02 +00:00
|
|
|
byte * key;
|
|
|
|
byte * value;
|
|
|
|
int keySize;
|
|
|
|
int valueSize;
|
|
|
|
|
|
|
|
while(ThashNext(xid, it, &key, &keySize, &value, &valueSize)) {
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
Tabort(xid);
|
|
|
|
|
|
|
|
Tdeinit();
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2005-03-01 07:32:02 +00:00
|
|
|
|
|
|
|
} END_TEST
|
|
|
|
|
2009-05-21 04:13:50 +00:00
|
|
|
START_TEST(lookupPrefix) {
|
|
|
|
int xid;
|
|
|
|
recordid directoryTable, rid, *rid1;
|
|
|
|
int found;
|
|
|
|
|
|
|
|
const char *path1 = "/home/ashok/datastore/ashok_vm/.lck-0300000000000000";
|
|
|
|
const char *path2 = "/home/ashok/datastore/ashok_vm/.lck-0400000000000000";
|
|
|
|
const char *path3 = "/home/ashok/datastore/ashok_vm/ashok_vm.vmx";
|
|
|
|
const char *path4 = "/home/ashok/datastore/";
|
|
|
|
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
xid = Tbegin();
|
|
|
|
directoryTable = ThashCreate(xid, VARIABLE_LENGTH, sizeof(recordid));
|
|
|
|
assert(directoryTable.page == ROOT_RECORD.page &&
|
|
|
|
directoryTable.slot == ROOT_RECORD.slot);
|
|
|
|
|
|
|
|
Tcommit(xid);
|
|
|
|
|
|
|
|
/* INSERT: /home/ashok/datastore/ashok_vm/.lck-0300000000000000 */
|
|
|
|
xid = Tbegin();
|
|
|
|
rid = Talloc(xid, sizeof(int));
|
|
|
|
ThashInsert(xid, directoryTable,
|
|
|
|
(byte*) path1, strlen(path1),
|
|
|
|
(byte*) &rid, sizeof(recordid));
|
|
|
|
Tcommit(xid);
|
|
|
|
|
|
|
|
/* INSERT: /home/ashok/datastore/ashok_vm/.lck-0400000000000000 */
|
|
|
|
xid = Tbegin();
|
|
|
|
rid = Talloc(xid, sizeof(int));
|
|
|
|
ThashInsert(xid, directoryTable,
|
|
|
|
(byte*) path2, strlen(path2),
|
|
|
|
(byte*) &rid, sizeof(recordid));
|
|
|
|
Tcommit(xid);
|
|
|
|
|
|
|
|
/* INSERT: /home/ashok/datastore/ashok_vm/ashok_vm.vmx */
|
|
|
|
xid = Tbegin();
|
|
|
|
rid = Talloc(xid, sizeof(int));
|
|
|
|
ThashInsert(xid, directoryTable,
|
|
|
|
(byte*) path3, strlen(path3),
|
|
|
|
(byte*) &rid, sizeof(recordid));
|
|
|
|
Tcommit(xid);
|
|
|
|
|
|
|
|
/* RETRIEVE: /home/ashok/datastore/ashok_vm/.lck-0300000000000000 */
|
|
|
|
xid = Tbegin();
|
|
|
|
found = ThashLookup(xid, directoryTable, (byte*) path1,
|
|
|
|
strlen(path1), (byte**) &rid1);
|
|
|
|
Tcommit(xid);
|
|
|
|
assert(found == sizeof(recordid));
|
|
|
|
|
|
|
|
/* RETRIEVE: /home/ashok/datastore/ashok_vm/.lck-0400000000000000 */
|
|
|
|
xid = Tbegin();
|
|
|
|
found = ThashLookup(xid, directoryTable, (byte*) path2,
|
|
|
|
strlen(path2), (byte**) &rid1);
|
|
|
|
Tcommit(xid);
|
|
|
|
assert(found == sizeof(recordid));
|
|
|
|
|
|
|
|
/* RETRIEVE: /home/ashok/datastore/ashok_vm/ashok_vm.vmx */
|
|
|
|
xid = Tbegin();
|
|
|
|
found = ThashLookup(xid, directoryTable, (byte*) path3,
|
|
|
|
strlen(path3), (byte**) &rid1);
|
|
|
|
Tcommit(xid);
|
|
|
|
assert(found == sizeof(recordid));
|
|
|
|
|
|
|
|
/* RETRIEVE: /home/ashok/datastore/ */
|
|
|
|
/* EXPECT FAILURE */
|
|
|
|
xid = Tbegin();
|
|
|
|
found = ThashLookup(xid, directoryTable, (byte*) path4,
|
|
|
|
strlen(path4), (byte**) &rid1);
|
|
|
|
Tcommit(xid);
|
|
|
|
DEBUG("found = %d\n", found);
|
|
|
|
assert(found == -1);
|
|
|
|
|
|
|
|
Tdeinit();
|
|
|
|
|
|
|
|
} END_TEST
|
|
|
|
|
2005-01-14 01:52:53 +00:00
|
|
|
Suite * check_suite(void) {
|
|
|
|
Suite *s = suite_create("linearHashNTA");
|
|
|
|
/* Begin a new test */
|
|
|
|
TCase *tc = tcase_create("simple");
|
|
|
|
|
2007-03-13 18:20:08 +00:00
|
|
|
tcase_set_timeout(tc, 1200); // 20 minute timeout
|
2005-01-14 01:52:53 +00:00
|
|
|
/* Sub tests are added, one per line, here */
|
2010-09-01 04:01:20 +00:00
|
|
|
tcase_add_test(tc, linearHashNTAabortTest);
|
2009-05-21 04:13:50 +00:00
|
|
|
tcase_add_test(tc, lookupPrefix);
|
2009-03-15 02:42:00 +00:00
|
|
|
tcase_add_test(tc, emptyHashIterator);
|
2006-10-04 04:34:23 +00:00
|
|
|
tcase_add_test(tc, emptyHashIterator2);
|
2009-03-15 02:42:00 +00:00
|
|
|
tcase_add_test(tc, linearHashNTAVariableSizetest);
|
2009-03-15 02:14:03 +00:00
|
|
|
tcase_add_test(tc, linearHashNTAFixedLengthIteratortest);
|
|
|
|
tcase_add_test(tc, linearHashNTAVariableLengthIteratortest);
|
2009-03-15 02:42:00 +00:00
|
|
|
tcase_add_test(tc, linearHashNTAtest);
|
2006-10-04 04:34:23 +00:00
|
|
|
tcase_add_test(tc, linearHashNTAThreadedTest);
|
2008-11-13 04:18:50 +00:00
|
|
|
tcase_add_test(tc, linearHashNTABlobTest);
|
2006-06-12 22:45:41 +00:00
|
|
|
#ifdef LONG_TEST
|
|
|
|
tcase_add_test(tc, linearHashNTAThreadedTestRandomized);
|
|
|
|
tcase_add_test(tc, linearHashNTAThreadedTestRandomized);
|
|
|
|
tcase_add_test(tc, linearHashNTAThreadedTestRandomized);
|
2006-09-26 20:22:20 +00:00
|
|
|
tcase_add_test(tc, linearHashNTAThreadedTestRandomized);
|
|
|
|
tcase_add_test(tc, linearHashNTAThreadedTestRandomized);
|
2009-03-15 02:42:00 +00:00
|
|
|
tcase_add_test(tc, linearHashNTAThreadedTestRandomized);
|
|
|
|
#endif
|
2006-07-21 01:07:09 +00:00
|
|
|
|
2005-01-14 01:52:53 +00:00
|
|
|
/* --------------------------------------------- */
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2005-01-14 01:52:53 +00:00
|
|
|
tcase_add_checked_fixture(tc, setup, teardown);
|
|
|
|
|
|
|
|
suite_add_tcase(s, tc);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "../check_setup.h"
|