From c522e1dd1ccc11827ac2fce444764081dca25746 Mon Sep 17 00:00:00 2001 From: weiyu Date: Mon, 26 Aug 2019 17:27:21 -0700 Subject: [PATCH] some edits to NewFuzzer --- execution.cc | 1 + fuzzer.h | 1 + model.cc | 2 +- model.h | 2 +- newfuzzer.cc | 27 +++++++++++++++++++++++++++ newfuzzer.h | 5 +++++ 6 files changed, 36 insertions(+), 2 deletions(-) diff --git a/execution.cc b/execution.cc index eefb9107..9ee91570 100644 --- a/execution.cc +++ b/execution.cc @@ -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 */ diff --git a/fuzzer.h b/fuzzer.h index eb6fd4ef..d2912686 100644 --- 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: }; diff --git a/model.cc b/model.cc index 58a78592..0a2e844d 100644 --- 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 82d9bc8c..a3a7bc0e 100644 --- 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; diff --git a/newfuzzer.cc b/newfuzzer.cc index 7bcda8f2..5ec1c5d2 100644 --- a/newfuzzer.cc +++ b/newfuzzer.cc @@ -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 * rf_set) { + thread_id_t tid = read->get_tid(); + int thread_id = id_to_int(tid); + + SnapVector * 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 * children = curr_pred->get_children(); + if (children->size() == 0) + return random() % rf_set->size(); + int random_index = random() % rf_set->size(); return random_index; } + diff --git a/newfuzzer.h b/newfuzzer.h index 0fb730ab..f50c4765 100644 --- a/newfuzzer.h +++ b/newfuzzer.h @@ -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__ */ -- 2.34.1