A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Ensure that the clang optimizer does not swallow the segfault I'm expecting
[simgrid.git]
/
teshsuite
/
mc
/
random-bug
/
random-bug.cpp
diff --git
a/teshsuite/mc/random-bug/random-bug.cpp
b/teshsuite/mc/random-bug/random-bug.cpp
index
03bc2ae
..
ba82292
100644
(file)
--- a/
teshsuite/mc/random-bug/random-bug.cpp
+++ b/
teshsuite/mc/random-bug/random-bug.cpp
@@
-1,30
+1,40
@@
-/* Copyright (c) 2014-20
19
. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2014-20
23
. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
#include <cstring>
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
#include <cstring>
+#include <signal.h>
#include <simgrid/modelchecker.h>
#include <simgrid/s4u.hpp>
#include <xbt/log.h>
XBT_LOG_NEW_DEFAULT_CATEGORY(random_bug, "For this example");
#include <simgrid/modelchecker.h>
#include <simgrid/s4u.hpp>
#include <xbt/log.h>
XBT_LOG_NEW_DEFAULT_CATEGORY(random_bug, "For this example");
-enum
{ ABORT, ASSERT, PRINTF } behavior
;
+enum
class Behavior { ABORT, ASSERT, PRINTF, SEGV }
;
-/** A fake application with a bug occuring for some random values */
+Behavior behavior;
+
+/** A fake application with a bug occurring for some random values */
static void app()
{
int x = MC_random(0, 5);
int y = MC_random(0, 5);
static void app()
{
int x = MC_random(0, 5);
int y = MC_random(0, 5);
+ XBT_DEBUG("got %d %d", x, y);
- if (behavior == ASSERT) {
+ if (behavior ==
Behavior::
ASSERT) {
MC_assert(x != 3 || y != 4);
MC_assert(x != 3 || y != 4);
- } else if (behavior == PRINTF) {
+ } else if (behavior ==
Behavior::
PRINTF) {
if (x == 3 && y == 4)
XBT_ERROR("Error reached");
if (x == 3 && y == 4)
XBT_ERROR("Error reached");
- } else { // behavior == ABORT
- abort();
+ } else if (behavior == Behavior::ABORT) {
+ if (x == 3 && y == 4)
+ abort();
+ } else if (behavior == Behavior::SEGV) {
+ if (x == 3 && y == 4)
+ kill(getpid(), SIGSEGV); // Simulate a segfault without displeasing the static analyzers
+ } else {
+ DIE_IMPOSSIBLE;
}
}
}
}
@@
-32,23
+42,26
@@
static void app()
int main(int argc, char* argv[])
{
simgrid::s4u::Engine e(&argc, argv);
int main(int argc, char* argv[])
{
simgrid::s4u::Engine e(&argc, argv);
- xbt_assert(argc == 3, "Usage: random-bug
raise|assert
<platformfile>");
+ xbt_assert(argc == 3, "Usage: random-bug
abort|assert|printf|segv
<platformfile>");
if (strcmp(argv[1], "abort") == 0) {
XBT_INFO("Behavior: abort");
if (strcmp(argv[1], "abort") == 0) {
XBT_INFO("Behavior: abort");
- behavior = ABORT;
+ behavior =
Behavior::
ABORT;
} else if (strcmp(argv[1], "assert") == 0) {
XBT_INFO("Behavior: assert");
} else if (strcmp(argv[1], "assert") == 0) {
XBT_INFO("Behavior: assert");
- behavior = ASSERT;
+ behavior =
Behavior::
ASSERT;
} else if (strcmp(argv[1], "printf") == 0) {
XBT_INFO("Behavior: printf");
} else if (strcmp(argv[1], "printf") == 0) {
XBT_INFO("Behavior: printf");
- behavior = PRINTF;
+ behavior = Behavior::PRINTF;
+ } else if (strcmp(argv[1], "segv") == 0) {
+ XBT_INFO("Behavior: segv");
+ behavior = Behavior::SEGV;
} else {
} else {
- xbt_die("Please use either 'abort', 'assert'
or 'printf' as first parameter, to specify what to do when the error
"
- "is found.");
+ xbt_die("Please use either 'abort', 'assert'
, 'printf', or 'segv' as first parameter,
"
+ "
to specify what to do when the error
is found.");
}
e.load_platform(argv[2]);
}
e.load_platform(argv[2]);
- simgrid::s4u::Actor::create("app",
simgrid::s4u::Host::
by_name("Fafard"), &app);
+ simgrid::s4u::Actor::create("app",
e.host_
by_name("Fafard"), &app);
e.run();
}
e.run();
}