libthreads: print out trace at end of execution
[c11tester.git] / model.cc
index b97352a97f15baebbf2c0ff578bab195a444928c..62b2925dc0e4f46ba79df049500363c4f29d9fdc 100644 (file)
--- a/model.cc
+++ b/model.cc
@@ -1,5 +1,8 @@
+#include <stdio.h>
+
 #include "model.h"
 #include "schedule.h"
+#include "common.h"
 
 ModelChecker *model;
 
@@ -9,6 +12,8 @@ ModelChecker::ModelChecker()
        this->used_thread_id = 0;
        /* Initialize default scheduler */
        this->scheduler = new DefaultScheduler();
+
+       this->current_action = NULL;
 }
 
 ModelChecker::~ModelChecker()
@@ -25,3 +30,59 @@ void ModelChecker::add_system_thread(struct thread *t)
 {
        this->system_thread = t;
 }
+
+void ModelChecker::check_current_action(void)
+{
+       if (this->current_action)
+               this->action_trace.push_back(this->current_action);
+       else
+               DEBUG("trying to push NULL action...\n");
+}
+
+void ModelChecker::print_trace(void)
+{
+       std::list<class ModelAction *>::iterator it;
+
+       for (it = action_trace.begin(); it != action_trace.end(); it++) {
+               DBG();
+               (*it)->print();
+       }
+}
+
+ModelAction::ModelAction(action_type_t type, memory_order order, void *loc, int value)
+{
+       struct thread *t = thread_current();
+       ModelAction *act = this;
+
+       act->type = type;
+       act->order = order;
+       act->location = loc;
+       act->tid = t->id;
+       act->value = value;
+}
+
+void ModelAction::print(void)
+{
+       const char *type_str;
+       switch (this->type) {
+       case THREAD_CREATE:
+               type_str = "thread create";
+               break;
+       case THREAD_YIELD:
+               type_str = "thread yield";
+               break;
+       case THREAD_JOIN:
+               type_str = "thread join";
+               break;
+       case ATOMIC_READ:
+               type_str = "atomic read";
+               break;
+       case ATOMIC_WRITE:
+               type_str = "atomic write";
+               break;
+       default:
+               type_str = "unknown type";
+       }
+
+       printf("Thread: %d\tAction: %s\tMO: %d\tLoc: %#014zx\tValue: %d\n", tid, type_str, order, (size_t)location, value);
+}