From fe73ee0797bb00244bdd4798a342633ac7e507fd Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Wed, 25 Oct 2023 19:53:16 +0200 Subject: [PATCH] sthread: do not intercept valgrind nor /bin/sh, and be verbose about what we intercept --- .../sthread/pthread-mc-mutex-recursive.tesh | 11 +++++++++++ examples/sthread/pthread-mc-mutex-simple.tesh | 2 +- .../pthread-mc-mutex-simpledeadlock.tesh | 2 +- .../sthread/pthread-mc-producer-consumer.tesh | 6 +++--- examples/sthread/pthread-mutex-recursive.tesh | 7 +++++++ examples/sthread/pthread-mutex-simple.tesh | 2 +- .../sthread/pthread-producer-consumer.tesh | 4 ++-- src/sthread/sthread_impl.cpp | 19 +++++++++++++------ 8 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 examples/sthread/pthread-mc-mutex-recursive.tesh create mode 100644 examples/sthread/pthread-mutex-recursive.tesh diff --git a/examples/sthread/pthread-mc-mutex-recursive.tesh b/examples/sthread/pthread-mc-mutex-recursive.tesh new file mode 100644 index 0000000000..9dbe680d4d --- /dev/null +++ b/examples/sthread/pthread-mc-mutex-recursive.tesh @@ -0,0 +1,11 @@ +# We ignore the LD_PRELOAD lines from the expected output because they contain the build path +! ignore .*LD_PRELOAD.* + +$ $VALGRIND_NO_TRACE_CHILDREN ${bindir:=.}/../../bin/simgrid-mc --cfg=model-check/setenv:LD_PRELOAD=${libdir:=.}/libsgmalloc.so:${libdir:=.}/libsthread.so ${bindir:=.}/pthread-mutex-recursive +> sthread is intercepting the execution of ./pthread-mutex-recursive +> [0.000000] [mc_dfs/INFO] Start a DFS exploration. Reduction is: dpor. +> Got the lock on the default mutex. +> Failed to relock the default mutex. +> Got the lock on the recursive mutex. +> Got the lock again on the recursive mutex. +> [0.000000] [mc_dfs/INFO] DFS exploration ended. 15 unique states visited; 1 backtracks (3 transition replays, 19 states visited overall) diff --git a/examples/sthread/pthread-mc-mutex-simple.tesh b/examples/sthread/pthread-mc-mutex-simple.tesh index 55ecc955dc..9e38ceadf3 100644 --- a/examples/sthread/pthread-mc-mutex-simple.tesh +++ b/examples/sthread/pthread-mc-mutex-simple.tesh @@ -3,7 +3,7 @@ ! ignore .*LD_PRELOAD.* $ $VALGRIND_NO_TRACE_CHILDREN ${bindir:=.}/../../bin/simgrid-mc --cfg=model-check/setenv:LD_PRELOAD=${libdir:=.}/libsgmalloc.so:${libdir:=.}/libsthread.so ${bindir:=.}/pthread-mutex-simple -> [0.000000] [sthread/INFO] Starting the simulation. +> sthread is intercepting the execution of ./pthread-mutex-simple > All threads are started. > [0.000000] [mc_dfs/INFO] Start a DFS exploration. Reduction is: dpor. > The thread 0 is terminating. diff --git a/examples/sthread/pthread-mc-mutex-simpledeadlock.tesh b/examples/sthread/pthread-mc-mutex-simpledeadlock.tesh index 2de4e42603..e843a409b9 100644 --- a/examples/sthread/pthread-mc-mutex-simpledeadlock.tesh +++ b/examples/sthread/pthread-mc-mutex-simpledeadlock.tesh @@ -6,7 +6,7 @@ ! ignore .*LD_PRELOAD.* $ $VALGRIND_NO_TRACE_CHILDREN ${bindir:=.}/../../bin/simgrid-mc --cfg=model-check/setenv:LD_PRELOAD=${libdir:=.}/libsgmalloc.so:${libdir:=.}/libsthread.so ${bindir:=.}/pthread-mutex-simpledeadlock -> [0.000000] [sthread/INFO] Starting the simulation. +> sthread is intercepting the execution of ./pthread-mutex-simpledeadlock > All threads are started. > [0.000000] [mc_dfs/INFO] Start a DFS exploration. Reduction is: dpor. > The thread 0 is terminating. diff --git a/examples/sthread/pthread-mc-producer-consumer.tesh b/examples/sthread/pthread-mc-producer-consumer.tesh index a9f5a723d7..584b7a5857 100644 --- a/examples/sthread/pthread-mc-producer-consumer.tesh +++ b/examples/sthread/pthread-mc-producer-consumer.tesh @@ -2,18 +2,18 @@ ! ignore .*LD_PRELOAD.* $ $VALGRIND_NO_TRACE_CHILDREN ${bindir:=.}/../../bin/simgrid-mc --cfg=model-check/setenv:LD_PRELOAD=${libdir:=.}/libsgmalloc.so:${libdir:=.}/libsthread.so ${bindir:=.}/pthread-producer-consumer -q -C 1 -P 1 -> [0.000000] [sthread/INFO] Starting the simulation. +> sthread is intercepting the execution of ./pthread-producer-consumer > [0.000000] [mc_dfs/INFO] Start a DFS exploration. Reduction is: dpor. > [0.000000] [mc_dfs/INFO] DFS exploration ended. 786 unique states visited; 97 backtracks (2049 transition replays, 2932 states visited overall) $ $VALGRIND_NO_TRACE_CHILDREN ${bindir:=.}/../../bin/simgrid-mc --cfg=model-check/reduction:sdpor --cfg=model-check/setenv:LD_PRELOAD=${libdir:=.}/libsgmalloc.so:${libdir:=.}/libsthread.so ${bindir:=.}/pthread-producer-consumer -q -C 1 -P 1 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'model-check/reduction' to 'sdpor' -> [0.000000] [sthread/INFO] Starting the simulation. +> sthread is intercepting the execution of ./pthread-producer-consumer > [0.000000] [mc_dfs/INFO] Start a DFS exploration. Reduction is: sdpor. > [0.000000] [mc_dfs/INFO] DFS exploration ended. 1186 unique states visited; 157 backtracks (3403 transition replays, 4746 states visited overall) $ $VALGRIND_NO_TRACE_CHILDREN ${bindir:=.}/../../bin/simgrid-mc --cfg=model-check/reduction:odpor --cfg=model-check/setenv:LD_PRELOAD=${libdir:=.}/libsgmalloc.so:${libdir:=.}/libsthread.so ${bindir:=.}/pthread-producer-consumer -q -C 1 -P 1 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'model-check/reduction' to 'odpor' -> [0.000000] [sthread/INFO] Starting the simulation. +> sthread is intercepting the execution of ./pthread-producer-consumer > [0.000000] [mc_dfs/INFO] Start a DFS exploration. Reduction is: odpor. > [0.000000] [mc_dfs/INFO] DFS exploration ended. 39 unique states visited; 0 backtracks (0 transition replays, 39 states visited overall) diff --git a/examples/sthread/pthread-mutex-recursive.tesh b/examples/sthread/pthread-mutex-recursive.tesh new file mode 100644 index 0000000000..afe8d88a90 --- /dev/null +++ b/examples/sthread/pthread-mutex-recursive.tesh @@ -0,0 +1,7 @@ +$ env ASAN_OPTIONS=verify_asan_link_order=0:$ASAN_OPTIONS LD_PRELOAD=${libdir:=.}/libsthread.so ./pthread-mutex-recursive +> sthread is intercepting the execution of ./pthread-mutex-recursive +> [0.000000] [sthread/INFO] All threads exited. Terminating the simulation. +> Got the lock on the default mutex. +> Failed to relock the default mutex. +> Got the lock on the recursive mutex. +> Got the lock again on the recursive mutex. \ No newline at end of file diff --git a/examples/sthread/pthread-mutex-simple.tesh b/examples/sthread/pthread-mutex-simple.tesh index 29d66a92df..2e12ec1204 100644 --- a/examples/sthread/pthread-mutex-simple.tesh +++ b/examples/sthread/pthread-mutex-simple.tesh @@ -1,5 +1,5 @@ $ env ASAN_OPTIONS=verify_asan_link_order=0:$ASAN_OPTIONS LD_PRELOAD=${libdir:=.}/libsthread.so ./pthread-mutex-simple -> [0.000000] [sthread/INFO] Starting the simulation. +> sthread is intercepting the execution of ./pthread-mutex-simple > All threads are started. > The thread 0 is terminating. > The thread 1 is terminating. diff --git a/examples/sthread/pthread-producer-consumer.tesh b/examples/sthread/pthread-producer-consumer.tesh index a54bed01af..d8bf22cf52 100644 --- a/examples/sthread/pthread-producer-consumer.tesh +++ b/examples/sthread/pthread-producer-consumer.tesh @@ -1,5 +1,5 @@ $ env ASAN_OPTIONS=verify_asan_link_order=0:$ASAN_OPTIONS LD_PRELOAD=${libdir:=.}/libsthread.so ./pthread-producer-consumer -> [0.000000] [sthread/INFO] Starting the simulation. +> sthread is intercepting the execution of ./pthread-producer-consumer > Producer 1: Insert Item 0 at 0 > Producer 2: Insert Item 0 at 1 > Consumer 1: Remove Item 0 from 0 @@ -15,7 +15,7 @@ $ env ASAN_OPTIONS=verify_asan_link_order=0:$ASAN_OPTIONS LD_PRELOAD=${libdir:=. > [0.000000] [sthread/INFO] All threads exited. Terminating the simulation. $ env ASAN_OPTIONS=verify_asan_link_order=0:$ASAN_OPTIONS LD_PRELOAD=${libdir:=.}/libsthread.so ./pthread-producer-consumer -c 2 -C 1 -p 2 -P 1 -> [0.000000] [sthread/INFO] Starting the simulation. +> sthread is intercepting the execution of ./pthread-producer-consumer > Producer 1: Insert Item 0 at 0 > Consumer 1: Remove Item 0 from 0 > Producer 1: Insert Item 1 at 1 diff --git a/src/sthread/sthread_impl.cpp b/src/sthread/sthread_impl.cpp index 45ba730029..c799eff515 100644 --- a/src/sthread/sthread_impl.cpp +++ b/src/sthread/sthread_impl.cpp @@ -38,14 +38,22 @@ int sthread_main(int argc, char** argv, char** envp, int (*raw_main)(int, char** { /* Do not intercept the main when run from SMPI: it will initialize the simulation properly */ for (int i = 0; envp[i] != nullptr; i++) - if (std::string_view(envp[i]).rfind("SMPI_GLOBAL_SIZE", 0) == 0) + if (std::string_view(envp[i]).rfind("SMPI_GLOBAL_SIZE", 0) == 0) { + printf("sthread refuses to intercept the SMPI application %s directly, as its interception is done otherwise.\n", + argv[0]); return raw_main(argc, argv, envp); + } - /* If not in SMPI, the old main becomes an actor in a newly created simulation */ - std::ostringstream id; - id << std::this_thread::get_id(); + /* Do not intercept valgrind step 1 */ + if (not strcmp(argv[0], "/usr/bin/valgrind.bin") || not strcmp(argv[0], "/bin/sh")) { + printf("sthread refuses to intercept the execution of %s. Running the application unmodified.\n", argv[0]); + fflush(stdout); + return raw_main(argc, argv, envp); + } - XBT_DEBUG("sthread main() is starting in thread %s", id.str().c_str()); + /* If not in SMPI, the old main becomes an actor in a newly created simulation */ + printf("sthread is intercepting the execution of %s\n", argv[0]); + fflush(stdout); sg4::Engine e(&argc, argv); auto* zone = sg4::create_full_zone("world"); @@ -56,7 +64,6 @@ int sthread_main(int argc, char** argv, char** envp, int (*raw_main)(int, char** sthread_enable(); sg4::ActorPtr main_actor = sg4::Actor::create("main thread", lilibeth, raw_main, argc, argv, envp); - XBT_INFO("Starting the simulation."); sg4::Engine::get_instance()->run(); sthread_disable(); XBT_INFO("All threads exited. Terminating the simulation."); -- 2.20.1