Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
use assignment to non-trivial class rather than artificial trivialization and memset
[simgrid.git] / teshsuite / mc / random-bug / random-bug.cpp
index 23e96cb..03bc2ae 100644 (file)
@@ -12,22 +12,19 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(random_bug, "For this example");
 
 enum { ABORT, ASSERT, PRINTF } behavior;
 
-/** An (fake) application with a bug occuring for some random values */
+/** A fake application with a bug occuring for some random values */
 static void app()
 {
   int x = MC_random(0, 5);
   int y = MC_random(0, 5);
 
-  switch (behavior) {
-    case ABORT:
-      abort();
-    case ASSERT:
-      MC_assert(x != 3 || y != 4);
-      break;
-    case PRINTF:
-      if (x == 3 && y == 4)
-        XBT_ERROR("Error reached");
-      break;
+  if (behavior == ASSERT) {
+    MC_assert(x != 3 || y != 4);
+  } else if (behavior == PRINTF) {
+    if (x == 3 && y == 4)
+      XBT_ERROR("Error reached");
+  } else { // behavior == ABORT
+    abort();
   }
 }
 
@@ -45,6 +42,9 @@ int main(int argc, char* argv[])
   } else if (strcmp(argv[1], "printf") == 0) {
     XBT_INFO("Behavior: printf");
     behavior = PRINTF;
+  } else {
+    xbt_die("Please use either 'abort', 'assert' or 'printf' as first parameter, to specify what to do when the error "
+            "is found.");
   }
 
   e.load_platform(argv[2]);