#include <stdio.h>
#include <algorithm>
-#include <mutex>
#include <new>
#include <stdarg.h>
+#include <string.h>
#include "model.h"
#include "action.h"
#include "execution.h"
#include "bugmessage.h"
-#define INITIAL_THREAD_ID 0
-
ModelChecker *model;
/** @brief Constructor */
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(new ModelVector<TraceAnalysis *>())
+ trace_analyses()
{
+ memset(&stats,0,sizeof(struct execution_stats));
}
/** @brief Destructor */
ModelChecker::~ModelChecker()
{
delete node_stack;
- for (unsigned int i = 0; i < trace_analyses->size(); i++)
- delete (*trace_analyses)[i];
- delete trace_analyses;
delete scheduler;
}
/** @brief Print bug report listing for this execution (if any bugs exist) */
void ModelChecker::print_bugs() const
{
- if (execution->have_bug_reports()) {
- SnapVector<bug_message *> *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<bug_message *> *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();
}
/**
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());
}
/**
*/
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 >= 3) {
+ model_print("\nEarliest divergence point since last feasible execution:\n");
if (earliest_diverge)
earliest_diverge->print();
else
}
/* Don't print invalid bugs */
- if (printbugs)
+ if (printbugs && execution->have_bug_reports()) {
+ model_print("\n");
print_bugs();
+ }
model_print("\n");
execution->print_summary();
record_stats();
/* Output */
- if (params.verbose || (complete && execution->have_bug_reports()))
+ if ( (complete && params.verbose) || params.verbose>1 || (complete && execution->have_bug_reports()))
print_execution(complete);
else
clear_program_output();
diverge->print();
}
- execution->increment_execution_number();
+ execution_number++;
+
+ if (params.maxexecutions != 0 && stats.num_complete >= params.maxexecutions)
+ return false;
+
reset_to_initial_state();
return true;
}
/** @brief Run trace analyses on complete trace */
void ModelChecker::run_trace_analyses() {
- for (unsigned int i = 0; i < trace_analyses->size(); i++)
- (*trace_analyses)[i]->analyze(execution->get_action_trace());
+ for (unsigned int i = 0; i < trace_analyses.size(); i++)
+ trace_analyses[i]->analyze(execution->get_action_trace());
}
/**
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
* 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()) {
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);
}
}
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();
}