From 236e7f6ba12d26eb02a1348858168ed939bcfa0a Mon Sep 17 00:00:00 2001 From: root Date: Wed, 25 Dec 2019 17:30:10 -0800 Subject: [PATCH] Bug fixes and make Fuzzer selectable --- execution.cc | 6 ++--- fuzzer.cc | 5 ++++ fuzzer.h | 6 ++--- history.cc | 8 +++---- newfuzzer.cc | 66 ++++++++++++++++++++++++++-------------------------- newfuzzer.h | 2 +- 6 files changed, 48 insertions(+), 45 deletions(-) diff --git a/execution.cc b/execution.cc index 9b179880..4e4a6bb2 100644 --- a/execution.cc +++ b/execution.cc @@ -69,7 +69,7 @@ ModelExecution::ModelExecution(ModelChecker *m, Scheduler *scheduler) : /* Initialize a model-checker thread, for special ModelActions */ model_thread = new Thread(get_next_id()); add_thread(model_thread); - fuzzer->register_engine(m->get_history(), this); + fuzzer->register_engine(this); scheduler->register_engine(this); #ifdef TLS pthread_key_create(&pthreadkey, tlsdestructor); @@ -320,7 +320,7 @@ bool ModelExecution::process_read(ModelAction *curr, SnapVector * read_from(curr, rf); get_thread(curr)->set_return_value(curr->get_return_value()); delete priorset; - return canprune && curr->get_type() == ATOMIC_READ; + return canprune && (curr->get_type() == ATOMIC_READ); } priorset->clear(); (*rf_set)[index] = rf_set->back(); @@ -1686,7 +1686,7 @@ void ModelExecution::removeAction(ModelAction *act) { void *mutex_loc = (void *) act->get_value(); get_safe_ptr_action(&obj_map, mutex_loc)->erase(listref); } - } else if (act->is_write()) { + } else if (act->is_free()) { sllnode * listref = act->getActionRef(); if (listref != NULL) { SnapVector *vec = get_safe_ptr_vect_action(&obj_wr_thrd_map, act->get_location()); diff --git a/fuzzer.cc b/fuzzer.cc index 12396dd9..371838dc 100644 --- a/fuzzer.cc +++ b/fuzzer.cc @@ -38,3 +38,8 @@ bool Fuzzer::shouldWake(const ModelAction *sleep) { return ((sleep->get_time()+sleep->get_value()) < lcurrtime); } + +bool Fuzzer::shouldWait(const ModelAction * act) +{ + return random() & 1; +} diff --git a/fuzzer.h b/fuzzer.h index d31c2267..b0f533d2 100644 --- a/fuzzer.h +++ b/fuzzer.h @@ -10,15 +10,13 @@ public: Fuzzer() {} virtual int selectWrite(ModelAction *read, SnapVector* rf_set); virtual bool has_paused_threads() { return false; } - virtual void notify_paused_thread(Thread * thread) = 0; virtual Thread * selectThread(int * threadlist, int numthreads); Thread * selectNotify(action_list_t * waiters); bool shouldSleep(const ModelAction *sleep); bool shouldWake(const ModelAction *sleep); - virtual bool shouldWait(const ModelAction *wait) = 0; - virtual void register_engine(ModelHistory * history, ModelExecution * execution) = 0; - virtual Predicate * get_selected_child_branch(thread_id_t tid) = 0; + virtual bool shouldWait(const ModelAction *wait); + virtual void register_engine(ModelExecution * execution) {} SNAPSHOTALLOC private: }; diff --git a/history.cc b/history.cc index 6f9fdad4..c15bb26f 100644 --- a/history.cc +++ b/history.cc @@ -190,7 +190,7 @@ void ModelHistory::process_action(ModelAction *act, thread_id_t tid) func_node->update_inst_act_map(tid, act); Fuzzer * fuzzer = model->get_execution()->getFuzzer(); - Predicate * selected_branch = fuzzer->get_selected_child_branch(tid); + Predicate * selected_branch = ((NewFuzzer *)fuzzer)->get_selected_child_branch(tid); func_node->set_predicate_tree_position(tid, selected_branch); } @@ -363,7 +363,7 @@ void ModelHistory::check_waiting_write(ModelAction * write_act) Thread * thread = model->get_thread(tid); //model_print("** thread %d is woken up\n", thread->get_id()); - model->get_execution()->getFuzzer()->notify_paused_thread(thread); + ((NewFuzzer *)model->get_execution()->getFuzzer())->notify_paused_thread(thread); } index++; @@ -431,7 +431,7 @@ void ModelHistory::stop_waiting_for_node(thread_id_t self_id, // model_print("\tthread %d waits for nobody, wake up\n", self_id); ModelExecution * execution = model->get_execution(); Thread * thread = execution->get_thread(self_id); - execution->getFuzzer()->notify_paused_thread(thread); + ((NewFuzzer *)execution->getFuzzer())->notify_paused_thread(thread); } } } @@ -533,7 +533,7 @@ void ModelHistory::monitor_waiting_thread_counter(thread_id_t tid) // model_print("\tthread %d waits for nobody, wake up\n", self_id); ModelExecution * execution = model->get_execution(); Thread * thread = execution->get_thread(waited_by_id); - execution->getFuzzer()->notify_paused_thread(thread); + ((NewFuzzer *)execution->getFuzzer())->notify_paused_thread(thread); } } } diff --git a/newfuzzer.cc b/newfuzzer.cc index e2e057d8..8ec30110 100644 --- a/newfuzzer.cc +++ b/newfuzzer.cc @@ -26,9 +26,9 @@ NewFuzzer::NewFuzzer() : /** * @brief Register the ModelHistory and ModelExecution engine */ -void NewFuzzer::register_engine(ModelHistory * history, ModelExecution *execution) +void NewFuzzer::register_engine(ModelExecution *execution) { - this->history = history; + this->history = model->get_history(); this->execution = execution; } @@ -95,7 +95,7 @@ int NewFuzzer::selectWrite(ModelAction *read, SnapVector * rf_set //model_print("the %d read action of thread %d at %p is unsuccessful\n", read->get_seq_number(), read_thread->get_id(), read->get_location()); SnapVector * pruned_writes = thrd_pruned_writes[thread_id]; - for (uint i = 0; i < pruned_writes->size(); i++) { + for (uint i = 0;i < pruned_writes->size();i++) { rf_set->push_back( (*pruned_writes)[i] ); } @@ -119,7 +119,7 @@ int NewFuzzer::selectWrite(ModelAction *read, SnapVector * rf_set * @return False if no child matches read_inst */ bool NewFuzzer::check_branch_inst(Predicate * curr_pred, FuncInst * read_inst, -inst_act_map_t * inst_act_map, SnapVector * rf_set) + inst_act_map_t * inst_act_map, SnapVector * rf_set) { available_branches_tmp_storage.clear(); @@ -187,7 +187,7 @@ int NewFuzzer::choose_branch_index(SnapVector * branches) double total_weight = 0; SnapVector weights; - for (uint i = 0; i < branches->size(); i++) { + for (uint i = 0;i < branches->size();i++) { Predicate * branch = (*branches)[i]; double weight = branch->get_weight(); total_weight += weight; @@ -198,7 +198,7 @@ int NewFuzzer::choose_branch_index(SnapVector * branches) double prob_sum = 0; int index = 0; - for (uint i = 0; i < weights.size(); i++) { + for (uint i = 0;i < weights.size();i++) { index = i; prob_sum += (double) (weights[i] / total_weight); if (prob_sum > prob) { @@ -225,7 +225,7 @@ Predicate * NewFuzzer::get_selected_child_branch(thread_id_t tid) * @return true if rf_set is pruned */ bool NewFuzzer::prune_writes(thread_id_t tid, Predicate * pred, -SnapVector * rf_set, inst_act_map_t * inst_act_map) + SnapVector * rf_set, inst_act_map_t * inst_act_map) { if (pred == NULL) return false; @@ -410,7 +410,7 @@ bool NewFuzzer::find_threads(ModelAction * pending_read) } bool NewFuzzer::check_predicate_expressions(PredExprSet * pred_expressions, -inst_act_map_t * inst_act_map, uint64_t write_val, bool * no_predicate) + inst_act_map_t * inst_act_map, uint64_t write_val, bool * no_predicate) { bool satisfy_predicate = true; @@ -420,31 +420,31 @@ inst_act_map_t * inst_act_map, uint64_t write_val, bool * no_predicate) bool equality; switch (expression->token) { - case NOPREDICATE: - *no_predicate = true; - break; - case EQUALITY: - FuncInst * to_be_compared; - ModelAction * last_act; - uint64_t last_read; - - to_be_compared = expression->func_inst; - last_act = inst_act_map->get(to_be_compared); - last_read = last_act->get_reads_from_value(); - - equality = (write_val == last_read); - if (equality != expression->value) - satisfy_predicate = false; - break; - case NULLITY: - // TODO: implement likely to be null - equality = ((void*) (write_val & 0xffffffff) == NULL); - if (equality != expression->value) - satisfy_predicate = false; - break; - default: - model_print("unknown predicate token\n"); - break; + case NOPREDICATE: + *no_predicate = true; + break; + case EQUALITY: + FuncInst * to_be_compared; + ModelAction * last_act; + uint64_t last_read; + + to_be_compared = expression->func_inst; + last_act = inst_act_map->get(to_be_compared); + last_read = last_act->get_reads_from_value(); + + equality = (write_val == last_read); + if (equality != expression->value) + satisfy_predicate = false; + break; + case NULLITY: + // TODO: implement likely to be null + equality = ((void*) (write_val & 0xffffffff) == NULL); + if (equality != expression->value) + satisfy_predicate = false; + break; + default: + model_print("unknown predicate token\n"); + break; } if (!satisfy_predicate) diff --git a/newfuzzer.h b/newfuzzer.h index 8e506ad7..bf01faf0 100644 --- a/newfuzzer.h +++ b/newfuzzer.h @@ -34,7 +34,7 @@ public: bool shouldWake(const ModelAction * sleep); bool shouldWait(const ModelAction * wait); - void register_engine(ModelHistory * history, ModelExecution * execution); + void register_engine(ModelExecution * execution); Predicate * get_selected_child_branch(thread_id_t tid); SNAPSHOTALLOC -- 2.34.1