1 /* Copyright (c) 2014-2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include <simgrid/modelchecker.h>
9 #include <simgrid/s4u.hpp>
12 XBT_LOG_NEW_DEFAULT_CATEGORY(random_bug, "For this example");
14 enum class Behavior { ABORT, ASSERT, PRINTF, SEGV };
18 /** A fake application with a bug occurring for some random values */
21 int x = MC_random(0, 5);
22 int y = MC_random(0, 5);
23 XBT_DEBUG("got %d %d", x, y);
25 if (behavior == Behavior::ASSERT) {
26 MC_assert(x != 3 || y != 4);
27 } else if (behavior == Behavior::PRINTF) {
29 XBT_ERROR("Error reached");
30 } else if (behavior == Behavior::ABORT) {
33 } else if (behavior == Behavior::SEGV) {
35 kill(getpid(), SIGSEGV); // Simulate a segfault without displeasing the static analyzers
42 int main(int argc, char* argv[])
44 simgrid::s4u::Engine e(&argc, argv);
45 xbt_assert(argc == 3, "Usage: random-bug abort|assert|printf|segv <platformfile>");
46 if (strcmp(argv[1], "abort") == 0) {
47 XBT_INFO("Behavior: abort");
48 behavior = Behavior::ABORT;
49 } else if (strcmp(argv[1], "assert") == 0) {
50 XBT_INFO("Behavior: assert");
51 behavior = Behavior::ASSERT;
52 } else if (strcmp(argv[1], "printf") == 0) {
53 XBT_INFO("Behavior: printf");
54 behavior = Behavior::PRINTF;
55 } else if (strcmp(argv[1], "segv") == 0) {
56 XBT_INFO("Behavior: segv");
57 behavior = Behavior::SEGV;
59 xbt_die("Please use either 'abort', 'assert', 'printf', or 'segv' as first parameter,"
60 " to specify what to do when the error is found.");
63 e.load_platform(argv[2]);
65 simgrid::s4u::Actor::create("app", e.host_by_name("Fafard"), &app);