some edits to NewFuzzer
authorweiyu <weiyuluo1232@gmail.com>
Tue, 27 Aug 2019 00:27:21 +0000 (17:27 -0700)
committerweiyu <weiyuluo1232@gmail.com>
Tue, 27 Aug 2019 00:27:21 +0000 (17:27 -0700)
execution.cc
fuzzer.h
model.cc
model.h
newfuzzer.cc
newfuzzer.h

index eefb910..9ee9157 100644 (file)
@@ -74,6 +74,7 @@ ModelExecution::ModelExecution(ModelChecker *m, Scheduler *scheduler) :
        model_thread = new Thread(get_next_id());
        add_thread(model_thread);
        scheduler->register_engine(this);
+       fuzzer->register_engine(m->get_history(), this);
 }
 
 /** @brief Destructor */
index eb6fd4e..d291268 100644 (file)
--- a/fuzzer.h
+++ b/fuzzer.h
@@ -12,6 +12,7 @@ public:
        Thread * selectNotify(action_list_t * waiters);
        bool shouldSleep(const ModelAction *sleep);
        bool shouldWake(const ModelAction *sleep);
+       virtual void register_engine(ModelHistory * history, ModelExecution * execution) {}
        MEMALLOC
 private:
 };
index 58a7859..0a2e844 100644 (file)
--- a/model.cc
+++ b/model.cc
@@ -33,8 +33,8 @@ ModelChecker::ModelChecker() :
        params(),
        restart_flag(false),
        scheduler(new Scheduler()),
-       execution(new ModelExecution(this, scheduler)),
        history(new ModelHistory()),
+       execution(new ModelExecution(this, scheduler)),
        execution_number(1),
        trace_analyses(),
        inspect_plugin(NULL)
diff --git a/model.h b/model.h
index 82d9bc8..a3a7bc0 100644 (file)
--- a/model.h
+++ b/model.h
@@ -76,9 +76,9 @@ private:
 
        /** The scheduler to use: tracks the running/ready Threads */
        Scheduler * const scheduler;
+       ModelHistory * history;
        ModelExecution *execution;
        Thread * init_thread;
-       ModelHistory *history;
 
        int execution_number;
 
index 7bcda8f..5ec1c5d 100644 (file)
@@ -2,9 +2,36 @@
 #include "threads-model.h"
 #include "model.h"
 #include "action.h"
+#include "execution.h"
+#include "funcnode.h"
+
+/**
+ * @brief Register the ModelHistory and ModelExecution engine
+ */
+void NewFuzzer::register_engine(ModelHistory * history, ModelExecution *execution)
+{
+       this->history = history;
+       this->execution = execution;
+}
+
 
 int NewFuzzer::selectWrite(ModelAction *read, SnapVector<ModelAction *> * rf_set)
 {
+       thread_id_t tid = read->get_tid();
+       int thread_id = id_to_int(tid);
+
+       SnapVector<func_id_list_t> * thrd_func_list = execution->get_thrd_func_list();
+       uint32_t func_id = (*thrd_func_list)[thread_id].back();
+
+       FuncNode * func_node = history->get_func_node(func_id);
+       FuncInst * read_inst = func_node->get_inst(read);
+       Predicate * curr_pred = func_node->get_predicate_tree_position(tid);
+
+       ModelVector<Predicate *> * children = curr_pred->get_children();
+       if (children->size() == 0)
+               return random() % rf_set->size();
+
        int random_index = random() % rf_set->size();
        return random_index;
 }
+
index 0fb730a..f50c476 100644 (file)
@@ -14,8 +14,13 @@ public:
        Thread * selectNotify(action_list_t * waiters);
        bool shouldSleep(const ModelAction *sleep);
        bool shouldWake(const ModelAction *sleep);
+
+       void register_engine(ModelHistory * history, ModelExecution * execution);
+
        MEMALLOC
 private:
+       ModelHistory * history;
+       ModelExecution * execution;
 };
 
 #endif /* end of __NEWFUZZER_H__ */