Starting to rip the old jbhash implementation out, and replace it with a

linear hash implementation.  In particular, I've implemented (sort of) an
iterator for linear hash, and (sort of) ported libdfa to linearhash.c

I say 'sort of' since this functionality is broken with this commit.  On the other hand, CVS should build now, and the tests under lladd will pass.  libdfa's new tests don't pass at the moment.
This commit is contained in:
Sears Russell 2005-01-10 03:02:02 +00:00
parent c45ed9f5d5
commit 6198522971
20 changed files with 245 additions and 105 deletions

View file

@ -29,7 +29,7 @@ int main(int argc, char** argv) {
for(k = 0; k < xact_count; k++) {
xid = Tbegin();
for(; i < (count*(k+1)) ; i++) {
ThashInsert(xid, hash, &i, sizeof(int), &i, sizeof(int));
TnaiveHashInsert(xid, hash, &i, sizeof(int), &i, sizeof(int));
}
Tcommit(xid);

View file

@ -16,7 +16,7 @@ static void * go (void * arg_ptr) {
int xid = Tbegin();
for(j = k * count; j < (k+1) *(count) ; j++) {
ThashInsert(xid, hash, &j, sizeof(int), &j, sizeof(int));
TnaiveHashInsert(xid, hash, &j, sizeof(int), &j, sizeof(int));
// printf("(%d)", k);
}

View file

@ -41,7 +41,7 @@ int main(int argc, char** argv) {
for(i = 0; i < count ; i++) {
int j;
assert(ThashLookup(xid, hash, &i, sizeof(int), &j, sizeof(int)));
assert(TlogicalHashLookup(xid, hash, &i, sizeof(int), &j, sizeof(int)));
assert(i == j);
}

View file

@ -41,7 +41,8 @@ terms specified in this license.
---*/
#include <pbl/pbl.h>
#include <pbl/jbhash.h>
//#include <pbl/jbhash.h>
#include <lladd/operations/linearHash.h>
#include <libdfa/statemachine.h>
/** State machine hash library. */
@ -52,7 +53,8 @@ typedef struct {
recordid store;
/* Need to save the recordid of the hash if we want to recover... (???)*/
recordid hash_store;
jbHashTable_t * hash;
//jbHashTable_t * hash;
recordid hash;
pthread_mutex_t * lock;
int xid;
pblHashTable_t * memHash;
@ -78,7 +80,7 @@ StateMachine* insertSmash(smash_t * smash, state_machine_id id);
int freeSmash (smash_t * smash, state_machine_id id);
void * getSmash (smash_t * smash, state_machine_id id);
int setSmash (smash_t * smash, state_machine_id id);
void setSmash (smash_t * smash, state_machine_id id);
int forceSmash (smash_t * smash);
/*StateMachine * enumerateSmash(smash_t * rb, int * count);*/

View file

@ -4,6 +4,7 @@
#ifndef __HASH_H
#define __HASH_H
/** @todo replace() powl in hash with something more efficient, if hash() becomes a bottleneck. */
unsigned int max_bucket(unsigned char tableBits, unsigned long nextExtension);
unsigned int hash(const void * val, long val_length, unsigned char tableBits, unsigned long nextExtension);
#define twoToThe(x) (1 << (x))

View file

@ -15,15 +15,15 @@
recordid ThashAlloc(int xid, int keySize, int valSize) ;
void ThashInsert(int xid, recordid hashRid,
void TnaiveHashInsert(int xid, recordid hashRid,
void * key, int keySize,
void * val, int valSize);
/*void ThashDelete(int xid, recordid hashRid,
void * key, int keySize);*/
int ThashDelete(int xid, recordid hashRid,
int TnaiveHashDelete(int xid, recordid hashRid,
void * key, int keySize, int valSize);
void ThashUpdate(int xid, recordid hashRid, void * key, int keySize, void * val, int valSize);
int ThashLookup(int xid, recordid hashRid, void * key, int keySize, void * buf, int valSize);
void TnaiveHashUpdate(int xid, recordid hashRid, void * key, int keySize, void * val, int valSize);
int TnaiveHashLookup(int xid, recordid hashRid, void * key, int keySize, void * buf, int valSize);
void ThashInit();
void ThashDeinit();
int ThashOpen(int xid, recordid hashRid, int keySize, int valSize);

View file

@ -140,12 +140,14 @@ void recover(DfaSet * dfaSet) {
StateMachine sm_stack;
StateMachine * sm = &sm_stack;
StateMachine * this;
// Need to write iterator...
int ret = (jbHtFirst(dfaSet->smash->xid, dfaSet->smash->hash, (byte*)sm) != -1);
assert(0); // need to call linear hash iterator here.
while(ret) {
this = getSmash(dfaSet->smash, sm->machine_id);
printf("StateMachine %ld\n", sm->machine_id);
DEBUG("StateMachine %ld\n", sm->machine_id);
this->worker_thread = spawn_worker_thread(dfaSet, sm->machine_id);
ret = (jbHtNext(dfaSet->smash->xid, dfaSet->smash->hash, (byte*)sm) != -1);
}
@ -217,7 +219,7 @@ void* main_loop(DfaSet *dfaSet) {
/*writelock(dfaSet->lock, 600);*/
printf("Allocate machine %ld->", message->to_machine_id); fflush(NULL);
DEBUG("Allocate machine %ld->", message->to_machine_id); fflush(NULL);
if(message->to_machine_id == NULL_MACHINE) {
@ -238,7 +240,7 @@ void* main_loop(DfaSet *dfaSet) {
/*writeunlock(dfaSet->lock);*/
printf("Too many state machines. Dropping request for new one.\n");
fprintf(stderr, "Too many state machines. Dropping request for new one.\n");
continue;
} else {
@ -288,7 +290,7 @@ void* main_loop(DfaSet *dfaSet) {
if(i == dfaSet->transition_count) {
printf("%ld received: %ld-%d:%d->? (bad message)\n", stateMachine->machine_id, message->from_machine_id,
fprintf(stderr, "%ld received: %ld-%d:%d->? (bad message)\n", stateMachine->machine_id, message->from_machine_id,
message->type, current_state);
/*pthread_mutex_unlock(&(stateMachine->mutex));*/
continue;
@ -354,9 +356,9 @@ void* main_loop(DfaSet *dfaSet) {
if(new_state != current_state) {
printf("%ld transitioned on: %ld-%d:%d->%d from %s\n", stateMachine->machine_id, message->from_machine_id,
DEBUG("%ld transitioned on: %ld-%d:%d->%d from %s\n", stateMachine->machine_id, message->from_machine_id,
dfaSet->transitions[i].remote_state, dfaSet->transitions[i].pre_state, dfaSet->transitions[i].post_state, from);
printf(" -> %d %ld\n", new_state, message->from_machine_id);
DEBUG(" -> %d %ld\n", new_state, message->from_machine_id);
assert(new_state != NULL_STATE);
stateMachine->current_state = new_state;
@ -613,7 +615,7 @@ void * worker_loop(void * arg_void) {
/* fflush(NULL); */
writelock(dfaSet->lock, machine_id);
printf("Freeing machine %ld\n", machine_id);
DEBUG("Freeing machine %ld\n", machine_id);
/* pthread_mutex_lock(&(stateMachine->mutex)); */
/*freeMachine(&(dfaSet->monoTree), machine_id); */
@ -654,7 +656,7 @@ pthread_t spawn_worker_thread(DfaSet * dfaSet, state_machine_id machine_id) {
*worker_loop_args = malloc(sizeof(WorkerLoopArgs));
printf("spawn_worker_thread(state_machine_id=%ld)\n", machine_id);
DEBUG("spawn_worker_thread(state_machine_id=%ld)\n", machine_id);
(*worker_loop_args)->dfaSet = dfaSet;
(*worker_loop_args)->machine_id = machine_id;
@ -762,4 +764,3 @@ DfaSet * dfa_malloc(int count, short port,
return dfaSet;
}

View file

@ -40,6 +40,7 @@ permission to use and distribute the software in accordance with the
terms specified in this license.
---*/
/*#include <sys/types.h> */
#include <lladd/common.h>
#include <sys/socket.h>
#include <sys/poll.h>
#include <netinet/in.h>
@ -66,7 +67,7 @@ char * parse_addr(const char * address) {
addr_s = strtok_r(addr_copy, ":", &strtok_buf);
if(addr_s == NULL) {
printf("Invalid address (%s) passed into parse_addr", address);
fprintf(stderr, "Invalid address (%s) passed into parse_addr", address);
return NULL;
}
@ -171,7 +172,7 @@ int _send_message(const NetworkSetup *ns, Message *message, const char *to);
int __send_message(const NetworkSetup *ns, Message *message, const char *to) {
printf("Sending %ld-%d: to %s:%ld\n", message->from_machine_id, message->type ,to, message->to_machine_id);
DEBUG("Sending %ld-%d: to %s:%ld\n", message->from_machine_id, message->type ,to, message->to_machine_id);
if(strncmp(to, "bc:", 3)==0) {
@ -179,11 +180,11 @@ int __send_message(const NetworkSetup *ns, Message *message, const char *to) {
int list_number = parse_port(to);
if(list_number < 0 || list_number >= ns->broadcast_lists_count) {
printf("Invalid list number %d passed into send_message: %s\n", list_number, to);
fprintf(stderr, "Invalid list number %d passed into send_message: %s\n", list_number, to);
return -1;
}
if(ns->broadcast_list_host_count[list_number] == 0) {
printf("Sending to empty broadcast list! Address was %s\n", to);
fprintf(stderr, "Sending to empty broadcast list! Address was %s\n", to);
}
for(i =0; i < ns->broadcast_list_host_count[list_number]; i++) {
int ret;
@ -213,12 +214,12 @@ int _send_message(const NetworkSetup *ns, Message *message, const char *to) {
port = parse_port(to);
if(addr == NULL) {
printf("Send failed. Could not parse addr.\n");
fprintf(stderr, "Send failed. Could not parse addr.\n");
return -1;
}
if(port == -1) {
printf("Send failed. Could not parse port.\n");
fprintf(stderr, "Send failed. Could not parse port.\n");
free(addr);
return -1;
}
@ -244,7 +245,7 @@ int _send_message(const NetworkSetup *ns, Message *message, const char *to) {
perror("send_message");
}
if(ret != sizeof(Message)) {
printf("send_message sent partial message!\n");
fprintf(stderr, "send_message sent partial message!\n");
return -1;
}
@ -297,7 +298,7 @@ int receive_message(NetworkSetup *ns, Message *message, char *from) {
if(message_size != sizeof(Message)) {
/* drop packet */
printf("Size mismatch: %d, %d\n", message_size, sizeof(Message));
fprintf(stderr, "Size mismatch: %d, %d\n", message_size, sizeof(Message));
return 0;
} else {
/* TODO: Callback to security stuff / crypto here? */

View file

@ -1,3 +1,4 @@
#include <lladd/common.h>
#include <libdfa/networksetup.h>
#include <confuse.h>
#include <stdlib.h>
@ -64,17 +65,17 @@ NetworkSetup * readNetworkConfig(char * name, int hostnumber) {
fflush(NULL);
return NULL;
}
printf("coordinator: %s\n", cfg_getstr(cfg, "coordinator"));
printf("subordinate count: %d\n", cfg_size(cfg, "subordinates"));
DEBUG("coordinator: %s\n", cfg_getstr(cfg, "coordinator"));
DEBUG("subordinate count: %d\n", cfg_size(cfg, "subordinates"));
int i;
for(i = 0; i < cfg_size(cfg, "subordinates"); i++) {
printf("\t%s\n", cfg_getnstr(cfg, "subordinates", i));
DEBUG("\t%s\n", cfg_getnstr(cfg, "subordinates", i));
}
if(hostnumber == COORDINATOR) {
printf("I am coordinator\n");
DEBUG("I am coordinator\n");
} else {
printf("I am subordinate # %d\n", hostnumber);
DEBUG("I am subordinate # %d\n", hostnumber);
}
NetworkSetup * ret = calloc(1, sizeof(NetworkSetup));
@ -95,10 +96,12 @@ NetworkSetup * readNetworkConfig(char * name, int hostnumber) {
int j;
ret->broadcast_list_host_count[i] = cfg_size(group_cfg, "members");
ret->broadcast_lists[i] = malloc(sizeof (int *) * ret->broadcast_list_host_count[i]);
printf("Group %d size %d\n", atoi(cfg_title(group_cfg)), ret->broadcast_list_host_count[i]);
DEBUG("Group %d size %d\n", atoi(cfg_title(group_cfg)), ret->broadcast_list_host_count[i]);
for(j = 0; j < ret->broadcast_list_host_count[i]; j++) {
(*ret->broadcast_lists)[i][j] = cfg_getnint(group_cfg, "members", j);
printf("\t->%d\n", (*ret->broadcast_lists)[i][j]);
ret->broadcast_lists[i][j] =
strdup(cfg_getnstr(cfg, "subordinates", cfg_getnint(group_cfg, "members", j)-1));
DEBUG("\t->%s\n", ret->broadcast_lists[i][j]);
}
}

View file

@ -52,7 +52,8 @@ smash_t * init_Smash(int size) {
ret->contents = 0;
ret->next_sm_id = 0;
ret->store = store;
ret->hash = jbHtCreate(xid, 3499);
// ret->hash = jbHtCreate(xid, 3499);
ret->hash = lHtCreate(xid, 7);
ret->xid = xid;
ret->lock = malloc(sizeof(pthread_mutex_t));
ret->memHash = pblHtCreate();
@ -74,8 +75,6 @@ void * _getSmash (smash_t * smash, state_machine_id id) {
}
StateMachine * _insertSmash(smash_t * smash, state_machine_id id) {
int ret;
StateMachine * new;
if(smash->contents+1 == smash->size) {
@ -93,7 +92,7 @@ StateMachine * _insertSmash(smash_t * smash, state_machine_id id) {
new->current_state = START_STATE;
/* printf("Insert %ld\n", id); */
ret = (-1 != jbHtInsert(smash->xid, smash->hash, (byte*)&id, sizeof(state_machine_id), (byte*)new, sizeof(StateMachine)));
TlogicalHashInsert(smash->xid, smash->hash, (byte*)&id, sizeof(state_machine_id), (byte*)new, sizeof(StateMachine));
pblHtInsert(smash->memHash, &id, sizeof(state_machine_id), new);
/* Tcommit(smash->xid);
smash->xid = Tbegin(); */
@ -135,8 +134,7 @@ StateMachine * insertSmash(smash_t * smash, state_machine_id id) {
pthread_mutex_lock(smash->lock);
if(jbHtLookup(smash->xid, smash->hash, (byte*)&(smash->next_sm_id), sizeof(state_machine_id), (byte*)&junk) != -1) {
if(TlogicalHashLookup(smash->xid, smash->hash, (byte*)&(smash->next_sm_id), sizeof(state_machine_id), (byte*)&junk, sizeof(state_machine_id)) != -1) {
pthread_mutex_unlock(smash->lock);
return NULL;
}
@ -167,7 +165,7 @@ int freeSmash (smash_t * smash, state_machine_id id) {
free(old->sleepCond);
pblHtRemove(smash->memHash, &(id), sizeof(state_machine_id));
ret = jbHtRemove(smash->xid, smash->hash, (byte*)&(id), sizeof(state_machine_id), NULL) != -1;
ret = TlogicalHashDelete(smash->xid, smash->hash, (byte*)&(id), sizeof(state_machine_id), NULL, sizeof(state_machine_id)) != -1;
free(old);
@ -190,25 +188,26 @@ void * getSmash (smash_t * smash, state_machine_id id) {
return ret;
}
int _setSmash(smash_t * smash, state_machine_id id) {
void _setSmash(smash_t * smash, state_machine_id id) {
StateMachine * machine;
machine = _getSmash(smash, id);
return (-1 != jbHtInsert(smash->xid, smash->hash, (byte*)&id, sizeof(state_machine_id),(byte*) machine, sizeof(StateMachine)));
TlogicalHashInsert(smash->xid, smash->hash, (byte*)&id, sizeof(state_machine_id),(byte*) machine, sizeof(StateMachine));
}
int setSmash (smash_t * smash, state_machine_id id) {
int ret;
void setSmash (smash_t * smash, state_machine_id id) {
// int ret;
/* printf("Set smash: %ld\n", machine->machine_id); */
pthread_mutex_lock(smash->lock);
ret = _setSmash(smash, id);
//ret =
_setSmash(smash, id);
pthread_mutex_unlock(smash->lock);
return ret;
// return ret;
}
int forceSmash (smash_t * smash) {

View file

@ -3,6 +3,11 @@
/*static int thomasWangs32BitMixFunction(int key);
static unsigned long thomasWangs64BitMixFunction(unsigned long key);*/
unsigned int max_bucket(unsigned char tableBits, unsigned long nextExtension) {
unsigned int oldTableLength = twoToThe(tableBits - 1);
return oldTableLength + nextExtension - 1;
}
/** @todo replace powl in hash with something more efficient, if hash() becomes a bottleneck. */
unsigned int hash(const void * val, long val_length, unsigned char tableBits, unsigned long nextExtension) {

View file

@ -5,6 +5,7 @@
#include <assert.h>
#include <stdlib.h>
#include "../page.h"
/**
A from-scratch implementation of linear hashing. Uses the
@ -147,7 +148,7 @@ void TlogicalHashInsert(int xid, recordid hashRid, void * key, int keySize, void
}
int TlogicalHashDelete(int xid, recordid hashRid, void * key, int keySize, void * val, int valSize) {
if(ThashLookup(xid, hashRid, key, keySize, val, valSize)) {
if(TnaiveHashLookup(xid, hashRid, key, keySize, val, valSize)) {
undoDeleteArg * arg = malloc(sizeof(undoDeleteArg) + keySize+valSize);
arg->keySize = keySize;
arg->valSize = valSize;
@ -322,6 +323,7 @@ static void recover_split(int xid, recordid hashRid, int i, int next_split, int
recordid bb = hashRid; bb.slot = next_split + twoToThe(i-1);
recordid NULLRID; NULLRID.page = 0; NULLRID.slot=0; NULLRID.size = -1;
if(headerHashBits <= i && headerNextSplit <= next_split) {
// The split has not been completed. First, look for a duplicate entry in
@ -810,3 +812,57 @@ int TlogicalHashLookup(int xid, recordid hashRid, void * key, int keySize, void
pthread_mutex_unlock(&linearHashMutex);
return ret;
}
typedef struct {
long current_hashBucket;
recordid current_rid;
} linearHash_iterator;
typedef struct {
byte * key;
byte * value;
} linearHash_iteratorPair;
linearHash_iterator * TlogicalHashIterator(int xid, recordid hashRid) {
recordid NULLRID; NULLRID.page = 0; NULLRID.slot=2; NULLRID.size = -1;
linearHash_iterator * ret = malloc(sizeof(linearHash_iterator));
ret->current_hashBucket = 0;
ret->current_rid = NULLRID;
return ret;
}
void TlogicalHashIteratorFree(linearHash_iterator * it) {
free(it);
}
linearHash_iteratorPair TlogicalHashIteratorNext(int xid, recordid hashRid, linearHash_iterator * it, int keySize, int valSize) {
recordid NULLRID; NULLRID.page = 0; NULLRID.slot=2; NULLRID.size = -1;
recordid * headerRidB = pblHtLookup(openHashes, &hashRid.page, sizeof(int));
hashEntry * e = malloc(sizeof(hashEntry) + keySize + valSize);
linearHash_iteratorPair p;// = malloc(sizeof(linearHash_iteratorPair));
//next.size == 0 -> empty bucket. == -1 -> end of list.
int inBucket = 0;
//while(!memcmp(&(it->current_rid), &(NULLRID), sizeof(recordid))
while(it->current_rid.size == -1
&& it->current_hashBucket <= max_bucket(headerHashBits, headerNextSplit)) {
hashRid.slot = it->current_hashBucket;
Tread(xid, hashRid, e);
if(e->next.size == -1) {
it->current_rid = hashRid;
inBucket = 1;
} // else, it stays NULLRID.
it->current_hashBucket++;
}
if(! it->current_hashBucket <= max_bucket(headerHashBits, headerNextSplit)) {
p.key = NULL;
p.value = NULL;
memcpy(&(it->current_rid), &(NULLRID), sizeof(recordid));
it->current_hashBucket = 0;
} else {
p.key = memcpy(malloc(keySize), (e+1), keySize);
p.value = memcpy(malloc(valSize), ((byte*)(e+1))+keySize, valSize);
it->current_rid = e->next;
}
free(e);
return p;
}

View file

@ -23,7 +23,10 @@
#include <string.h>
#include <lladd/operations/linearHash.h>
#include <pbl/pbl.h>
/**
next.size == 0 implies empty bucket
next.size == -1 implies end of list
*/
typedef struct {
recordid next;
} hashEntry;
@ -436,7 +439,7 @@ void ThashDeinit() {
pblHtDelete(lockedBuckets);
}
void ThashInsert(int xid, recordid hashRid,
void TnaiveHashInsert(int xid, recordid hashRid,
void * key, int keySize,
void * val, int valSize) {
@ -463,7 +466,7 @@ void ThashInsert(int xid, recordid hashRid,
}
/** @todo hash hable probably should track the number of items in it,
so that expand can be selectively called. */
int ThashDelete(int xid, recordid hashRid,
int TnaiveHashDelete(int xid, recordid hashRid,
void * key, int keySize, int valSize) {
recordid * headerRidB = pblHtLookup(openHashes, &(hashRid.page), sizeof(int));
@ -496,9 +499,9 @@ int ThashOpen(int xid, recordid hashRid, int keySize, int valSize) {
return 0;
}
void ThashUpdate(int xid, recordid hashRid, void * key, int keySize, void * val, int valSize) {
ThashDelete(xid, hashRid, key, keySize, valSize);
ThashInsert(xid, hashRid, key, keySize, val, valSize);
void TnaiveHashUpdate(int xid, recordid hashRid, void * key, int keySize, void * val, int valSize) {
TnaiveHashDelete(xid, hashRid, key, keySize, valSize);
TnaiveHashInsert(xid, hashRid, key, keySize, val, valSize);
}
@ -510,7 +513,7 @@ int ThashClose(int xid, recordid hashRid) {
return 0;
}
int ThashLookup(int xid, recordid hashRid, void * key, int keySize, void * buf, int valSize) {
int TnaiveHashLookup(int xid, recordid hashRid, void * key, int keySize, void * buf, int valSize) {
recordid * headerRidB = pblHtLookup(openHashes, &(hashRid.page), sizeof(int));
/* printf("lookup header: %d %d\n", headerHashBits, headerNextSplit); */

View file

@ -10,4 +10,3 @@ void setup (void) {
void teardown(void) {
setup();
}

View file

@ -2,7 +2,7 @@ LDADD= @CHECK_LIBS@ $(top_builddir)/src/libdfa/libdfa.a $(top_builddir)/src/llad
bin_PROGRAMS=ping_pong_dfa fork_bomb star
AM_FLAGS= -g -Wall -pedantic -std=c99
if HAVE_CHECK
TESTS = check_networksetup
TESTS = check_networksetup ping_pong_dfa
else
TESTS =
endif

View file

@ -48,13 +48,32 @@ terms specified in this license.
#include "../check_includes.h"
#include <assert.h>
#include <libdfa/networksetup.h>
#include <libdfa/messages.h>
#define LOG_NAME "check_networksetup.log"
/**
@test
*/
START_TEST (networksetup_check) {
assert(readNetworkConfig("../../libdfa/networksetup.sample", COORDINATOR));
NetworkSetup * ns = readNetworkConfig("../../libdfa/networksetup.sample", COORDINATOR);
assert(ns);
assert(ns->localport == 20000);
assert(!strcmp(ns->localhost, "127.0.0.1"));
assert(ns->broadcast_lists);
assert(ns->broadcast_lists_count == 2);
int i;
for(i = 0; i < ns->broadcast_lists_count; i++) {
assert(ns->broadcast_list_host_count[i] == 2);
int j;
for(j = 0; j < ns->broadcast_list_host_count[i]; j++) {
assert(!strcmp("127.0.0.1", parse_addr(ns->broadcast_lists[i][j])));
assert(20000 + i + 2*j + 1 == parse_port(ns->broadcast_lists[i][j]));
}
}
// check contents of broadcast_lists
}
END_TEST
/**

View file

@ -39,10 +39,23 @@ 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 <assert.h> */
//#include <lladd/transactional.h>
//#include "../../src/lladd/logger/logWriter.h"
#include "../check_includes.h"
#include <assert.h>
#include <libdfa/networksetup.h>
#include <libdfa/messages.h>
#define LOG_NAME "check_networksetup.log"
#include "../../libdfa/libdfa.h"
#include <stdio.h>
#include <malloc.h>
#include <assert.h>
//#include <assert.h>
#include <stdlib.h>
#include <string.h>
callback_fcn recv_ping, recv_pong;
@ -51,7 +64,18 @@ callback_fcn recv_ping, recv_pong;
#define PING2 4
#define PONG1 1
#define PONG2 2
int main (int argc, char** argv) {
int global_kill = 100000;
/**
@todo the dfa implementation uses jbhash!
@test
*/
START_TEST (pingpong_check) {
//int main (int argc, char** argv) {
DfaSet * dfaSet = calloc(1, sizeof(DfaSet));
/* callback_fcn* callbacks[MAX_MESSAGE_COUNT]; */
@ -80,7 +104,7 @@ int main (int argc, char** argv) {
initial_sm2->message.from_machine_id = initial_sm2->machine_id;
initial_sm2->message.to_machine_id = initial_sm1->machine_id;
printf("sm1 %ld, sm2 %ld\n", initial_sm1->machine_id, initial_sm2->machine_id);
DEBUG("sm1 %ld, sm2 %ld\n", initial_sm1->machine_id, initial_sm2->machine_id);
initial_sm1->current_state = PING1;
initial_sm2->current_state = PONG1;
@ -112,25 +136,25 @@ int main (int argc, char** argv) {
transitions[0].pre_state = PING1;
transitions[0].post_state= PING2;
transitions[0].fcn_ptr = &recv_ping;
transitions[0].force = 1;
transitions[0].force = 0;
transitions[1].remote_state = PONG2;
transitions[1].pre_state = PING2;
transitions[1].post_state= PING1;
transitions[1].fcn_ptr = &recv_ping;
transitions[1].force = 1;
transitions[1].force = 0;
transitions[2].remote_state = PING1;
transitions[2].pre_state = PONG2;
transitions[2].post_state= PONG1;
transitions[2].fcn_ptr = &recv_pong;
transitions[2].force = 1;
transitions[2].force = 0;
transitions[3].remote_state = PING2;
transitions[3].pre_state = PONG1;
transitions[3].post_state= PONG2;
transitions[3].fcn_ptr = &recv_pong;
transitions[3].force = 1;
transitions[3].force = 0;
if(dfa_reinitialize(dfaSet, "127.0.0.1:10000", transitions, 4, states, 4) < 0) {
printf("Error. Exiting.\n");
@ -138,25 +162,52 @@ int main (int argc, char** argv) {
main_loop(dfaSet);
/* Can't get here. */
return 0;
// return 0;
}
END_TEST
state_name recv_ping(void * dfaSet, StateMachine * stateMachine, Message * m, char * from) {
if(stateMachine != NULL) {
printf("%ld(%d): Got a ping from %s Machine %ld\n", stateMachine->machine_id, stateMachine->current_state, from, m->from_machine_id);
if((global_kill--) <= 0) {
printf("Done: %d\n", stateMachine->machine_id);
exit(0);
} else if(stateMachine != NULL) {
DEBUG("%ld(%d): Got a ping from %s Machine %ld\n", stateMachine->machine_id, stateMachine->current_state, from, m->from_machine_id);
return 1;
} else {
printf("Got message from %s for non-existant machine.\n", from);
fprintf(stderr, "Got message from %s for non-existant machine.\n", from);
return 0;
}
}
state_name recv_pong(void * dfaSet, StateMachine * stateMachine, Message * m, char * from) {
if(stateMachine != NULL) {
printf("%ld(%d): Got a pong from %s Machine %ld\n", stateMachine->machine_id, stateMachine->current_state, from, m->from_machine_id);
if((global_kill--) <= 0) {
printf("Done: %d\n", stateMachine->machine_id);
exit(0);
} else if(stateMachine != NULL) {
DEBUG("%ld(%d): Got a pong from %s Machine %ld\n", stateMachine->machine_id, stateMachine->current_state, from, m->from_machine_id);
return 1;
} else {
printf("Got message from %s for non-existant machine.\n", from);
fprintf(stderr, "Got message from %s for non-existant machine.\n", from);
return 0;
}
}
/**
Add suite declarations here
*/
Suite * check_suite(void) {
Suite *s = suite_create("pingpong");
/* Begin a new test */
TCase *tc = tcase_create("pingpong");
/* void * foobar; */ /* used to supress warnings. */
/* Sub tests are added, one per line, here */
tcase_add_test(tc, pingpong_check);
/* --------------------------------------------- */
tcase_add_checked_fixture(tc, setup, teardown);
suite_add_tcase(s, tc);
return s;
}
#include "../check_setup.h"

View file

@ -102,8 +102,8 @@ START_TEST(simpleLinearHashTest)
/* assert(isNullRecord(lHtInsert(xid, hash, &i, sizeof(int), rid)));
assert(!isNullRecord(lHtInsert(xid, hash, &i, sizeof(int), rid))); */
ThashInsert(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid));
assert(ThashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
TnaiveHashInsert(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid));
assert(TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert(rid.page == i+1);
assert(rid.slot == i+2);
@ -122,13 +122,13 @@ START_TEST(simpleLinearHashTest)
for(int i = 0; i < NUM_ENTRIES; i+=10) {
/*recordid rid = lHtRemove(xid, hash, &i, sizeof(int)); */
recordid rid;
assert(ThashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert(TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert(rid.page == (i+1));
assert(rid.slot == (i+2));
assert(rid.size == (i+3));
assert(ThashDelete(xid, hashRoot, &i, sizeof(int), sizeof(recordid)));
assert(!ThashDelete(xid, hashRoot, &i, sizeof(int), sizeof(recordid)));
assert(!ThashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert(TnaiveHashDelete(xid, hashRoot, &i, sizeof(int), sizeof(recordid)));
assert(!TnaiveHashDelete(xid, hashRoot, &i, sizeof(int), sizeof(recordid)));
assert(!TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
}
@ -139,12 +139,12 @@ START_TEST(simpleLinearHashTest)
for(int i = 0; i < NUM_ENTRIES; i++) {
recordid rid;
if(i % 10) {
assert(ThashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert(TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert(rid.page == (i+1));
assert(rid.slot == (i+2));
assert(rid.size == (i+3));
} else {
assert(!ThashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert(!TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
}
}
@ -156,14 +156,14 @@ START_TEST(simpleLinearHashTest)
for(int i = 0; i < NUM_ENTRIES; i++) {
if(i % 10) {
assert(ThashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
ThashDelete(xid, hashRoot, &i, sizeof(int), sizeof(recordid));
assert(TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
TnaiveHashDelete(xid, hashRoot, &i, sizeof(int), sizeof(recordid));
assert(rid.page == (i+1));
assert(rid.slot == (i+2));
assert(rid.size == (i+3));
} else {
assert(!ThashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
ThashDelete(xid, hashRoot, &i, sizeof(int), sizeof(recordid));
assert(!TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
TnaiveHashDelete(xid, hashRoot, &i, sizeof(int), sizeof(recordid));
}
}
@ -171,7 +171,7 @@ START_TEST(simpleLinearHashTest)
fflush(NULL);
for(int i = 0; i < NUM_ENTRIES; i++) {
assert(!ThashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert(!TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
}
printf("Aborting..\n");
@ -184,12 +184,12 @@ START_TEST(simpleLinearHashTest)
for(int i = 0; i < NUM_ENTRIES; i++) {
if(i % 10) {
assert( ThashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert( TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert(rid.page == (i+1));
assert(rid.slot == (i+2));
assert(rid.size == (i+3));
} else {
assert(!ThashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert(!TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
}
}
printf("done checking..\n");
@ -225,12 +225,12 @@ START_TEST(transactionalLinearHashTest)
insMe.page = i;
insMe.slot = i+1;
insMe.size = i+2;
ThashInsert(xid, hashRoot, &i, sizeof(int), &insMe, sizeof(recordid));
TnaiveHashInsert(xid, hashRoot, &i, sizeof(int), &insMe, sizeof(recordid));
}
for(i = 0; i < NUM_ENTRIES_XACT; i+=10) {
recordid theVal;
assert(ThashLookup(xid, hashRoot, &i, sizeof(int), &theVal, sizeof(recordid)));
assert(TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &theVal, sizeof(recordid)));
assert(theVal.page == i);
assert(theVal.slot == i+1);
assert(theVal.size == i+2);
@ -243,7 +243,7 @@ START_TEST(transactionalLinearHashTest)
for(i = 0; i < NUM_ENTRIES_XACT; i++) {
if(!(i%10)) {
recordid theVal;
assert(ThashLookup(xid, hashRoot, &i, sizeof(int), &theVal, sizeof(recordid)));
assert(TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &theVal, sizeof(recordid)));
assert(theVal.page == i);
assert(theVal.slot == i+1);
assert(theVal.size == i+2);
@ -252,7 +252,7 @@ START_TEST(transactionalLinearHashTest)
insMe.page = i;
insMe.slot = i+1;
insMe.size = i+2;
ThashInsert(xid, hashRoot, &i, sizeof(int), &insMe, sizeof(recordid));
TnaiveHashInsert(xid, hashRoot, &i, sizeof(int), &insMe, sizeof(recordid));
}
}
@ -264,13 +264,13 @@ START_TEST(transactionalLinearHashTest)
for(i = 0; i < NUM_ENTRIES_XACT; i++) {
if(!(i%10)) {
recordid theVal;
assert(ThashLookup(xid, hashRoot, &i, sizeof(int), &theVal, sizeof(recordid)));
assert(TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &theVal, sizeof(recordid)));
assert(theVal.page == i);
assert(theVal.slot == i+1);
assert(theVal.size == i+2);
} else {
recordid theVal;
assert(!ThashLookup(xid, hashRoot, &i, sizeof(int), &theVal, sizeof(recordid)));
assert(!TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &theVal, sizeof(recordid)));
}
}
Tabort(xid);

View file

@ -103,7 +103,7 @@ START_TEST(simpleLinearHashTest)
assert(!isNullRecord(lHtInsert(xid, hash, &i, sizeof(int), rid))); */
TlogicalHashInsert(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid));
assert(ThashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert(TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert(rid.page == i+1);
assert(rid.slot == i+2);
@ -122,7 +122,7 @@ START_TEST(simpleLinearHashTest)
for(int i = 0; i < NUM_ENTRIES; i+=10) {
/*recordid rid = lHtRemove(xid, hash, &i, sizeof(int)); */
recordid rid;
assert(ThashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert(TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert(rid.page == (i+1));
assert(rid.slot == (i+2));
assert(rid.size == (i+3));
@ -137,12 +137,12 @@ START_TEST(simpleLinearHashTest)
for(int i = 0; i < NUM_ENTRIES; i++) {
recordid rid;
if(i % 10) {
assert(ThashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert(TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert(rid.page == (i+1));
assert(rid.slot == (i+2));
assert(rid.size == (i+3));
} else {
assert(!ThashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert(!TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
}
}
@ -154,13 +154,13 @@ START_TEST(simpleLinearHashTest)
for(int i = 0; i < NUM_ENTRIES; i++) {
if(i % 10) {
assert(ThashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert(TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
TlogicalHashDelete(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid));
assert(rid.page == (i+1));
assert(rid.slot == (i+2));
assert(rid.size == (i+3));
} else {
assert(!ThashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert(!TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
TlogicalHashDelete(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid));
}
}
@ -169,7 +169,7 @@ START_TEST(simpleLinearHashTest)
/* fflush(NULL);*/
for(int i = 0; i < NUM_ENTRIES; i++) {
assert(!ThashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert(!TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
}
@ -183,12 +183,12 @@ START_TEST(simpleLinearHashTest)
for(int i = 0; i < NUM_ENTRIES; i++) {
if(i % 10) {
assert( ThashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert( TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert(rid.page == (i+1));
assert(rid.slot == (i+2));
assert(rid.size == (i+3));
} else {
assert(!ThashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
assert(!TnaiveHashLookup(xid, hashRoot, &i, sizeof(int), &rid, sizeof(recordid)));
}
}
printf("done checking..\n");

View file

@ -525,7 +525,7 @@ START_TEST(operation_alloc_test) {
recordid rid2 = Talloc(xid, 100);
Tcommit(xid);
printf("rid1={%d,%d,%d} rid2={%d,%d,%d}\n",
printf("rid1={%d,%d,%ld} rid2={%d,%d,%ld}\n",
rid1.page, rid1.slot, rid1.size,
rid2.page, rid2.slot, rid2.size);