Fix bug
authorweiyu <weiyuluo1232@gmail.com>
Sat, 12 Oct 2019 02:35:06 +0000 (19:35 -0700)
committerweiyu <weiyuluo1232@gmail.com>
Sat, 12 Oct 2019 02:35:06 +0000 (19:35 -0700)
funcnode.cc
newfuzzer.cc
predicate.cc
predicate.h

index d6672cb8901c4dbdb72d1db84c3f6cd1e401a53d..8cb39da9697efbbe0f7a8da397c2988f314f2c57 100644 (file)
@@ -306,7 +306,7 @@ void FuncNode::update_predicate_tree(action_list_t * act_list)
                        inst_id_map.put(next_inst, inst_counter++);
 
                it = it->getNext();
-               curr_pred->incr_count();
+               curr_pred->incr_expl_count();
        }
 
        curr_pred->set_exit(predicate_tree_exit);
index e290db4187e35e27717c3eee27290c1f38d5e368..5675c7907152d53169ed83981405f1f2dc2a6e4c 100644 (file)
@@ -72,12 +72,11 @@ int NewFuzzer::selectWrite(ModelAction *read, SnapVector<ModelAction *> * rf_set
                        execution->restore_last_seq_num();
 
                        conditional_sleep(read_thread);
-
                        // Returning -1 stops the while loop of ModelExecution::process_read
                        return -1;
                } else {
                        Predicate * selected_branch = get_selected_child_branch(tid);
-//                     selected_branch->incr_count();
+                       selected_branch->incr_fail_count();
                        failed_predicates.put(selected_branch, true);
 
                        SnapVector<ModelAction *> * pruned_writes = thrd_pruned_writes[thread_id];
@@ -128,8 +127,8 @@ Predicate * NewFuzzer::selectBranch(thread_id_t tid, Predicate * curr_pred, Func
                        branches.push_back(child);
 
                        // max of (exploration counts + 1)
-                       if (child->get_count() + 1 > numerator)
-                               numerator = child->get_count() + 1;
+                       if (child->get_expl_count() + 1 > numerator)
+                               numerator = child->get_expl_count() + 1;
                }
        }
 
@@ -172,12 +171,12 @@ int NewFuzzer::choose_index(SnapVector<Predicate *> * branches, uint32_t numerat
                return 0;
 
        double total_factor = 0;
-       SnapVector<double> factors = SnapVector<double>( branches->size() );
+       SnapVector<double> factors = SnapVector<double>( branches->size() + 1 );
        for (uint i = 0; i < branches->size(); i++) {
                Predicate * branch = (*branches)[i];
-               double factor = (double) numerator / (branch->get_count() + 1);
+               double factor = (double) numerator / (branch->get_expl_count() + 2 * branch->get_fail_count() + 1);
                total_factor += factor;
-               factors[i] = factor;
+               factors.push_back(factor);
        }
 
        double prob = (double) random() / RAND_MAX;
@@ -185,9 +184,9 @@ int NewFuzzer::choose_index(SnapVector<Predicate *> * branches, uint32_t numerat
        int index = 0;
 
        for (uint i = 0; i < factors.size(); i++) {
-               prob_sum += (double) factors[i] / total_factor;
+               index = i;
+               prob_sum += (double) (factors[i] / total_factor);
                if (prob_sum > prob) {
-                       index = i;
                        break;
                }
        }
@@ -352,6 +351,10 @@ void NewFuzzer::wake_up_paused_threads(int * threadlist, int * numthreads)
        //model_print("thread %d is woken up\n", tid);
        threadlist[*numthreads] = tid;
        (*numthreads)++;
+
+       Predicate * selected_branch = get_selected_child_branch(tid);
+       selected_branch->incr_fail_count();
+       model_print("thread %d is woken up\n", tid);
 }
 
 /* Wake up conditional sleeping threads if the desired write is available */
@@ -371,6 +374,8 @@ void NewFuzzer::notify_paused_thread(Thread * thread)
        thread_id_t tid = thread->get_id();
        history->remove_waiting_write(tid);
        history->remove_waiting_thread(tid);
+
+       model_print("** thread %d is woken up\n", tid);
 }
 
 /* Find threads that may write values that the pending read action is waiting for
index 0f7c620d5e48a471c94ad9ee3e5d070900d51712..4094b615514b48deee3caa34c98c73f6ebba4902 100644 (file)
@@ -8,6 +8,7 @@ Predicate::Predicate(FuncInst * func_inst, bool is_entry, bool is_exit) :
        exit_predicate(is_exit),
        does_write(false),
        exploration_count(0),
+       failure_count(0),
        pred_expressions(16),
        children(),
        parent(NULL),
index fd1c768bbc3cba726260042e4e1c405688b70a0a..6a35fcc406f207e6c1daefe3a3992cdf34ab6e76 100644 (file)
@@ -39,8 +39,10 @@ public:
 
        ConcretePredicate * evaluate(inst_act_map_t * inst_act_map, thread_id_t tid);
 
-       uint32_t get_count() { return exploration_count; }
-       void incr_count() { exploration_count++; }
+       uint32_t get_expl_count() { return exploration_count; }
+       uint32_t get_fail_count() { return failure_count; }
+       void incr_expl_count() { exploration_count++; }
+       void incr_fail_count() { failure_count++; }
 
        void print_predicate();
        void print_pred_subtree();
@@ -52,6 +54,7 @@ private:
        bool exit_predicate;
        bool does_write;
        uint32_t exploration_count;
+       uint32_t failure_count;
 
        /* May have multiple predicate expressions */
        PredExprSet pred_expressions;