mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-24 10:31:09 +02:00
new tests
This commit is contained in:
@ -110,6 +110,10 @@ set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
|
|||||||
find_package(Doxygen)
|
find_package(Doxygen)
|
||||||
find_package(ZeroMQ 4 REQUIRED)
|
find_package(ZeroMQ 4 REQUIRED)
|
||||||
|
|
||||||
|
if (SLS_USE_TESTS)
|
||||||
|
enable_testing()
|
||||||
|
add_subdirectory(tests)
|
||||||
|
endif(SLS_USE_TESTS)
|
||||||
|
|
||||||
# Support library containing functionallity common to
|
# Support library containing functionallity common to
|
||||||
# detector and receiver
|
# detector and receiver
|
||||||
@ -135,9 +139,7 @@ if (SLS_USE_GUI)
|
|||||||
endif()
|
endif()
|
||||||
endif (SLS_USE_GUI)
|
endif (SLS_USE_GUI)
|
||||||
|
|
||||||
if (SLS_USE_TESTS)
|
|
||||||
enable_testing()
|
|
||||||
endif(SLS_USE_TESTS)
|
|
||||||
|
|
||||||
if (SLS_USE_INTEGRATION_TESTS)
|
if (SLS_USE_INTEGRATION_TESTS)
|
||||||
add_subdirectory(integrationTests)
|
add_subdirectory(integrationTests)
|
||||||
|
@ -1,23 +1 @@
|
|||||||
|
target_sources(tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test-SharedMemory.cpp)
|
||||||
|
|
||||||
include_directories(
|
|
||||||
${PROJECT_SOURCE_DIR}/catch
|
|
||||||
)
|
|
||||||
|
|
||||||
set(SOURCES
|
|
||||||
test.cpp
|
|
||||||
test-SharedMemory.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(testSlsDetector ${SOURCES})
|
|
||||||
target_link_libraries(testSlsDetector
|
|
||||||
slsSupportLib
|
|
||||||
slsDetectorShared
|
|
||||||
pthread
|
|
||||||
rt
|
|
||||||
)
|
|
||||||
set_target_properties(testSlsDetector PROPERTIES
|
|
||||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
|
||||||
)
|
|
||||||
#TODO! Move to automatic test discovery
|
|
||||||
add_test(test-testSlsDetector ${CMAKE_BINARY_DIR}/bin/testSlsDetector)
|
|
@ -13,7 +13,7 @@ struct Data {
|
|||||||
|
|
||||||
using namespace sls;
|
using namespace sls;
|
||||||
|
|
||||||
TEST_CASE("Create SharedMemory read and write") {
|
TEST_CASE("Create SharedMemory read and write", "[detector]") {
|
||||||
|
|
||||||
SharedMemory<Data> shm(0, -1);
|
SharedMemory<Data> shm(0, -1);
|
||||||
shm.CreateSharedMemory();
|
shm.CreateSharedMemory();
|
||||||
@ -33,7 +33,7 @@ TEST_CASE("Create SharedMemory read and write") {
|
|||||||
CHECK(shm.IsExisting() == false);
|
CHECK(shm.IsExisting() == false);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Open existing SharedMemory and read") {
|
TEST_CASE("Open existing SharedMemory and read", "[detector]") {
|
||||||
|
|
||||||
{
|
{
|
||||||
SharedMemory<double> shm(0, -1);
|
SharedMemory<double> shm(0, -1);
|
||||||
@ -48,7 +48,8 @@ TEST_CASE("Open existing SharedMemory and read") {
|
|||||||
shm2.RemoveSharedMemory();
|
shm2.RemoveSharedMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Creating a second shared memory with the same name throws") {
|
TEST_CASE("Creating a second shared memory with the same name throws",
|
||||||
|
"[detector]") {
|
||||||
|
|
||||||
SharedMemory<double> shm0(0, -1);
|
SharedMemory<double> shm0(0, -1);
|
||||||
SharedMemory<double> shm1(0, -1);
|
SharedMemory<double> shm1(0, -1);
|
||||||
@ -58,7 +59,7 @@ TEST_CASE("Creating a second shared memory with the same name throws") {
|
|||||||
shm0.RemoveSharedMemory();
|
shm0.RemoveSharedMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Open two shared memories to the same place") {
|
TEST_CASE("Open two shared memories to the same place", "[detector]") {
|
||||||
|
|
||||||
//Create the first shared memory
|
//Create the first shared memory
|
||||||
SharedMemory<Data> shm(0, -1);
|
SharedMemory<Data> shm(0, -1);
|
||||||
@ -83,8 +84,7 @@ TEST_CASE("Open two shared memories to the same place") {
|
|||||||
CHECK(shm2.IsExisting() == false);
|
CHECK(shm2.IsExisting() == false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Move SharedMemory", "[detector]") {
|
||||||
TEST_CASE("Move SharedMemory"){
|
|
||||||
|
|
||||||
SharedMemory<Data> shm(0,-1);
|
SharedMemory<Data> shm(0,-1);
|
||||||
CHECK(shm.GetName() == "/slsDetectorPackage_multi_0");
|
CHECK(shm.GetName() == "/slsDetectorPackage_multi_0");
|
||||||
@ -105,8 +105,7 @@ TEST_CASE("Move SharedMemory"){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Create several shared memories", "[detector]") {
|
||||||
TEST_CASE("Create several shared memories") {
|
|
||||||
constexpr int N = 5;
|
constexpr int N = 5;
|
||||||
std::vector<SharedMemory<int>> v;
|
std::vector<SharedMemory<int>> v;
|
||||||
v.reserve(N);
|
v.reserve(N);
|
||||||
|
@ -81,7 +81,9 @@ if (HDF5_FOUND)
|
|||||||
target_link_libraries(slsReceiver PUBLIC ${HDF5_LIBRARIES})
|
target_link_libraries(slsReceiver PUBLIC ${HDF5_LIBRARIES})
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
if (SLS_USE_TESTS)
|
||||||
|
add_subdirectory(tests)
|
||||||
|
endif(SLS_USE_TESTS)
|
||||||
|
|
||||||
install(TARGETS slsReceiverShared
|
install(TARGETS slsReceiverShared
|
||||||
EXPORT "${TARGETS_EXPORT_NAME}"
|
EXPORT "${TARGETS_EXPORT_NAME}"
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
#include "sls_detector_defs.h"
|
#include "sls_detector_defs.h"
|
||||||
#include "receiver_defs.h"
|
#include "receiver_defs.h"
|
||||||
|
#include "logger.h"
|
||||||
#include <math.h> //ceil
|
#include <math.h> //ceil
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -633,32 +633,31 @@ class MoenchData : public GeneralData {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
/** Structure of an jungfrau ctb packet header (10G Udp) */
|
/** Structure of an jungfrau ctb packet header (10G Udp) */
|
||||||
typedef struct {
|
struct jfrauctb_packet_header {
|
||||||
unsigned char emptyHeader[6];
|
unsigned char emptyHeader[6];
|
||||||
unsigned char reserved[4];
|
unsigned char reserved[4];
|
||||||
unsigned char packetNumber[1];
|
uint32_t packetFrameNumber;
|
||||||
unsigned char frameNumber[3];
|
uint64_t bunchid;
|
||||||
unsigned char bunchid[8];
|
} __attribute__((packed));
|
||||||
} jfrauctb_packet_header_t;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/** Constructor */
|
||||||
/** Constructor */
|
MoenchData() {
|
||||||
MoenchData(){
|
myDetectorType = slsDetectorDefs::MOENCH;
|
||||||
myDetectorType = slsDetectorDefs::MOENCH;
|
nPixelsX = 32; // total number of channels
|
||||||
nPixelsX = 32; // total number of channels
|
nPixelsY = 1; // number of samples
|
||||||
nPixelsY = 1; // number of samples
|
headerSizeinPacket = sizeof(slsDetectorDefs::sls_detector_header);
|
||||||
headerSizeinPacket = sizeof(slsDetectorDefs::sls_detector_header);
|
dataSize = UDP_PACKET_DATA_BYTES;
|
||||||
dataSize = UDP_PACKET_DATA_BYTES;
|
packetSize = headerSizeinPacket + dataSize;
|
||||||
packetSize = headerSizeinPacket + dataSize;
|
// packetsPerFrame = 1;
|
||||||
//packetsPerFrame = 1;
|
imageSize = nPixelsX * nPixelsY * 2;
|
||||||
imageSize = nPixelsX * nPixelsY * 2;
|
packetsPerFrame = ceil((double)imageSize / (double)UDP_PACKET_DATA_BYTES);
|
||||||
packetsPerFrame = ceil((double)imageSize / (double)UDP_PACKET_DATA_BYTES);
|
frameIndexMask = 0xFFFFFF;
|
||||||
frameIndexMask = 0xFFFFFF;
|
maxFramesPerFile = CTB_MAX_FRAMES_PER_FILE;
|
||||||
maxFramesPerFile = CTB_MAX_FRAMES_PER_FILE;
|
fifoBufferHeaderSize =
|
||||||
fifoBufferHeaderSize= FIFO_HEADER_NUMBYTES + sizeof(slsDetectorDefs::sls_receiver_header);
|
FIFO_HEADER_NUMBYTES + sizeof(slsDetectorDefs::sls_receiver_header);
|
||||||
defaultFifoDepth = 2500;
|
defaultFifoDepth = 2500;
|
||||||
standardheader = true;
|
standardheader = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -674,10 +673,10 @@ private:
|
|||||||
void GetHeaderInfo(int index, char* packetData, uint32_t dynamicRange, bool oddStartingPacket,
|
void GetHeaderInfo(int index, char* packetData, uint32_t dynamicRange, bool oddStartingPacket,
|
||||||
uint64_t& frameNumber, uint32_t& packetNumber, uint32_t& subFrameNumber, uint64_t& bunchId) const {
|
uint64_t& frameNumber, uint32_t& packetNumber, uint32_t& subFrameNumber, uint64_t& bunchId) const {
|
||||||
subFrameNumber = -1;
|
subFrameNumber = -1;
|
||||||
jfrauctb_packet_header_t* header = (jfrauctb_packet_header_t*)(packetData);
|
jfrauctb_packet_header* header = (jfrauctb_packet_header*)(packetData);
|
||||||
frameNumber = (uint64_t)((*( (uint32_t*) header->frameNumber)) & frameIndexMask);
|
frameNumber = (header->packetFrameNumber >> 8) & frameIndexMask;
|
||||||
packetNumber = (uint32_t)(*( (uint8_t*) header->packetNumber));
|
packetNumber = header->packetFrameNumber & 0xFF;
|
||||||
bunchId = (*((uint64_t*) header->bunchid));
|
bunchId = header->bunchid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
24
slsReceiverSoftware/tests/CMakeLists.txt
Normal file
24
slsReceiverSoftware/tests/CMakeLists.txt
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# include_directories(
|
||||||
|
# ${PROJECT_SOURCE_DIR}/catch
|
||||||
|
# )
|
||||||
|
|
||||||
|
# set(SOURCES
|
||||||
|
# test.cpp
|
||||||
|
# test-GeneralData.cpp
|
||||||
|
# )
|
||||||
|
|
||||||
|
target_sources(tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test-GeneralData.cpp)
|
||||||
|
|
||||||
|
# add_executable(testSlsReceiver ${SOURCES})
|
||||||
|
# target_link_libraries(testSlsReceiver
|
||||||
|
# slsSupportLib
|
||||||
|
# slsDetectorShared
|
||||||
|
# slsReceiverShared
|
||||||
|
# pthread
|
||||||
|
# rt
|
||||||
|
# )
|
||||||
|
# set_target_properties(testSlsReceiver PROPERTIES
|
||||||
|
# RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
||||||
|
# )
|
||||||
|
# #TODO! Move to automatic test discovery
|
||||||
|
# add_test(test-testSlsReceiver ${CMAKE_BINARY_DIR}/bin/testSlsReceiver)
|
68
slsReceiverSoftware/tests/test-GeneralData.cpp
Normal file
68
slsReceiverSoftware/tests/test-GeneralData.cpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
|
||||||
|
#include "GeneralData.h"
|
||||||
|
#include "catch.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// using namespace sls;
|
||||||
|
|
||||||
|
TEST_CASE("Parse jungfrauctb header", "[receiver]") {
|
||||||
|
|
||||||
|
// typedef struct {
|
||||||
|
// unsigned char emptyHeader[6];
|
||||||
|
// unsigned char reserved[4];
|
||||||
|
// unsigned char packetNumber[1];
|
||||||
|
// unsigned char frameNumber[3];
|
||||||
|
// unsigned char bunchid[8];
|
||||||
|
// } jfrauctb_packet_header_t;
|
||||||
|
|
||||||
|
struct packet {
|
||||||
|
unsigned char emptyHeader[6];
|
||||||
|
unsigned char reserved[4];
|
||||||
|
unsigned char packetNumber[1];
|
||||||
|
unsigned char frameNumber[3];
|
||||||
|
unsigned char bunchid[8];
|
||||||
|
unsigned char data[1024];
|
||||||
|
};
|
||||||
|
|
||||||
|
MoenchData data;
|
||||||
|
// GetHeaderInfo(int index, char *packetData, uint32_t dynamicRange,
|
||||||
|
// bool oddStartingPacket, uint64_t &frameNumber,
|
||||||
|
// uint32_t &packetNumber, uint32_t &subFrameNumber,
|
||||||
|
// uint64_t &bunchId)
|
||||||
|
|
||||||
|
|
||||||
|
packet test_packet;
|
||||||
|
test_packet.packetNumber[0] = (unsigned char)53;
|
||||||
|
test_packet.frameNumber[0] = (unsigned char)32;
|
||||||
|
test_packet.frameNumber[1] = (unsigned char)15;
|
||||||
|
test_packet.frameNumber[2] = (unsigned char)91;
|
||||||
|
|
||||||
|
test_packet.bunchid[0] = (unsigned char)91;
|
||||||
|
test_packet.bunchid[1] = (unsigned char)25;
|
||||||
|
test_packet.bunchid[2] = (unsigned char)15;
|
||||||
|
test_packet.bunchid[3] = (unsigned char)1;
|
||||||
|
test_packet.bunchid[4] = (unsigned char)32;
|
||||||
|
test_packet.bunchid[5] = (unsigned char)251;
|
||||||
|
test_packet.bunchid[6] = (unsigned char)18;
|
||||||
|
test_packet.bunchid[7] = (unsigned char)240;
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
char *packetData = reinterpret_cast<char *>(&test_packet);
|
||||||
|
uint32_t dynamicRange{0};
|
||||||
|
bool oddStartingPacket{0};
|
||||||
|
uint64_t frameNumber{0};
|
||||||
|
uint32_t packetNumber{0};
|
||||||
|
uint32_t subFrameNumber{0};
|
||||||
|
uint64_t bunchId{0};
|
||||||
|
|
||||||
|
data.GetHeaderInfo(index, packetData, dynamicRange, oddStartingPacket,
|
||||||
|
frameNumber, packetNumber, subFrameNumber, bunchId);
|
||||||
|
|
||||||
|
CHECK(packetNumber == 53);
|
||||||
|
CHECK(frameNumber == 0x5b0f20);
|
||||||
|
CHECK(bunchId == 0xf012fb20010f195b);
|
||||||
|
}
|
@ -1,28 +1,8 @@
|
|||||||
|
target_sources(tests PRIVATE
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/test-ClientInterface.cpp
|
||||||
include_directories(
|
${CMAKE_CURRENT_SOURCE_DIR}/test-CmdLineParser.cpp
|
||||||
${PROJECT_SOURCE_DIR}/catch
|
${CMAKE_CURRENT_SOURCE_DIR}/test-container_utils.cpp
|
||||||
../include
|
${CMAKE_CURRENT_SOURCE_DIR}/test-network_utils.cpp
|
||||||
)
|
${CMAKE_CURRENT_SOURCE_DIR}/test-string_utils.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/test-Timer.cpp
|
||||||
set(SOURCES
|
)
|
||||||
test.cpp
|
|
||||||
test-ClientInterface.cpp
|
|
||||||
test-CmdLineParser.cpp
|
|
||||||
test-container_utils.cpp
|
|
||||||
test-network_utils.cpp
|
|
||||||
test-string_utils.cpp
|
|
||||||
test-Timer.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(testSlsSupportLib ${SOURCES})
|
|
||||||
target_link_libraries(testSlsSupportLib
|
|
||||||
slsSupportLib
|
|
||||||
pthread
|
|
||||||
rt
|
|
||||||
)
|
|
||||||
set_target_properties(testSlsSupportLib PROPERTIES
|
|
||||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
|
||||||
)
|
|
||||||
#TODO! Move to automatic test discovery
|
|
||||||
add_test(test-slsSupportLib ${CMAKE_BINARY_DIR}/bin/testSlsSupportLib)
|
|
23
tests/CMakeLists.txt
Normal file
23
tests/CMakeLists.txt
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
include_directories(
|
||||||
|
${PROJECT_SOURCE_DIR}/catch
|
||||||
|
)
|
||||||
|
|
||||||
|
set(SLS_TEST_SOURCES
|
||||||
|
test.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(tests ${SLS_TEST_SOURCES})
|
||||||
|
target_link_libraries(tests
|
||||||
|
slsProjectOptions
|
||||||
|
slsProjectWarnings
|
||||||
|
slsSupportLib
|
||||||
|
slsDetectorShared
|
||||||
|
slsReceiverShared
|
||||||
|
pthread
|
||||||
|
rt
|
||||||
|
)
|
||||||
|
set_target_properties(tests PROPERTIES
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
||||||
|
)
|
||||||
|
# #TODO! Move to automatic test discovery
|
||||||
|
# add_test(test ${CMAKE_BINARY_DIR}/bin/testSlsReceiver)
|
3
tests/test.cpp
Normal file
3
tests/test.cpp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
// tests-main.cpp
|
||||||
|
#define CATCH_CONFIG_MAIN
|
||||||
|
#include "catch.hpp"
|
Reference in New Issue
Block a user