Bug fixes and make Fuzzer selectable
authorroot <root@plrg-1.ics.uci.edu>
Thu, 26 Dec 2019 01:30:10 +0000 (17:30 -0800)
committerroot <root@plrg-1.ics.uci.edu>
Thu, 26 Dec 2019 01:30:10 +0000 (17:30 -0800)
execution.cc
fuzzer.cc
fuzzer.h
history.cc
newfuzzer.cc
newfuzzer.h

index 9b17988..4e4a6bb 100644 (file)
@@ -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<ModelAction *> *
                        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<ModelAction *> * listref = act->getActionRef();
                if (listref != NULL) {
                        SnapVector<action_list_t> *vec = get_safe_ptr_vect_action(&obj_wr_thrd_map, act->get_location());
index 12396dd..371838d 100644 (file)
--- 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;
+}
index d31c226..b0f533d 100644 (file)
--- a/fuzzer.h
+++ b/fuzzer.h
@@ -10,15 +10,13 @@ public:
        Fuzzer() {}
        virtual int selectWrite(ModelAction *read, SnapVector<ModelAction *>* 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:
 };
index 6f9fdad..c15bb26 100644 (file)
@@ -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);
                        }
                }
        }
index e2e057d..8ec3011 100644 (file)
@@ -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<ModelAction *> * 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<ModelAction *> * 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<ModelAction *> * 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<ModelAction *> * rf_set)
+                                                                                                                                       inst_act_map_t * inst_act_map, SnapVector<ModelAction *> * rf_set)
 {
        available_branches_tmp_storage.clear();
 
@@ -187,7 +187,7 @@ int NewFuzzer::choose_branch_index(SnapVector<Predicate *> * branches)
 
        double total_weight = 0;
        SnapVector<double> 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<Predicate *> * 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<ModelAction *> * rf_set, inst_act_map_t * inst_act_map)
+                                                                                                                SnapVector<ModelAction *> * 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)
index 8e506ad..bf01faf 100644 (file)
@@ -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