Fix bug when vectors of action lists get reallocated
[c11tester.git] / newfuzzer.cc
index be483886bdcde90b5b878cdebd0dcf17c19b115a..01eed86ba1489b983fadd0bc34cc9cfb94d5b875 100644 (file)
@@ -33,7 +33,7 @@ void NewFuzzer::register_engine(ModelChecker *_model, ModelExecution *execution)
 
 int NewFuzzer::selectWrite(ModelAction *read, SnapVector<ModelAction *> * rf_set)
 {
-//     return random() % rf_set->size();
+       return random() % rf_set->size();
 
        thread_id_t tid = read->get_tid();
        int thread_id = id_to_int(tid);
@@ -49,9 +49,6 @@ int NewFuzzer::selectWrite(ModelAction *read, SnapVector<ModelAction *> * rf_set
                Predicate * curr_pred = func_node->get_predicate_tree_position(tid);
                FuncInst * read_inst = func_node->get_inst(read);
 
-               int index = func_node->get_recursion_depth(tid);
-               uint32_t marker = func_node->get_marker(tid);
-
                if (curr_pred != NULL)  {
                        Predicate * selected_branch = NULL;
 
@@ -74,7 +71,7 @@ int NewFuzzer::selectWrite(ModelAction *read, SnapVector<ModelAction *> * rf_set
                        }
 
                        thrd_selected_child_branch[thread_id] = selected_branch;
-                       prune_writes(tid, index, marker, selected_branch, rf_set);
+                       prune_writes(tid, selected_branch, rf_set);
                }
 
                thrd_last_read_act[thread_id] = read;
@@ -86,11 +83,9 @@ int NewFuzzer::selectWrite(ModelAction *read, SnapVector<ModelAction *> * rf_set
                Predicate * selected_branch = get_selected_child_branch(tid);
                FuncNode * func_node = history->get_curr_func_node(tid);
 
-               int index = func_node->get_recursion_depth(tid);
-               uint32_t marker = func_node->get_marker(tid);
-
                // Increment failure count
                selected_branch->incr_fail_count();
+               func_node->add_predicate_to_trace(tid, selected_branch);        // For updating predicate weight
 
                //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());
 
@@ -105,7 +100,7 @@ int NewFuzzer::selectWrite(ModelAction *read, SnapVector<ModelAction *> * rf_set
                selected_branch = selectBranch(tid, curr_pred, read_inst);
                thrd_selected_child_branch[thread_id] = selected_branch;
 
-               prune_writes(tid, index, marker, selected_branch, rf_set);
+               prune_writes(tid, selected_branch, rf_set);
 
                ASSERT(selected_branch);
        }
@@ -223,8 +218,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, int index, uint32_t marker, 
-                       Predicate * pred, SnapVector<ModelAction *> * rf_set)
+bool NewFuzzer::prune_writes(thread_id_t tid, Predicate * pred, SnapVector<ModelAction *> * rf_set)
 {
        if (pred == NULL)
                return false;
@@ -265,10 +259,12 @@ bool NewFuzzer::prune_writes(thread_id_t tid, int index, uint32_t marker,
                                break;
                        case EQUALITY:
                                FuncInst * to_be_compared;
+                               FuncNode * func_node;
                                uint64_t last_read;
 
                                to_be_compared = expression->func_inst;
-                               last_read = to_be_compared->get_associated_read(tid, index, marker);
+                               func_node = history->get_curr_func_node(tid);
+                               last_read = func_node->get_associated_read(tid, to_be_compared);
                                ASSERT(last_read != VALUE_NONE);
 
                                equality = (write_val == last_read);
@@ -348,7 +344,6 @@ Thread * NewFuzzer::selectThread(int * threadlist, int numthreads)
                wake_up_paused_threads(threadlist, &numthreads);
                //model_print("list size: %d, active t id: %d\n", numthreads, threadlist[0]);
        }
-
        int random_index = random() % numthreads;
        int thread = threadlist[random_index];
        thread_id_t curr_tid = int_to_id(thread);
@@ -452,5 +447,5 @@ bool NewFuzzer::find_threads(ModelAction * pending_read)
 
 bool NewFuzzer::shouldWait(const ModelAction * act)
 {
-       return random() & 1;
+       return true;
 }