diff --git a/benchmarks/seekMap.c b/benchmarks/seekMap.c index af38e4d..e07874e 100644 --- a/benchmarks/seekMap.c +++ b/benchmarks/seekMap.c @@ -1,19 +1,12 @@ #include #include #include +#include #include #include #include -uint64_t myrandom(uint64_t x) { - double xx = x; - double r = random(); - double max = ((uint64_t)RAND_MAX)+1; - max /= xx; - return (uint64_t)((r/max)); -} - void * buf; static void my_pread_help(int fd, long long off) { int err = pread(fd, buf, 512, off); @@ -82,7 +75,7 @@ int main(int argc, char * argv[]) { // position head (do not count the time this takes) if(random_mode) { - my_pread(start_off, xstep * stride + myrandom(stride)); + my_pread(start_off, xstep * stride + stasis_util_random64(stride)); } else { my_pread(start_off, xstep * stride); @@ -91,7 +84,7 @@ int main(int argc, char * argv[]) { struct timeval start, stop; gettimeofday(&start, 0); if(random_mode) { - my_pread(start_off, ystep * stride + myrandom(stride)); + my_pread(start_off, ystep * stride + stasis_util_random64(stride)); } else { my_pread(start_off, ystep * stride); } @@ -106,8 +99,8 @@ int main(int argc, char * argv[]) { } } else { for(long x = 0; x < steps * steps; x++) { - long long start_pos = myrandom(length); - long long stop_pos = myrandom(length); + long long start_pos = stasis_util_random64(length); + long long stop_pos = stasis_util_random64(length); int xstep = start_pos / stride; int ystep = stop_pos / stride; diff --git a/src/stasis/CMakeLists.txt b/src/stasis/CMakeLists.txt index 8b9d09d..ef868aa 100644 --- a/src/stasis/CMakeLists.txt +++ b/src/stasis/CMakeLists.txt @@ -11,6 +11,7 @@ ADD_LIBRARY(stasis util/crc32.c util/hashFunctions.c util/min.c util/ringbuffer.c + util/random.c util/multiset.c util/slab.c util/stlredblack.cpp diff --git a/src/stasis/util/random.c b/src/stasis/util/random.c new file mode 100644 index 0000000..1a687fe --- /dev/null +++ b/src/stasis/util/random.c @@ -0,0 +1,18 @@ +/* + * @file Random number generators. + * + * Created on: Aug 31, 2011 + * Author: sears + */ + +#include +#include +#include + +uint64_t stasis_util_random64(uint64_t x) { + double xx = x; + double r = random(); + double max = ((uint64_t)RAND_MAX)+1; + max /= xx; + return (uint64_t)((r/max)); +} diff --git a/stasis/util/hashFunctions.h b/stasis/util/hashFunctions.h index 60da30c..a3481e7 100644 --- a/stasis/util/hashFunctions.h +++ b/stasis/util/hashFunctions.h @@ -30,7 +30,7 @@ #include #include -#define stasis_hash_util_define_fnv_1(TYPE, FNV_prime, offset_basis) \ +#define stasis_util_hash_define_fnv_1(TYPE, FNV_prime, offset_basis) \ static inline TYPE stasis_util_hash_fnv_1_##TYPE(const byte* octets, int len){\ TYPE hash = offset_basis; \ \ @@ -43,11 +43,11 @@ static inline TYPE stasis_util_hash_fnv_1_##TYPE(const byte* octets, int len){\ /** * Implementation of FNV-1 (32-bit). Function is called stasis_util_hash_fnv_uint32_t(). */ -stasis_hash_util_define_fnv_1(uint32_t, 16777619U, 2166136261U) +stasis_util_hash_define_fnv_1(uint32_t, 16777619U, 2166136261U) /** * Implementation of FNV-1 (64-bit). Function is called stasis_util_hash_fnv_uint64_t(). */ -stasis_hash_util_define_fnv_1(uint64_t, 1099511628211ULL, 14695981039346656037ULL) +stasis_util_hash_define_fnv_1(uint64_t, 1099511628211ULL, 14695981039346656037ULL) /** * Macro to define xor folding for dynamically set of bits. This is static inline, diff --git a/stasis/util/random.h b/stasis/util/random.h new file mode 100644 index 0000000..ad0d1be --- /dev/null +++ b/stasis/util/random.h @@ -0,0 +1,18 @@ +/* + * random.h + * + * Created on: Aug 31, 2011 + * Author: sears + */ + +#ifndef RANDOM_H_ +#define RANDOM_H_ + +#include + +BEGIN_C_DECLS + +uint64_t stasis_util_random64(uint64_t x); + +END_C_DECLS +#endif /* RANDOM_H_ */ diff --git a/test/check_includes.h b/test/check_includes.h index 935eec0..57c8d75 100644 --- a/test/check_includes.h +++ b/test/check_includes.h @@ -9,15 +9,6 @@ #include "check_impl.h" -uint64_t myrandom(uint64_t x) { - double xx = x; - double r = random(); - double max = ((uint64_t)RAND_MAX)+1; - max /= xx; - return (uint64_t)((r/max)); -} - - void setup (void) { remove("logfile.txt"); remove("storefile.txt"); diff --git a/test/stasis/check_allocationPolicy.c b/test/stasis/check_allocationPolicy.c index 7142350..5a43358 100644 --- a/test/stasis/check_allocationPolicy.c +++ b/test/stasis/check_allocationPolicy.c @@ -44,6 +44,7 @@ terms specified in this license. #include #include +#include #include #include @@ -128,16 +129,16 @@ static int nextxid = 0; int activexidcount = 0; static void takeRandomAction(stasis_allocation_policy_t * ap, int * xids, pageid_t * pages1, pageid_t * pages2) { - switch(myrandom(5)) { + switch(stasis_util_random64(5)) { case 0 : { // find page - int thexid = myrandom(XACT_COUNT); + int thexid = stasis_util_random64(XACT_COUNT); if(xids[thexid] == -1) { xids[thexid] = nextxid; nextxid++; activexidcount++; DEBUG("xid begins\n"); } - int thefreespace = myrandom(MAX_DESIRED_FREESPACE); + int thefreespace = stasis_util_random64(MAX_DESIRED_FREESPACE); pageid_t p = stasis_allocation_policy_pick_suitable_page(ap, xids[thexid], thefreespace); if(p != INVALID_PAGE) { @@ -150,17 +151,17 @@ static void takeRandomAction(stasis_allocation_policy_t * ap, int * xids, case 1 : { // xact completed if(!activexidcount) { break; } int thexid; - while(xids[thexid = myrandom(XACT_COUNT)] == -1) { } + while(xids[thexid = stasis_util_random64(XACT_COUNT)] == -1) { } stasis_allocation_policy_transaction_completed(ap, xids[thexid]); xids[thexid] = -1; activexidcount--; DEBUG("complete"); } break; case 2 : { // update freespace unlocked - int thespacediff = myrandom(MAX_DESIRED_FREESPACE) - (MAX_DESIRED_FREESPACE/2); + int thespacediff = stasis_util_random64(MAX_DESIRED_FREESPACE) - (MAX_DESIRED_FREESPACE/2); int thexid; if(!activexidcount) { break; } - while(xids[thexid = myrandom(XACT_COUNT)] == -1) { } + while(xids[thexid = stasis_util_random64(XACT_COUNT)] == -1) { } int minfreespace; if(thespacediff < 0) { minfreespace = 0-thespacediff; @@ -170,7 +171,7 @@ static void takeRandomAction(stasis_allocation_policy_t * ap, int * xids, pageid_t p = stasis_allocation_policy_pick_suitable_page(ap, xids[thexid], minfreespace); if(p != INVALID_PAGE) { - int thenewfreespace = myrandom(MAX_DESIRED_FREESPACE/2)+thespacediff; + int thenewfreespace = stasis_util_random64(MAX_DESIRED_FREESPACE/2)+thespacediff; stasis_allocation_policy_update_freespace(ap, p, thenewfreespace); // printf("updated freespace unlocked"); } @@ -178,15 +179,15 @@ static void takeRandomAction(stasis_allocation_policy_t * ap, int * xids, case 3 : { // dealloc from page int thexid; if(!activexidcount) { break; } - while(xids[thexid = myrandom(XACT_COUNT)] == -1) {} - pageid_t p = pages1[myrandom(AVAILABLE_PAGE_COUNT_A)]; + while(xids[thexid = stasis_util_random64(XACT_COUNT)] == -1) {} + pageid_t p = pages1[stasis_util_random64(AVAILABLE_PAGE_COUNT_A)]; stasis_allocation_policy_dealloced_from_page(ap, xids[thexid], p); } break; case 4 : { // alloced from page int thexid; if(!activexidcount) { break; } - while(xids[thexid = myrandom(XACT_COUNT)] == -1) {} - pageid_t p = pages1[myrandom(AVAILABLE_PAGE_COUNT_A)]; + while(xids[thexid = stasis_util_random64(XACT_COUNT)] == -1) {} + pageid_t p = pages1[stasis_util_random64(AVAILABLE_PAGE_COUNT_A)]; if(stasis_allocation_policy_can_xid_alloc_from_page(ap, xids[thexid], p)) { stasis_allocation_policy_alloced_from_page(ap, xids[thexid], p); } diff --git a/test/stasis/check_blobRecovery.c b/test/stasis/check_blobRecovery.c index 61443ef..8dc4970 100644 --- a/test/stasis/check_blobRecovery.c +++ b/test/stasis/check_blobRecovery.c @@ -44,6 +44,7 @@ terms specified in this license. #include #include #include +#include #include @@ -90,11 +91,11 @@ START_TEST(recoverBlob__randomized) { int xid = Tbegin(); for(int i = 0; i < NUM_OPS; i++) { if(!(i % 100)) { printf("."); fflush(stdout); } - int blobid = myrandom(NUM_BLOBS); + int blobid = stasis_util_random64(NUM_BLOBS); if(blobs[blobid].size == -1) { blobs[blobid] = Talloc(xid, BLOB_SIZE); Tset(xid, blobs[blobid], gen_blob(blobid)); - } else if (myrandom(2)) { + } else if (stasis_util_random64(2)) { Tread(xid, blobs[blobid], buf); assert(!memcmp(buf, gen_blob(blobid),BLOB_SIZE)); } else { diff --git a/test/stasis/check_bufferManager.c b/test/stasis/check_bufferManager.c index d1b9fc4..c0d848a 100644 --- a/test/stasis/check_bufferManager.c +++ b/test/stasis/check_bufferManager.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -286,9 +287,9 @@ void * blindRandomWorker(void * v) { } for(int i = 0; i < BLIND_ITERS; i ++) { - int j = myrandom(PINNED_PAGE_COUNT); + int j = stasis_util_random64(PINNED_PAGE_COUNT); if(pageids[j] == -1) { - pageids[j] = myrandom(MAX_PAGE_ID); + pageids[j] = stasis_util_random64(MAX_PAGE_ID); pages[j] = loadPage(-1, pageids[j]); assert(pages[j]->id == pageids[j]); } else { diff --git a/test/stasis/check_concurrentHash.c b/test/stasis/check_concurrentHash.c index a5b24e1..21a2b0e 100644 --- a/test/stasis/check_concurrentHash.c +++ b/test/stasis/check_concurrentHash.c @@ -50,6 +50,7 @@ terms specified in this license. #include "../check_includes.h" #include +#include #include #include @@ -81,9 +82,9 @@ hashtable_t * ht; void * worker(void * arg) { pageid_t *data = (pageid_t *)arg; for(int j = 0; j < NUM_OPS/ NUM_THREADS; j++) { - int op = myrandom(2); + int op = stasis_util_random64(2); - int i = myrandom(THREAD_ENTRIES); + int i = stasis_util_random64(THREAD_ENTRIES); pageid_t scratch = data[i]; if(data[i] < 0) { @@ -147,7 +148,7 @@ START_TEST(wraparoundHashTest) { pageid_t *data = malloc(sizeof(pageid_t) * THREAD_ENTRIES); for(int i = 1; i <= THREAD_ENTRIES; i++) { - data[i-1] = -1 * (((i << power) - 6 + myrandom(13)) / 13); + data[i-1] = -1 * (((i << power) - 6 + stasis_util_random64(13)) / 13); } worker(data); hashtable_deinit(ht); diff --git a/test/stasis/check_concurrentRingbuffer.c b/test/stasis/check_concurrentRingbuffer.c index c1c4d28..282dde7 100644 --- a/test/stasis/check_concurrentRingbuffer.c +++ b/test/stasis/check_concurrentRingbuffer.c @@ -42,6 +42,7 @@ terms specified in this license. #include "../check_includes.h" #include +#include #include #include @@ -83,7 +84,7 @@ static void * consumerWorker(void * arg) { stasis_ringbuffer_t * ring = arg; lsn_t cursor = 0; while(cursor < PROD_CONS_SIZE) { - lsn_t rnd_size = myrandom(2048); + lsn_t rnd_size = stasis_util_random64(2048); if(rnd_size + cursor > PROD_CONS_SIZE) { rnd_size = PROD_CONS_SIZE - cursor; } byte const * rd_buf = stasis_ringbuffer_get_rd_buf(ring, RING_NEXT, rnd_size); for(lsn_t i = 0; i < rnd_size; i++) { @@ -99,7 +100,7 @@ static void * producerWorker(void * arg) { stasis_ringbuffer_t * ring = arg; lsn_t cursor = 0; while(cursor < PROD_CONS_SIZE) { - int rnd_size = myrandom(2048); + int rnd_size = stasis_util_random64(2048); if(rnd_size + cursor > PROD_CONS_SIZE) { rnd_size = PROD_CONS_SIZE - cursor; } lsn_t wr_off = stasis_ringbuffer_reserve_space(ring, rnd_size, 0); assert(wr_off == cursor); @@ -138,7 +139,7 @@ static void * concurrentReader(void * argp) { lsn_t cursor = 0; lsn_t rd_handle; while(cursor < BYTES_PER_THREAD) { - lsn_t rnd_size = 1+myrandom(2047/NUM_READERS); + lsn_t rnd_size = 1+stasis_util_random64(2047/NUM_READERS); if(rnd_size + cursor > BYTES_PER_THREAD) { rnd_size = BYTES_PER_THREAD - cursor; } stasis_ringbuffer_consume_bytes(ring, &rnd_size, &rd_handle); @@ -159,7 +160,7 @@ static void * concurrentWriter(void * argp) { lsn_t cursor = 0; lsn_t wr_handle; while(cursor < BYTES_PER_THREAD) { - int rnd_size = 1+myrandom(2047/NUM_WRITERS); + int rnd_size = 1+stasis_util_random64(2047/NUM_WRITERS); if(rnd_size + cursor > BYTES_PER_THREAD) { rnd_size = BYTES_PER_THREAD- cursor; } stasis_ringbuffer_reserve_space(ring, rnd_size, &wr_handle); byte * wr_buf = stasis_ringbuffer_get_wr_buf(ring, wr_handle, rnd_size); diff --git a/test/stasis/check_dirtyPageTable.c b/test/stasis/check_dirtyPageTable.c index 70f95e7..e7f5b82 100644 --- a/test/stasis/check_dirtyPageTable.c +++ b/test/stasis/check_dirtyPageTable.c @@ -53,6 +53,7 @@ terms specified in this license. #include #include +#include #include #include @@ -75,11 +76,11 @@ terms specified in this license. void * worker(void*arg) { stasis_dirty_page_table_t * dpt = stasis_runtime_dirty_page_table(); for(int i = 0; i < NUM_STEPS; i++) { - pageid_t page = myrandom(NUM_PAGES); + pageid_t page = stasis_util_random64(NUM_PAGES); Page * p = loadPage(-1, page); writelock(p->rwlatch, 0); if(! (i % 100000)) { printf("."); fflush(stdout); } - switch(myrandom(6)) { + switch(stasis_util_random64(6)) { case 0: { stasis_dirty_page_table_set_dirty(dpt, p); } break; @@ -98,8 +99,8 @@ void * worker(void*arg) { case 5: { unlock(p->rwlatch); releasePage(p); - pageid_t start = myrandom(NUM_PAGES); - pageid_t stop = myrandom(NUM_PAGES); + pageid_t start = stasis_util_random64(NUM_PAGES); + pageid_t stop = stasis_util_random64(NUM_PAGES); if(start > stop) { page = start; start = stop; diff --git a/test/stasis/check_io.c b/test/stasis/check_io.c index 27c1619..bde5a7a 100644 --- a/test/stasis/check_io.c +++ b/test/stasis/check_io.c @@ -44,6 +44,7 @@ terms specified in this license. #include #include #include +#include #include #include #include @@ -101,16 +102,16 @@ void load_handle(thread_arg* t) { offsets[i] = i * sizeof(int); } for(int i = 0; i < OPS_PER_THREAD; i++) { - int val = myrandom(t->count); + int val = stasis_util_random64(t->count); if(offsets[val] == -1) { // Need to write it somewhere. - long choice = myrandom(2); + long choice = stasis_util_random64(2); switch(choice) { case 0: { // overwrite old entry with write() - long val2 = myrandom(t->count); + long val2 = stasis_util_random64(t->count); offsets[val] = offsets[val2]; offsets[val2] = -1; if(offsets[val] != -1) { @@ -125,7 +126,7 @@ void load_handle(thread_arg* t) { } } break; case 1: { // overwrite old entry with write_buffer() - long val2 = myrandom(t->count); + long val2 = stasis_util_random64(t->count); offsets[val] = offsets[val2]; offsets[val2] = -1; if(offsets[val] != -1) { @@ -159,7 +160,7 @@ void load_handle(thread_arg* t) { } else { // Read the value. - long choice = myrandom(2); + long choice = stasis_util_random64(2); switch(choice) { case 0: { // read @@ -188,7 +189,7 @@ void load_handle(thread_arg* t) { } // Force 1% of the time. - if(!myrandom(100)) { + if(!stasis_util_random64(100)) { h->force(h); } } @@ -213,7 +214,7 @@ void handle_sequentialtest(stasis_handle_t * h) { } void handle_concurrencytest(stasis_handle_t * h) { - int vc = myrandom(VALUE_COUNT) + 10; + int vc = stasis_util_random64(VALUE_COUNT) + 10; printf("Running concurrency test with %d values\n", vc); fflush(stdout); diff --git a/test/stasis/check_lhtable.c b/test/stasis/check_lhtable.c index cf8accf..28141e3 100644 --- a/test/stasis/check_lhtable.c +++ b/test/stasis/check_lhtable.c @@ -44,6 +44,7 @@ terms specified in this license. #include "../check_includes.h" #include +#include #include #include @@ -132,8 +133,8 @@ START_TEST(lhtableRandomized) { srandom(seed); #endif - struct LH_ENTRY(table) * t = LH_ENTRY(create)(myrandom(10000)); - int numSets = myrandom(MAXSETS); + struct LH_ENTRY(table) * t = LH_ENTRY(create)(stasis_util_random64(10000)); + int numSets = stasis_util_random64(MAXSETS); int* setLength = malloc(numSets * sizeof(int)); long** sets = malloc(numSets * sizeof(long*)); int64_t nextVal = 1; @@ -144,7 +145,7 @@ START_TEST(lhtableRandomized) { int* setNextRead = calloc(numSets, sizeof(int)); for(int i =0; i < numSets; i++) { - setLength[i] = myrandom(MAXSETLEN); + setLength[i] = stasis_util_random64(MAXSETLEN); sets[i] = malloc(setLength[i] * sizeof(long)); eventCount += setLength[i]; for(int j =0; j < setLength[i]; j++) { @@ -153,12 +154,12 @@ START_TEST(lhtableRandomized) { } } - eventCount = myrandom(eventCount * 4); + eventCount = stasis_util_random64(eventCount * 4); printf("Running %lld events.\n", (long long) eventCount); for(int iii = 0; iii < eventCount; iii++) { - int eventType = myrandom(3); // 0 = insert; 1 = read; 2 = delete. - int set = myrandom(numSets); + int eventType = stasis_util_random64(3); // 0 = insert; 1 = read; 2 = delete. + int set = stasis_util_random64(numSets); switch(eventType) { case 0: // insert if(setNextAlloc[set] != setLength[set]) { diff --git a/test/stasis/check_min.c b/test/stasis/check_min.c index 53f10f6..0e2411b 100644 --- a/test/stasis/check_min.c +++ b/test/stasis/check_min.c @@ -42,6 +42,7 @@ terms specified in this license. #include "../check_includes.h" #include +#include #include #include @@ -122,12 +123,12 @@ START_TEST(minRandomTest) { } for(int i = 0; i < COUNT; i++) { if(! (i & 1023)) { printf("%d\n", i); } - switch(myrandom(3)) { + switch(stasis_util_random64(3)) { case 0: { int j; int tries = 0; - while((j = myrandom(i))) { + while((j = stasis_util_random64(i))) { if(!bits[j]) { bits[j] = 1; @@ -144,7 +145,7 @@ START_TEST(minRandomTest) { { int j; int tries = 0; - while((j = myrandom(i))) { + while((j = stasis_util_random64(i))) { if(bits[j]) { bits[j] = 0; diff --git a/test/stasis/check_page.c b/test/stasis/check_page.c index 03fde82..06e3854 100644 --- a/test/stasis/check_page.c +++ b/test/stasis/check_page.c @@ -53,6 +53,7 @@ terms specified in this license. #include #include #include +#include #include #include @@ -164,7 +165,7 @@ static void* latchFree_worker_thread(void * arg_ptr) { int alloced_count = 0; while(1) { - int off = myrandom(arg->num_pages); + int off = stasis_util_random64(arg->num_pages); Page * p = arg->pages[off]; if(off == arg->my_page) { recordid rid = stasis_record_alloc_begin(-1, p, sizeof(char)); @@ -180,7 +181,7 @@ static void* latchFree_worker_thread(void * arg_ptr) { } } else if(*stasis_page_slotted_numslots_cptr(p)) { // if the page is empty, try another. // read a random record - int slot = myrandom(stasis_record_last(-1, p).slot+1); + int slot = stasis_util_random64(stasis_record_last(-1, p).slot+1); recordid rid; rid.page = p->id; rid.slot = slot; diff --git a/test/stasis/check_rangeTracker.c b/test/stasis/check_rangeTracker.c index ad0dc2a..abb1b38 100644 --- a/test/stasis/check_rangeTracker.c +++ b/test/stasis/check_rangeTracker.c @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -245,8 +246,8 @@ END_TEST #define ITERATIONS 10000 //1000 #define RANGE_COUNT 1000 // 100 void randomRange(range * r) { - long start = myrandom(RANGE_SIZE-1); - long len = 1+myrandom(RANGE_SIZE - start - 1); + long start = stasis_util_random64(RANGE_SIZE-1); + long len = 1+stasis_util_random64(RANGE_SIZE - start - 1); r->start = start; r->stop = start + len; @@ -304,8 +305,8 @@ START_TEST (rangeTracker_randomTest) { for(long i = 0; i < ITERATIONS; i++) { - int range = myrandom(RANGE_COUNT); - switch(myrandom(3)) { + int range = stasis_util_random64(RANGE_COUNT); + switch(stasis_util_random64(3)) { case 0: { // add range s = rangeToString(&ranges[range]); // printf("pin %s\n", s); @@ -371,7 +372,7 @@ START_TEST (rangeTracker_randomTest) { break; } case 2: { // change range - if(!myrandom(100)) { + if(!stasis_util_random64(100)) { for(long i = 0; i < RANGE_COUNT; i++) { if(!pins[i]) { randomRange(&ranges[i]); diff --git a/test/stasis/check_redblack.c b/test/stasis/check_redblack.c index 9b102bd..6cbb94f 100644 --- a/test/stasis/check_redblack.c +++ b/test/stasis/check_redblack.c @@ -9,6 +9,7 @@ extern int dbug_choice(int); #include #include +#include #include #include @@ -79,9 +80,9 @@ START_TEST(rbRandTest) { # define myrandom(a) dbug_choice(a) #else uint64_t NUM_OPERATIONS = 1000 * 1000; - uint64_t NUM_ENTRIES = myrandom(100 * 1000); - uint64_t NUM_A = myrandom(200); - uint64_t NUM_B = myrandom(50000); + uint64_t NUM_ENTRIES = stasis_util_random64(100 * 1000); + uint64_t NUM_A = stasis_util_random64(200); + uint64_t NUM_B = stasis_util_random64(50000); #endif printf("NUM_OPERATIONS = %lld NUM_ENTRIES = %lld NUM_A = %lld NUM_B = %lld\n", (long long int)NUM_OPERATIONS, (long long int)NUM_ENTRIES, (long long int)NUM_A, (long long int)NUM_B); @@ -99,18 +100,18 @@ START_TEST(rbRandTest) { } #else for(uint64_t i = 0; i < NUM_ENTRIES; i++) { - entries[i].a = myrandom(NUM_A); - entries[i].b = myrandom(NUM_B); + entries[i].a = stasis_util_random64(NUM_A); + entries[i].b = stasis_util_random64(NUM_B); } #endif uint64_t num_found = 0; uint64_t num_collide = 0; for(uint64_t i = 0; i < NUM_OPERATIONS; i++) { - uint64_t off = myrandom(NUM_ENTRIES); + uint64_t off = stasis_util_random64(NUM_ENTRIES); #ifdef DBUG_TEST - switch(myrandom(3)+1) { + switch(stasis_util_random64(3)+1) { #else - switch(myrandom(4)) { + switch(stasis_util_random64(4)) { case 0: #endif case 1: { // insert diff --git a/test/stasis/check_regions.c b/test/stasis/check_regions.c index 38f2073..8e4badf 100644 --- a/test/stasis/check_regions.c +++ b/test/stasis/check_regions.c @@ -41,6 +41,7 @@ terms specified in this license. #include "../check_includes.h" #include +#include #include #include @@ -136,14 +137,14 @@ START_TEST(regions_randomizedTest) { fsckRegions(xid); } - if(myrandom(2)) { - unsigned int size = myrandom(100); + if(stasis_util_random64(2)) { + unsigned int size = stasis_util_random64(100); TregionAlloc(xid, size, 0); pagesAlloced += size; regionsAlloced ++; } else { if(regionsAlloced) { - pageid_t victim = myrandom(regionsAlloced); + pageid_t victim = stasis_util_random64(regionsAlloced); pageid_t victimSize; pageid_t victimPage; TregionFindNthActive(xid, victim, &victimPage, &victimSize); @@ -258,9 +259,9 @@ START_TEST(regions_lockRandomizedTest) { if(!(i % (NUM_OPS/NUM_XACTS))) { // abort or commit one transaction randomly. activeXacts --; - j = myrandom(activeXacts); + j = stasis_util_random64(activeXacts); - if(myrandom(2)) { + if(stasis_util_random64(2)) { Tcommit(xids[j]); } else { Tabort(xids[j]); @@ -275,16 +276,16 @@ START_TEST(regions_lockRandomizedTest) { fsckRegions(longXid); } - j = myrandom(activeXacts); + j = stasis_util_random64(activeXacts); - if(myrandom(2)) { + if(stasis_util_random64(2)) { // alloc - xidRegions[xids[j]][xidRegionCounts[xids[j]]] = TregionAlloc(xids[j], myrandom(100), 0); + xidRegions[xids[j]][xidRegionCounts[xids[j]]] = TregionAlloc(xids[j], stasis_util_random64(100), 0); xidRegionCounts[xids[j]]++; } else { // free if(xidRegionCounts[xids[j]]) { - pageid_t k = myrandom(xidRegionCounts[xids[j]]); + pageid_t k = stasis_util_random64(xidRegionCounts[xids[j]]); TregionDealloc(xids[j], xidRegions[xids[j]][k]); @@ -315,8 +316,8 @@ START_TEST(regions_recoveryTest) { int xid1 = Tbegin(); int xid2 = Tbegin(); for(int i = 0; i < 50; i+=2) { - pages[i] = TregionAlloc(xid1, myrandom(4)+1, 0); - pages[i+1] = TregionAlloc(xid2, myrandom(2)+1, 0); + pages[i] = TregionAlloc(xid1, stasis_util_random64(4)+1, 0); + pages[i+1] = TregionAlloc(xid2, stasis_util_random64(2)+1, 0); } fsckRegions(xid1); diff --git a/test/stasis/check_replacementPolicy.c b/test/stasis/check_replacementPolicy.c index 2a25081..412a3b1 100644 --- a/test/stasis/check_replacementPolicy.c +++ b/test/stasis/check_replacementPolicy.c @@ -2,6 +2,7 @@ #include #include +#include #include @@ -53,9 +54,9 @@ void randomTest(replacementPolicy * lru, unsigned long count) { for(unsigned long j = 0; j < count /*100000000UL*/; j++) { if(0 == (j % progress_indicator)) { printf("."); fflush(stdout); } - int op = myrandom(100); + int op = stasis_util_random64(100); - int i = myrandom(OBJECT_COUNT); + int i = stasis_util_random64(OBJECT_COUNT); if(op < 10) { // TOGGLE IN CACHE pthread_mutex_lock(&t[i].mut); diff --git a/test/stasis/check_transactional2.c b/test/stasis/check_transactional2.c index 57447eb..9f189e0 100644 --- a/test/stasis/check_transactional2.c +++ b/test/stasis/check_transactional2.c @@ -42,6 +42,7 @@ terms specified in this license. #include #include +#include #include #include @@ -477,7 +478,7 @@ START_TEST(transactional_noop_xacts) { // Scramble the xids. for(int i = 0; i < MAX_TRANSACTIONS; i++) { int xid = xids[i]; - int off = myrandom(MAX_TRANSACTIONS); + int off = stasis_util_random64(MAX_TRANSACTIONS); xids[i] = xids[off]; xids[off] = xid; }