From c98615d9dab06a7d902e1c62ddab30d2e90d6f17 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Mon, 6 Mar 2023 10:50:07 +0100 Subject: [PATCH] Fix clang build and make output more portable/predictible --- examples/sthread/stdobject/stdobject.tesh | 38 ++++++++++---------- src/mc/transition/TransitionObjectAccess.cpp | 15 +++++--- src/sthread/ObjectAccess.cpp | 14 ++++++-- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/examples/sthread/stdobject/stdobject.tesh b/examples/sthread/stdobject/stdobject.tesh index 1ce83ab48d..37d6d250d7 100644 --- a/examples/sthread/stdobject/stdobject.tesh +++ b/examples/sthread/stdobject/stdobject.tesh @@ -4,25 +4,25 @@ # We ignore the LD_PRELOAD lines from the expected output because they contain the build path ! ignore .*LD_PRELOAD.* -$ ${bindir:=.}/../../../bin/simgrid-mc --cfg=model-check/sleep-set:true --cfg=model-check/setenv:LD_PRELOAD=${libdir:=.}/libsgmalloc.so:${libdir:=.}/libsthread.so ${bindir:=.}/stdobject -> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'model-check/sleep-set' to 'true' -> [0.000000] [sthread/INFO] Starting the simulation. +$ ${bindir:=.}/../../../bin/simgrid-mc --cfg=model-check/sleep-set:true --cfg=model-check/setenv:LD_PRELOAD=${libdir:=.}/libsgmalloc.so:${libdir:=.}/libsthread.so ${bindir:=.}/stdobject "--log=root.fmt:[%11.6r]%e(%a@%h)%e%m%n" --log=no_loc +> [ 0.000000] (maestro@) Configuration change: Set 'model-check/sleep-set' to 'true' +> [ 0.000000] (maestro@) Starting the simulation. > starting two helpers... > waiting for helpers to finish... -> [0.000000] [mc_dfs/INFO] Start a DFS exploration. Reduction is: dpor. -> [0.000000] [sthread/INFO] thread 1 takes &v -> [0.000000] [sthread/INFO] thread 1 releases &v -> [0.000000] [sthread/INFO] thread 2 takes &v -> [0.000000] [sthread/INFO] thread 2 releases &v +> [ 0.000000] (maestro@) Start a DFS exploration. Reduction is: dpor. +> [ 0.000000] (maestro@) thread 1 takes &v +> [ 0.000000] (maestro@) thread 1 releases &v +> [ 0.000000] (maestro@) thread 2 takes &v +> [ 0.000000] (maestro@) thread 2 releases &v > v = { 1, 2, 3, 5, 8, 13, 21, 21, }; -> [0.000000] [sthread/INFO] thread 1 takes &v -> [0.000000] [sthread/INFO] thread 2 takes &v -> [0.000000] ../../src/sthread/ObjectAccess.cpp:87: [sthread/CRITICAL] Unprotected concurent access to &v: thread 1 at ../../examples/sthread/stdobject/stdobject.cpp:20 vs. thread 2 at ../../examples/sthread/stdobject/stdobject.cpp:20. -> [0.000000] [mc_ModelChecker/INFO] ************************** -> [0.000000] [mc_ModelChecker/INFO] *** PROPERTY NOT VALID *** -> [0.000000] [mc_ModelChecker/INFO] ************************** -> [0.000000] [mc_ModelChecker/INFO] Counter-example execution trace: -> [0.000000] [mc_ModelChecker/INFO] 2: BeginObjectAccess(&v @ ../../examples/sthread/stdobject/stdobject.cpp:20) -> [0.000000] [mc_ModelChecker/INFO] 3: BeginObjectAccess(&v @ ../../examples/sthread/stdobject/stdobject.cpp:20) -> [0.000000] [mc_ModelChecker/INFO] You can debug the problem (and see the whole details) by rerunning out of simgrid-mc with --cfg=model-check/replay:'2;3' -> [0.000000] [mc_dfs/INFO] DFS exploration ended. 7 unique states visited; 1 backtracks (9 transition replays, 1 states visited overall) +> [ 0.000000] (maestro@) thread 1 takes &v +> [ 0.000000] (maestro@) thread 2 takes &v +> [ 0.000000] (maestro@) Unprotected concurent access to &v: thread 1 vs thread 2 (locations hidden because of --log=no_loc). +> [ 0.000000] (maestro@) ************************** +> [ 0.000000] (maestro@) *** PROPERTY NOT VALID *** +> [ 0.000000] (maestro@) ************************** +> [ 0.000000] (maestro@) Counter-example execution trace: +> [ 0.000000] (maestro@) 2: BeginObjectAccess(&v) +> [ 0.000000] (maestro@) 3: BeginObjectAccess(&v) +> [ 0.000000] (maestro@) You can debug the problem (and see the whole details) by rerunning out of simgrid-mc with --cfg=model-check/replay:'2;3' +> [ 0.000000] (maestro@) DFS exploration ended. 7 unique states visited; 1 backtracks (9 transition replays, 1 states visited overall) diff --git a/src/mc/transition/TransitionObjectAccess.cpp b/src/mc/transition/TransitionObjectAccess.cpp index 144107dc75..d16472e98a 100644 --- a/src/mc/transition/TransitionObjectAccess.cpp +++ b/src/mc/transition/TransitionObjectAccess.cpp @@ -19,11 +19,18 @@ ObjectAccessTransition::ObjectAccessTransition(aid_t issuer, int times_considere } std::string ObjectAccessTransition::to_string(bool verbose) const { + std::string res; if (type_ == ObjectAccessType::ENTER) - return xbt::string_printf("BeginObjectAccess(%s @ %s:%d)", objname_.c_str(), file_.c_str(), line_); - if (type_ == ObjectAccessType::EXIT) - return xbt::string_printf("EndObjectAccess(%s @ %s:%d)", objname_.c_str(), file_.c_str(), line_); - return xbt::string_printf("ObjectAccess(%s @ %s:%d)", objname_.c_str(), file_.c_str(), line_); + res = std::string("BeginObjectAccess("); + else if (type_ == ObjectAccessType::EXIT) + res = std::string("EndObjectAccess("); + else + res = std::string("ObjectAccess("); + res += objname_; + if (not xbt_log_no_loc) + res += std::string(" @ ") + file_ + ":" + std::to_string(line_); + res += std::string(")"); + return res; } bool ObjectAccessTransition::depends(const Transition* o) const { diff --git a/src/sthread/ObjectAccess.cpp b/src/sthread/ObjectAccess.cpp index 93224388f0..35994bdeeb 100644 --- a/src/sthread/ObjectAccess.cpp +++ b/src/sthread/ObjectAccess.cpp @@ -11,6 +11,7 @@ #include "src/kernel/actor/ActorImpl.hpp" #include "src/kernel/actor/SimcallObserver.hpp" #include "src/sthread/sthread.h" +#include "xbt/string.hpp" #include @@ -85,8 +86,15 @@ int sthread_access_begin(void* objaddr, const char* objname, const char* file, i XBT_INFO("%s takes %s", self->get_cname(), objname); auto* ownership = get_owner(objaddr); if (ownership->owner != nullptr) { - XBT_CRITICAL("Unprotected concurent access to %s: %s at %s:%d vs. %s at %s:%d.", objname, - ownership->owner->get_cname(), ownership->file, ownership->line, self->get_cname(), file, line); + auto msg = std::string("Unprotected concurent access to ") + objname + ": " + ownership->owner->get_name(); + if (not xbt_log_no_loc) + msg += simgrid::xbt::string_printf(" at %s:%d", ownership->file, ownership->line); + msg += " vs " + self->get_name(); + if (xbt_log_no_loc) + msg += std::string(" (locations hidden because of --log=no_loc)."); + else + msg += simgrid::xbt::string_printf(" at %s:%d.", file, line); + XBT_CRITICAL("%s", msg.c_str()); return false; } ownership->owner = self; @@ -107,7 +115,7 @@ void sthread_access_end(void* objaddr, const char* objname, const char* file, in simgrid::sthread::ObjectAccessObserver observer(self, simgrid::sthread::AccessType::EXIT, objaddr, objname, file, line); simgrid::kernel::actor::simcall_answered( - [self, objaddr, objname, file, line]() -> void { + [self, objaddr, objname]() -> void { XBT_INFO("%s releases %s", self->get_cname(), objname); auto* ownership = get_owner(objaddr); xbt_assert(ownership->owner == self, "safety check failed: I'm not owner of the object I'm releasing."); -- 2.20.1