mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 05:17:13 +02:00
Setting dac names for CTB (C++ and Python) (#413)
# Setting DAC names for CTB * Introduced new shared memory for CTB only * Prepared for additional functionality * Works from C++ and Python Co-authored-by: Dhanya Thattil <dhanya.thattil@psi.ch>
This commit is contained in:
@ -18,6 +18,7 @@ target_sources(tests PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test-CmdParser.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test-Module.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test-Pattern.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test-CtbConfig.cpp
|
||||
)
|
||||
|
||||
target_include_directories(tests PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../src>")
|
@ -590,13 +590,13 @@ TEST_CASE("master", "[.cmd]") {
|
||||
}
|
||||
{
|
||||
std::ostringstream oss1;
|
||||
proxy.Call("master", {"0"}, 0, PUT, oss3);
|
||||
REQUIRE(oss3.str() == "master 0\n");
|
||||
proxy.Call("master", {"0"}, 0, PUT, oss1);
|
||||
REQUIRE(oss1.str() == "master 0\n");
|
||||
}
|
||||
{
|
||||
std::ostringstream oss1;
|
||||
proxy.Call("master", {"1"}, 0, PUT, oss3);
|
||||
REQUIRE(oss3.str() == "master 1\n");
|
||||
proxy.Call("master", {"1"}, 0, PUT, oss1);
|
||||
REQUIRE(oss1.str() == "master 1\n");
|
||||
}
|
||||
REQUIRE_THROWS(proxy.Call("master", {"1"}, -1, PUT));
|
||||
// set all to slaves, and then master
|
||||
|
59
slsDetectorSoftware/tests/test-CtbConfig.cpp
Normal file
59
slsDetectorSoftware/tests/test-CtbConfig.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include "catch.hpp"
|
||||
#include <string>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "SharedMemory.h"
|
||||
#include "CtbConfig.h"
|
||||
using namespace sls;
|
||||
#include <fstream>
|
||||
|
||||
|
||||
TEST_CASE("Default construction"){
|
||||
static_assert(sizeof(CtbConfig) == 360); // 18*20
|
||||
|
||||
CtbConfig c;
|
||||
auto names = c.getDacNames();
|
||||
REQUIRE(names.size() == 18);
|
||||
REQUIRE(names[0] == "dac0");
|
||||
REQUIRE(names[1] == "dac1");
|
||||
REQUIRE(names[2] == "dac2");
|
||||
REQUIRE(names[3] == "dac3");
|
||||
}
|
||||
|
||||
TEST_CASE("Set and get a single dac name"){
|
||||
CtbConfig c;
|
||||
c.setDacName(3, "vrf");
|
||||
auto names = c.getDacNames();
|
||||
|
||||
REQUIRE(c.getDacName(3) == "vrf");
|
||||
REQUIRE(names[3] == "vrf");
|
||||
}
|
||||
|
||||
TEST_CASE("Set a name that is too large throws"){
|
||||
CtbConfig c;
|
||||
REQUIRE_THROWS(c.setDacName(3, "somestringthatisreallytolongforadatac"));
|
||||
}
|
||||
|
||||
TEST_CASE("Length of dac name cannot be 0"){
|
||||
CtbConfig c;
|
||||
REQUIRE_THROWS(c.setDacName(1, ""));
|
||||
}
|
||||
|
||||
TEST_CASE("Copy a CTB config"){
|
||||
CtbConfig c1;
|
||||
c1.setDacName(5, "somename");
|
||||
|
||||
auto c2 = c1;
|
||||
//change the name on the first object
|
||||
//to detecto shallow copy
|
||||
c1.setDacName(5, "someothername");
|
||||
REQUIRE(c2.getDacName(5) == "somename");
|
||||
}
|
||||
|
||||
TEST_CASE("Move CtbConfig "){
|
||||
CtbConfig c1;
|
||||
c1.setDacName(3, "yetanothername");
|
||||
CtbConfig c2(std::move(c1));
|
||||
REQUIRE(c2.getDacName(3) == "yetanothername");
|
||||
}
|
@ -134,3 +134,31 @@ TEST_CASE("Create several shared memories", "[detector]") {
|
||||
CHECK(v[i].IsExisting() == false);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Create create a shared memory with a tag"){
|
||||
SharedMemory<int> shm(0, -1, "ctbdacs");
|
||||
REQUIRE(shm.GetName() == "/slsDetectorPackage_detector_0_ctbdacs");
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Create create a shared memory with a tag when SLSDETNAME is set"){
|
||||
|
||||
// if SLSDETNAME is already set we unset it but
|
||||
// save the value
|
||||
std::string old_slsdetname;
|
||||
if (getenv(SHM_ENV_NAME))
|
||||
old_slsdetname = getenv(SHM_ENV_NAME);
|
||||
unsetenv(SHM_ENV_NAME);
|
||||
setenv(SHM_ENV_NAME, "myprefix", 1);
|
||||
|
||||
SharedMemory<int> shm(0, -1, "ctbdacs");
|
||||
REQUIRE(shm.GetName() == "/slsDetectorPackage_detector_0_myprefix_ctbdacs");
|
||||
|
||||
// Clean up after us
|
||||
if (old_slsdetname.empty())
|
||||
unsetenv(SHM_ENV_NAME);
|
||||
else
|
||||
setenv(SHM_ENV_NAME, old_slsdetname.c_str(), 1);
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user