X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=fuzzer.cc;h=7e488ce85fe84dbf6126b81b90aa9c48f8bf2c6f;hb=HEAD;hp=9ad61c3c5cddbc96073e85c15e8dd05f46bffadb;hpb=07a0b575fabd521fb3f4a3f1f2483d46349c35dd;p=c11tester.git diff --git a/fuzzer.cc b/fuzzer.cc index 9ad61c3c..7e488ce8 100644 --- a/fuzzer.cc +++ b/fuzzer.cc @@ -2,25 +2,84 @@ #include #include "threads-model.h" #include "model.h" +#include "action.h" int Fuzzer::selectWrite(ModelAction *read, SnapVector * rf_set) { int random_index = random() % rf_set->size(); return random_index; } -Thread * Fuzzer::selectThread(Node *n, int * threadlist, int numthreads) { +Thread * Fuzzer::selectThread(int * threadlist, int numthreads) { int random_index = random() % numthreads; int thread = threadlist[random_index]; thread_id_t curr_tid = int_to_id(thread); return model->get_thread(curr_tid); } -Thread * Fuzzer::selectNotify(action_list_t * waiters) { +Thread * Fuzzer::selectNotify(simple_action_list_t * waiters) { int numwaiters = waiters->size(); int random_index = random() % numwaiters; - action_list_t::iterator it = waiters->begin(); - advance(it, random_index); - Thread *thread = model->get_thread(*it); + sllnode * it = waiters->begin(); + while(random_index--) + it=it->getNext(); + Thread *thread = model->get_thread(it->getVal()); waiters->erase(it); return thread; } + +bool Fuzzer::shouldSleep(const ModelAction *sleep) { + return true; +} + +bool Fuzzer::shouldWake(const ModelAction *sleep) { + struct timespec currtime; + clock_gettime(CLOCK_MONOTONIC, &currtime); + uint64_t lcurrtime = currtime.tv_sec * 1000000000 + currtime.tv_nsec; + + return ((sleep->get_time()+sleep->get_value()) < lcurrtime); +} + +/* Decide whether wait should spuriously fail or not */ +bool Fuzzer::waitShouldFail(ModelAction * wait) +{ + if ((random() & 1) == 0) { + struct timespec currtime; + clock_gettime(CLOCK_MONOTONIC, &currtime); + uint64_t lcurrtime = currtime.tv_sec * 1000000000 + currtime.tv_nsec; + + // The time after which wait fail spuriously, in nanoseconds + uint64_t time = random() % 1000000; + wait->set_time(time + lcurrtime); + return true; + } + + return false; +} + +bool Fuzzer::waitShouldWakeUp(const ModelAction * wait) +{ + struct timespec currtime; + clock_gettime(CLOCK_MONOTONIC, &currtime); + uint64_t lcurrtime = currtime.tv_sec * 1000000000 + currtime.tv_nsec; + + return (wait->get_time() < lcurrtime); +} + +bool Fuzzer::randomizeWaitTime(ModelAction * timed_wait) +{ + uint64_t abstime = timed_wait->get_time(); + struct timespec currtime; + clock_gettime(CLOCK_MONOTONIC, &currtime); + uint64_t lcurrtime = currtime.tv_sec * 1000000000 + currtime.tv_nsec; + if (abstime <= lcurrtime) + return false; + + // Shorten wait time + if ((random() & 1) == 0) { + uint64_t tmp = abstime - lcurrtime; + uint64_t time_to_expire = random() % tmp + lcurrtime; + timed_wait->set_time(time_to_expire); + } + + return true; +}