From 028bae82e91d02a05973da509f0edf8ebec8e76e Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 9 Sep 2025 15:35:14 +0200 Subject: [PATCH] Dev/verify shm 2 (#1292) * userdetails refinedg * fixed caller test --- slsDetectorSoftware/src/Detector.cpp | 24 ++++++++++++------- .../tests/Caller/test-Caller.cpp | 13 ++-------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index efabec931..f6dd395af 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -67,8 +67,13 @@ std::string getUserDetails(const int detectorIndex) { std::string user = "Unknown"; std::string date = "Unknown"; - SharedMemory detectorShm(detectorIndex, -1); - if (detectorShm.exists()) { + { + SharedMemory detectorShm(detectorIndex, -1); + if (!detectorShm.exists()) { + throw SharedMemoryError("No detector with index " + + std::to_string(detectorIndex) + + " in shared memory!"); + } detectorShm.openSharedMemory(false); if (detectorShm()->shmversion < DETECTOR_SHMAPIVERSION) { detectorShm.unmapSharedMemory(); @@ -86,13 +91,16 @@ std::string getUserDetails(const int detectorIndex) { for (int imod = 0; imod != numModules; ++imod) { SharedMemory moduleShm(detectorIndex, imod); - moduleShm.openSharedMemory(false); - if (moduleShm()->shmversion < MODULE_SHMAPIVERSION) { - LOG(logWARNING) << "Module Shared Memory too old to get hostname"; - } else { - hostname = moduleShm()->hostname; + if (moduleShm.exists()) { + moduleShm.openSharedMemory(false); + if (moduleShm()->shmversion < MODULE_SHMAPIVERSION) { + LOG(logWARNING) + << "Module Shared Memory too old to get hostname"; + } else { + hostname = moduleShm()->hostname; + } + moduleShm.unmapSharedMemory(); } - moduleShm.unmapSharedMemory(); } std::ostringstream userDetails; diff --git a/slsDetectorSoftware/tests/Caller/test-Caller.cpp b/slsDetectorSoftware/tests/Caller/test-Caller.cpp index cf81dc715..c96f6d4b1 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller.cpp @@ -3635,17 +3635,8 @@ TEST_CASE("frametime", "[.cmdcall]") { TEST_CASE("user", "[.cmdcall]") { Detector det; Caller caller(&det); - // stays the same across calls - std::ostringstream oss1, oss2, oss3; - caller.call("user", {}, -1, GET, oss1); - caller.call("user", {}, -1, GET, oss2); - caller.call("user", {}, -1, GET, oss3); - REQUIRE(oss1.str() == oss2.str()); - REQUIRE(oss2.str() == oss3.str()); - - // This is a get only command - // REQUIRE_THROWS(caller.call("user", {}, -1, PUT)); exit with failure - REQUIRE_NOTHROW(caller.call("user", {}, -1, GET)); + // caller only has help. cmdApp takes care of put and get + REQUIRE_NOTHROW(caller.call("user", {}, -1, defs::HELP_ACTION)); } TEST_CASE("sleep", "[.cmdcall]") {