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 <config.h>
|
|
|
|
#include <check.h>
|
|
|
|
#include "../check_includes.h"
|
|
|
|
|
|
|
|
#include <lladd/transactional.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <math.h>
|
2005-01-15 01:45:27 +00:00
|
|
|
#include <pthread.h>
|
2005-01-14 01:52:53 +00:00
|
|
|
#define LOG_NAME "check_linearHashNTA.log"
|
|
|
|
#define NUM_ENTRIES 100000
|
2005-01-15 01:45:27 +00:00
|
|
|
/** @test
|
|
|
|
*/
|
2005-01-14 01:52:53 +00:00
|
|
|
START_TEST(linearHashNTAtest)
|
|
|
|
{
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
int xid = Tbegin();
|
|
|
|
recordid val;
|
|
|
|
recordid hashHeader = ThashCreate(xid, sizeof(int), sizeof(recordid));
|
|
|
|
recordid * val2;
|
|
|
|
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;
|
|
|
|
assert(-1 == ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2));
|
|
|
|
ThashInsert(xid, hashHeader, (byte*)&i, sizeof(int), (byte*)&val, sizeof(recordid));
|
|
|
|
assert(sizeof(recordid) == ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2));
|
|
|
|
assert(val2->page == i * NUM_ENTRIES);
|
|
|
|
assert(val2->slot == val2->page * NUM_ENTRIES);
|
|
|
|
assert(val2->size == val2->slot * NUM_ENTRIES);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
assert(sizeof(recordid) == ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2));
|
|
|
|
free(val2);
|
|
|
|
assert(ThashRemove(xid, hashHeader, (byte*)&i, sizeof(int)));
|
|
|
|
assert(-1==ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2));
|
|
|
|
assert(!ThashRemove(xid, hashHeader, (byte*)&i, sizeof(int)));
|
|
|
|
}
|
|
|
|
printf("\nabort()\n"); fflush(stdout);
|
|
|
|
Tabort(xid);
|
|
|
|
xid = Tbegin();
|
|
|
|
for(i = 0; i < NUM_ENTRIES; i++) {
|
|
|
|
if(!(i % (NUM_ENTRIES/10))) {
|
|
|
|
printf("+"); fflush(stdout);
|
|
|
|
}
|
|
|
|
assert(sizeof(recordid) == ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2));
|
|
|
|
assert(val2->page == i * NUM_ENTRIES);
|
|
|
|
assert(val2->slot == val2->page * NUM_ENTRIES);
|
|
|
|
assert(val2->size == val2->slot * NUM_ENTRIES);
|
|
|
|
free(val2);
|
|
|
|
}
|
|
|
|
Tcommit(xid);
|
|
|
|
Tdeinit();
|
|
|
|
} END_TEST
|
2005-01-28 21:28:23 +00:00
|
|
|
|
|
|
|
/** @test
|
|
|
|
*/
|
|
|
|
START_TEST(linearHashNTAVariableSizetest)
|
|
|
|
{
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
int xid = Tbegin();
|
|
|
|
recordid val;
|
|
|
|
recordid hashHeader = ThashCreate(xid, VARIABLE_LENGTH, VARIABLE_LENGTH);
|
|
|
|
recordid * val2;
|
|
|
|
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;
|
2005-01-29 01:17:37 +00:00
|
|
|
val2 = 0;
|
2005-01-28 21:28:23 +00:00
|
|
|
assert(-1 == ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2));
|
|
|
|
ThashInsert(xid, hashHeader, (byte*)&i, sizeof(int), (byte*)&val, sizeof(recordid));
|
2005-01-29 01:17:37 +00:00
|
|
|
val2 =0;
|
|
|
|
int ret = ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2);
|
|
|
|
assert(sizeof(recordid) == ret);
|
2005-01-28 21:28:23 +00:00
|
|
|
assert(val2->page == i * NUM_ENTRIES);
|
|
|
|
assert(val2->slot == val2->page * NUM_ENTRIES);
|
|
|
|
assert(val2->size == val2->slot * NUM_ENTRIES);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
assert(sizeof(recordid) == ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2));
|
|
|
|
free(val2);
|
|
|
|
assert(ThashRemove(xid, hashHeader, (byte*)&i, sizeof(int)));
|
|
|
|
assert(-1==ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2));
|
|
|
|
assert(!ThashRemove(xid, hashHeader, (byte*)&i, sizeof(int)));
|
|
|
|
}
|
|
|
|
printf("\nabort()\n"); fflush(stdout);
|
|
|
|
Tabort(xid);
|
|
|
|
xid = Tbegin();
|
|
|
|
for(i = 0; i < NUM_ENTRIES; i++) {
|
|
|
|
if(!(i % (NUM_ENTRIES/10))) {
|
|
|
|
printf("+"); fflush(stdout);
|
|
|
|
}
|
|
|
|
assert(sizeof(recordid) == ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2));
|
|
|
|
assert(val2->page == i * NUM_ENTRIES);
|
|
|
|
assert(val2->slot == val2->page * NUM_ENTRIES);
|
|
|
|
assert(val2->size == val2->slot * NUM_ENTRIES);
|
|
|
|
free(val2);
|
|
|
|
}
|
|
|
|
Tcommit(xid);
|
|
|
|
Tdeinit();
|
|
|
|
} END_TEST
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-01-15 01:45:27 +00:00
|
|
|
#define NUM_THREADS 100
|
|
|
|
#define NUM_T_ENTRIES 1000
|
|
|
|
typedef struct {
|
|
|
|
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;
|
|
|
|
|
|
|
|
int xid = Tbegin();
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
Tcommit(xid);
|
|
|
|
xid = Tbegin();
|
|
|
|
|
|
|
|
for(i = 0; i < NUM_T_ENTRIES; i+=10) {
|
|
|
|
int * value;
|
|
|
|
recordid key = makekey(thread,i);
|
|
|
|
assert(ThashRemove(xid, hash, (byte*)&key, sizeof(recordid)));
|
|
|
|
assert(-1==ThashLookup(xid, hash, (byte*)&key, sizeof(recordid), (byte**)&value));
|
|
|
|
assert(!ThashRemove(xid, hash, (byte*)&key, sizeof(recordid)));
|
|
|
|
}
|
|
|
|
|
|
|
|
Tabort(xid);
|
|
|
|
xid = Tbegin();
|
|
|
|
|
|
|
|
for(i = 0; i < NUM_T_ENTRIES; i+=10) {
|
|
|
|
recordid key = makekey(thread,i);
|
|
|
|
int * value;
|
|
|
|
assert(sizeof(int) == ThashLookup(xid, hash, (byte*)&key, sizeof(recordid), (byte**)&value));
|
|
|
|
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;
|
|
|
|
pthread_join(threads[i], ret);
|
|
|
|
}
|
|
|
|
Tdeinit();
|
|
|
|
} END_TEST
|
|
|
|
|
|
|
|
START_TEST(linearHashNTAIteratortest) {
|
|
|
|
Tinit();
|
|
|
|
int xid = Tbegin();
|
|
|
|
|
|
|
|
recordid hash = ThashCreate(xid, sizeof(int), sizeof(recordid));
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
for(i = 0; i < NUM_ENTRIES; i++) {
|
|
|
|
recordid value = makekey(0, i);
|
|
|
|
assert(!ThashInsert(xid, hash, (byte*)&i, sizeof(int), (byte*)&value, sizeof(recordid)));
|
|
|
|
}
|
|
|
|
|
|
|
|
int seen[NUM_ENTRIES];
|
|
|
|
|
|
|
|
for(i = 0; i < NUM_ENTRIES; i++) {
|
|
|
|
seen[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
lladd_hash_iterator * it = ThashIterator(xid, hash, sizeof(int), sizeof(recordid));
|
|
|
|
|
|
|
|
int * key;
|
|
|
|
recordid * value;
|
|
|
|
int keySize;
|
|
|
|
int valueSize;
|
|
|
|
|
|
|
|
while(ThashNext(xid, it, (byte**)&key, &keySize, (byte**)&value, &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);
|
|
|
|
}
|
|
|
|
|
|
|
|
Tcommit(xid);
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
|
|
/* Sub tests are added, one per line, here */
|
2005-01-28 21:28:23 +00:00
|
|
|
tcase_add_test(tc, linearHashNTAVariableSizetest);
|
2005-01-15 01:45:27 +00:00
|
|
|
tcase_add_test(tc, linearHashNTAIteratortest);
|
2005-01-14 01:52:53 +00:00
|
|
|
tcase_add_test(tc, linearHashNTAtest);
|
2005-01-15 01:45:27 +00:00
|
|
|
tcase_add_test(tc, linearHashNTAThreadedTest);
|
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"
|