X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=model.cc;h=230607a0137c957ab475ae0aee3d32f960e231c1;hb=130a35155171503883aaf18e57f8957ce63d06e8;hp=48fa28acb71cf1b8d49112df717d2ac460dc2e9b;hpb=f9fe0087091f88deeb814d0768eecdfb1b51a94d;p=model-checker.git diff --git a/model.cc b/model.cc index 48fa28a..230607a 100644 --- a/model.cc +++ b/model.cc @@ -16,8 +16,6 @@ #include "execution.h" #include "bugmessage.h" -#define INITIAL_THREAD_ID 0 - ModelChecker *model; /** @brief Constructor */ @@ -26,7 +24,8 @@ ModelChecker::ModelChecker(struct model_params params) : params(params), scheduler(new Scheduler()), node_stack(new NodeStack()), - execution(new ModelExecution(¶ms, scheduler, node_stack)), + execution(new ModelExecution(this, &this->params, scheduler, node_stack)), + execution_number(1), diverge(NULL), earliest_diverge(NULL), trace_analyses() @@ -37,8 +36,6 @@ ModelChecker::ModelChecker(struct model_params params) : ModelChecker::~ModelChecker() { delete node_stack; - for (unsigned int i = 0; i < trace_analyses.size(); i++) - delete trace_analyses[i]; delete scheduler; } @@ -200,15 +197,13 @@ void ModelChecker::assert_user_bug(const char *msg) /** @brief Print bug report listing for this execution (if any bugs exist) */ void ModelChecker::print_bugs() const { - if (execution->have_bug_reports()) { - SnapVector *bugs = execution->get_bugs(); - - model_print("Bug report: %zu bug%s detected\n", - bugs->size(), - bugs->size() > 1 ? "s" : ""); - for (unsigned int i = 0; i < bugs->size(); i++) - (*bugs)[i]->print(); - } + SnapVector *bugs = execution->get_bugs(); + + model_print("Bug report: %zu bug%s detected\n", + bugs->size(), + bugs->size() > 1 ? "s" : ""); + for (unsigned int i = 0; i < bugs->size(); i++) + (*bugs)[i]->print(); } /** @@ -246,7 +241,8 @@ void ModelChecker::print_stats() const model_print("Number of buggy executions: %d\n", stats.num_buggy_executions); model_print("Number of infeasible executions: %d\n", stats.num_infeasible); model_print("Total executions: %d\n", stats.num_total); - model_print("Total nodes created: %d\n", node_stack->get_total_nodes()); + if (params.verbose) + model_print("Total nodes created: %d\n", node_stack->get_total_nodes()); } /** @@ -255,10 +251,12 @@ void ModelChecker::print_stats() const */ void ModelChecker::print_execution(bool printbugs) const { + model_print("Program output from execution %d:\n", + get_execution_number()); print_program_output(); - if (params.verbose) { - model_print("Earliest divergence point since last feasible execution:\n"); + if (params.verbose >= 2) { + model_print("\nEarliest divergence point since last feasible execution:\n"); if (earliest_diverge) earliest_diverge->print(); else @@ -269,8 +267,10 @@ void ModelChecker::print_execution(bool printbugs) const } /* Don't print invalid bugs */ - if (printbugs) + if (printbugs && execution->have_bug_reports()) { + model_print("\n"); print_bugs(); + } model_print("\n"); execution->print_summary(); @@ -319,7 +319,8 @@ bool ModelChecker::next_execution() diverge->print(); } - execution->increment_execution_number(); + execution_number++; + reset_to_initial_state(); return true; } @@ -350,26 +351,6 @@ Thread * ModelChecker::get_thread(const ModelAction *act) const return execution->get_thread(act); } -/** - * @brief Check if a Thread is currently enabled - * @param t The Thread to check - * @return True if the Thread is currently enabled - */ -bool ModelChecker::is_enabled(Thread *t) const -{ - return scheduler->is_enabled(t); -} - -/** - * @brief Check if a Thread is currently enabled - * @param tid The ID of the Thread to check - * @return True if the Thread is currently enabled - */ -bool ModelChecker::is_enabled(thread_id_t tid) const -{ - return scheduler->is_enabled(tid); -} - /** * Switch from a model-checker context to a user-thread context. This is the * complement of ModelChecker::switch_to_master and must be called from the @@ -444,7 +425,7 @@ void ModelChecker::run() * thread which just took a step--plus the first step * for any newly-created thread */ - for (unsigned int i = 0; i < execution->get_num_threads(); i++) { + for (unsigned int i = 0; i < get_num_threads(); i++) { thread_id_t tid = int_to_id(i); Thread *thr = get_thread(tid); if (!thr->is_model_thread() && !thr->is_complete() && !thr->get_pending()) { @@ -458,7 +439,7 @@ void ModelChecker::run() for (unsigned int i = 0; i < get_num_threads(); i++) { Thread *th = get_thread(int_to_id(i)); ModelAction *act = th->get_pending(); - if (act && is_enabled(th) && !execution->check_action_enabled(act)) { + if (act && execution->is_enabled(th) && !execution->check_action_enabled(act)) { scheduler->sleep(th); } } @@ -485,4 +466,8 @@ void ModelChecker::run() model_print("******* Model-checking complete: *******\n"); print_stats(); + + /* Have the trace analyses dump their output. */ + for (unsigned int i = 0; i < trace_analyses.size(); i++) + trace_analyses[i]->finish(); }