31 #define strlen(s1) ((int) strlen(s1)) 34 #define RAND_BLOCKS 64 35 #define RAND_BLOCK_SIZE 1000000 36 #define RAND_SIZE RAND_BLOCKS * RAND_BLOCK_SIZE 39 #define PTHREAD_ABORT_AND_EXIT(code) \ 72 unsigned long long int data;
106 ((
XENTRY *) entry)->data = 0;
120 ((
XENTRY *) entry)->data = -1;
133 int *ikey = (
int *) key;
134 return (*ikey) % htsize;
140 int *ik1 = (
int *) k1, *ik2 = (
int *) k2;
141 return !(*ik1 == *ik2);
147 int *isrc = (
int *) src, *idest = (
int *) dest;
186 printf (
"Testing %s", test_name);
201 printf (
" %s: %s\n",
"FAILED", message);
209 struct timeval end_time;
210 long long int elapsed_msec = 0;
212 gettimeofday (&end_time,
NULL);
214 elapsed_msec = (end_time.tv_usec -
start_time.tv_usec) / 1000;
215 elapsed_msec += (end_time.tv_sec -
start_time.tv_sec) * 1000;
217 printf (
" %s [%9.3f sec]\n",
"OK", (
float) elapsed_msec / 1000.0f);
241 for (i = 0; i <
NOPS; i++)
290 for (i = 0; i <
NOPS; i++)
329 int i, rand_base,
key;
346 for (i = 0; i <
NOPS; i++)
354 hashmap->
unlock (te, entry);
358 (void) hashmap->
erase (te, key);
381 int i, rand_base,
key;
398 for (i = 0; i <
NOPS; i++)
410 if (te->locked_mutex != &entry->
mutex)
414 te->locked_mutex =
NULL;
415 hashmap->
unlock (te, entry);
419 (void) hashmap->
erase (te, key);
446 int i, rand_base,
key, local_del_op_count = 0;
463 for (i = 0; i <
NOPS; i++)
472 if (entry->
key != key)
479 if (entry->
data >= 10)
481 local_del_op_count += entry->
data;
490 if (te->locked_mutex != &entry->
mutex)
494 te->locked_mutex =
NULL;
495 hashmap->
unlock (te, entry);
521 int i, rand_base,
key;
538 for (i = 0; i <
NOPS; i++)
549 hashmap->
unlock (te, entry);
551 else if (i % 1000 < 999)
553 (void) hashmap->
erase (te, key);
581 int i, rand_base,
key;
598 for (i = 0; i <
NOPS; i++)
612 if (te->locked_mutex != &entry->
mutex)
616 te->locked_mutex =
NULL;
617 hashmap->
unlock (te, entry);
621 (void) hashmap->
erase (te, key);
650 int i, rand_base,
key;
667 for (i = 0; i <
NOPS; i++)
685 if (entry->
data >= 10)
691 if (te->locked_mutex != &entry->
mutex)
695 te->locked_mutex =
NULL;
696 hashmap->
unlock (te, entry);
701 if (te->locked_mutex != &entry->
mutex)
705 te->locked_mutex =
NULL;
706 hashmap->
unlock (te, entry);
723 #define MAX_THREADS 64 731 sprintf (msg,
"freelist (transaction=%s, %d threads)", test_local_tran ?
"n" :
"y", nthreads);
737 return fail (
"too many threads");
742 return fail (
"transaction system init");
747 return fail (
"freelist init");
751 for (i = 0; i < nthreads; i++)
756 return fail (
"thread create");
760 for (i = 0; i < nthreads; i++)
764 pthread_join (threads[i], &retval);
767 return fail (
"thread proc error");
774 volatile int active, retired, _a, _r, _t;
796 if ((_t - active - retired) != 0)
798 sprintf (msg,
"leak problem (lost %d entries)", _t - active + retired);
802 if ((active != _a) || (retired != _r))
804 sprintf (msg,
"counting problem (%d != %d) or (%d != %d)", active, _a, retired, _r);
821 #define MAX_THREADS 1024 822 #define HASH_SIZE 113 835 sprintf (msg,
"hash (mutex=%s, %d threads)", edesc->
using_mutex ?
"y" :
"n", nthreads);
838 lf_reset_counters ();
843 return fail (
"too many threads");
848 return fail (
"transaction system init");
854 for (i = 0; i < nthreads; i++)
856 if (pthread_create (&threads[i],
NULL, proc, (
void *) &hashmap) !=
NO_ERROR)
858 return fail (
"thread create");
862 for (i = 0; i < nthreads; i++)
866 pthread_join (threads[i], &retval);
869 return fail (
"thread proc error");
877 if (edesc->
f_hash (&e->
key, HASH_SIZE) != (
unsigned int) i)
879 sprintf (msg,
"hash (%d) = %d != %d", e->
key, edesc->
f_hash (&e->
key, HASH_SIZE),
i);
888 int nondel_op_count = 0;
894 nondel_op_count += e->
data;
901 if (nondel_op_count +
del_op_count != nthreads * 1000000)
903 sprintf (msg,
"op count fail (%d + %d != %d)", nondel_op_count,
del_op_count, nthreads * 1000000);
912 int ecount = 0, acount = 0, rcount = 0;
940 sprintf (msg,
"counting fail (available %d != %d)", freelist.
available_cnt, acount);
945 sprintf (msg,
"counting fail (retired %d != %d)", freelist.
retired_cnt, rcount);
969 #define HASH_SIZE 200 970 #define HASH_POPULATION HASH_SIZE * 5 971 #define NUM_THREADS 16 980 begin (
"hash table iterator");
985 return fail (
"transaction system init");
991 return fail (
"failed to fetch tran entry");
1004 return fail (
"null insert error");
1010 hashmap.
unlock (te, entry);
1022 for (curr = it.iterate (); curr !=
NULL; curr = it.iterate ())
1027 if (sum != ((HASH_POPULATION - 1) * HASH_POPULATION) / 2)
1029 sprintf (msg,
"counting error (%d != %d)", sum, (HASH_POPULATION - 1) * HASH_POPULATION / 2);
1046 #undef HASH_POPULATION 1055 bool test_local_tran;
1065 test_local_tran =
false;
1066 for (i = 1; i <= 64; i *= 2)
1074 test_local_tran =
true;
1075 for (i = 1; i <= 64; i *= 2)
1090 for (i = 1; i <= 64; i *= 2)
1104 for (i = 1; i <= 64; i *= 2)
1119 for (i = 1; i <= 64; i *= 2)
1139 printf (
"Unit tests failed!\n");
#define LF_EM_NOT_USING_MUTEX
static void generate_random()
void * test_hash_proc_1(void *param)
static int xentry_free(void *entry)
static unsigned int xentry_hash(void *key, int htsize)
static int fail(const char *message)
#define pthread_mutex_init(a, b)
LF_TRAN_ENTRY * lf_tran_request_entry(LF_TRAN_SYSTEM *sys)
void unlock(lf_tran_entry *t_entry, T *&t)
void * test_hash_proc_2(void *param)
bool erase_locked(lf_tran_entry *t_entry, Key &key, T *&t)
lf_hash_table & get_hash_table()
void lf_tran_system_destroy(LF_TRAN_SYSTEM *sys)
lf_freelist & get_freelist()
#define lf_tran_end_with_mb(entry)
void * lf_freelist_claim(LF_TRAN_ENTRY *tran_entry, LF_FREELIST *freelist)
static int random_numbers[RAND_SIZE]
int main(int argc, char **argv)
void * test_clear_proc_2(void *param)
#define lf_tran_start_with_mb(entry, incr)
void init(lf_tran_system &transys, int hash_size, int freelist_block_count, int freelist_block_size, lf_entry_descriptor &edes)
void * test_freelist_proc(void *param)
int lf_tran_system_init(LF_TRAN_SYSTEM *sys, int max_threads)
void * test_clear_proc_3(void *param)
static int xentry_key_compare(void *k1, void *k2)
void * test_hash_proc_3(void *param)
static int xentry_init(void *entry)
void lf_tran_return_entry(LF_TRAN_ENTRY *entry)
LF_TRAN_SYSTEM * tran_system
int lf_freelist_retire(LF_TRAN_ENTRY *tran_entry, LF_FREELIST *freelist, void *entry)
void * test_freelist_proc_local_tran(void *param)
static struct timeval start_time
int lf_freelist_init(LF_FREELIST *freelist, int initial_blocks, int block_size, LF_ENTRY_DESCRIPTOR *edesc, LF_TRAN_SYSTEM *tran_system)
LF_ENTRY_HASH_FUNC f_hash
static int xentry_uninit(void *entry)
void * test_clear_proc_1(void *param)
void clear(lf_tran_entry *t_entry)
static LF_ENTRY_DESCRIPTOR xentry_desc
#define PTHREAD_ABORT_AND_EXIT(code)
bool find_or_insert(lf_tran_entry *t_entry, Key &key, T *&t)
static int test_hash_table(LF_ENTRY_DESCRIPTOR *edesc, int nthreads, void *(*proc)(void *))
void lf_freelist_destroy(LF_FREELIST *freelist)
static int xentry_key_copy(void *src, void *dest)
bool erase(lf_tran_entry *t_entry, Key &key)
#define VOLATILE_ACCESS(v, t)
static void begin(const char *test_name)
static int test_freelist(LF_ENTRY_DESCRIPTOR *edesc, int nthreads, bool test_local_tran)
#define LF_EM_USING_MUTEX
static void * xentry_alloc()
unsigned long long int data
#define pthread_mutex_destroy(a)
static int test_hash_iterator()