Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MC: Extend the random-bug example to test what's going on when the app is segfaulting
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Mon, 8 Mar 2021 13:49:55 +0000 (14:49 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Mon, 8 Mar 2021 13:50:00 +0000 (14:50 +0100)
teshsuite/mc/random-bug/random-bug.cpp
teshsuite/mc/random-bug/random-bug.tesh

index ca5b2fe..7d987d2 100644 (file)
@@ -10,7 +10,7 @@
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(random_bug, "For this example");
 
-enum class Behavior { ABORT, ASSERT, PRINTF };
+enum class Behavior { ABORT, ASSERT, PRINTF, SEGV };
 
 Behavior behavior;
 
@@ -26,8 +26,15 @@ static void app()
   } else if (behavior == Behavior::PRINTF) {
     if (x == 3 && y == 4)
       XBT_ERROR("Error reached");
-  } else { // behavior == Behavior::ABORT
-    abort();
+  } else if (behavior == Behavior::ABORT) {
+    if (x == 3 && y == 4)
+      abort();
+  } else if (behavior == Behavior::SEGV) {
+    int* A = 0;
+    if (x == 3 && y == 4)
+      *A = 1;
+  } else {
+    DIE_IMPOSSIBLE;
   }
 }
 
@@ -35,7 +42,7 @@ static void app()
 int main(int argc, char* argv[])
 {
   simgrid::s4u::Engine e(&argc, argv);
-  xbt_assert(argc == 3, "Usage: random-bug abort|assert|printf <platformfile>");
+  xbt_assert(argc == 3, "Usage: random-bug abort|assert|printf|segv <platformfile>");
   if (strcmp(argv[1], "abort") == 0) {
     XBT_INFO("Behavior: abort");
     behavior = Behavior::ABORT;
@@ -45,8 +52,12 @@ int main(int argc, char* argv[])
   } else if (strcmp(argv[1], "printf") == 0) {
     XBT_INFO("Behavior: printf");
     behavior = Behavior::PRINTF;
+  } else if (strcmp(argv[1], "segv") == 0) {
+    XBT_INFO("Behavior: segv");
+    behavior = Behavior::SEGV;
   } else {
-    xbt_die("Please use either 'abort', 'assert' or 'printf' as first parameter, to specify what to do when the error "
+    xbt_die("Please use either 'abort', 'assert', 'printf', or 'segv' as first parameter, to specify what to do when "
+            "the error "
             "is found.");
   }
 
index fa0d374..84cba92 100644 (file)
@@ -24,12 +24,12 @@ $ ${bindir:=.}/../../../bin/simgrid-mc ${bindir:=.}/random-bug abort ${platfdir}
 > [  0.000000] (0:maestro@) **************************
 > [  0.000000] (0:maestro@) From signal: Aborted
 > [  0.000000] (0:maestro@) Counter-example execution trace:
-> [  0.000000] (0:maestro@)   [(1)Fafard (app)] MC_RANDOM(0)
-> [  0.000000] (0:maestro@)   [(1)Fafard (app)] MC_RANDOM(0)
-> [  0.000000] (0:maestro@) Path = 1;1
-> [  0.000000] (0:maestro@) Expanded states = 2
-> [  0.000000] (0:maestro@) Visited states = 2
-> [  0.000000] (0:maestro@) Executed transitions = 2
+> [  0.000000] (0:maestro@)   [(1)Fafard (app)] MC_RANDOM(3)
+> [  0.000000] (0:maestro@)   [(1)Fafard (app)] MC_RANDOM(4)
+> [  0.000000] (0:maestro@) Path = 1/3;1/4
+> [  0.000000] (0:maestro@) Expanded states = 27
+> [  0.000000] (0:maestro@) Visited states = 68
+> [  0.000000] (0:maestro@) Executed transitions = 46
 > [  0.000000] (0:maestro@) Stack trace not displayed because you passed --log=no_loc
 
 $ ${bindir:=.}/../../../bin/simgrid-mc ${bindir:=.}/random-bug printf ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" --log=xbt_cfg.thresh:warning
@@ -40,3 +40,22 @@ $ ${bindir:=.}/../../../bin/simgrid-mc ${bindir:=.}/random-bug printf ${platfdir
 > [  0.000000] (0:maestro@) Expanded states = 43
 > [  0.000000] (0:maestro@) Visited states = 108
 > [  0.000000] (0:maestro@) Executed transitions = 72
+
+! expect return 6
+# because SIMGRID_MC_EXIT_PROGRAM_CRASH = 6
+$ ${bindir:=.}/../../../bin/simgrid-mc ${bindir:=.}/random-bug segv ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" --log=xbt_cfg.thresh:warning --log=no_loc
+> [  0.000000] (0:maestro@) Check a safety property. Reduction is: dpor.
+> [  0.000000] (0:maestro@) Behavior: segv
+> Segmentation fault.
+> [  0.000000] (0:maestro@) **************************
+> [  0.000000] (0:maestro@) ** CRASH IN THE PROGRAM **
+> [  0.000000] (0:maestro@) **************************
+> [  0.000000] (0:maestro@) From signal: Segmentation fault
+> [  0.000000] (0:maestro@) Counter-example execution trace:
+> [  0.000000] (0:maestro@)   [(1)Fafard (app)] MC_RANDOM(3)
+> [  0.000000] (0:maestro@)   [(1)Fafard (app)] MC_RANDOM(4)
+> [  0.000000] (0:maestro@) Path = 1/3;1/4
+> [  0.000000] (0:maestro@) Expanded states = 27
+> [  0.000000] (0:maestro@) Visited states = 68
+> [  0.000000] (0:maestro@) Executed transitions = 46
+> [  0.000000] (0:maestro@) Stack trace not displayed because you passed --log=no_loc