mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-07-16 23:26:03 +02:00
Build on RHEL9 docker image / build (push) Successful in 4m15s
Build on RHEL8 docker image / build (push) Successful in 5m21s
Build and Deploy on local RHEL9 / build (push) Successful in 2m12s
Build and Deploy on local RHEL8 / build (push) Successful in 5m12s
Run Simulator Tests on local RHEL9 / build (push) Successful in 18m55s
Run Simulator Tests on local RHEL8 / build (push) Successful in 22m19s
* added fetch fmt server library * added first draft of matterhorn * added cpp TCP Interface to slsDetectorServer * bug: added std::signal for proper handling of ctr+c * added compile option to set log level * WIP * dont use c project settings when building matterhornserver * updated logger * WIP * WIP * linked fmt to slsProjectOptions * solved merge conflict * some refactoring * cleaned up logs * WIP * generated register defs from csv file * oops given in hex * properly added fmt as a dependency * some format changes * WIP * used CRTP for virtual detector * WIP * added udp functions to matterhornserver * fixed build * added Server class usable for all detectors * removed stopserver * added some more functions * wrong overload * porper cleanup of matterhorn app * PR Review * refactored directory structure * added shared memory for aqcuisition status * implemented bus read and write * added Matterhorn data class * modified memory model * added SPI communication * moved memory for Bus communication to BucCommunication class * WIP added HelperFunction for mask conversion * completed HelperFunctions * added tests for MatterHorn Helper Functions * removed shared memory in destructor * fixed SPI communication * moved SharedMemory to slsSupportLib * added toolchain file for cross compilation * fix constructor for HarwareSPICommunication is public * update receiver parameters function * updated mac address * uploaded matterhorn server binary tracked as lfs * small fixes from tests on board * automatically update matterhorn api version when cross compiling binaries * fix bug in SPI read * copy to server_directory/bin when cross compiling * fixed cmake list * update generate_registerdefs.py * fixed copy of server binary * always return error message * add error log when opening dev/mem * code review * fixed eiger, mythen tests for dynamic range * second Review * member function getDerived for better readability * split code into implementation class and actual class doing tcp communication * added slsWarnings and c++17 compiler option * added git lfs to workflow * fix gitea workflows * bug: add extra clock register * implement initial checks * bug: client excpetcs 4 bytes * refactoring directory structure and rename to .hpp * check if detector already set up * missed .h to .hpp * Code Review 3 * use temmplate value for stopserver * use internal CMAKE_CROSSCOMPILING variable * moved boolean stop server flag to DetectorImpl - moving template parameter up * missed a file * replace baseclass:: with this * add Matterhorn server in github workflow * whatever workflow bug- lets see * fixed receiving trim bits changed to int64_t
267 lines
7.4 KiB
C++
267 lines
7.4 KiB
C++
// SPDX-License-Identifier: LGPL-3.0-or-other
|
|
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
|
|
|
#define DISABLE_STATIC_ASSERT // to be able to test obsolete shm without isValid
|
|
#include "catch.hpp"
|
|
#include "sls/SharedMemory.h"
|
|
#include "sls/string_utils.h"
|
|
#include <filesystem>
|
|
|
|
namespace sls {
|
|
|
|
struct Data {
|
|
int shmversion{SHM_IS_VALID_CHECK_VERSION};
|
|
int x;
|
|
double y;
|
|
char mess[50];
|
|
bool isValid{true};
|
|
};
|
|
|
|
struct ObsoleteData {
|
|
int shmversion{SHM_IS_VALID_CHECK_VERSION - 10};
|
|
int x;
|
|
double y;
|
|
char mess[50];
|
|
};
|
|
|
|
struct ObsoleteCtbData {
|
|
int x;
|
|
double y;
|
|
char mess[50];
|
|
};
|
|
|
|
void freeShm(const int dindex, const int mIndex) {
|
|
SharedMemory<Data> shm(dindex, mIndex);
|
|
if (shm.exists()) {
|
|
shm.removeSharedMemory();
|
|
}
|
|
}
|
|
|
|
constexpr int shm_id = 10;
|
|
|
|
// macOS does not expose shm in the filesystem
|
|
#ifndef __APPLE__
|
|
|
|
const char *env_p = std::getenv(SHM_ENV_NAME);
|
|
std::string env_name = env_p ? ("_" + std::string(env_p)) : "";
|
|
const std::string file_path =
|
|
std::string("/dev/shm/slsDetectorPackage_detector_") +
|
|
std::to_string(shm_id) + env_name;
|
|
|
|
TEST_CASE("Free obsolete (without isValid)", "[detector][shm]") {
|
|
|
|
// ensure its clean to start
|
|
freeShm(shm_id, -1);
|
|
|
|
{
|
|
// create actual shm and free
|
|
SharedMemory<Data> shm(shm_id, -1);
|
|
shm.createSharedMemory();
|
|
REQUIRE(std::filesystem::exists(file_path) == true);
|
|
REQUIRE(shm.memoryHasValidFlag() == true);
|
|
REQUIRE_NOTHROW(freeShm(shm_id, -1));
|
|
REQUIRE(std::filesystem::exists(file_path) == false);
|
|
}
|
|
|
|
{
|
|
// create obsolete and free
|
|
SharedMemory<ObsoleteData> shm(shm_id, -1);
|
|
shm.createSharedMemory();
|
|
REQUIRE(std::filesystem::exists(file_path) == true);
|
|
shm.unmapSharedMemory();
|
|
}
|
|
|
|
{
|
|
SharedMemory<Data> shm(shm_id, -1);
|
|
shm.openSharedMemory(false);
|
|
REQUIRE(shm.memoryHasValidFlag() == false);
|
|
REQUIRE_NOTHROW(freeShm(shm_id, -1));
|
|
REQUIRE(std::filesystem::exists(file_path) == false);
|
|
}
|
|
|
|
{
|
|
// create obsolete ctb (without shmversion) and free
|
|
SharedMemory<ObsoleteCtbData> shm(shm_id, -1);
|
|
shm.createSharedMemory();
|
|
REQUIRE(std::filesystem::exists(file_path) == true);
|
|
shm.unmapSharedMemory();
|
|
}
|
|
{
|
|
SharedMemory<Data> shm(shm_id, -1);
|
|
shm.openSharedMemory(false);
|
|
REQUIRE(shm.memoryHasValidFlag() == false);
|
|
REQUIRE_NOTHROW(freeShm(shm_id, -1));
|
|
REQUIRE(std::filesystem::exists(file_path) == false);
|
|
}
|
|
}
|
|
|
|
#endif
|
|
|
|
TEST_CASE("Create SharedMemory read and write", "[detector][shm]") {
|
|
SharedMemory<Data> shm(shm_id, -1);
|
|
if (shm.exists()) {
|
|
shm.removeSharedMemory();
|
|
}
|
|
shm.createSharedMemory();
|
|
|
|
const char *env_p = std::getenv(SHM_ENV_NAME);
|
|
std::string env_name = env_p ? ("_" + std::string(env_p)) : "";
|
|
CHECK(shm.getName() ==
|
|
std::string(SHM_DETECTOR_PREFIX) + std::to_string(shm_id) + env_name);
|
|
shm()->x = 3;
|
|
shm()->y = 5.7;
|
|
strcpy_safe(shm()->mess, "Some string");
|
|
|
|
CHECK(shm()->x == 3);
|
|
CHECK(shm()->y == 5.7);
|
|
CHECK(std::string(shm()->mess) == "Some string");
|
|
|
|
shm.removeSharedMemory();
|
|
|
|
CHECK(shm.exists() == false);
|
|
}
|
|
|
|
TEST_CASE("Open existing SharedMemory and read", "[detector][shm]") {
|
|
{
|
|
SharedMemory<Data> shm(shm_id, -1);
|
|
if (shm.exists()) {
|
|
shm.removeSharedMemory();
|
|
}
|
|
shm.createSharedMemory();
|
|
shm()->x = 3;
|
|
shm()->y = 5.9;
|
|
}
|
|
|
|
SharedMemory<Data> shm2(shm_id, -1);
|
|
shm2.openSharedMemory(true);
|
|
CHECK(shm2()->y == 5.9);
|
|
|
|
shm2.removeSharedMemory();
|
|
}
|
|
|
|
TEST_CASE("Creating a second shared memory with the same name throws",
|
|
"[detector][shm]") {
|
|
|
|
SharedMemory<Data> shm0(shm_id, -1);
|
|
SharedMemory<Data> shm1(shm_id, -1);
|
|
|
|
shm0.createSharedMemory();
|
|
CHECK_THROWS(shm1.createSharedMemory());
|
|
shm0.removeSharedMemory();
|
|
}
|
|
|
|
TEST_CASE("Open two shared memories to the same place", "[detector][shm]") {
|
|
|
|
// Create the first shared memory
|
|
SharedMemory<Data> shm(shm_id, -1);
|
|
shm.createSharedMemory();
|
|
shm()->x = 5;
|
|
CHECK(shm()->x == 5);
|
|
|
|
// Open the second shared memory with the same name
|
|
SharedMemory<Data> shm2(shm_id, -1);
|
|
shm2.openSharedMemory(true);
|
|
CHECK(shm2()->x == 5);
|
|
CHECK(shm.getName() == shm2.getName());
|
|
|
|
// Check that they still point to the same place
|
|
shm2()->x = 7;
|
|
CHECK(shm()->x == 7);
|
|
|
|
// Remove only needs to be done once since they refer
|
|
// to the same memory
|
|
shm2.removeSharedMemory();
|
|
CHECK(shm.exists() == false);
|
|
CHECK(shm2.exists() == false);
|
|
}
|
|
|
|
TEST_CASE("Move SharedMemory", "[detector][shm]") {
|
|
const char *env_p = std::getenv(SHM_ENV_NAME);
|
|
std::string env_name = env_p ? ("_" + std::string(env_p)) : "";
|
|
|
|
SharedMemory<Data> shm(shm_id, -1);
|
|
CHECK(shm.getName() ==
|
|
std::string(SHM_DETECTOR_PREFIX) + std::to_string(shm_id) + env_name);
|
|
shm.createSharedMemory();
|
|
shm()->x = 9;
|
|
|
|
SharedMemory<Data> shm2(shm_id + 1, -1);
|
|
shm2 = std::move(shm); // shm is now a moved from object!
|
|
|
|
CHECK(shm2()->x == 9);
|
|
REQUIRE_THROWS(
|
|
shm()); // trying to access should throw instead of returning a nullptr
|
|
CHECK(shm2.getName() ==
|
|
std::string(SHM_DETECTOR_PREFIX) + std::to_string(shm_id) + env_name);
|
|
shm2.removeSharedMemory();
|
|
}
|
|
|
|
TEST_CASE("Create several shared memories", "[detector][shm]") {
|
|
const char *env_p = std::getenv(SHM_ENV_NAME);
|
|
std::string env_name = env_p ? ("_" + std::string(env_p)) : "";
|
|
|
|
constexpr int N = 5;
|
|
std::vector<SharedMemory<Data>> v;
|
|
v.reserve(N);
|
|
for (int i = 0; i != N; ++i) {
|
|
v.emplace_back(shm_id + i, -1);
|
|
CHECK(v[i].exists() == false);
|
|
v[i].createSharedMemory();
|
|
v[i]()->x = i;
|
|
CHECK(v[i]()->x == i);
|
|
}
|
|
|
|
for (int i = 0; i != N; ++i) {
|
|
CHECK(v[i]()->x == i);
|
|
CHECK(v[i].getName() == std::string(SHM_DETECTOR_PREFIX) +
|
|
std::to_string(i + shm_id) + env_name);
|
|
}
|
|
|
|
for (int i = 0; i != N; ++i) {
|
|
v[i].removeSharedMemory();
|
|
CHECK(v[i].exists() == false);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("Create create a shared memory with a tag") {
|
|
const char *env_p = std::getenv(SHM_ENV_NAME);
|
|
std::string env_name = env_p ? ("_" + std::string(env_p)) : "";
|
|
|
|
SharedMemory<Data> shm(0, -1, "ctbdacs");
|
|
REQUIRE(shm.getName() ==
|
|
std::string(SHM_DETECTOR_PREFIX) + "0" + env_name + "_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<Data> shm(0, -1, "ctbdacs");
|
|
REQUIRE(shm.getName() ==
|
|
std::string(SHM_DETECTOR_PREFIX) + "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);
|
|
}
|
|
|
|
TEST_CASE("Access to already freed shm object", "[detector][shm]") {
|
|
SharedMemory<Data> shm(shm_id, -1);
|
|
shm.createSharedMemory();
|
|
shm()->x = 10;
|
|
|
|
freeShm(shm_id, -1);
|
|
CHECK(shm.exists() == false);
|
|
REQUIRE_THROWS(shm()); // trying to access should throw
|
|
}
|
|
|
|
} // namespace sls
|