model-assert: add MODEL_ASSERT() for user programs
authorBrian Norris <banorris@uci.edu>
Sat, 3 Nov 2012 22:52:16 +0000 (15:52 -0700)
committerBrian Norris <banorris@uci.edu>
Sat, 3 Nov 2012 22:52:16 +0000 (15:52 -0700)
common.cc
include/model-assert.h [new file with mode: 0644]

index b274989..20102b0 100644 (file)
--- a/common.cc
+++ b/common.cc
@@ -2,6 +2,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include <model-assert.h>
+
 #include "common.h"
 #include "model.h"
 #include "stacktrace.h"
@@ -40,3 +42,12 @@ void assert_hook(void)
 {
        printf("Add breakpoint to line %u in file %s.\n",__LINE__,__FILE__);
 }
+
+void model_assert(bool expr, const char *file, int line)
+{
+       if (!expr) {
+               printf("  [BUG] Program has hit assertion in file %s at line %d\n",
+                               file, line);
+               model->set_assert();
+       }
+}
diff --git a/include/model-assert.h b/include/model-assert.h
new file mode 100644 (file)
index 0000000..a091e15
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef __MODEL_ASSERT_H__
+#define __MODEL_ASSERT_H__
+
+#if __cplusplus
+extern "C" {
+#endif
+
+void model_assert(bool expr, const char *file, int line);
+#define MODEL_ASSERT(expr) model_assert((expr), __FILE__, __LINE__)
+
+#if __cplusplus
+}
+#endif
+
+#endif /* __MODEL_ASSERT_H__ */