Files
slsDetectorPackage/slsDetectorSoftware/tests/Caller/test-Caller-rx.cpp
AliceMazzoleni99 28b2aa9673
All checks were successful
Build on RHEL9 / build (push) Successful in 3m50s
Build on RHEL8 / build (push) Successful in 4m46s
Run Simulator Tests on local RHEL9 / build (push) Successful in 14m37s
Build on local RHEL9 / build (push) Successful in 1m26s
Run Simulator Tests on local RHEL8 / build (push) Successful in 16m57s
Build on local RHEL8 / build (push) Successful in 3m33s
Dev/add simulator tests in GitHub workflows (#1337)
* added simulator tests in github workflows

* indentation error

* typo

* debug

* Logging for debugging

* added more debug lines

* more debugging

* debug

* debug

* debug

* dont throw if process does not exist

* debug

* added absolute path to sls_detector commands

* some refactoring in test scripts

* added absolute path to all slsdet command

* typo

* ../tests/scripts/test_frame_synchronizer.py

* raise exception upon failure for github workflows

* removed hidden tags

* some refactoring in test scripts

* some refactoring

* fixed CMakeLists

* fixed unsuccesful merge

* updated python tests using simulators

* debug import error

* debug module import

* python -m runs module pytest as script - everything in path available

* removed integartion tests

* enable file write not to log files

* run tests without log files

* increased sleep time for udp packets

* added logg level variable to cmake

* added testing policies to documenattion

* disabled check for num_frames for jungfrau & xilinx

* set log level as cmake cached variable

* disable tests for jungfrau and xilinx_ctb

* check frames for HDF5

* updated Documentation of Testing

* changed withdetectorsimulators to detectorintegration

* replaced [.cmdcall] with [.detectorintegration]

* check_file_size only disabled for jungfrau - disable for all roi tests

* changed time to wait after receive to 5 ms

* take into account half modules of eiger

* num udp interfaces needs to be consistent across modules

* suppressed warning enclosing if

* config added 2 udp ports per default for moench and jungfrau

* write detector output to console

* allow jungfrau to tests num frames, remove unused variable (numinterfaces), add comment for future to handle traceback to know which calling function threw the files unmatched, added documentation for tests (examples for .detectoritnegration and how to disable marked tests, removed addditional argumetns to disable for test_simulator as one can just use ~, removed the check that checks for jungfrau checking number of frames at master attributes and at rx test, removed unused advanced_test_settings in test_simulator script, the num_mods check for multiple modules is removed and default num  modules set to 1 for test_simulator (to be increased later), back to raising exception for killprocess

* removed integration tests from cmakelists.txt and cmk.sh, modified the tests workflow command to reflect the disable argument and removed xilinx_ctb from test (fix fromdeveloper merge to be done)

* filtering by actual name for disable certain tests on github workflow

* minor refactor

* wip

* wip

* changes to run on local rh9 runner instead of github workfloa

* modified yml to remove some leftover from github workflow

* test

* fix build_dir in scripts (github workflow) and pytest dir in gitea workflow

* making the local machine use python3.13 binary

* pythonpath added

* changes for build_Dir back

* allowing ctb api tests

* allowed ctb api tests and set up slsdetname envt variable for shared memory being reserved just for these tests

* added rh8 workflow for local runner on gitea

* remnants from rh9 local runner

* remnants from rh9 local runner

* conda env for all shell for local runner

* allowing hdf5 to build on local runner

* run all tests for both the runners

* refactored fixtures a bit and merged some tests that use one session for entire server

* test fail

* test fix

* adding github workflow to test without data file checks and without logs

* documentation changes

* unnecessary import in conftest

* allowing the session_simulator to test for multiple modules and interfaces etc

* allow test_simulator script to run for 2 modules for all modules except ctb and xilinx ctb

* run upon push

* removing the disable file check on github workflow

* minor adjustment

* testing without synch

* reverting to previous

* with log file

* without the space

* summary from file and more error extracts from file to terminal

* minor

* trying nlf for more details

* updated with no log file to print everything to screen  also for det and rxr

* trying a no throw

* stoi was more about indent in yaml

* tries

* wip

* debug

* number of frames inconsistent fix=>just take first one, only test xilinx

* jungfrau tests without frames caught check

* extend the disable file check to everywhere that creates files

* specify path for test_simulator

* withoutprinting ==

* wip

* back with printing===, but not parsing file for errors anymore

* lang?

* wip

* safe log?

* wip2

* wip

* dont split error as its streaming live, just raise

* with log files

* lang?

* last resort

* wip

* test no det with general tests

* show tests live

* also include hidden integration tests

* without extra summary?

* revert

* last resort again

* tsquash on int64_t?

* tsquash on int64_t? mroe print

* writing to /tmp?

* all tests

* might be the fix?

* write to file

* fixed a few quiet mode no log file tests

* work on any branch for github tests, work on also release candidates for gitea tests

* added frame synchronizer tests to github workflow

* moved tests to run_tests.yaml from cmake.yaml

* documentation

* disabled general tests

---------

Co-authored-by: Dhanya Thattil <dhanya.thattil@psi.ch>
2026-02-03 11:45:12 +01:00

1311 lines
45 KiB
C++

// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include "Caller.h"
#include "catch.hpp"
#include "sls/Detector.h"
#include "sls/Version.h"
#include "sls/sls_detector_defs.h"
#include "test-Caller-global.h"
#include <filesystem>
#include <sstream>
#include "sls/versionAPI.h"
#include "tests/globals.h"
namespace sls {
using test::GET;
using test::PUT;
/*
This file should contain receiver specific tests use
python/scripts/list_tested_cmd.py to check if all commands are covered
*/
/* configuration */
TEST_CASE("rx_version", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
std::ostringstream oss;
caller.call("rx_version", {}, -1, GET, oss);
sls::Version v(APIRECEIVER);
std::ostringstream vs;
vs << "rx_version " << v.concise() << '\n';
REQUIRE(oss.str() == vs.str());
REQUIRE_THROWS(caller.call("rx_version", {"0"}, -1, PUT));
}
/* acquisition */
TEST_CASE("rx_start", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
det.setFileWrite(false); // avoid writing or error on file creation
// PUT only command
REQUIRE_THROWS(caller.call("rx_start", {}, -1, GET));
{
std::ostringstream oss;
caller.call("rx_start", {}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_start successful\n");
}
{
std::ostringstream oss;
caller.call("rx_status", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_status running\n");
}
}
TEST_CASE("rx_stop", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
// PUT only command
REQUIRE_THROWS(caller.call("rx_stop", {}, -1, GET));
{
std::ostringstream oss;
caller.call("rx_stop", {}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_stop successful\n");
}
{
std::ostringstream oss;
caller.call("rx_status", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_status idle\n");
}
}
TEST_CASE("rx_status", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
det.setFileWrite(false); // avoid writing or error on file creation
det.startReceiver();
{
std::ostringstream oss;
caller.call("rx_status", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_status running\n");
}
det.stopReceiver();
{
std::ostringstream oss;
caller.call("rx_status", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_status idle\n");
}
}
TEST_CASE("rx_framescaught", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
// This ensures 0 caught frames
auto prev_val = det.getFileWrite();
det.setFileWrite(false); // avoid writing or error on file creation
det.startReceiver();
det.stopReceiver();
{
std::ostringstream oss;
caller.call("rx_framescaught", {}, -1, GET, oss);
if (det.getNumberofUDPInterfaces().tsquash(
"inconsistent number of interfaces") == 1) {
REQUIRE(oss.str() == "rx_framescaught [0]\n");
} else {
REQUIRE(oss.str() == "rx_framescaught [0, 0]\n");
}
}
// Currently disabled may activate if we have a stable env
// Now take one frame and see that we caught it
// det.setNumberOfFrames(1);
// det.acquire();
// {
// std::ostringstream oss;
// caller.call("rx_framescaught", {}, -1, GET, oss);
// REQUIRE(oss.str() == "rx_framescaught 1\n");
// }
for (int i = 0; i != det.size(); ++i) {
det.setFileWrite(prev_val[i], {i});
}
}
TEST_CASE("rx_missingpackets", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
auto prev_val = det.getFileWrite();
det.setFileWrite(false); // avoid writing or error on file creation
auto prev_frames =
det.getNumberOfFrames().tsquash("inconsistent #frames in test");
det.setNumberOfFrames(100);
{
// some missing packets
det.startReceiver();
det.stopReceiver();
std::ostringstream oss;
caller.call("rx_missingpackets", {}, -1, GET, oss);
if (det.getNumberofUDPInterfaces().tsquash(
"inconsistent number of interfaces") == 1) {
REQUIRE(oss.str() != "rx_missingpackets [0]\n");
} else {
REQUIRE(oss.str() != "rx_missingpackets [0, 0]\n");
}
}
auto det_type = det.getDetectorType().squash();
if (det_type != defs::CHIPTESTBOARD &&
det_type != defs::XILINX_CHIPTESTBOARD) {
// 0 missing packets (takes into account that acquisition is
// stopped)
det.startReceiver();
det.startDetector();
det.stopDetector();
det.stopReceiver();
std::ostringstream oss;
caller.call("rx_missingpackets", {}, -1, GET, oss);
if (det.getNumberofUDPInterfaces().tsquash(
"inconsistent number of interfaces") == 1) {
REQUIRE(oss.str() == "rx_missingpackets [0]\n");
} else {
REQUIRE(oss.str() == "rx_missingpackets [0, 0]\n");
}
}
for (int i = 0; i != det.size(); ++i) {
det.setFileWrite(prev_val[i], {i});
}
det.setNumberOfFrames(prev_frames);
}
TEST_CASE("rx_frameindex", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
caller.call("rx_frameindex", {}, -1, GET);
// This is a get only command
REQUIRE_THROWS(caller.call("rx_frameindex", {"2"}, -1, PUT));
}
/* Network Configuration (Detector<->Receiver) */
TEST_CASE("rx_printconfig", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
REQUIRE_NOTHROW(caller.call("rx_printconfig", {}, -1, GET));
}
/* Receiver Config */
TEST_CASE("rx_hostname", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
auto prev_val = det.getRxHostname();
// Cannot set rx_hostname (will reset parameters in rxr and no shm
// variables to update)
// {
// // disable receiver
// std::ostringstream oss;
// caller.call("rx_hostname", {"none"}, -1, PUT, oss);
// REQUIRE(oss.str() == "rx_hostname [none]\n");
// }
// {
// std::ostringstream oss;
// caller.call("rx_hostname", {}, -1, GET, oss);
// REQUIRE(oss.str() == "rx_hostname none\n");
// // receiver should be disabled
// REQUIRE(det.getUseReceiverFlag().tsquash(
// "different values of flag in test") == false);
// }
// put back old values (not necessary when we dont set it to none)
// for (int i = 0; i != det.size(); ++i) {
// det.setRxHostname(prev_val[i], {i});
// }
{
std::ostringstream oss;
caller.call("rx_hostname", {}, 0, GET, oss);
REQUIRE(oss.str() == "rx_hostname " + prev_val[0] + "\n");
}
}
TEST_CASE("rx_tcpport", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
auto prev_val = det.getRxPort();
uint16_t port = 3500;
caller.call("rx_tcpport", {std::to_string(port)}, -1, PUT);
for (int i = 0; i != det.size(); ++i) {
std::ostringstream oss;
caller.call("rx_tcpport", {}, i, GET, oss);
REQUIRE(oss.str() == "rx_tcpport " + std::to_string(port + i) + '\n');
}
port = 5754;
caller.call("rx_tcpport", {std::to_string(port)}, -1, PUT);
for (int i = 0; i != det.size(); ++i) {
std::ostringstream oss;
caller.call("rx_tcpport", {}, i, GET, oss);
REQUIRE(oss.str() == "rx_tcpport " + std::to_string(port + i) + '\n');
}
test_valid_port_caller("rx_tcpport", {}, -1, PUT);
test_valid_port_caller("rx_tcpport", {}, 0, PUT);
// should fail for the second module
if (det.size() > 1) {
REQUIRE_THROWS(caller.call("rx_tcpport", {"65535"}, -1, PUT));
auto rxHostname = det.getRxHostname().squash("none");
if (rxHostname != "none") {
std::ostringstream oss;
for (int i = 0; i != det.size(); ++i) {
oss << rxHostname << ":" << 65536 + i << "+";
}
REQUIRE_THROWS(caller.call("rx_hostname", {oss.str()}, -1, PUT));
}
}
for (int i = 0; i != det.size(); ++i) {
det.setRxPort(prev_val[i], i);
}
}
TEST_CASE("rx_fifodepth", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
auto prev_val = det.getRxFifoDepth();
{
std::ostringstream oss;
caller.call("rx_fifodepth", {"10"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_fifodepth 10\n");
}
{
std::ostringstream oss;
caller.call("rx_fifodepth", {"100"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_fifodepth 100\n");
}
{
std::ostringstream oss;
caller.call("rx_fifodepth", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_fifodepth 100\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setRxFifoDepth(prev_val[i], {i});
}
}
TEST_CASE("rx_silent", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
auto prev_val = det.getRxSilentMode();
{
std::ostringstream oss;
caller.call("rx_silent", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_silent 1\n");
}
{
std::ostringstream oss;
caller.call("rx_silent", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_silent 1\n");
}
{
std::ostringstream oss;
caller.call("rx_silent", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_silent 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setRxSilentMode(prev_val[i], {i});
}
}
TEST_CASE("rx_discardpolicy", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
auto prev_val = det.getRxFrameDiscardPolicy();
{
std::ostringstream oss;
caller.call("rx_discardpolicy", {"discardempty"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_discardpolicy discardempty\n");
}
{
std::ostringstream oss;
caller.call("rx_discardpolicy", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_discardpolicy discardempty\n");
}
{
std::ostringstream oss;
caller.call("rx_discardpolicy", {"discardpartial"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_discardpolicy discardpartial\n");
}
{
std::ostringstream oss;
caller.call("rx_discardpolicy", {"nodiscard"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_discardpolicy nodiscard\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setRxFrameDiscardPolicy(prev_val[i], {i});
}
}
TEST_CASE("rx_padding", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
auto prev_val = det.getPartialFramesPadding();
{
std::ostringstream oss;
caller.call("rx_padding", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_padding 0\n");
}
{
std::ostringstream oss;
caller.call("rx_padding", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_padding 0\n");
}
{
std::ostringstream oss;
caller.call("rx_padding", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_padding 1\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setPartialFramesPadding(prev_val[i], {i});
}
}
TEST_CASE("rx_udpsocksize", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
int64_t prev_val = det.getRxUDPSocketBufferSize().tsquash(
"Need same udp socket buffer size to test");
std::string s_new_val = std::to_string(prev_val);
/*std::string s_new_val = std::to_string(prev_val - 1000);
{ Need permissions
std::ostringstream oss;
caller.call("rx_udpsocksize", {s_new_val}, -1, PUT, oss);
REQUIRE(oss.str() >= "rx_udpsocksize " + s_new_val + "\n");
}*/
{
std::ostringstream oss;
caller.call("rx_udpsocksize", {}, -1, GET, oss);
REQUIRE(oss.str() >= "rx_udpsocksize " + s_new_val + "\n");
}
det.setRxUDPSocketBufferSize(prev_val);
}
TEST_CASE("rx_realudpsocksize", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
uint64_t val = 0;
{
std::ostringstream oss;
caller.call("rx_udpsocksize", {}, -1, GET, oss);
std::string s = (oss.str()).erase(0, strlen("rx_udpsocksize "));
val = std::stol(s);
}
{
std::ostringstream oss;
caller.call("rx_realudpsocksize", {}, -1, GET, oss);
std::string s = (oss.str()).erase(0, strlen("rx_realudpsocksize "));
uint64_t rval = std::stol(s);
REQUIRE(rval >= val * 2);
}
}
TEST_CASE("rx_lock", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
auto prev_val = det.getRxLock();
{
std::ostringstream oss;
caller.call("rx_lock", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_lock 1\n");
}
{
std::ostringstream oss;
caller.call("rx_lock", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_lock 1\n");
}
{
std::ostringstream oss;
caller.call("rx_lock", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_lock 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setRxLock(prev_val[i], {i});
}
}
TEST_CASE("rx_lastclient", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
std::ostringstream oss;
REQUIRE_NOTHROW(caller.call("rx_lastclient", {}, -1, GET, oss));
if (test::my_ip != "undefined") {
REQUIRE(oss.str() == "rx_lastclient " + test::my_ip + "\n");
}
}
TEST_CASE("rx_threads", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
std::ostringstream oss;
REQUIRE_NOTHROW(caller.call("rx_threads", {}, -1, GET, oss));
}
TEST_CASE("rx_arping", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
auto prev_val = det.getRxArping();
if (det.getDestinationUDPIP()[0].str() != "127.0.0.1") {
{
std::ostringstream oss;
caller.call("rx_arping", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_arping 1\n");
}
{
std::ostringstream oss;
caller.call("rx_arping", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_arping 1\n");
}
{
std::ostringstream oss;
caller.call("rx_arping", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_arping 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setRxArping(prev_val[i], {i});
}
}
}
TEST_CASE("rx_roi", "[.detectorintegration][.disable_check_data_file]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD ||
det_type == defs::XILINX_CHIPTESTBOARD) {
REQUIRE_THROWS(caller.call("rx_roi", {"5", "10"}, -1, PUT));
} else {
auto prev_val = det.getRxROI();
defs::xy detsize = det.getDetectorSize();
auto portSize = det.getPortSize()[0];
int delta = 50;
int numinterfaces = det.getNumberofUDPInterfaces().tsquash(
"inconsistent number of interfaces");
// 1d
if (det_type == defs::GOTTHARD2 || det_type == defs::MYTHEN3) {
{
std::ostringstream oss;
caller.call("rx_roi", {"5", "10"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_roi [[5, 10]]\n");
}
{
std::ostringstream oss;
caller.call("rx_roi", {"10", "15"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_roi [[10, 15]]\n");
}
REQUIRE_THROWS(caller.call("rx_roi", {"0", "0"}, -1, PUT));
REQUIRE_THROWS(caller.call("rx_roi", {"-1", "-1"}, -1, PUT));
// xmin > xmax
REQUIRE_THROWS(caller.call("rx_roi", {"[12, 8, -1, -1]"}, -1, PUT));
// outside detector bounds
REQUIRE_THROWS(caller.call(
"rx_roi",
{"[95," + std::to_string(detsize.x + 5) + ", -1, -1]"}, -1,
PUT));
// module level not allowed
REQUIRE_THROWS(caller.call("rx_roi", {"[5, 10, -1, -1]"}, 0, PUT));
// vector of rois
// square brackets missing
REQUIRE_THROWS(caller.call(
"rx_roi", {"[5, 20, -1, -1]; 25, 30, -1, -1]"}, -1, PUT));
REQUIRE_THROWS(caller.call(
"rx_roi", {"[5, 20, -1, -1]; [25, 30, -1, -1"}, -1, PUT));
// invalid roi, 4 parts expected
REQUIRE_THROWS(caller.call(
"rx_roi", {"[5, 20, -1] [25, 30, -1, -1]"}, -1, PUT));
// overlapping rois
REQUIRE_THROWS(caller.call(
"rx_roi", {"[0, 10,-1, -1] [5, 15, -1, -1]"}, -1, PUT));
if (det.size() == 2) {
auto moduleSize = det.getModuleSize()[0];
std::string stringMin = std::to_string(moduleSize.x);
std::string stringMax = std::to_string(moduleSize.x + 1);
// separated by space is allowed
REQUIRE_NOTHROW(caller.call(
"rx_roi",
{"[5, 10, -1, -1]",
"[" + stringMin + ", " + stringMax + ", -1, -1]"},
-1, PUT));
std::ostringstream oss;
// separated by semicolon with quotes is allowed (skips
// cmdParser)
REQUIRE_NOTHROW(caller.call("rx_roi",
{"[5, 10, -1, -1];[" + stringMin +
", " + stringMax + ", -1, -1]"},
-1, PUT, oss));
REQUIRE(oss.str() == "rx_roi [[5, 10], [" + stringMin + ", " +
stringMax + "]]\n");
// verify individual roi
{
stringMin = std::to_string(moduleSize.x - 50);
stringMax = std::to_string(moduleSize.x + 50);
std::ostringstream oss, oss1;
REQUIRE_NOTHROW(caller.call(
"rx_roi", {"[" + stringMin + ", " + stringMax + "]"},
-1, PUT, oss));
REQUIRE(oss.str() == "rx_roi [[" + stringMin + ", " +
stringMax + "]]\n");
REQUIRE_NOTHROW(caller.call("rx_roi", {}, 0, GET, oss1));
REQUIRE(oss1.str() == "rx_roi [[" + stringMin + ", " +
std::to_string(moduleSize.x - 1) +
"]]\n");
}
}
// valid roi before acquiring
else {
std::ostringstream oss;
caller.call("rx_roi", {"10", "15"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_roi [[10, 15]]\n");
}
}
// 2d eiger, jungfrau, moench
else {
{
std::ostringstream oss;
caller.call("rx_roi", {"10", "15", "1", "5"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_roi [[10, 15, 1, 5]]\n");
}
{
std::ostringstream oss;
caller.call("rx_roi", {"10", "22", "18", "19"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_roi [[10, 22, 18, 19]]\n");
}
{
std::ostringstream oss;
caller.call("rx_roi",
{"1", std::to_string(detsize.x - 5), "1",
std::to_string(detsize.y - 5)},
-1, PUT, oss);
REQUIRE(oss.str() == std::string("rx_roi [[1, ") +
std::to_string(detsize.x - 5) +
std::string(", 1, ") +
std::to_string(detsize.y - 5) +
std::string("]]\n"));
}
REQUIRE_THROWS(
caller.call("rx_roi", {"0", "0", "0", "0"}, -1, PUT));
REQUIRE_THROWS(
caller.call("rx_roi", {"-1", "-1", "-1", "-1"}, -1, PUT));
// xmin > xmax
REQUIRE_THROWS(caller.call("rx_roi", {"[12, 8, 0, 10]"}, -1, PUT));
// ymin > ymax
REQUIRE_THROWS(caller.call("rx_roi", {"[0, 10, 20, 5]"}, -1, PUT));
// outside detector bounds
REQUIRE_THROWS(caller.call(
"rx_roi", {"[95," + std::to_string(detsize.x + 5) + ", 0, 10]"},
-1, PUT));
REQUIRE_THROWS(caller.call(
"rx_roi",
{"[95, 100, 0, " + std::to_string(detsize.y + 5) + "]"}, -1,
PUT));
// module level not allowed
REQUIRE_THROWS(caller.call("rx_roi", {"[5, 10, 20, 30]"}, 0, PUT));
// vector of rois
// square brackets missing
REQUIRE_THROWS(caller.call(
"rx_roi", {"[5, 20, 20, 30]; 25, 30, 14, 15]"}, -1, PUT));
REQUIRE_THROWS(caller.call(
"rx_roi", {"[5, 20, 20, 30]; [25, 30, 14, 15"}, -1, PUT));
// invalid roi, 4 parts expected
REQUIRE_THROWS(caller.call(
"rx_roi", {"[5, 20, 20] [25, 30, 14, 15]"}, -1, PUT));
// overlapping rois
REQUIRE_THROWS(caller.call(
"rx_roi", {"[0, 10, 0, 10] [5, 15, 0, 10]"}, -1, PUT));
REQUIRE_THROWS(caller.call(
"rx_roi", {"[0, 10, 0, 10] [0, 10, 9, 11]"}, -1, PUT));
// multiple ports horizontally
if (det_type == defs::EIGER ||
(det.size() == 2 && det.getModuleGeometry().x > 1)) {
std::string stringMin = std::to_string(portSize.x);
std::string stringMax = std::to_string(portSize.x + 1);
// separated by space is allowed
REQUIRE_NOTHROW(caller.call(
"rx_roi",
{"[5, 10, 20, 30]",
"[" + stringMin + ", " + stringMax + ", 20, 30]"},
-1, PUT));
std::ostringstream oss;
// separated by semicolon with quotes is allowed (skips
// cmdParser)
REQUIRE_NOTHROW(caller.call("rx_roi",
{"[5, 10, 20, 30];[" + stringMin +
", " + stringMax + ", 20, 30]"},
-1, PUT, oss));
REQUIRE(oss.str() == "rx_roi [[5, 10, 20, 30], [" + stringMin +
", " + stringMax + ", 20, 30]]\n");
// verify individual roi
{
stringMin = std::to_string(portSize.x - delta);
stringMax = std::to_string(portSize.x + delta);
std::ostringstream oss, oss1;
REQUIRE_NOTHROW(caller.call(
"rx_roi",
{"[" + stringMin + ", " + stringMax + ", 20, 30]"}, -1,
PUT, oss));
REQUIRE(oss.str() == "rx_roi [[" + stringMin + ", " +
stringMax + ", 20, 30]]\n");
REQUIRE_NOTHROW(caller.call("rx_roi", {}, 0, GET, oss1));
// eiger returns 2 values for 2 ports per module
if (det_type == defs::EIGER) {
REQUIRE(oss1.str() ==
"rx_roi [[" + stringMin + ", " +
std::to_string(portSize.x - 1) +
", 20, 30], [0, " + std::to_string(delta) +
", 20, 30]]\n");
}
// others return only 1 roi per module (1 port per module)
else {
REQUIRE(oss1.str() ==
"rx_roi [[" + stringMin + ", " +
std::to_string(portSize.x - 1) +
", 20, 30]]\n");
}
}
}
// valid roi before acquiring
else {
std::ostringstream oss;
caller.call("rx_roi",
{"1", std::to_string(detsize.x - 5), "1",
std::to_string(detsize.y - 5)},
-1, PUT, oss);
REQUIRE(oss.str() == std::string("rx_roi [[1, ") +
std::to_string(detsize.x - 5) +
std::string(", 1, ") +
std::to_string(detsize.y - 5) +
std::string("]]\n"));
}
// multiple ports vertically
if (((det_type == defs::JUNGFRAU || det_type == defs::MOENCH) &&
(numinterfaces == 2)) ||
(det.size() == 2 && det.getModuleGeometry().y > 1)) {
std::string stringMin = std::to_string(portSize.y);
std::string stringMax = std::to_string(portSize.y + 1);
// separated by space is allowed
REQUIRE_NOTHROW(
caller.call("rx_roi",
{"[5, 10, 20, 30]", "[25, 28, " + stringMin +
", " + stringMax + "]"},
-1, PUT));
std::ostringstream oss;
// separated by semicolon is allowed with quotes (skips
// cmdParser)
REQUIRE_NOTHROW(
caller.call("rx_roi",
{"[5, 10, 20, 30];[25, 28, " + stringMin +
", " + stringMax + "]"},
-1, PUT, oss));
REQUIRE(oss.str() == "rx_roi [[5, 10, 20, 30], [25, 28, " +
stringMin + ", " + stringMax + "]]\n");
// verify individual roi
{
stringMin = std::to_string(portSize.y - delta);
stringMax = std::to_string(portSize.y + delta);
std::ostringstream oss, oss1;
REQUIRE_NOTHROW(caller.call(
"rx_roi",
{"[ 20, 30, " + stringMin + ", " + stringMax + "]"}, -1,
PUT, oss));
REQUIRE(oss.str() == "rx_roi [[20, 30, " + stringMin +
", " + stringMax + "]]\n");
REQUIRE_NOTHROW(caller.call("rx_roi", {}, 0, GET, oss1));
// non-eiger with 2 interfaces returns 2 values for 2 ports
// per module
if ((det_type == defs::JUNGFRAU ||
det_type == defs::MOENCH) &&
(numinterfaces == 2)) {
REQUIRE(oss1.str() ==
"rx_roi [[20, 30, " + stringMin + ", " +
std::to_string(portSize.y - 1) +
"], [20, 30, 0, " + std::to_string(delta) +
"]]\n");
}
// others return only 1 roi per module (1 port per module)
else {
// (eiger 2 ports)
if (det_type == defs::EIGER) {
REQUIRE(oss1.str() ==
"rx_roi [[20, 30, " + stringMin + ", " +
std::to_string(portSize.y - 1) +
"], [-1, -1]]\n");
} else {
REQUIRE(oss1.str() ==
"rx_roi [[20, 30, " + stringMin + ", " +
std::to_string(portSize.y - 1) +
"]]\n");
}
}
}
}
}
// check master file creation
// TODO: check roi in master file
{
REQUIRE_NOTHROW(create_files_for_acquire(det, caller));
testFileInfo file_info;
std::string master_file_prefix =
file_info.getMasterFileNamePrefix();
std::string fname = master_file_prefix + ".json";
REQUIRE(std::filesystem::exists(fname) == true);
#ifdef HDF5C
fname = master_file_prefix + ".h5";
REQUIRE(std::filesystem::exists(fname) == true);
if (det.size() > 1 || numinterfaces > 1) {
fname = file_info.getVirtualFileName();
REQUIRE(std::filesystem::exists(fname) == true);
}
#endif
}
for (int i = 0; i != det.size(); ++i) {
if (prev_val.size() == 1 && prev_val[0].completeRoi()) {
det.clearRxROI();
} else
det.setRxROI(prev_val);
}
}
}
TEST_CASE("rx_clearroi", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD ||
det_type == defs::XILINX_CHIPTESTBOARD) {
REQUIRE_THROWS(caller.call("rx_clearroi", {}, -1, PUT));
} else {
auto prev_val = det.getRxROI();
{
std::ostringstream oss;
caller.call("rx_clearroi", {}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_clearroi successful\n");
}
for (int i = 0; i != det.size(); ++i) {
if (prev_val.size() == 1 && prev_val[0].completeRoi()) {
det.clearRxROI();
} else {
det.setRxROI(prev_val);
}
}
}
}
/* File */
TEST_CASE("fformat", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto prev_val = det.getFileFormat();
{
std::ostringstream oss;
caller.call("fformat", {"binary"}, -1, PUT, oss);
REQUIRE(oss.str() == "fformat binary\n");
}
{
std::ostringstream oss;
caller.call("fformat", {}, -1, GET, oss);
REQUIRE(oss.str() == "fformat binary\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setFileFormat(prev_val[i], {i});
}
}
TEST_CASE("fpath", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto prev_val = det.getFilePath();
{
std::ostringstream oss;
caller.call("fpath", {"/tmp"}, -1, PUT, oss);
REQUIRE(oss.str() == "fpath /tmp\n");
}
{
std::ostringstream oss;
caller.call("fpath", {}, -1, GET, oss);
REQUIRE(oss.str() == "fpath /tmp\n");
}
for (int i = 0; i != det.size(); ++i) {
if (prev_val[i].empty()) {
continue;
}
det.setFilePath(prev_val[i], {i});
}
}
TEST_CASE("fname", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto prev_val = det.getFileNamePrefix();
{
std::ostringstream oss;
caller.call("fname", {"somename"}, -1, PUT, oss);
REQUIRE(oss.str() == "fname somename\n");
}
{
std::ostringstream oss;
caller.call("fname", {}, -1, GET, oss);
REQUIRE(oss.str() == "fname somename\n");
}
{
std::ostringstream oss;
caller.call("fname", {"run"}, -1, PUT, oss);
REQUIRE(oss.str() == "fname run\n");
}
REQUIRE_THROWS(caller.call("fname", {"fdf/dfd"}, -1, PUT));
REQUIRE_THROWS(caller.call("fname", {"fdf dfd"}, -1, PUT));
for (int i = 0; i != det.size(); ++i) {
det.setFileNamePrefix(prev_val[i], {i});
}
}
TEST_CASE("findex", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto prev_val = det.getAcquisitionIndex();
{
std::ostringstream oss;
caller.call("findex", {"57"}, -1, PUT, oss);
REQUIRE(oss.str() == "findex 57\n");
}
{
std::ostringstream oss;
caller.call("findex", {}, -1, GET, oss);
REQUIRE(oss.str() == "findex 57\n");
}
{
std::ostringstream oss;
caller.call("findex", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "findex 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setAcquisitionIndex(prev_val[i], {i});
}
}
TEST_CASE("fwrite", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto prev_val = det.getFileWrite();
{
std::ostringstream oss;
caller.call("fwrite", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "fwrite 1\n");
}
{
std::ostringstream oss;
caller.call("fwrite", {}, -1, GET, oss);
REQUIRE(oss.str() == "fwrite 1\n");
}
{
std::ostringstream oss;
caller.call("fwrite", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "fwrite 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setFileWrite(prev_val[i], {i});
}
}
TEST_CASE("fmaster", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto prev_val = det.getMasterFileWrite();
{
std::ostringstream oss;
caller.call("fmaster", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "fmaster 0\n");
}
{
std::ostringstream oss;
caller.call("fmaster", {}, -1, GET, oss);
REQUIRE(oss.str() == "fmaster 0\n");
}
{
std::ostringstream oss;
caller.call("fmaster", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "fmaster 1\n");
}
det.setMasterFileWrite(prev_val);
}
TEST_CASE("foverwrite", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto prev_val = det.getFileOverWrite();
{
std::ostringstream oss;
caller.call("foverwrite", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "foverwrite 1\n");
}
{
std::ostringstream oss;
caller.call("foverwrite", {}, -1, GET, oss);
REQUIRE(oss.str() == "foverwrite 1\n");
}
{
std::ostringstream oss;
caller.call("foverwrite", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "foverwrite 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setFileOverWrite(prev_val[i], {i});
}
}
TEST_CASE("rx_framesperfile", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
auto prev_val = det.getFramesPerFile();
{
std::ostringstream oss;
caller.call("rx_framesperfile", {"50"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_framesperfile 50\n");
}
{
std::ostringstream oss;
caller.call("rx_framesperfile", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_framesperfile 50\n");
}
{
std::ostringstream oss;
caller.call("rx_framesperfile", {"10000"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_framesperfile 10000\n");
}
{
std::ostringstream oss;
caller.call("rx_framesperfile", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_framesperfile 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setFramesPerFile(prev_val[i], {i});
}
}
/* ZMQ Streaming Parameters (Receiver<->Client) */
TEST_CASE("rx_zmqstream", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
auto prev_val = det.getRxZmqDataStream();
{
std::ostringstream oss;
caller.call("rx_zmqstream", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_zmqstream 1\n");
REQUIRE(det.getRxZmqDataStream().squash() == true);
}
{
std::ostringstream oss;
caller.call("rx_zmqstream", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_zmqstream 1\n");
}
{
std::ostringstream oss;
caller.call("rx_zmqstream", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_zmqstream 0\n");
REQUIRE(det.getRxZmqDataStream().squash() == false);
}
for (int i = 0; i != det.size(); ++i) {
det.setRxZmqDataStream(prev_val[i], {i});
}
}
TEST_CASE("rx_zmqfreq", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
auto prev_val = det.getRxZmqFrequency();
{
std::ostringstream oss;
caller.call("rx_zmqfreq", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_zmqfreq 1\n");
}
{
std::ostringstream oss;
caller.call("rx_zmqfreq", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_zmqfreq 1\n");
}
{
std::ostringstream oss;
caller.call("rx_zmqfreq", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_zmqfreq 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setRxZmqFrequency(prev_val[i], {i});
}
}
TEST_CASE("rx_zmqstartfnum", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
auto prev_val = det.getRxZmqStartingFrame();
{
std::ostringstream oss;
caller.call("rx_zmqstartfnum", {"5"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_zmqstartfnum 5\n");
}
{
std::ostringstream oss;
caller.call("rx_zmqstartfnum", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_zmqstartfnum 5\n");
}
{
std::ostringstream oss;
caller.call("rx_zmqstartfnum", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_zmqstartfnum 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setRxZmqStartingFrame(prev_val[i], {i});
}
}
TEST_CASE("rx_zmqport", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
auto prev_val_zmqport = det.getRxZmqPort();
auto prev_val_numinterfaces = det.getNumberofUDPInterfaces().tsquash(
"inconsistent number of udp interfaces to test");
int socketsperdetector = 1;
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
socketsperdetector *= 2;
} else if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) {
caller.call("numinterfaces", {"2"}, -1, PUT);
socketsperdetector *= 2;
}
uint16_t port = 3500;
caller.call("rx_zmqport", {std::to_string(port)}, -1, PUT);
for (int i = 0; i != det.size(); ++i) {
std::ostringstream oss;
caller.call("rx_zmqport", {}, i, GET, oss);
REQUIRE(oss.str() == "rx_zmqport " +
std::to_string(port + i * socketsperdetector) +
'\n');
}
port = 30001;
caller.call("rx_zmqport", {std::to_string(port)}, -1, PUT);
for (int i = 0; i != det.size(); ++i) {
std::ostringstream oss;
caller.call("rx_zmqport", {}, i, GET, oss);
REQUIRE(oss.str() == "rx_zmqport " +
std::to_string(port + i * socketsperdetector) +
'\n');
}
test_valid_port_caller("rx_zmqport", {}, -1, PUT);
test_valid_port_caller("rx_zmqport", {}, 0, PUT);
// should fail for the second module
if (det.size() > 1) {
REQUIRE_THROWS(caller.call("rx_zmqport", {"65535"}, -1, PUT));
}
for (int i = 0; i != det.size(); ++i) {
det.setRxZmqPort(prev_val_zmqport[i], i);
}
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) {
det.setNumberofUDPInterfaces(prev_val_numinterfaces);
}
}
TEST_CASE("rx_zmqhwm", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto prev_val =
det.getRxZmqHwm().tsquash("Inconsistent values for rx_zmqhwm to test");
{
std::ostringstream oss;
caller.call("rx_zmqhwm", {"50"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_zmqhwm 50\n");
}
{
std::ostringstream oss;
caller.call("rx_zmqhwm", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_zmqhwm 50\n");
}
{
std::ostringstream oss;
caller.call("rx_zmqhwm", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_zmqhwm 0\n");
}
{
std::ostringstream oss;
caller.call("rx_zmqhwm", {"-1"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_zmqhwm -1\n");
}
det.setRxZmqHwm(prev_val);
}
/* CTB Specific */
TEST_CASE("rx_dbitlist", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD ||
det_type == defs::XILINX_CHIPTESTBOARD) {
auto prev_val = det.getRxDbitList();
{
std::ostringstream oss;
caller.call("rx_dbitlist",
{"0", "4", "5", "8", "9", "10", "52", "63"}, -1, PUT,
oss);
REQUIRE(oss.str() == "rx_dbitlist [0, 4, 5, 8, 9, 10, 52, 63]\n");
}
{
std::ostringstream oss;
caller.call("rx_dbitlist", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_dbitlist [0, 4, 5, 8, 9, 10, 52, 63]\n");
}
REQUIRE_THROWS(caller.call("rx_dbitlist", {"67"}, -1, PUT));
REQUIRE_THROWS(caller.call("rx_dbitlist", {"-1"}, -1, PUT));
REQUIRE_NOTHROW(caller.call("rx_dbitlist", {"all"}, -1, PUT));
for (int i = 0; i != det.size(); ++i) {
det.setRxDbitList(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("rx_dbitlist", {}, -1, GET));
}
}
TEST_CASE("rx_dbitoffset", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD ||
det_type == defs::XILINX_CHIPTESTBOARD) {
auto prev_val = det.getRxDbitOffset();
{
std::ostringstream oss;
caller.call("rx_dbitoffset", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_dbitoffset 1\n");
}
{
std::ostringstream oss;
caller.call("rx_dbitoffset", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_dbitoffset 0\n");
}
{
std::ostringstream oss;
caller.call("rx_dbitoffset", {"15"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_dbitoffset 15\n");
}
{
std::ostringstream oss;
caller.call("rx_dbitoffset", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_dbitoffset 15\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setRxDbitOffset(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("rx_dbitoffset", {}, -1, GET));
}
}
TEST_CASE("rx_dbitreorder", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD ||
det_type == defs::XILINX_CHIPTESTBOARD) {
auto prev_val = det.getRxDbitReorder();
{
std::ostringstream oss;
caller.call("rx_dbitreorder", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_dbitreorder 0\n");
}
{
std::ostringstream oss;
caller.call("rx_dbitreorder", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_dbitreorder 1\n");
}
{
std::ostringstream oss;
caller.call("rx_dbitreorder", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_dbitreorder 1\n");
}
REQUIRE_THROWS(caller.call("rx_dbitreorder", {"15"}, -1, PUT));
for (int i = 0; i != det.size(); ++i) {
det.setRxDbitReorder(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("rx_dbitreorder", {}, -1, GET));
}
}
TEST_CASE("rx_jsonaddheader", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
auto prev_val = det.getAdditionalJsonHeader();
{
std::ostringstream oss;
caller.call("rx_jsonaddheader", {"key1", "value1", "key2", "value2"},
-1, PUT, oss);
REQUIRE(oss.str() == "rx_jsonaddheader {key1: value1, key2: value2}\n");
}
{
std::ostringstream oss;
caller.call("rx_jsonaddheader", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_jsonaddheader {key1: value1, key2: value2}\n");
}
{
std::ostringstream oss;
caller.call("rx_jsonaddheader", {}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_jsonaddheader {}\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setAdditionalJsonHeader(prev_val[i], {i});
}
}
TEST_CASE("rx_jsonpara", "[.detectorintegration][.rx]") {
Detector det;
Caller caller(&det);
auto prev_val = det.getAdditionalJsonHeader();
{
std::ostringstream oss;
caller.call("rx_jsonpara", {"key1", "value1"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_jsonpara {key1: value1}\n");
}
{
std::ostringstream oss;
caller.call("rx_jsonpara", {"key1", "value2"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_jsonpara {key1: value2}\n");
}
{
std::ostringstream oss;
caller.call("rx_jsonpara", {"key1"}, -1, GET, oss);
REQUIRE(oss.str() == "rx_jsonpara value2\n");
}
{
std::ostringstream oss;
caller.call("rx_jsonpara", {"key1"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_jsonpara key1 deleted\n");
}
REQUIRE_THROWS(caller.call("rx_jsonpara", {"key1"}, -1, GET));
for (int i = 0; i != det.size(); ++i) {
det.setAdditionalJsonHeader(prev_val[i], {i});
}
}
/* Insignificant */
} // namespace sls