X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/50c7df514872f832ef270099ca32302a28ff55ff..5ed37babb2fa9097abe82df299c0aa259ed84d5a:/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 87c26da104..9bade15c0a 100644 --- a/teshsuite/mc/random-bug/random-bug.cpp +++ b/teshsuite/mc/random-bug/random-bug.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2014-2021. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2014-2023. 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. */ @@ -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; @@ -19,15 +19,24 @@ static void app() { int x = MC_random(0, 5); int y = MC_random(0, 5); - // XBT_INFO("got %d %d",x,y); + XBT_DEBUG("got %d %d", x, y); if (behavior == Behavior::ASSERT) { MC_assert(x != 3 || y != 4); } 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) { +#ifndef __clang_analyzer__ + int* A = nullptr; + if (x == 3 && y == 4) + *A = 1; +#endif + } else { + DIE_IMPOSSIBLE; } } @@ -35,7 +44,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 "); + xbt_assert(argc == 3, "Usage: random-bug abort|assert|printf|segv "); if (strcmp(argv[1], "abort") == 0) { XBT_INFO("Behavior: abort"); behavior = Behavior::ABORT; @@ -45,13 +54,16 @@ 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 " - "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]); - 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(); }