commands code generation (#871)

* commands code generation  (#803)

* commands code generation for only frames command

* fix cmake file and add Caller files

* working exptime, fully extended commands file and its variants

* start adding template commands

* add INT_CMD_VEC_ID template

* add list command, generate multiple bins, format code

* reach 208 commands using the cpp macros

* add tests for command parser

* start adding tests for commands parser

* fix typo to use commands.yaml

* add more tests for command_parser

* add all template functions (up to 218 commands)

* finish template functions and add more CmdProxy.cpp functions (250+)

* 257 commands

* 300 commands the rest are very special commands

* add special commands without generation

* separate special functions from generated c++ file

* implementing one command for put and get (buggy)

* add infer action in a separate file

* generate header for special commands from yaml

* allow only 0 or 1 for bool inputs

* group all commands in gen_commands.py

* add help to gen_commands.py

* add autocomplete bash script

* autocompletion: add support for module levels and help

* remove debugging line

* add autocompletion, help to commands, change int [0,1] to bool

* copy tests for Caller.cpp. Tests pass

* update with the new developer branch changes

* fix errors after merging (there is problems with tests)

* fixed port/stopport in yaml (intput typo), added '_caller' to the test dac and test on chip dac command in global test for cmdcaller

* undo previous test simulator debug change

* add documentation for the generated code

* reducing the comment to be replaced in length so formatting does not split into 2 lines

* removed formatting specific style of C++11 in gen_commands.py to keep with the top level clang format of the project
* regeneratign code for commands

* automation generated

* Redirect deprecated commands (#872)

* working implementation, need to fix dac

* fixed deprecation redirect for dac command

* Detector specific autocomplete (#873)

* working implementation, need to fix dac

* fixed deprecation redirect for dac command

* detector specific completion for dac

* added autocomplete using detector specific

* fixed error when autocompleting partial words

* Generate commands/fix commands (#875)

* fix vm_a, im_a etc have deg Celsius suffix, also help missing or changed in some places

* dac: require det id for all, arg0 to be printed at output, help for onchip dac and dac, onchipdac: spacing

* getscan detid and blocking trigger help

* udp_Dstlist det_id fixed, but rx_id invalid

* cmdApp in line with cmdLineApp (missing version, receiver_id, not creating det object in help action

* added set_command to differentiate between check_det_id and require_det_id (mixed up), args: -1 needs to check for at least one argument

* reordering

* reordering and checked till integer_command_hex

* fixed a lot more commands

* fix caller tests for eiger

* changes to tests after Bechir left

* changing .cmd to .cmdcall for the caller commands

* fixed tests for caller, still warning for setexptime about cast input

* autocomplete ran

* add moench test

* regenerating autocomplete and commands

* fixing other things from merge conflicts (renaming slsDetectorDefs to defs in commands.yaml)

* formatting

* added code injection to help (#876)

* updated 3 commands to have get output that can be put into put (#877)

* updated some commands to have get output that can be put into put

* fix tests for clkdiv

* adding help to free (#878)

* removing old commands and renaming them, (also making it work for parameters command as it was still calling cmdproxy) (#879)

* More helpful error messages for unsupported actions (#880)

* removing old commands and renaming them, (also making it work for parameters command as it was still calling cmdproxy)

* Added specific help for unsupported actions

* fixed a vetofile get special exception message. more specific warning for special exception message instead of no function warning

* added condition checking true in exceptions for special message

---------
Co-authored-by: Bechir Brahem <bachbrahem@gmail.com>
Co-authored-by: Erik Frojdh <erik.frojdh@gmail.com>
Co-authored-by: Dhanya Thattil <dhanya.thattil@psi.ch>
This commit is contained in:
2023-12-13 14:43:38 +01:00
committed by GitHub
parent d72c9e29a4
commit ce7270e8a2
63 changed files with 180123 additions and 9134 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,668 @@
// 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/sls_detector_defs.h"
#include <array>
#include <sstream>
#include <thread>
#include "sls/versionAPI.h"
#include "test-Caller-global.h"
#include "tests/globals.h"
namespace sls {
using test::GET;
using test::PUT;
/** temperature */
TEST_CASE("CALLER::temp_fpgaext", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
REQUIRE_NOTHROW(caller.call("temp_fpgaext", {}, -1, GET));
std::ostringstream oss;
REQUIRE_NOTHROW(caller.call("temp_fpgaext", {}, 0, GET, oss));
std::string s = (oss.str()).erase(0, strlen("temp_fpgaext "));
REQUIRE(std::stoi(s) != -1);
} else {
REQUIRE_THROWS(caller.call("temp_fpgaext", {}, -1, GET));
}
}
TEST_CASE("CALLER::temp_10ge", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
REQUIRE_NOTHROW(caller.call("temp_10ge", {}, -1, GET));
std::ostringstream oss;
REQUIRE_NOTHROW(caller.call("temp_10ge", {}, 0, GET, oss));
std::string s = (oss.str()).erase(0, strlen("temp_10ge "));
REQUIRE(std::stoi(s) != -1);
} else {
REQUIRE_THROWS(caller.call("temp_10ge", {}, -1, GET));
}
}
TEST_CASE("CALLER::temp_dcdc", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
REQUIRE_NOTHROW(caller.call("temp_dcdc", {}, -1, GET));
std::ostringstream oss;
REQUIRE_NOTHROW(caller.call("temp_dcdc", {}, 0, GET, oss));
std::string s = (oss.str()).erase(0, strlen("temp_dcdc "));
REQUIRE(std::stoi(s) != -1);
} else {
REQUIRE_THROWS(caller.call("temp_dcdc", {}, -1, GET));
}
}
TEST_CASE("CALLER::temp_sodl", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
REQUIRE_NOTHROW(caller.call("temp_sodl", {}, -1, GET));
std::ostringstream oss;
REQUIRE_NOTHROW(caller.call("temp_sodl", {}, 0, GET, oss));
std::string s = (oss.str()).erase(0, strlen("temp_sodl "));
REQUIRE(std::stoi(s) != -1);
} else {
REQUIRE_THROWS(caller.call("temp_sodl", {}, -1, GET));
}
}
TEST_CASE("CALLER::temp_sodr", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
REQUIRE_NOTHROW(caller.call("temp_sodr", {}, -1, GET));
std::ostringstream oss;
REQUIRE_NOTHROW(caller.call("temp_sodr", {}, 0, GET, oss));
std::string s = (oss.str()).erase(0, strlen("temp_sodr "));
REQUIRE(std::stoi(s) != -1);
} else {
REQUIRE_THROWS(caller.call("temp_sodr", {}, -1, GET));
}
}
TEST_CASE("CALLER::temp_fpgafl", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
REQUIRE_NOTHROW(caller.call("temp_fpgafl", {}, -1, GET));
std::ostringstream oss;
REQUIRE_NOTHROW(caller.call("temp_fpgafl", {}, 0, GET, oss));
std::string s = (oss.str()).erase(0, strlen("temp_fpgafl "));
REQUIRE(std::stoi(s) != -1);
} else {
REQUIRE_THROWS(caller.call("temp_fpgafl", {}, -1, GET));
}
}
TEST_CASE("CALLER::temp_fpgafr", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
REQUIRE_NOTHROW(caller.call("temp_fpgafr", {}, -1, GET));
std::ostringstream oss;
REQUIRE_NOTHROW(caller.call("temp_fpgafr", {}, 0, GET, oss));
std::string s = (oss.str()).erase(0, strlen("temp_fpgafr "));
REQUIRE(std::stoi(s) != -1);
} else {
REQUIRE_THROWS(caller.call("temp_fpgafr", {}, -1, GET));
}
}
/* dacs */
TEST_CASE("CALLER::Setting and reading back EIGER dacs", "[.cmdcall][.dacs]") {
// vsvp, vtr, vrf, vrs, vsvn, vtgstv, vcmp_ll, vcmp_lr, vcal, vcmp_rl,
// rxb_rb, rxb_lb, vcmp_rr, vcp, vcn, vis, vthreshold
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
SECTION("vsvp") { test_dac_caller(defs::VSVP, "vsvp", 5); }
SECTION("vtrim") { test_dac_caller(defs::VTRIM, "vtrim", 1200); }
SECTION("vrpreamp") {
test_dac_caller(defs::VRPREAMP, "vrpreamp", 1500);
}
SECTION("vrshaper") {
test_dac_caller(defs::VRSHAPER, "vrshaper", 1510);
}
SECTION("vsvn") { test_dac_caller(defs::VSVN, "vsvn", 3800); }
SECTION("vtgstv") { test_dac_caller(defs::VTGSTV, "vtgstv", 2550); }
SECTION("vcmp_ll") { test_dac_caller(defs::VCMP_LL, "vcmp_ll", 1400); }
SECTION("vcmp_lr") { test_dac_caller(defs::VCMP_LR, "vcmp_lr", 1400); }
SECTION("vcal") { test_dac_caller(defs::VCAL, "vcal", 1400); }
SECTION("vcmp_rl") { test_dac_caller(defs::VCMP_RL, "vcmp_rl", 1400); }
SECTION("rxb_rb") { test_dac_caller(defs::RXB_RB, "rxb_rb", 1400); }
SECTION("rxb_lb") { test_dac_caller(defs::RXB_LB, "rxb_lb", 1400); }
SECTION("vcmp_rr") { test_dac_caller(defs::VCMP_RR, "vcmp_rr", 1400); }
SECTION("vcp") { test_dac_caller(defs::VCP, "vcp", 1400); }
SECTION("vcn") { test_dac_caller(defs::VCN, "vcn", 1400); }
SECTION("vishaper") {
test_dac_caller(defs::VISHAPER, "vishaper", 1400);
}
SECTION("iodelay") { test_dac_caller(defs::IO_DELAY, "iodelay", 1400); }
SECTION("vthreshold") {
// Read out individual vcmp to be able to reset after
// the test is done
auto vcmp_ll = det.getDAC(defs::VCMP_LL, false);
auto vcmp_lr = det.getDAC(defs::VCMP_LR, false);
auto vcmp_rl = det.getDAC(defs::VCMP_RL, false);
auto vcmp_rr = det.getDAC(defs::VCMP_RR, false);
auto vcp = det.getDAC(defs::VCP, false);
{
std::ostringstream oss;
caller.call("dac", {"vthreshold", "1234"}, -1, PUT, oss);
REQUIRE(oss.str() == "dac vthreshold 1234\n");
}
{
std::ostringstream oss;
caller.call("dac", {"vthreshold"}, -1, GET, oss);
REQUIRE(oss.str() == "dac vthreshold 1234\n");
}
// Reset dacs after test
for (int i = 0; i != det.size(); ++i) {
det.setDAC(defs::VCMP_LL, vcmp_ll[i], false, {i});
det.setDAC(defs::VCMP_LR, vcmp_lr[i], false, {i});
det.setDAC(defs::VCMP_RL, vcmp_rl[i], false, {i});
det.setDAC(defs::VCMP_RR, vcmp_rr[i], false, {i});
det.setDAC(defs::VCP, vcp[i], false, {i});
}
}
// gotthard
REQUIRE_THROWS(caller.call("vref_ds", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcascn_pb", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcascp_pb", {}, -1, GET));
REQUIRE_THROWS(caller.call("vout_cm", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcasc_out", {}, -1, GET));
REQUIRE_THROWS(caller.call("vin_cm", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_comp", {}, -1, GET));
REQUIRE_THROWS(caller.call("ib_test_c", {}, -1, GET));
// mythen3
// REQUIRE_THROWS(caller.call("vrpreamp", {}, -1, GET));
// REQUIRE_THROWS(caller.call("vrshaper", {}, -1, GET));
REQUIRE_THROWS(caller.call("vrshaper_n", {}, -1, GET));
REQUIRE_THROWS(caller.call("vipre", {}, -1, GET));
// REQUIRE_THROWS(caller.call("vishaper", {}, -1, GET));
REQUIRE_THROWS(caller.call("vdcsh", {}, -1, GET));
REQUIRE_THROWS(caller.call("vth1", {}, -1, GET));
REQUIRE_THROWS(caller.call("vth2", {}, -1, GET));
REQUIRE_THROWS(caller.call("vth3", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcal_n", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcal_p", {}, -1, GET));
// REQUIRE_THROWS(caller.call("vtrim", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcassh", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcas", {}, -1, GET));
REQUIRE_THROWS(caller.call("vicin", {}, -1, GET));
REQUIRE_THROWS(caller.call("vipre_out", {}, -1, GET));
// gotthard2
REQUIRE_THROWS(caller.call("vref_h_adc", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_comp_fe", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_comp_adc", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcom_cds", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_rstore", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_opa_1st", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_comp_fe", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcom_adc1", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_l_adc", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_cds", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_cs", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_opa_fd", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcom_adc2", {}, -1, GET));
// jungfrau
REQUIRE_THROWS(caller.call("vb_comp", {}, -1, GET));
REQUIRE_THROWS(caller.call("vdd_prot", {}, -1, GET));
REQUIRE_THROWS(caller.call("vin_com", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_prech", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_pixbuf", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_ds", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_ds", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_comp", {}, -1, GET));
}
}
/* acquisition */
/* Network Configuration (Detector<->Receiver) */
TEST_CASE("CALLER::txdelay_left", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
auto prev_val = det.getTransmissionDelayLeft();
{
std::ostringstream oss1, oss2;
caller.call("txdelay_left", {"5000"}, -1, PUT, oss1);
REQUIRE(oss1.str() == "txdelay_left 5000\n");
caller.call("txdelay_left", {}, -1, GET, oss2);
REQUIRE(oss2.str() == "txdelay_left 5000\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setTransmissionDelayLeft(prev_val[i]);
}
} else {
REQUIRE_THROWS(caller.call("txdelay_left", {}, -1, GET));
}
}
TEST_CASE("CALLER::txdelay_right", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
auto prev_val = det.getTransmissionDelayRight();
{
std::ostringstream oss1, oss2;
caller.call("txdelay_right", {"5000"}, -1, PUT, oss1);
REQUIRE(oss1.str() == "txdelay_right 5000\n");
caller.call("txdelay_right", {}, -1, GET, oss2);
REQUIRE(oss2.str() == "txdelay_right 5000\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setTransmissionDelayRight(prev_val[i]);
}
} else {
REQUIRE_THROWS(caller.call("txdelay_right", {}, -1, GET));
}
}
/* Eiger Specific */
TEST_CASE("CALLER::subexptime", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
auto time = det.getSubExptime();
std::ostringstream oss1, oss2;
caller.call("subexptime", {"2.5us"}, -1, PUT, oss1);
REQUIRE(oss1.str() == "subexptime 2.5us\n");
caller.call("subexptime", {}, -1, GET, oss2);
REQUIRE(oss2.str() == "subexptime 2.5us\n");
for (int i = 0; i != det.size(); ++i) {
det.setSubExptime(time[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("subexptime", {}, -1, GET));
REQUIRE_THROWS(caller.call("subexptime", {"2.13"}, -1, PUT));
}
}
TEST_CASE("CALLER::subdeadtime", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
auto time = det.getSubDeadTime();
std::ostringstream oss1, oss2;
caller.call("subdeadtime", {"500us"}, -1, PUT, oss1);
REQUIRE(oss1.str() == "subdeadtime 500us\n");
caller.call("subdeadtime", {}, -1, GET, oss2);
REQUIRE(oss2.str() == "subdeadtime 500us\n");
for (int i = 0; i != det.size(); ++i) {
det.setSubDeadTime(time[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("subdeadtime", {}, -1, GET));
REQUIRE_THROWS(caller.call("subdeadtime", {"2.13"}, -1, PUT));
}
}
TEST_CASE("CALLER::overflow", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
auto previous = det.getOverFlowMode();
std::ostringstream oss1, oss2, oss3;
caller.call("overflow", {"1"}, -1, PUT, oss1);
REQUIRE(oss1.str() == "overflow 1\n");
caller.call("overflow", {}, -1, GET, oss2);
REQUIRE(oss2.str() == "overflow 1\n");
caller.call("overflow", {"0"}, -1, PUT, oss3);
REQUIRE(oss3.str() == "overflow 0\n");
for (int i = 0; i != det.size(); ++i) {
det.setOverFlowMode(previous[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("overflow", {}, -1, GET));
}
}
TEST_CASE("CALLER::ratecorr", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
auto prev_dr = det.getDynamicRange().tsquash("inconsistent dr to test");
auto prev_tau = det.getRateCorrection();
det.setDynamicRange(16);
{
std::ostringstream oss;
caller.call("ratecorr", {"120"}, -1, PUT, oss);
REQUIRE(oss.str() == "ratecorr 120ns\n");
}
{
std::ostringstream oss;
caller.call("ratecorr", {}, -1, GET, oss);
REQUIRE(oss.str() == "ratecorr 120ns\n");
}
// may fail if default settings not loaded
// REQUIRE_NOTHROW(caller.call("ratecorr", {"-1"}, -1, PUT));
{
std::ostringstream oss;
caller.call("ratecorr", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "ratecorr 0ns\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setRateCorrection(prev_tau[i], {i});
}
det.setDynamicRange(prev_dr);
} else {
REQUIRE_THROWS(caller.call("ratecorr", {}, -1, GET));
}
}
TEST_CASE("CALLER::interruptsubframe", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
auto prev_val = det.getInterruptSubframe();
std::ostringstream oss1, oss2, oss3;
caller.call("interruptsubframe", {"1"}, -1, PUT, oss1);
REQUIRE(oss1.str() == "interruptsubframe 1\n");
caller.call("interruptsubframe", {}, -1, GET, oss2);
REQUIRE(oss2.str() == "interruptsubframe 1\n");
caller.call("interruptsubframe", {"0"}, -1, PUT, oss3);
REQUIRE(oss3.str() == "interruptsubframe 0\n");
for (int i = 0; i != det.size(); ++i) {
det.setInterruptSubframe(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("interruptsubframe", {}, -1, GET));
REQUIRE_THROWS(caller.call("interruptsubframe", {"1"}, -1, PUT));
}
}
TEST_CASE("CALLER::measuredperiod", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
auto prev_frames = det.getNumberOfFrames().tsquash(
"inconsistent number of frames to test");
auto prev_timing =
det.getTimingMode().tsquash("inconsistent timing mode to test");
auto prev_period = det.getPeriod();
det.setNumberOfFrames(2);
det.setPeriod(std::chrono::seconds(1));
det.setTimingMode(defs::AUTO_TIMING);
det.startDetector();
std::this_thread::sleep_for(std::chrono::seconds(3));
std::ostringstream oss;
caller.call("measuredperiod", {}, -1, GET, oss);
std::string st = oss.str();
std::string s;
if (st.find('[') != std::string::npos) {
s = st.erase(0, strlen("measuredperiod ["));
} else {
s = st.erase(0, strlen("measuredperiod "));
}
double val = std::stod(s);
// REQUIRE(val >= 1.0);
REQUIRE(val < 2.0);
for (int i = 0; i != det.size(); ++i) {
det.setPeriod(prev_period[i], {i});
}
det.setNumberOfFrames(prev_frames);
det.setTimingMode(prev_timing);
} else {
REQUIRE_THROWS(caller.call("measuredperiod", {}, -1, GET));
}
}
TEST_CASE("CALLER::measuredsubperiod", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
auto prev_frames = det.getNumberOfFrames().tsquash(
"inconsistent number of frames to test");
auto prev_timing =
det.getTimingMode().tsquash("inconsistent timing mode to test");
auto prev_period = det.getPeriod();
auto prev_dr = det.getDynamicRange().tsquash("inconsistent dr to test");
det.setNumberOfFrames(1);
det.setPeriod(std::chrono::seconds(1));
det.setTimingMode(defs::AUTO_TIMING);
det.setDynamicRange(32);
det.startDetector();
std::this_thread::sleep_for(std::chrono::seconds(3));
std::ostringstream oss;
caller.call("measuredsubperiod", {}, -1, GET, oss);
std::string st = oss.str();
std::string s;
if (st.find('[') != std::string::npos) {
s = st.erase(0, strlen("measuredsubperiod ["));
} else {
s = st.erase(0, strlen("measuredsubperiod "));
}
double val = std::stod(s);
REQUIRE(val >= 0);
REQUIRE(val < 1000);
for (int i = 0; i != det.size(); ++i) {
det.setPeriod(prev_period[i], {i});
}
det.setNumberOfFrames(prev_frames);
det.setTimingMode(prev_timing);
det.setDynamicRange(prev_dr);
} else {
REQUIRE_THROWS(caller.call("measuredsubperiod", {}, -1, GET));
}
}
TEST_CASE("CALLER::activate", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
auto prev_val = det.getActive();
{
std::ostringstream oss;
caller.call("activate", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "activate 1\n");
}
{
std::ostringstream oss;
caller.call("activate", {}, -1, GET, oss);
REQUIRE(oss.str() == "activate 1\n");
}
{
std::ostringstream oss;
caller.call("activate", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "activate 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setActive(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("activate", {}, -1, GET));
REQUIRE_THROWS(caller.call("activate", {"1"}, -1, PUT));
}
}
TEST_CASE("CALLER::partialreset", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
auto prev_val = det.getPartialReset();
std::ostringstream oss1, oss2, oss3;
caller.call("partialreset", {"1"}, -1, PUT, oss1);
REQUIRE(oss1.str() == "partialreset 1\n");
caller.call("partialreset", {}, -1, GET, oss2);
REQUIRE(oss2.str() == "partialreset 1\n");
caller.call("partialreset", {"0"}, -1, PUT, oss3);
REQUIRE(oss3.str() == "partialreset 0\n");
for (int i = 0; i != det.size(); ++i) {
det.setPartialReset(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("partialreset", {}, -1, GET));
REQUIRE_THROWS(caller.call("partialreset", {"1"}, -1, PUT));
}
}
TEST_CASE("CALLER::pulse", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
REQUIRE_THROWS(caller.call("pulse", {}, -1, GET));
std::ostringstream oss;
caller.call("pulse", {"1", "1", "5"}, -1, PUT, oss);
REQUIRE(oss.str() == "pulse [1, 1, 5]\n");
} else {
REQUIRE_THROWS(caller.call("pulse", {}, -1, GET));
REQUIRE_THROWS(caller.call("pulse", {"1", "1", "5"}, -1, PUT));
}
}
TEST_CASE("CALLER::pulsenmove", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
REQUIRE_THROWS(caller.call("pulsenmove", {}, -1, GET));
std::ostringstream oss;
caller.call("pulsenmove", {"1", "1", "5"}, -1, PUT, oss);
REQUIRE(oss.str() == "pulsenmove [1, 1, 5]\n");
} else {
REQUIRE_THROWS(caller.call("pulsenmove", {}, -1, GET));
REQUIRE_THROWS(caller.call("pulsenmove", {"1", "1", "5"}, -1, PUT));
}
}
TEST_CASE("CALLER::pulsechip", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
REQUIRE_THROWS(caller.call("pulsechip", {}, -1, GET));
std::ostringstream oss;
caller.call("pulsechip", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "pulsechip 1\n");
} else {
REQUIRE_THROWS(caller.call("pulsechip", {}, -1, GET));
REQUIRE_THROWS(caller.call("pulsechip", {"1"}, -1, PUT));
}
}
TEST_CASE("CALLER::quad", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
auto prev_val = det.getQuad().tsquash("inconsistent quad to test");
// Quad only works with a single half module EIGER
std::ostringstream oss;
caller.call("quad", {}, -1, GET, oss);
REQUIRE(oss.str() == "quad 0\n");
det.setQuad(prev_val);
} else {
REQUIRE_THROWS(caller.call("quad", {}, -1, GET));
}
}
TEST_CASE("CALLER::datastream", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
auto prev_val_left = det.getDataStream(defs::LEFT);
auto prev_val_right = det.getDataStream(defs::RIGHT);
// no "left" or "right"
REQUIRE_THROWS(caller.call("datastream", {"1"}, -1, PUT));
{
std::ostringstream oss;
caller.call("datastream", {"left", "0"}, -1, PUT, oss);
REQUIRE(oss.str() == "datastream [left, 0]\n");
}
{
std::ostringstream oss;
caller.call("datastream", {"right", "0"}, -1, PUT, oss);
REQUIRE(oss.str() == "datastream [right, 0]\n");
}
{
std::ostringstream oss;
caller.call("datastream", {"left", "1"}, -1, PUT, oss);
REQUIRE(oss.str() == "datastream [left, 1]\n");
}
{
std::ostringstream oss;
caller.call("datastream", {"right", "1"}, -1, PUT, oss);
REQUIRE(oss.str() == "datastream [right, 1]\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setDataStream(defs::LEFT, prev_val_left[i], {i});
det.setDataStream(defs::RIGHT, prev_val_right[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("datastream", {}, -1, GET));
REQUIRE_THROWS(caller.call("datastream", {"1"}, -1, PUT));
REQUIRE_THROWS(caller.call("datastream", {"left", "1"}, -1, PUT));
}
}
TEST_CASE("CALLER::top", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
auto prev_val = det.getTop();
int numModulesTested = 1;
if (det.size() > 1) {
numModulesTested = 2;
}
for (int i = 0; i != numModulesTested; ++i) {
std::ostringstream oss1, oss2, oss3;
caller.call("top", {"1"}, i, PUT, oss1);
REQUIRE(oss1.str() == "top 1\n");
caller.call("top", {}, i, GET, oss2);
REQUIRE(oss2.str() == "top 1\n");
caller.call("top", {"0"}, i, PUT, oss3);
REQUIRE(oss3.str() == "top 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setTop(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("top", {}, -1, GET));
REQUIRE_THROWS(caller.call("top", {"1"}, -1, PUT));
}
}
} // namespace sls

View File

@@ -0,0 +1,91 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include "test-Caller-global.h"
#include "Caller.h"
#include "catch.hpp"
#include "sls/Detector.h"
#include "tests/globals.h"
namespace sls {
using test::GET;
using test::PUT;
void test_valid_port_caller(const std::string &command,
const std::vector<std::string> &arguments,
int detector_id, int action) {
Detector det;
Caller caller(&det);
std::vector<std::string> arg(arguments);
if (arg.empty())
arg.push_back("0");
int test_values[3] = {77797, -1, 0};
for (int i = 0; i != 3; ++i) {
int port_number = test_values[i];
arg[arg.size() - 1] = std::to_string(port_number);
REQUIRE_THROWS(caller.call(command, arg, detector_id, action));
/*REQUIRE_THROWS_WITH(proxy.Call(command, arguments, detector_id,
action), "Invalid port range. Must be between 1 - 65535.");*/
}
}
void test_dac_caller(defs::dacIndex index, const std::string &dacname,
int dacvalue) {
Detector det;
Caller caller(&det);
std::ostringstream oss_set, oss_get;
auto dacstr = std::to_string(dacvalue);
auto previous = det.getDAC(index, false);
// chip test board
if (dacname == "dac") {
auto dacIndexstr = std::to_string(static_cast<int>(index));
caller.call(dacname, {dacIndexstr, dacstr}, -1, PUT, oss_set);
REQUIRE(oss_set.str() ==
dacname + " " + dacIndexstr + " " + dacstr + "\n");
caller.call(dacname, {dacIndexstr}, -1, GET, oss_get);
REQUIRE(oss_get.str() ==
dacname + " " + dacIndexstr + " " + dacstr + "\n");
}
// other detectors
else {
caller.call("dac", {dacname, dacstr}, -1, PUT, oss_set);
REQUIRE(oss_set.str() == "dac " + dacname + " " + dacstr + "\n");
caller.call("dac", {dacname}, -1, GET, oss_get);
REQUIRE(oss_get.str() == "dac " + dacname + " " + dacstr + "\n");
}
// Reset all dacs to previous value
for (int i = 0; i != det.size(); ++i) {
det.setDAC(index, previous[i], false, {i});
}
}
void test_onchip_dac_caller(defs::dacIndex index, const std::string &dacname,
int dacvalue) {
Detector det;
Caller caller(&det);
REQUIRE_THROWS(caller.call(dacname, {}, -1, GET));
REQUIRE_THROWS(
caller.call(dacname, {"10", "0x0"}, -1, PUT)); // chip index (-1 to 9)
REQUIRE_THROWS(
caller.call(dacname, {"-1", "0x400"}, -1, PUT)); // max val is 0x3ff
int chipIndex = -1; // for now, it is -1 only
auto prev_val = det.getOnChipDAC(index, chipIndex);
auto dacValueStr = ToStringHex(dacvalue);
auto chipIndexStr = std::to_string(chipIndex);
std::ostringstream oss_set, oss_get;
caller.call(dacname, {chipIndexStr, dacValueStr}, -1, PUT, oss_set);
REQUIRE(oss_set.str() ==
dacname + " " + chipIndexStr + " " + dacValueStr + "\n");
caller.call(dacname, {chipIndexStr}, -1, GET, oss_get);
REQUIRE(oss_get.str() ==
dacname + " " + chipIndexStr + " " + dacValueStr + "\n");
// Reset all dacs to previous value
for (int i = 0; i != det.size(); ++i) {
det.setOnChipDAC(index, chipIndex, prev_val[i], {i});
}
}
} // namespace sls

View File

@@ -0,0 +1,16 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#pragma once
#include "sls/sls_detector_defs.h"
namespace sls {
void test_valid_port_caller(const std::string &command,
const std::vector<std::string> &arguments,
int detector_id, int action);
void test_dac_caller(slsDetectorDefs::dacIndex index,
const std::string &dacname, int dacvalue);
void test_onchip_dac_caller(slsDetectorDefs::dacIndex index,
const std::string &dacname, int dacvalue);
} // namespace sls

View File

@@ -0,0 +1,175 @@
// 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/sls_detector_defs.h"
#include <sstream>
#include "sls/Result.h"
#include "sls/ToString.h"
#include "sls/versionAPI.h"
#include "test-Caller-global.h"
#include "tests/globals.h"
namespace sls {
using test::GET;
using test::PUT;
/* dacs */
TEST_CASE("Caller::Setting and reading back GOTTHARD dacs",
"[.cmdcall][.dacs]") {
// vref_ds, vcascn_pb, vcascp_pb, vout_cm, vcasc_out, vin_cm, vref_comp,
// ib_test_c
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD) {
SECTION("vref_ds") { test_dac_caller(defs::VREF_DS, "vref_ds", 660); }
SECTION("vcascn_pb") {
test_dac_caller(defs::VCASCN_PB, "vcascn_pb", 650);
}
SECTION("vcascp_pb") {
test_dac_caller(defs::VCASCP_PB, "vcascp_pb", 1480);
}
SECTION("vout_cm") { test_dac_caller(defs::VOUT_CM, "vout_cm", 1520); }
SECTION("vcasc_out") {
test_dac_caller(defs::VCASC_OUT, "vcasc_out", 1320);
}
SECTION("vin_cm") { test_dac_caller(defs::VIN_CM, "vin_cm", 1350); }
SECTION("vref_comp") {
test_dac_caller(defs::VREF_COMP, "vref_comp", 350);
}
SECTION("ib_test_c") {
test_dac_caller(defs::IB_TESTC, "ib_test_c", 2001);
}
// eiger
REQUIRE_THROWS(caller.call("dac", {"vthreshold"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vsvp"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vsvn"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vtrim"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vrpreamp"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vrshaper"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vtgstv"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcmp_ll"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcmp_lr"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcal"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcmp_rl"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcmp_rr"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"rxb_rb"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"rxb_lb"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcp"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcn"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vishaper"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"iodelay"}, -1, GET));
// jungfrau
REQUIRE_THROWS(caller.call("dac", {"vb_comp"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vdd_prot"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vin_com"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vref_prech"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vb_pixbuf"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vb_ds"}, -1, GET));
// REQUIRE_THROWS(caller.call("dac", {"vref_ds"}, -1, GET));
// REQUIRE_THROWS(caller.call("dac", {"vref_comp"}, -1, GET));
// mythen3
REQUIRE_THROWS(caller.call("dac", {"vrpreamp"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vrshaper"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vrshaper_n"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vipre"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vishaper"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vdcsh"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vth1"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vth2"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vth3"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcal_n"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcal_p"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vtrim"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcassh"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcas"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vicin"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vipre_out"}, -1, GET));
// gotthard2
REQUIRE_THROWS(caller.call("dac", {"vref_h_adc"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vb_comp_fe"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vb_comp_adc"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcom_cds"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vref_rstore"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vb_opa_1st"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vref_comp_fe"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcom_adc1"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vref_l_adc"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vref_cds"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vb_cs"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vb_opa_fd"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcom_adc2"}, -1, GET));
}
}
/* Gotthard Specific */
TEST_CASE("Caller::roi", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD) {
if (det.size() > 1) {
REQUIRE_THROWS(caller.call("roi", {"0", "255"}, -1, PUT));
REQUIRE_NOTHROW(caller.call("roi", {}, -1, GET));
} else {
auto prev_val = det.getROI();
{
std::ostringstream oss;
caller.call("roi", {"0", "255"}, -1, PUT, oss);
REQUIRE(oss.str() == "roi [0, 255]\n");
}
{
std::ostringstream oss;
caller.call("roi", {"256", "511"}, -1, PUT, oss);
REQUIRE(oss.str() == "roi [256, 511]\n");
}
REQUIRE_THROWS(caller.call("roi", {"0", "256"}, -1, PUT));
for (int i = 0; i != det.size(); ++i) {
det.setROI(prev_val[i], i);
}
}
} else {
REQUIRE_THROWS(caller.call("roi", {}, -1, GET));
}
}
TEST_CASE("Caller::clearroi", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD) {
auto prev_val = det.getROI();
{
std::ostringstream oss;
caller.call("clearroi", {}, -1, PUT, oss);
REQUIRE(oss.str() == "clearroi successful\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setROI(prev_val[i], i);
}
} else {
REQUIRE_THROWS(caller.call("clearroi", {}, -1, PUT));
}
}
TEST_CASE("Caller::exptimel", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD) {
REQUIRE_NOTHROW(caller.call("exptimel", {}, -1, GET));
} else {
REQUIRE_THROWS(caller.call("exptimel", {}, -1, GET));
}
}
} // namespace sls

View File

@@ -0,0 +1,755 @@
// 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/sls_detector_defs.h"
#include <sstream>
#include "sls/Result.h"
#include "sls/ToString.h"
#include "sls/versionAPI.h"
#include "test-Caller-global.h"
#include "tests/globals.h"
namespace sls {
using test::GET;
using test::PUT;
// time specific measurements for gotthard2
TEST_CASE("Caller::timegotthard2", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
// exptime
auto prev_val = det.getExptime();
{
std::ostringstream oss;
caller.call("exptime", {"220ns"}, -1, PUT, oss);
REQUIRE(oss.str() == "exptime 220ns\n");
}
{
std::ostringstream oss;
caller.call("exptime", {}, -1, GET, oss);
REQUIRE(oss.str() == "exptime 221ns\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setExptime(prev_val[i], {i});
}
// burst period
prev_val = det.getBurstPeriod();
{
std::ostringstream oss;
caller.call("burstperiod", {"220ns"}, -1, PUT, oss);
REQUIRE(oss.str() == "burstperiod 220ns\n");
}
{
std::ostringstream oss;
caller.call("burstperiod", {}, -1, GET, oss);
REQUIRE(oss.str() == "burstperiod 221ns\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setBurstPeriod(prev_val[i], {i});
}
// delay after trigger
prev_val = det.getDelayAfterTrigger();
{
std::ostringstream oss;
caller.call("delay", {"220ns"}, -1, PUT, oss);
REQUIRE(oss.str() == "delay 220ns\n");
}
{
std::ostringstream oss;
caller.call("delay", {}, -1, GET, oss);
REQUIRE(oss.str() == "delay 221ns\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setDelayAfterTrigger(prev_val[i], {i});
}
// period in burst mode
auto burst_prev_val = det.getBurstMode();
det.setBurstMode(defs::BURST_INTERNAL, {});
prev_val = det.getPeriod();
{
std::ostringstream oss;
caller.call("period", {"220ns"}, -1, PUT, oss);
REQUIRE(oss.str() == "period 220ns\n");
}
{
std::ostringstream oss;
caller.call("period", {}, -1, GET, oss);
REQUIRE(oss.str() == "period 221ns\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setPeriod(prev_val[i], {i});
}
// period in continuous mode
det.setBurstMode(defs::CONTINUOUS_INTERNAL, {});
prev_val = det.getPeriod();
{
std::ostringstream oss;
caller.call("period", {"220ns"}, -1, PUT, oss);
REQUIRE(oss.str() == "period 220ns\n");
}
{
std::ostringstream oss;
caller.call("period", {}, -1, GET, oss);
REQUIRE(oss.str() == "period 221ns\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setPeriod(prev_val[i], {i});
det.setBurstMode(burst_prev_val[i], {i});
}
}
}
/* dacs */
TEST_CASE("Caller::Setting and reading back GOTTHARD2 dacs",
"[.cmdcall][.dacs]") {
// vref_h_adc, vb_comp_fe, vb_comp_adc, vcom_cds,
// vref_restore, vb_opa_1st, vref_comp_fe, vcom_adc1,
// vref_prech, vref_l_adc, vref_cds, vb_cs,
// vb_opa_fd, vcom_adc2
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
SECTION("vref_h_adc") {
test_dac_caller(defs::VREF_H_ADC, "vref_h_adc", 2099);
}
SECTION("vb_comp_fe") {
test_dac_caller(defs::VB_COMP_FE, "vb_comp_fe", 0);
}
SECTION("vb_comp_adc") {
test_dac_caller(defs::VB_COMP_ADC, "vb_comp_adc", 0);
}
SECTION("vcom_cds") {
test_dac_caller(defs::VCOM_CDS, "vcom_cds", 1400);
}
SECTION("vref_rstore") {
test_dac_caller(defs::VREF_RSTORE, "vref_rstore", 640);
}
SECTION("vb_opa_1st") {
test_dac_caller(defs::VB_OPA_1ST, "vb_opa_1st", 0);
}
SECTION("vref_comp_fe") {
test_dac_caller(defs::VREF_COMP_FE, "vref_comp_fe", 0);
}
SECTION("vcom_adc1") {
test_dac_caller(defs::VCOM_ADC1, "vcom_adc1", 1400);
}
SECTION("vref_prech") {
test_dac_caller(defs::VREF_PRECH, "vref_prech", 1720);
}
SECTION("vref_l_adc") {
test_dac_caller(defs::VREF_L_ADC, "vref_l_adc", 700);
}
SECTION("vref_cds") {
test_dac_caller(defs::VREF_CDS, "vref_cds", 1200);
}
SECTION("vb_cs") { test_dac_caller(defs::VB_CS, "vb_cs", 2799); }
SECTION("vb_opa_fd") {
test_dac_caller(defs::VB_OPA_FD, "vb_opa_fd", 0);
}
SECTION("vcom_adc2") {
test_dac_caller(defs::VCOM_ADC2, "vcom_adc2", 1400);
}
// eiger
REQUIRE_THROWS(caller.call("dac", {"vthreshold"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vsvp"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vsvn"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vtrim"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vrpreamp"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vrshaper"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vtgstv"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcmp_ll"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcmp_lr"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcal"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcmp_rl"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcmp_rr"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"rxb_rb"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"rxb_lb"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcp"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcn"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vishaper"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"iodelay"}, -1, GET));
// gotthard
REQUIRE_THROWS(caller.call("dac", {"vref_ds"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcascn_pb"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcascp_pb"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vout_cm"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcasc_out"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vin_cm"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vref_comp"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"ib_test_c"}, -1, GET));
// jungfrau
REQUIRE_THROWS(caller.call("dac", {"vb_comp"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vdd_prot"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vin_com"}, -1, GET));
// REQUIRE_THROWS(caller.call("dac", {"vref_prech"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vb_pixbuf"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vb_ds"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vref_ds"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vref_comp"}, -1, GET));
// mythen3
REQUIRE_THROWS(caller.call("dac", {"vrpreamp"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vrshaper"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vrshaper_n"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vipre"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vishaper"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vdcsh"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vth1"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vth2"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vth3"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcal_n"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcal_p"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vtrim"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcassh"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcas"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vicin"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vipre_out"}, -1, GET));
}
}
/* on chip dacs */
TEST_CASE("Caller::vchip_comp_fe", "[.cmdcall][.onchipdacs]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
SECTION("vchip_comp_fe") {
test_onchip_dac_caller(defs::VB_COMP_FE, "vchip_comp_fe", 0x137);
}
} else {
REQUIRE_THROWS(caller.call("vchip_comp_fe", {}, -1, GET));
}
}
TEST_CASE("Caller::vchip_opa_1st", "[.cmdcall][.onchipdacs]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
SECTION("vchip_opa_1st") {
test_onchip_dac_caller(defs::VB_OPA_1ST, "vchip_opa_1st", 0x000);
}
} else {
REQUIRE_THROWS(caller.call("vchip_opa_1st", {}, -1, GET));
}
}
TEST_CASE("Caller::vchip_opa_fd", "[.cmdcall][.onchipdacs]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
SECTION("vchip_opa_fd") {
test_onchip_dac_caller(defs::VB_OPA_FD, "vchip_opa_fd", 0x134);
}
} else {
REQUIRE_THROWS(caller.call("vchip_opa_fd", {}, -1, GET));
}
}
TEST_CASE("Caller::vchip_comp_adc", "[.cmdcall][.onchipdacs]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
SECTION("vchip_comp_adc") {
test_onchip_dac_caller(defs::VB_COMP_ADC, "vchip_comp_adc", 0x3FF);
}
} else {
REQUIRE_THROWS(caller.call("vchip_comp_adc", {}, -1, GET));
}
}
TEST_CASE("Caller::vchip_ref_comp_fe", "[.cmdcall][.onchipdacs]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
SECTION("vchip_ref_comp_fe") {
test_onchip_dac_caller(defs::VREF_COMP_FE, "vchip_ref_comp_fe",
0x100);
}
} else {
REQUIRE_THROWS(caller.call("vchip_ref_comp_fe", {}, -1, GET));
}
}
TEST_CASE("Caller::vchip_cs", "[.cmdcall][.onchipdacs]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
SECTION("vchip_cs") {
test_onchip_dac_caller(defs::VB_CS, "vchip_cs", 0x0D0);
}
} else {
REQUIRE_THROWS(caller.call("vchip_cs", {}, -1, GET));
}
}
/* Gotthard2 Specific */
TEST_CASE("Caller::bursts", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
auto prev_burst =
det.getNumberOfBursts().tsquash("#bursts should be same to test");
auto prev_trigger =
det.getNumberOfFrames().tsquash("#frames should be same to test");
auto prev_frames = det.getNumberOfTriggers().tsquash(
"#triggers should be same to test");
auto prev_timingMode = det.getTimingMode();
auto prev_burstMode = det.getBurstMode();
// changing continuous mode frames and bursts
det.setBurstMode(defs::BURST_INTERNAL);
det.setTimingMode(defs::AUTO_TIMING);
{
std::ostringstream oss;
caller.call("bursts", {"3"}, -1, PUT, oss);
REQUIRE(oss.str() == "bursts 3\n");
}
{
std::ostringstream oss;
caller.call("bursts", {}, -1, GET, oss);
REQUIRE(oss.str() == "bursts 3\n");
}
REQUIRE_THROWS(caller.call("bursts", {"0"}, -1, PUT));
// trigger mode: reg set to 1, but bursts must be same
det.setTimingMode(defs::TRIGGER_EXPOSURE);
{
std::ostringstream oss;
caller.call("bursts", {}, -1, GET, oss);
REQUIRE(oss.str() == "bursts 3\n");
}
det.setTimingMode(defs::AUTO_TIMING);
{
std::ostringstream oss;
caller.call("bursts", {}, -1, GET, oss);
REQUIRE(oss.str() == "bursts 3\n");
}
// continuous mode: reg set to #frames,
// but bursts should return same value
det.setBurstMode(defs::CONTINUOUS_INTERNAL);
det.setNumberOfFrames(2);
{
std::ostringstream oss;
caller.call("bursts", {}, -1, GET, oss);
REQUIRE(oss.str() == "bursts 3\n");
}
det.setTimingMode(defs::TRIGGER_EXPOSURE);
{
std::ostringstream oss;
caller.call("bursts", {}, -1, GET, oss);
REQUIRE(oss.str() == "bursts 3\n");
}
det.setBurstMode(defs::BURST_INTERNAL);
{
std::ostringstream oss;
caller.call("bursts", {}, -1, GET, oss);
REQUIRE(oss.str() == "bursts 3\n");
}
// set to previous values
det.setNumberOfBursts(prev_burst);
det.setNumberOfFrames(prev_frames);
det.setNumberOfTriggers(prev_trigger);
for (int i = 0; i != det.size(); ++i) {
det.setTimingMode(prev_timingMode[i], {i});
det.setBurstMode(prev_burstMode[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("bursts", {}, -1, GET));
}
}
TEST_CASE("Caller::burstperiod", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
auto previous = det.getBurstPeriod();
std::ostringstream oss_set, oss_get;
caller.call("burstperiod", {"30ms"}, -1, PUT, oss_set);
REQUIRE(oss_set.str() == "burstperiod 30ms\n");
caller.call("burstperiod", {}, -1, GET, oss_get);
REQUIRE(oss_get.str() == "burstperiod 30ms\n");
// Reset to previous value
for (int i = 0; i != det.size(); ++i) {
det.setBurstPeriod(previous[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("burstperiod", {}, -1, GET));
}
}
TEST_CASE("Caller::burstsl", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
REQUIRE_NOTHROW(caller.call("burstsl", {}, -1, GET));
} else {
REQUIRE_THROWS(caller.call("burstsl", {}, -1, GET));
}
}
TEST_CASE("Caller::inj_ch", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
REQUIRE_THROWS(
caller.call("inj_ch", {"-1", "1"}, -1, PUT)); // invalid offset
REQUIRE_THROWS(
caller.call("inj_ch", {"0", "0"}, -1, PUT)); // invalid increment
{
std::ostringstream oss;
caller.call("inj_ch", {"0", "1"}, -1, PUT, oss);
REQUIRE(oss.str() == "inj_ch [0, 1]\n");
}
{
std::ostringstream oss;
caller.call("inj_ch", {}, -1, GET, oss);
REQUIRE(oss.str() == "inj_ch [0, 1]\n");
}
} else {
REQUIRE_THROWS(caller.call("inj_ch", {}, -1, GET));
}
}
TEST_CASE("Caller::vetophoton", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
REQUIRE_THROWS(caller.call("vetophoton", {}, -1, GET));
REQUIRE_THROWS(caller.call("vetophoton", {"-1"}, -1, GET));
REQUIRE_NOTHROW(
caller.call("vetophoton", {"-1", "/tmp/bla.txt"}, -1, GET));
REQUIRE_THROWS(caller.call("vetophoton", {"12", "1", "39950"}, -1,
PUT)); // invalid chip index
REQUIRE_THROWS(caller.call("vetophoton", {"-1", "0"}, -1,
PUT)); // invalid photon number
REQUIRE_THROWS(caller.call("vetophoton", {"-1", "1", "39950"}, -1,
PUT)); // invald file
} else {
REQUIRE_THROWS(
caller.call("vetophoton", {"-1", "/tmp/bla.txt"}, -1, GET));
}
}
TEST_CASE("Caller::vetoref", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
REQUIRE_THROWS(caller.call("vetoref", {}, -1, GET));
REQUIRE_THROWS(caller.call("vetoref", {"3", "0x3ff"}, -1,
PUT)); // invalid chip index
REQUIRE_NOTHROW(caller.call("vetoref", {"1", "0x010"}, -1, PUT));
} else {
REQUIRE_THROWS(caller.call("vetoref", {"3", "0x0"}, -1, PUT));
}
}
TEST_CASE("Caller::vetofile", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
REQUIRE_THROWS(caller.call("vetofile", {}, -1, GET));
REQUIRE_THROWS(caller.call("vetofile", {"12", "/tmp/bla.txt"}, -1,
PUT)); // invalid chip index
} else {
REQUIRE_THROWS(caller.call("vetofile", {"-1"}, -1, GET));
}
}
TEST_CASE("Caller::burstmode", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
auto burst = det.getBurstMode();
auto burststr = ToString(burst);
{
std::ostringstream oss;
caller.call("burstmode", {"burst_internal"}, -1, PUT, oss);
REQUIRE(oss.str() == "burstmode burst_internal\n");
}
{
std::ostringstream oss;
caller.call("burstmode", {"cw_internal"}, -1, PUT, oss);
REQUIRE(oss.str() == "burstmode cw_internal\n");
}
{
std::ostringstream oss;
caller.call("burstmode", {}, -1, GET, oss);
REQUIRE(oss.str() == "burstmode cw_internal\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setBurstMode(burst[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("burstmode", {}, -1, GET));
}
}
TEST_CASE("Caller::cdsgain", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
auto prev_val = det.getCDSGain();
{
std::ostringstream oss;
caller.call("cdsgain", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "cdsgain 1\n");
}
{
std::ostringstream oss;
caller.call("cdsgain", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "cdsgain 0\n");
}
{
std::ostringstream oss;
caller.call("cdsgain", {}, -1, GET, oss);
REQUIRE(oss.str() == "cdsgain 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setCDSGain(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("cdsgain", {}, -1, GET));
}
}
TEST_CASE("Caller::timingsource", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
auto prev_val = det.getTimingSource();
/* { until its activated in fpga
std::ostringstream oss;
caller.call("timingsource", {"external"}, -1, PUT, oss);
REQUIRE(oss.str() == "timingsource external\n");
}*/
{
std::ostringstream oss;
caller.call("timingsource", {"internal"}, -1, PUT, oss);
REQUIRE(oss.str() == "timingsource internal\n");
}
{
std::ostringstream oss;
caller.call("timingsource", {}, -1, GET, oss);
REQUIRE(oss.str() == "timingsource internal\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setTimingSource(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("timingsource", {}, -1, GET));
}
}
TEST_CASE("Caller::veto", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
auto prev_val = det.getVeto();
{
std::ostringstream oss;
caller.call("veto", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "veto 1\n");
}
{
std::ostringstream oss;
caller.call("veto", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "veto 0\n");
}
{
std::ostringstream oss;
caller.call("veto", {}, -1, GET, oss);
REQUIRE(oss.str() == "veto 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setVeto(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("veto", {}, -1, GET));
}
}
TEST_CASE("Caller::vetostream", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
auto prev_val =
det.getVetoStream().tsquash("inconsistent veto stream to test");
{
std::ostringstream oss;
caller.call("vetostream", {"none"}, -1, PUT, oss);
REQUIRE(oss.str() == "vetostream none\n");
}
{
std::ostringstream oss;
caller.call("vetostream", {}, -1, GET, oss);
REQUIRE(oss.str() == "vetostream none\n");
}
{
std::ostringstream oss;
caller.call("vetostream", {"lll"}, -1, PUT, oss);
REQUIRE(oss.str() == "vetostream lll\n");
}
{
std::ostringstream oss;
caller.call("vetostream", {}, -1, GET, oss);
REQUIRE(oss.str() == "vetostream lll\n");
}
{
std::ostringstream oss;
caller.call("vetostream", {"lll", "10gbe"}, -1, PUT, oss);
REQUIRE(oss.str() == "vetostream lll, 10gbe\n");
}
{
std::ostringstream oss;
caller.call("vetostream", {}, -1, GET, oss);
REQUIRE(oss.str() == "vetostream lll, 10gbe\n");
}
REQUIRE_THROWS(caller.call("vetostream", {"lll", "none"}, -1, PUT));
det.setVetoStream(prev_val);
} else {
REQUIRE_THROWS(caller.call("vetostream", {}, -1, GET));
REQUIRE_THROWS(caller.call("vetostream", {"none"}, -1, PUT));
}
REQUIRE_THROWS(caller.call("vetostream", {"dfgd"}, -1, GET));
}
TEST_CASE("Caller::vetoalg", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
auto prev_val_lll =
det.getVetoAlgorithm(defs::streamingInterface::LOW_LATENCY_LINK);
auto prev_val_10g =
det.getVetoAlgorithm(defs::streamingInterface::ETHERNET_10GB);
{
std::ostringstream oss;
caller.call("vetoalg", {"hits", "lll"}, -1, PUT, oss);
REQUIRE(oss.str() == "vetoalg hits lll\n");
}
{
std::ostringstream oss;
caller.call("vetoalg", {"lll"}, -1, GET, oss);
REQUIRE(oss.str() == "vetoalg hits lll\n");
}
{
std::ostringstream oss;
caller.call("vetoalg", {"hits", "10gbe"}, -1, PUT, oss);
REQUIRE(oss.str() == "vetoalg hits 10gbe\n");
}
{
std::ostringstream oss;
caller.call("vetoalg", {"10gbe"}, -1, GET, oss);
REQUIRE(oss.str() == "vetoalg hits 10gbe\n");
}
{
std::ostringstream oss;
caller.call("vetoalg", {"raw", "lll"}, -1, PUT, oss);
REQUIRE(oss.str() == "vetoalg raw lll\n");
}
{
std::ostringstream oss;
caller.call("vetoalg", {"raw", "10gbe"}, -1, PUT, oss);
REQUIRE(oss.str() == "vetoalg raw 10gbe\n");
}
REQUIRE_THROWS(
caller.call("vetoalg", {"default", "lll", "10gbe"}, -1, PUT));
REQUIRE_THROWS(caller.call("vetoalg", {"hits", "none"}, -1, PUT));
for (int i = 0; i != det.size(); ++i) {
det.setVetoAlgorithm(prev_val_lll[i],
defs::streamingInterface::LOW_LATENCY_LINK,
{i});
det.setVetoAlgorithm(prev_val_10g[i],
defs::streamingInterface::ETHERNET_10GB, {i});
}
} else {
REQUIRE_THROWS(caller.call("vetoalg", {"lll"}, -1, GET));
REQUIRE_THROWS(caller.call("vetoalg", {"none"}, -1, PUT));
}
REQUIRE_THROWS(caller.call("vetoalg", {"dfgd"}, -1, GET));
}
TEST_CASE("Caller::confadc", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
const int ndet = det.size();
const int nchip = 10;
const int nadc = 32;
std::vector<std::vector<std::vector<int>>> prev_val(
ndet, std::vector<std::vector<int>>(nchip, std::vector<int>(nadc)));
for (int i = 0; i != ndet; ++i) {
for (int j = 0; j != nchip; ++j) {
for (int k = 0; k != nadc; ++k) {
prev_val[i][j][k] =
det.getADCConfiguration(j, k, {i}).squash();
}
}
}
REQUIRE_THROWS(caller.call("confadc", {"11", "2", "0x7f"}, -1,
PUT)); // invalid chip index
REQUIRE_THROWS(caller.call("confadc", {"-1", "32", "0x7f"}, -1,
PUT)); // invalid adc index
REQUIRE_THROWS(caller.call("confadc", {"-1", "10", "0x80"}, -1,
PUT)); // invalid value
{
std::ostringstream oss;
caller.call("confadc", {"-1", "-1", "0x11"}, -1, PUT, oss);
REQUIRE(oss.str() == "confadc [-1, -1, 0x11]\n");
}
{
std::ostringstream oss;
caller.call("confadc", {"2", "3"}, -1, GET, oss);
REQUIRE(oss.str() == "confadc 0x11\n");
}
for (int i = 0; i != ndet; ++i) {
for (int j = 0; j != nchip; ++j) {
for (int k = 0; k != nadc; ++k) {
det.setADCConfiguration(-1, k, prev_val[i][j][k], {i});
}
}
}
} else {
REQUIRE_THROWS(caller.call("confadc", {}, -1, GET));
}
}
} // namespace sls

View File

@@ -0,0 +1,749 @@
// 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/sls_detector_defs.h"
#include <sstream>
#include "sls/versionAPI.h"
#include "test-Caller-global.h"
#include "tests/globals.h"
namespace sls {
using test::GET;
using test::PUT;
/* dacs */
TEST_CASE("Caller::Setting and reading back Jungfrau dacs",
"[.cmdcall][.dacs]") {
// vb_comp, vdd_prot, vin_com, vref_prech, vb_pixbuf, vb_ds, vref_ds,
// vref_comp
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
SECTION("vb_comp") { test_dac_caller(defs::VB_COMP, "vb_comp", 1220); }
SECTION("vdd_prot") {
test_dac_caller(defs::VDD_PROT, "vdd_prot", 3000);
}
SECTION("vin_com") { test_dac_caller(defs::VIN_COM, "vin_com", 1053); }
SECTION("vref_prech") {
test_dac_caller(defs::VREF_PRECH, "vref_prech", 1450);
}
SECTION("vb_pixbuf") {
test_dac_caller(defs::VB_PIXBUF, "vb_pixbuf", 750);
}
SECTION("vb_ds") { test_dac_caller(defs::VB_DS, "vb_ds", 1000); }
SECTION("vref_ds") { test_dac_caller(defs::VREF_DS, "vref_ds", 480); }
SECTION("vref_comp") {
test_dac_caller(defs::VREF_COMP, "vref_comp", 420);
}
// eiger
REQUIRE_THROWS(caller.call("vthreshold", {}, -1, GET));
REQUIRE_THROWS(caller.call("vsvp", {}, -1, GET));
REQUIRE_THROWS(caller.call("vsvn", {}, -1, GET));
REQUIRE_THROWS(caller.call("vtrim", {}, -1, GET));
REQUIRE_THROWS(caller.call("vrpreamp", {}, -1, GET));
REQUIRE_THROWS(caller.call("vrshaper", {}, -1, GET));
REQUIRE_THROWS(caller.call("vtgstv", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcmp_ll", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcmp_lr", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcal", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcmp_rl", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcmp_rr", {}, -1, GET));
REQUIRE_THROWS(caller.call("rxb_rb", {}, -1, GET));
REQUIRE_THROWS(caller.call("rxb_lb", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcp", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcn", {}, -1, GET));
REQUIRE_THROWS(caller.call("vishaper", {}, -1, GET));
REQUIRE_THROWS(caller.call("iodelay", {}, -1, GET));
// gotthard
// REQUIRE_THROWS(caller.call("vref_ds", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcascn_pb", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcascp_pb", {}, -1, GET));
REQUIRE_THROWS(caller.call("vout_cm", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcasc_out", {}, -1, GET));
REQUIRE_THROWS(caller.call("vin_cm", {}, -1, GET));
// REQUIRE_THROWS(caller.call("vref_comp", {}, -1, GET));
REQUIRE_THROWS(caller.call("ib_test_c", {}, -1, GET));
// mythen3
REQUIRE_THROWS(caller.call("vrpreamp", {}, -1, GET));
REQUIRE_THROWS(caller.call("vrshaper", {}, -1, GET));
REQUIRE_THROWS(caller.call("vrshaper_n", {}, -1, GET));
REQUIRE_THROWS(caller.call("vipre", {}, -1, GET));
REQUIRE_THROWS(caller.call("vishaper", {}, -1, GET));
REQUIRE_THROWS(caller.call("vdcsh", {}, -1, GET));
REQUIRE_THROWS(caller.call("vth1", {}, -1, GET));
REQUIRE_THROWS(caller.call("vth2", {}, -1, GET));
REQUIRE_THROWS(caller.call("vth3", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcal_n", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcal_p", {}, -1, GET));
REQUIRE_THROWS(caller.call("vtrim", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcassh", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcas", {}, -1, GET));
REQUIRE_THROWS(caller.call("vicin", {}, -1, GET));
REQUIRE_THROWS(caller.call("vipre_out", {}, -1, GET));
// gotthard2
REQUIRE_THROWS(caller.call("vref_h_adc", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_comp_fe", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_comp_adc", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcom_cds", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_rstore", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_opa_1st", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_comp_fe", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcom_adc1", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_l_adc", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_cds", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_cs", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_opa_fd", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcom_adc2", {}, -1, GET));
}
}
/* Network Configuration (Detector<->Receiver) */
TEST_CASE("Caller::selinterface", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) {
auto prev_val = det.getSelectedUDPInterface().tsquash(
"inconsistent selected interface to test");
{
std::ostringstream oss;
caller.call("selinterface", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "selinterface 1\n");
}
{
std::ostringstream oss;
caller.call("selinterface", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "selinterface 0\n");
}
{
std::ostringstream oss;
caller.call("selinterface", {}, -1, GET, oss);
REQUIRE(oss.str() == "selinterface 0\n");
}
det.selectUDPInterface(prev_val);
REQUIRE_THROWS(caller.call("selinterface", {"2"}, -1, PUT));
} else {
REQUIRE_THROWS(caller.call("selinterface", {}, -1, GET));
}
}
/* Jungfrau/moench Specific */
TEST_CASE("Caller::temp_threshold", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) {
auto prev_val = det.getThresholdTemperature();
{
std::ostringstream oss;
caller.call("temp_threshold", {"65"}, -1, PUT, oss);
REQUIRE(oss.str() == "temp_threshold 65\n");
}
{
std::ostringstream oss;
caller.call("temp_threshold", {"70"}, -1, PUT, oss);
REQUIRE(oss.str() == "temp_threshold 70\n");
}
{
std::ostringstream oss;
caller.call("temp_threshold", {}, -1, GET, oss);
REQUIRE(oss.str() == "temp_threshold 70\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setThresholdTemperature(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("temp_threshold", {}, -1, GET));
REQUIRE_THROWS(caller.call("temp_threshold", {"70"}, -1, PUT));
}
}
TEST_CASE("Caller::chipversion", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
REQUIRE_NOTHROW(caller.call("chipversion", {}, -1, GET));
} else {
REQUIRE_THROWS(caller.call("chipversion", {}, -1, GET));
}
REQUIRE_THROWS(caller.call("chipversion", {"0"}, -1, PUT));
}
TEST_CASE("Caller::temp_control", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) {
auto prev_val = det.getTemperatureControl();
{
std::ostringstream oss;
caller.call("temp_control", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "temp_control 0\n");
}
{
std::ostringstream oss;
caller.call("temp_control", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "temp_control 1\n");
}
{
std::ostringstream oss;
caller.call("temp_control", {}, -1, GET, oss);
REQUIRE(oss.str() == "temp_control 1\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setTemperatureControl(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("temp_control", {}, -1, GET));
REQUIRE_THROWS(caller.call("temp_control", {"0"}, -1, PUT));
}
}
TEST_CASE("Caller::temp_event", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) {
{
std::ostringstream oss;
caller.call("temp_event", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "temp_event cleared\n");
}
{
std::ostringstream oss;
caller.call("temp_event", {}, -1, GET, oss);
REQUIRE(oss.str() == "temp_event 0\n");
}
} else {
REQUIRE_THROWS(caller.call("temp_event", {}, -1, GET));
REQUIRE_THROWS(caller.call("temp_event", {"0"}, -1, PUT));
}
}
TEST_CASE("Caller::autocompdisable", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
auto prev_val = det.getAutoComparatorDisable();
{
std::ostringstream oss;
caller.call("autocompdisable", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "autocompdisable 0\n");
}
{
std::ostringstream oss;
caller.call("autocompdisable", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "autocompdisable 1\n");
}
{
std::ostringstream oss;
caller.call("autocompdisable", {}, -1, GET, oss);
REQUIRE(oss.str() == "autocompdisable 1\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setAutoComparatorDisable(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("autocompdisable", {}, -1, GET));
REQUIRE_THROWS(caller.call("autocompdisable", {"0"}, -1, PUT));
}
}
TEST_CASE("Caller::compdisabletime", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU &&
det.getChipVersion().squash() * 10 == 11) {
auto prev_val = det.getComparatorDisableTime();
{
std::ostringstream oss;
caller.call("compdisabletime", {"125ns"}, -1, PUT, oss);
REQUIRE(oss.str() == "compdisabletime 125ns\n");
}
{
std::ostringstream oss;
caller.call("compdisabletime", {}, -1, GET, oss);
REQUIRE(oss.str() == "compdisabletime 125ns\n");
}
{
std::ostringstream oss;
caller.call("compdisabletime", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "compdisabletime 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setComparatorDisableTime(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("compdisabletime", {}, -1, GET));
REQUIRE_THROWS(caller.call("compdisabletime", {"0"}, -1, PUT));
}
}
TEST_CASE("Caller::extrastoragecells", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
// chip version 1.0
if (det.getChipVersion().squash() * 10 == 10) {
auto prev_val = det.getNumberOfAdditionalStorageCells().tsquash(
"inconsistent #additional storage cells to test");
{
std::ostringstream oss;
caller.call("extrastoragecells", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "extrastoragecells 1\n");
}
{
std::ostringstream oss;
caller.call("extrastoragecells", {"15"}, -1, PUT, oss);
REQUIRE(oss.str() == "extrastoragecells 15\n");
}
{
std::ostringstream oss;
caller.call("extrastoragecells", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "extrastoragecells 0\n");
}
{
std::ostringstream oss;
caller.call("extrastoragecells", {}, -1, GET, oss);
REQUIRE(oss.str() == "extrastoragecells 0\n");
}
REQUIRE_THROWS(caller.call("extrastoragecells", {"16"}, -1, PUT));
det.setNumberOfAdditionalStorageCells(prev_val);
}
// chip version 1.1
else {
// cannot set number of addl. storage cells
REQUIRE_THROWS(caller.call("extrastoragecells", {"1"}, -1, PUT));
}
} else {
REQUIRE_THROWS(caller.call("extrastoragecells", {}, -1, GET));
REQUIRE_THROWS(caller.call("extrastoragecells", {"0"}, -1, PUT));
}
}
TEST_CASE("Caller::storagecell_start", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
auto prev_val = det.getStorageCellStart();
{
std::ostringstream oss;
caller.call("storagecell_start", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "storagecell_start 1\n");
}
// chip version 1.0
if (det.getChipVersion().squash() * 10 == 10) {
std::ostringstream oss;
caller.call("storagecell_start", {"15"}, -1, PUT, oss);
REQUIRE(oss.str() == "storagecell_start 15\n");
}
// chip version 1.1
else {
// max is 3
REQUIRE_THROWS(caller.call("storagecell_start", {"15"}, -1, PUT));
std::ostringstream oss;
caller.call("storagecell_start", {"3"}, -1, PUT, oss);
REQUIRE(oss.str() == "storagecell_start 3\n");
}
{
std::ostringstream oss;
caller.call("storagecell_start", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "storagecell_start 0\n");
}
{
std::ostringstream oss;
caller.call("storagecell_start", {}, -1, GET, oss);
REQUIRE(oss.str() == "storagecell_start 0\n");
}
REQUIRE_THROWS(caller.call("storagecell_start", {"16"}, -1, PUT));
for (int i = 0; i != det.size(); ++i) {
det.setStorageCellStart(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("storagecell_start", {}, -1, GET));
REQUIRE_THROWS(caller.call("storagecell_start", {"0"}, -1, PUT));
}
}
TEST_CASE("Caller::storagecell_delay", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
// chip version 1.0
if (det.getChipVersion().squash() * 10 == 10) {
auto prev_val = det.getStorageCellDelay();
{
std::ostringstream oss;
caller.call("storagecell_delay", {"1.62ms"}, -1, PUT, oss);
REQUIRE(oss.str() == "storagecell_delay 1.62ms\n");
}
{
std::ostringstream oss;
caller.call("storagecell_delay", {}, -1, GET, oss);
REQUIRE(oss.str() == "storagecell_delay 1.62ms\n");
}
{
std::ostringstream oss;
caller.call("storagecell_delay", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "storagecell_delay 0\n");
}
REQUIRE_THROWS(
caller.call("storagecell_delay", {"1638376ns"}, -1, PUT));
for (int i = 0; i != det.size(); ++i) {
det.setStorageCellDelay(prev_val[i], {i});
}
}
// chip version 1.1
else {
// cannot set storage cell delay
REQUIRE_THROWS(
caller.call("storagecell_delay", {"1.62ms"}, -1, PUT));
}
} else {
REQUIRE_THROWS(caller.call("storagecell_delay", {}, -1, GET));
REQUIRE_THROWS(caller.call("storagecell_delay", {"0"}, -1, PUT));
}
}
TEST_CASE("Caller::gainmode", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
auto prev_val = det.getGainMode();
{
std::ostringstream oss;
caller.call("gainmode", {"forceswitchg1"}, -1, PUT, oss);
REQUIRE(oss.str() == "gainmode forceswitchg1\n");
}
{
std::ostringstream oss;
caller.call("gainmode", {}, -1, GET, oss);
REQUIRE(oss.str() == "gainmode forceswitchg1\n");
}
{
std::ostringstream oss;
caller.call("gainmode", {"dynamic"}, -1, PUT, oss);
REQUIRE(oss.str() == "gainmode dynamic\n");
}
{
std::ostringstream oss;
caller.call("gainmode", {"forceswitchg2"}, -1, PUT, oss);
REQUIRE(oss.str() == "gainmode forceswitchg2\n");
}
{
std::ostringstream oss;
caller.call("gainmode", {"fixg1"}, -1, PUT, oss);
REQUIRE(oss.str() == "gainmode fixg1\n");
}
{
std::ostringstream oss;
caller.call("gainmode", {"fixg2"}, -1, PUT, oss);
REQUIRE(oss.str() == "gainmode fixg2\n");
}
{
std::ostringstream oss;
caller.call("gainmode", {"fixg0"}, -1, PUT, oss);
REQUIRE(oss.str() == "gainmode fixg0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setGainMode(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("gainmode", {}, -1, GET));
}
}
TEST_CASE("Caller::filtercells", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
// chip version 1.1
if (det.getChipVersion().squash() * 10 == 11) {
auto prev_val = det.getNumberOfFilterCells();
{
std::ostringstream oss;
caller.call("filtercells", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "filtercells 1\n");
}
{
std::ostringstream oss;
caller.call("filtercells", {"12"}, -1, PUT, oss);
REQUIRE(oss.str() == "filtercells 12\n");
}
{
std::ostringstream oss;
caller.call("filtercells", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "filtercells 0\n");
}
{
std::ostringstream oss;
caller.call("filtercells", {}, -1, GET, oss);
REQUIRE(oss.str() == "filtercells 0\n");
}
REQUIRE_THROWS(caller.call("filtercells", {"13"}, -1, PUT));
for (int i = 0; i != det.size(); ++i) {
det.setNumberOfFilterCells(prev_val[i], {i});
}
}
// chip version 1.0
else {
// cannot set/get filter cell
REQUIRE_THROWS(caller.call("filtercells", {"1"}, -1, PUT));
REQUIRE_THROWS(caller.call("filtercells", {}, -1, GET));
}
} else {
REQUIRE_THROWS(caller.call("filtercells", {}, -1, GET));
REQUIRE_THROWS(caller.call("filtercells", {"0"}, -1, PUT));
}
}
TEST_CASE("Caller::pedestalmode", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
auto prev_val = det.getPedestalMode();
auto prev_frames = det.getNumberOfFrames().tsquash(
"Inconsistent number of frames to test");
auto prev_triggers = det.getNumberOfTriggers().tsquash(
"Inconsistent number of triggers to test");
auto prev_timingmode =
det.getTimingMode().tsquash("Inconsistent timing mode to test");
REQUIRE_NOTHROW(caller.call("pedestalmode", {}, 0, GET));
REQUIRE_NOTHROW(caller.call("pedestalmode", {}, -1, GET));
REQUIRE_THROWS(caller.call("pedestalmode", {"0"}, -1, GET));
REQUIRE_THROWS(caller.call("pedestalmode", {"256", "10"}, -1, PUT));
REQUIRE_THROWS(caller.call("pedestalmode", {"-1", "10"}, 0, PUT));
REQUIRE_THROWS(caller.call("pedestalmode", {"20", "65536"}, 0, PUT));
REQUIRE_THROWS(caller.call("pedestalmode", {"20", "-1"}, 0, PUT));
{
std::ostringstream oss;
caller.call("pedestalmode", {"30", "1000"}, -1, PUT, oss);
REQUIRE(oss.str() == "pedestalmode [30, 1000]\n");
}
// cannot change any of these in pedestal mode
REQUIRE_THROWS_WITH(caller.call("frames", {"200"}, -1, PUT),
"Detector returned: Cannot set frames in pedestal "
"mode. It is overwritten anyway.\n");
REQUIRE_THROWS_WITH(caller.call("triggers", {"200"}, -1, PUT),
"Detector returned: Cannot set triggers in "
"pedestal mode. It is overwritten anyway.\n");
REQUIRE_THROWS_WITH(
caller.call("timing", {"auto"}, -1, PUT),
"Detector returned: Cannot set timing mode in pedestal mode. "
"Switch off pedestal mode to change timing mode.\n");
REQUIRE_THROWS_WITH(
caller.call("scan", {"vb_comp", "500", "1500", "10"}, -1, PUT),
"Detector returned: Cannot set scan when in pedestal mode.\n");
REQUIRE_THROWS_WITH(
caller.call("scan", {"0"}, -1, PUT),
"Detector returned: Cannot set scan when in pedestal mode.\n");
// should not throw to get these values though
REQUIRE_NOTHROW(caller.call("frames", {}, -1, GET));
REQUIRE_NOTHROW(caller.call("triggers", {}, -1, GET));
REQUIRE_NOTHROW(caller.call("timing", {}, -1, GET));
REQUIRE_NOTHROW(caller.call("scan", {}, -1, GET));
{
std::ostringstream oss;
caller.call("pedestalmode", {"50", "500"}, -1, PUT, oss);
REQUIRE(oss.str() == "pedestalmode [50, 500]\n");
}
{
std::ostringstream oss;
caller.call("pedestalmode", {}, -1, GET, oss);
REQUIRE(oss.str() == "pedestalmode [enabled, 50, 500]\n");
}
{
auto pedemode = det.getPedestalMode().tsquash(
"Inconsistent pedestal mode to test");
REQUIRE(pedemode.enable == true);
REQUIRE(pedemode.frames == 50);
REQUIRE(pedemode.loops == 500);
}
{
std::ostringstream oss;
caller.call("pedestalmode", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "pedestalmode [0]\n");
}
{
std::ostringstream oss;
caller.call("pedestalmode", {}, -1, GET, oss);
REQUIRE(oss.str() == "pedestalmode [disabled]\n");
}
uint8_t pedestalFrames = 50;
uint16_t pedestalLoops = 1000;
int64_t expNumFrames = pedestalFrames * pedestalLoops * 2;
auto origFrames = det.getNumberOfFrames().squash(-1);
auto origTriggers = det.getNumberOfTriggers().squash(-1);
// auto mode
det.setTimingMode(defs::AUTO_TIMING);
REQUIRE_NOTHROW(caller.call(
"pedestalmode",
{std::to_string(pedestalFrames), std::to_string(pedestalLoops)}, -1,
PUT));
auto numTriggers = det.getNumberOfTriggers().squash(-1);
auto numFrames = det.getNumberOfFrames().squash(-1);
REQUIRE(numFrames == expNumFrames);
REQUIRE(numTriggers == 1);
// pedestal mode off
REQUIRE_NOTHROW(caller.call("pedestalmode", {"0"}, -1, PUT));
numTriggers = det.getNumberOfTriggers().squash(-1);
numFrames = det.getNumberOfFrames().squash(-1);
REQUIRE(numFrames == origFrames);
REQUIRE(numTriggers == origTriggers);
// trigger mode (frames > 1)
REQUIRE_NOTHROW(det.setTimingMode(defs::TRIGGER_EXPOSURE));
origFrames = 5;
REQUIRE_NOTHROW(det.setNumberOfFrames(origFrames));
REQUIRE_NOTHROW(caller.call(
"pedestalmode",
{std::to_string(pedestalFrames), std::to_string(pedestalLoops)}, -1,
PUT));
numTriggers = det.getNumberOfTriggers().squash(-1);
numFrames = det.getNumberOfFrames().squash(-1);
REQUIRE(numFrames == expNumFrames);
REQUIRE(numTriggers == 1);
// pedestal mode off
REQUIRE_NOTHROW(caller.call("pedestalmode", {"0"}, -1, PUT));
numTriggers = det.getNumberOfTriggers().squash(-1);
numFrames = det.getNumberOfFrames().squash(-1);
REQUIRE(numFrames == origFrames);
REQUIRE(numTriggers == origTriggers);
// trigger mode (frames = 1)
origFrames = 1;
REQUIRE_NOTHROW(det.setNumberOfFrames(origFrames));
origTriggers = 10;
REQUIRE_NOTHROW(det.setNumberOfTriggers(origTriggers));
REQUIRE_NOTHROW(caller.call(
"pedestalmode",
{std::to_string(pedestalFrames), std::to_string(pedestalLoops)}, -1,
PUT));
numTriggers = det.getNumberOfTriggers().squash(-1);
numFrames = det.getNumberOfFrames().squash(-1);
REQUIRE(numFrames == 1);
REQUIRE(numTriggers == expNumFrames);
// pedestal mode off
REQUIRE_NOTHROW(caller.call("pedestalmode", {"0"}, -1, PUT));
numTriggers = det.getNumberOfTriggers().squash(-1);
numFrames = det.getNumberOfFrames().squash(-1);
REQUIRE(numFrames == origFrames);
REQUIRE(numTriggers == origTriggers);
det.setNumberOfFrames(prev_frames);
det.setNumberOfTriggers(prev_triggers);
det.setTimingMode(prev_timingmode);
for (int i = 0; i != det.size(); ++i) {
det.setPedestalMode(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("pedestalmode", {}, -1, GET));
REQUIRE_THROWS(caller.call("pedestalmode", {"0"}, -1, PUT));
}
}
TEST_CASE("Caller::sync", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) {
auto prev_val = det.getSynchronization().tsquash(
"inconsistent synchronization to test");
{
std::ostringstream oss;
caller.call("sync", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "sync 0\n");
}
{
std::ostringstream oss;
caller.call("sync", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "sync 1\n");
}
// setting to master or slave when synced
{
// get previous master
int prevMaster = 0;
auto previous = det.getMaster();
for (int i = 0; i != det.size(); ++i) {
if (previous[i] == 1) {
prevMaster = i;
break;
}
}
caller.call("master", {"1"}, 0, PUT);
caller.call("master", {"0"}, 0, PUT);
std::ostringstream oss;
caller.call("status", {}, -1, GET, oss);
REQUIRE(oss.str() != "status running\n");
// set all to slaves, and then master
for (int i = 0; i != det.size(); ++i) {
det.setMaster(0, {i});
}
det.setMaster(1, prevMaster);
}
{
std::ostringstream oss;
caller.call("sync", {}, -1, GET, oss);
REQUIRE(oss.str() == "sync 1\n");
}
// setting sync when running
{
auto prev_timing =
det.getTimingMode().tsquash("inconsistent timing mode in test");
auto prev_frames =
det.getNumberOfFrames().tsquash("inconsistent #frames in test");
auto prev_exptime =
det.getExptime().tsquash("inconsistent exptime in test");
auto prev_period =
det.getPeriod().tsquash("inconsistent period in test");
det.setTimingMode(defs::AUTO_TIMING);
det.setNumberOfFrames(10000);
det.setExptime(std::chrono::microseconds(200));
det.setPeriod(std::chrono::milliseconds(1000));
det.setSynchronization(1);
det.startDetector();
REQUIRE_THROWS(caller.call("sync", {"0"}, -1, PUT));
{
std::ostringstream oss;
caller.call("sync", {}, -1, GET, oss);
REQUIRE(oss.str() == "sync 1\n");
}
det.stopDetector();
det.setTimingMode(prev_timing);
det.setNumberOfFrames(prev_frames);
det.setExptime(prev_exptime);
det.setPeriod(prev_period);
}
det.setSynchronization(prev_val);
} else {
REQUIRE_THROWS(caller.call("sync", {}, -1, GET));
REQUIRE_THROWS(caller.call("sync", {"0"}, -1, PUT));
}
}
} // namespace sls

View File

@@ -0,0 +1,114 @@
// 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/sls_detector_defs.h"
#include <sstream>
#include "sls/versionAPI.h"
#include "test-Caller-global.h"
#include "tests/globals.h"
namespace sls {
using test::GET;
using test::PUT;
/* dacs */
TEST_CASE("Caller::Setting and reading back moench dacs", "[.cmdcall][.dacs]") {
// vbp_colbuf, vipre, vin_cm, vb_sda, vcasc_sfp, vout_cm, vipre_cds,
// ibias_sfp
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::MOENCH) {
SECTION("vbp_colbuf") {
test_dac_caller(defs::VBP_COLBUF, "vbp_colbuf", 1300);
}
SECTION("vipre") { test_dac_caller(defs::VIPRE, "vipre", 1000); }
SECTION("vin_cm") { test_dac_caller(defs::VIN_CM, "vin_cm", 1400); }
SECTION("vb_sda") { test_dac_caller(defs::VB_SDA, "vb_sda", 680); }
SECTION("vcasc_sfp") {
test_dac_caller(defs::VCASC_SFP, "vcasc_sfp", 1428);
}
SECTION("vout_cm") { test_dac_caller(defs::VOUT_CM, "vout_cm", 1200); }
SECTION("vipre_cds") {
test_dac_caller(defs::VIPRE_CDS, "vipre_cds", 800);
}
SECTION("ibias_sfp") {
test_dac_caller(defs::IBIAS_SFP, "ibias_sfp", 900);
}
// eiger
REQUIRE_THROWS(caller.call("vthreshold", {}, -1, GET));
REQUIRE_THROWS(caller.call("vsvp", {}, -1, GET));
REQUIRE_THROWS(caller.call("vsvn", {}, -1, GET));
REQUIRE_THROWS(caller.call("vtrim", {}, -1, GET));
REQUIRE_THROWS(caller.call("vrpreamp", {}, -1, GET));
REQUIRE_THROWS(caller.call("vrshaper", {}, -1, GET));
REQUIRE_THROWS(caller.call("vtgstv", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcmp_ll", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcmp_lr", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcal", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcmp_rl", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcmp_rr", {}, -1, GET));
REQUIRE_THROWS(caller.call("rxb_rb", {}, -1, GET));
REQUIRE_THROWS(caller.call("rxb_lb", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcp", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcn", {}, -1, GET));
REQUIRE_THROWS(caller.call("vishaper", {}, -1, GET));
REQUIRE_THROWS(caller.call("iodelay", {}, -1, GET));
// gotthard
REQUIRE_THROWS(caller.call("vref_ds", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcascn_pb", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcascp_pb", {}, -1, GET));
// REQUIRE_THROWS(caller.call("vout_cm", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcasc_out", {}, -1, GET));
// REQUIRE_THROWS(caller.call("vin_cm", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_comp", {}, -1, GET));
REQUIRE_THROWS(caller.call("ib_test_c", {}, -1, GET));
// mythen3
REQUIRE_THROWS(caller.call("vrpreamp", {}, -1, GET));
REQUIRE_THROWS(caller.call("vrshaper", {}, -1, GET));
REQUIRE_THROWS(caller.call("vrshaper_n", {}, -1, GET));
// REQUIRE_THROWS(caller.call("vipre", {}, -1, GET));
REQUIRE_THROWS(caller.call("vishaper", {}, -1, GET));
REQUIRE_THROWS(caller.call("vdcsh", {}, -1, GET));
REQUIRE_THROWS(caller.call("vth1", {}, -1, GET));
REQUIRE_THROWS(caller.call("vth2", {}, -1, GET));
REQUIRE_THROWS(caller.call("vth3", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcal_n", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcal_p", {}, -1, GET));
REQUIRE_THROWS(caller.call("vtrim", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcassh", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcas", {}, -1, GET));
REQUIRE_THROWS(caller.call("vicin", {}, -1, GET));
REQUIRE_THROWS(caller.call("vipre_out", {}, -1, GET));
// gotthard2
REQUIRE_THROWS(caller.call("vref_h_adc", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_comp_fe", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_comp_adc", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcom_cds", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_rstore", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_opa_1st", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_comp_fe", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcom_adc1", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_l_adc", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_cds", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_cs", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_opa_fd", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcom_adc2", {}, -1, GET));
// jungfrau
REQUIRE_THROWS(caller.call("vb_comp", {}, -1, GET));
REQUIRE_THROWS(caller.call("vdd_prot", {}, -1, GET));
REQUIRE_THROWS(caller.call("vin_com", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_prech", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_pixbuf", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_ds", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_ds", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_comp", {}, -1, GET));
}
}
} // namespace sls

View File

@@ -0,0 +1,692 @@
// 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/sls_detector_defs.h"
#include <sstream>
#include "sls/Result.h"
#include "sls/ToString.h"
#include "sls/versionAPI.h"
#include "test-Caller-global.h"
#include "tests/globals.h"
namespace sls {
using test::GET;
using test::PUT;
/* dacs */
TEST_CASE("Caller::Setting and reading back MYTHEN3 dacs",
"[.cmdcall][.dacs]") {
// vcassh, vth2, vshaper, vshaperneg, vipre_out, vth3, vth1,
// vicin, vcas, vpreamp, vpl, vipre, viinsh, vph, vtrim, vdcsh,
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::MYTHEN3) {
SECTION("vcassh") { test_dac_caller(defs::VCASSH, "vcassh", 1200); }
SECTION("vth2") { test_dac_caller(defs::VTH2, "vth2", 2800); }
SECTION("vrshaper") {
test_dac_caller(defs::VRSHAPER, "vrshaper", 1280);
}
SECTION("vrshaper_n") {
test_dac_caller(defs::VRSHAPER_N, "vrshaper_n", 2800);
}
SECTION("vipre_out") {
test_dac_caller(defs::VIPRE_OUT, "vipre_out", 1220);
}
SECTION("vth3") { test_dac_caller(defs::VTH3, "vth3", 2800); }
SECTION("vth1") { test_dac_caller(defs::VTH1, "vth1", 2880); }
SECTION("vicin") { test_dac_caller(defs::VICIN, "vicin", 1708); }
SECTION("vcas") { test_dac_caller(defs::VCAS, "vcas", 1800); }
SECTION("vrpreamp") {
test_dac_caller(defs::VRPREAMP, "vrpreamp", 1100);
}
SECTION("vcal_n") { test_dac_caller(defs::VCAL_N, "vcal_n", 1100); }
SECTION("vipre") { test_dac_caller(defs::VIPRE, "vipre", 2624); }
SECTION("vishaper") {
test_dac_caller(defs::VISHAPER, "vishaper", 1708);
}
SECTION("vcal_p") { test_dac_caller(defs::VCAL_P, "vcal_p", 1712); }
SECTION("vtrim") { test_dac_caller(defs::VTRIM, "vtrim", 2800); }
SECTION("vdcsh") { test_dac_caller(defs::VDCSH, "vdcsh", 800); }
SECTION("vthreshold") {
// Read out individual vcmp to be able to reset after
// the test is done
auto vth1 = det.getDAC(defs::VTH1, false);
auto vth2 = det.getDAC(defs::VTH2, false);
auto vth3 = det.getDAC(defs::VTH3, false);
auto mask = det.getCounterMask();
{
std::ostringstream oss;
caller.call("dac", {"vthreshold", "1234"}, -1, PUT, oss);
REQUIRE(oss.str() == "dac vthreshold 1234\n");
}
{
std::ostringstream oss;
caller.call("dac", {"vthreshold"}, -1, GET, oss);
REQUIRE(oss.str() == "dac vthreshold 1234\n");
}
// disabling counters change vth values
caller.call("counters", {"0"}, -1, PUT);
{
std::ostringstream oss1, oss2, oss3;
caller.call("dac", {"vth1"}, -1, GET, oss1);
REQUIRE(oss1.str() == "dac vth1 1234\n");
caller.call("dac", {"vth2"}, -1, GET, oss2);
REQUIRE(oss2.str() == "dac vth2 2800\n");
caller.call("dac", {"vth3"}, -1, GET, oss3);
REQUIRE(oss3.str() == "dac vth3 2800\n");
}
// vthreshold changes vth for only enabled counters
REQUIRE_NOTHROW(
caller.call("dac", {"vthreshold", "2100"}, -1, PUT));
{
std::ostringstream oss;
caller.call("dac", {"vthreshold"}, -1, GET, oss);
REQUIRE(oss.str() == "dac vthreshold 2100\n");
std::ostringstream oss1, oss2, oss3;
caller.call("dac", {"vth1"}, -1, GET, oss1);
REQUIRE(oss1.str() == "dac vth1 2100\n");
caller.call("dac", {"vth2"}, -1, GET, oss2);
REQUIRE(oss2.str() == "dac vth2 2800\n");
caller.call("dac", {"vth3"}, -1, GET, oss3);
REQUIRE(oss3.str() == "dac vth3 2800\n");
}
// vth overwrite vth even if counter disabled
{
std::ostringstream oss;
caller.call("dac", {"vth2", "2200"}, -1, PUT);
caller.call("dac", {"vth2"}, -1, GET, oss);
REQUIRE(oss.str() == "dac vth2 2200\n");
}
// counters enabled, sets remembered values
caller.call("counters", {"0", "1", "2"}, -1, PUT);
{
std::ostringstream oss1, oss2, oss3;
caller.call("dac", {"vth1"}, -1, GET, oss1);
REQUIRE(oss1.str() == "dac vth1 2100\n");
caller.call("dac", {"vth2"}, -1, GET, oss2);
REQUIRE(oss2.str() == "dac vth2 2200\n");
caller.call("dac", {"vth3"}, -1, GET, oss3);
REQUIRE(oss3.str() == "dac vth3 2100\n");
}
// counters enabled, sets remembered values
caller.call("counters", {"0", "1"}, -1, PUT);
{
std::ostringstream oss1, oss2, oss3;
caller.call("dac", {"vth1"}, -1, GET, oss1);
REQUIRE(oss1.str() == "dac vth1 2100\n");
caller.call("dac", {"vth2"}, -1, GET, oss2);
REQUIRE(oss2.str() == "dac vth2 2200\n");
caller.call("dac", {"vth3"}, -1, GET, oss3);
REQUIRE(oss3.str() == "dac vth3 2800\n");
}
// Reset dacs after test
for (int i = 0; i != det.size(); ++i) {
det.setCounterMask(mask[i], {i});
det.setDAC(defs::VTH1, vth1[i], false, {i});
det.setDAC(defs::VTH2, vth2[i], false, {i});
det.setDAC(defs::VTH3, vth3[i], false, {i});
}
}
REQUIRE_THROWS(caller.call("dac", {"vsvp"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vsvn"}, -1, GET));
// REQUIRE_THROWS(caller.call("dac", {"vtrim"}, -1, GET));
// REQUIRE_THROWS(caller.call("dac", {"vrpreamp"}, -1, GET));
// REQUIRE_THROWS(caller.call("dac", {"vrshaper"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vtgstv"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcmp_ll"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcmp_lr"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcal"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcmp_rl"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcmp_rr"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"rxb_rb"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"rxb_lb"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcp"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcn"}, -1, GET));
// REQUIRE_THROWS(caller.call("dac", {"vishaper"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"iodelay"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vref_ds"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcascn_pb"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcascp_pb"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vout_cm"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcasc_out"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vin_cm"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vref_comp"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"ib_test_c"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vref_h_adc"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vb_comp_fe"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vb_comp_adc"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcom_cds"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vref_rstore"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vb_opa_1st"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vref_comp_fe"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcom_adc1"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vref_prech"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vref_l_adc"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vref_cds"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vb_cs"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vb_opa_fd"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vcom_adc2"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vb_ds"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vb_comp"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vb_pixbuf"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vin_com"}, -1, GET));
REQUIRE_THROWS(caller.call("dac", {"vdd_prot"}, -1, GET));
}
}
/* acquisition */
TEST_CASE("Caller::readout", "[.cmdcall]") {
Detector det;
Caller caller(&det);
// PUT only command
REQUIRE_THROWS(caller.call("readout", {}, -1, GET));
auto det_type = det.getDetectorType().squash();
if (det_type != defs::MYTHEN3) {
REQUIRE_THROWS(caller.call("readout", {}, -1, GET));
} else {
std::ostringstream oss;
caller.call("readout", {}, -1, PUT, oss);
REQUIRE(oss.str() == "readout successful\n");
}
}
/* Mythen3 Specific */
TEST_CASE("Caller::counters", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::MYTHEN3) {
REQUIRE_THROWS(caller.call("counters", {}, -1, PUT));
REQUIRE_THROWS(caller.call("counters", {"3"}, -1, GET));
REQUIRE_THROWS(caller.call("counters", {"0", "-1"}, -1, GET));
REQUIRE_THROWS(caller.call("counters", {"0", "1", "1"}, -1, GET));
auto mask = det.getCounterMask({0}).squash(-1);
std::vector<std::string> list_str;
for (int i = 0; i < 32; ++i) {
if (mask & (1 << i)) {
list_str.push_back(std::to_string(i));
}
}
std::ostringstream oss_set, oss_set2, oss_set3, oss_get;
caller.call("counters", {"0", "2", "1"}, -1, PUT, oss_set);
REQUIRE(oss_set.str() == "counters [0, 2, 1]\n");
caller.call("counters", {"0", "2"}, -1, PUT, oss_set2);
REQUIRE(oss_set2.str() == "counters [0, 2]\n");
// put back old value
caller.call("counters", list_str, -1, PUT, oss_set3);
REQUIRE(oss_set3.str() == "counters " + ToString(list_str) + "\n");
caller.call("counters", {}, -1, GET, oss_get);
REQUIRE(oss_get.str() == "counters " + ToString(list_str) + "\n");
} else {
REQUIRE_THROWS(caller.call("counters", {}, -1, GET));
}
}
TEST_CASE("Caller::gates", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::MYTHEN3) {
auto prev_val = det.getNumberOfGates();
{
std::ostringstream oss;
caller.call("gates", {"1000"}, -1, PUT, oss);
REQUIRE(oss.str() == "gates 1000\n");
}
{
std::ostringstream oss;
caller.call("gates", {}, -1, GET, oss);
REQUIRE(oss.str() == "gates 1000\n");
}
{
std::ostringstream oss;
caller.call("gates", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "gates 1\n");
}
REQUIRE_THROWS(caller.call("gates", {"0"}, -1, PUT));
for (int i = 0; i != det.size(); ++i) {
det.setNumberOfGates(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("gates", {}, -1, GET));
}
}
TEST_CASE("Caller::exptime1", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::MYTHEN3) {
auto prev_val = det.getExptime(0);
{
std::ostringstream oss;
caller.call("exptime1", {"1.25s"}, -1, PUT, oss);
REQUIRE(oss.str() == "exptime1 1.25s\n");
}
{
std::ostringstream oss;
caller.call("exptime1", {}, -1, GET, oss);
REQUIRE(oss.str() == "exptime1 1.25s\n");
}
{
std::ostringstream oss;
caller.call("exptime1", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "exptime1 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setExptime(0, prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("exptime1", {}, -1, GET));
}
}
TEST_CASE("Caller::exptime2", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::MYTHEN3) {
auto prev_val = det.getExptime(1);
{
std::ostringstream oss;
caller.call("exptime2", {"1.25s"}, -1, PUT, oss);
REQUIRE(oss.str() == "exptime2 1.25s\n");
}
{
std::ostringstream oss;
caller.call("exptime2", {}, -1, GET, oss);
REQUIRE(oss.str() == "exptime2 1.25s\n");
}
{
std::ostringstream oss;
caller.call("exptime2", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "exptime2 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setExptime(1, prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("exptime2", {}, -1, GET));
}
}
TEST_CASE("Caller::exptime3", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::MYTHEN3) {
auto prev_val = det.getExptime(2);
{
std::ostringstream oss;
caller.call("exptime3", {"1.25s"}, -1, PUT, oss);
REQUIRE(oss.str() == "exptime3 1.25s\n");
}
{
std::ostringstream oss;
caller.call("exptime3", {}, -1, GET, oss);
REQUIRE(oss.str() == "exptime3 1.25s\n");
}
{
std::ostringstream oss;
caller.call("exptime3", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "exptime3 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setExptime(2, prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("exptime3", {}, -1, GET));
}
}
TEST_CASE("Caller::gatedelay", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::MYTHEN3) {
auto prev_val = det.getExptimeForAllGates().tsquash(
"inconsistent gatedelay to test");
if (prev_val[0] != prev_val[1] || prev_val[1] != prev_val[2]) {
throw RuntimeError("inconsistent gatedelay for all gates");
}
{
std::ostringstream oss;
caller.call("gatedelay", {"0.05"}, -1, PUT, oss);
REQUIRE(oss.str() == "gatedelay 0.05\n");
}
if (det_type != defs::MYTHEN3) {
std::ostringstream oss;
caller.call("gatedelay", {}, -1, GET, oss);
REQUIRE(oss.str() == "gatedelay 50ms\n");
}
{
std::ostringstream oss;
caller.call("gatedelay", {"1s"}, -1, PUT, oss);
REQUIRE(oss.str() == "gatedelay 1s\n");
}
{
std::ostringstream oss;
caller.call("gatedelay", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "gatedelay 0\n");
}
det.setGateDelay(-1, prev_val[0]);
} else {
REQUIRE_THROWS(caller.call("gatedelay", {}, -1, GET));
}
}
TEST_CASE("Caller::gatedelay1", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::MYTHEN3) {
auto prev_val = det.getGateDelay(0);
{
std::ostringstream oss;
caller.call("gatedelay1", {"1.25s"}, -1, PUT, oss);
REQUIRE(oss.str() == "gatedelay1 1.25s\n");
}
{
std::ostringstream oss;
caller.call("gatedelay1", {}, -1, GET, oss);
REQUIRE(oss.str() == "gatedelay1 1.25s\n");
}
{
std::ostringstream oss;
caller.call("gatedelay1", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "gatedelay1 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setGateDelay(0, prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("gatedelay1", {}, -1, GET));
}
}
TEST_CASE("Caller::gatedelay2", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::MYTHEN3) {
auto prev_val = det.getGateDelay(1);
{
std::ostringstream oss;
caller.call("gatedelay2", {"1.25s"}, -1, PUT, oss);
REQUIRE(oss.str() == "gatedelay2 1.25s\n");
}
{
std::ostringstream oss;
caller.call("gatedelay2", {}, -1, GET, oss);
REQUIRE(oss.str() == "gatedelay2 1.25s\n");
}
{
std::ostringstream oss;
caller.call("gatedelay2", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "gatedelay2 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setGateDelay(1, prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("gatedelay2", {}, -1, GET));
}
}
TEST_CASE("Caller::gatedelay3", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::MYTHEN3) {
auto prev_val = det.getGateDelay(2);
{
std::ostringstream oss;
caller.call("gatedelay3", {"1.25s"}, -1, PUT, oss);
REQUIRE(oss.str() == "gatedelay3 1.25s\n");
}
{
std::ostringstream oss;
caller.call("gatedelay3", {}, -1, GET, oss);
REQUIRE(oss.str() == "gatedelay3 1.25s\n");
}
{
std::ostringstream oss;
caller.call("gatedelay3", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "gatedelay3 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setGateDelay(2, prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("gatedelay3", {}, -1, GET));
}
}
TEST_CASE("Caller::polarity", "[.cmdcall]") {
Detector det;
Caller caller(&det);
if (det.getDetectorType().squash() == defs::MYTHEN3) {
auto prev_val = det.getPolarity();
{
std::ostringstream oss;
caller.call("polarity", {"pos"}, -1, PUT, oss);
REQUIRE(oss.str() == "polarity pos\n");
}
{
std::ostringstream oss;
caller.call("polarity", {"neg"}, -1, PUT, oss);
REQUIRE(oss.str() == "polarity neg\n");
}
{
std::ostringstream oss;
caller.call("polarity", {}, -1, GET, oss);
REQUIRE(oss.str() == "polarity neg\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setPolarity(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("polarity", {}, -1, GET));
}
}
TEST_CASE("Caller::interpolation", "[.cmdcall]") {
Detector det;
Caller caller(&det);
if (det.getDetectorType().squash() == defs::MYTHEN3) {
auto prev_interpolation = det.getInterpolation();
auto prev_mask = det.getCounterMask();
auto prev_vth3DacVal = det.getDAC(defs::VTH3, 0, {});
int disabledDacValue = 2800;
auto fixedVth3DacVal = 1000;
det.setDAC(defs::VTH3, fixedVth3DacVal, 0, {});
// mask with counter 3 disabled and enabled(to test vth3)
uint32_t fixedMask[2] = {0x2, 0x4};
for (int i = 0; i != 2; ++i) {
det.setCounterMask(fixedMask[i]);
{
std::ostringstream oss;
caller.call("interpolation", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "interpolation 1\n");
REQUIRE(det.getCounterMask().tsquash(
"inconsistent counter mask") == 7);
REQUIRE(det.getDAC(defs::VTH3, 0, {0})
.tsquash("inconsistent vth3 dac value") ==
disabledDacValue);
}
{
std::ostringstream oss;
caller.call("interpolation", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "interpolation 0\n");
REQUIRE(det.getCounterMask().tsquash(
"inconsistent counter mask") == fixedMask[i]);
int expectedVth3DacVal =
(fixedMask[i] & 0x4 ? fixedVth3DacVal : disabledDacValue);
REQUIRE(det.getDAC(defs::VTH3, 0, {0})
.tsquash("inconsistent vth3 dac value") ==
expectedVth3DacVal);
}
}
{
std::ostringstream oss;
caller.call("interpolation", {}, -1, GET, oss);
REQUIRE(oss.str() == "interpolation 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setCounterMask(prev_mask[i], {i});
det.setInterpolation(prev_interpolation[i], {i});
det.setDAC(defs::VTH3, prev_vth3DacVal[i], 0, {i});
}
} else {
REQUIRE_THROWS(caller.call("interpolation", {}, -1, GET));
}
}
TEST_CASE("Caller::pumpprobe", "[.cmdcall]") {
Detector det;
Caller caller(&det);
if (det.getDetectorType().squash() == defs::MYTHEN3) {
auto prev_val = det.getPumpProbe();
auto prev_interpolation = det.getInterpolation();
auto prev_mask = det.getCounterMask();
auto prev_vth1DacVal = det.getDAC(defs::VTH1, 0, {});
auto prev_vth2DacVal = det.getDAC(defs::VTH2, 0, {});
auto prev_vth3DacVal = det.getDAC(defs::VTH3, 0, {});
int disabledDacValue = 2800;
auto fixedVthDacVal = 1000;
det.setDAC(defs::VTH1, fixedVthDacVal, 0, {});
det.setDAC(defs::VTH2, fixedVthDacVal, 0, {});
det.setDAC(defs::VTH3, fixedVthDacVal, 0, {});
// mask with counter 2 disabled and enabled(to test vth2)
uint32_t fixedMask[2] = {0x4, 0x3};
for (int i = 0; i != 2; ++i) {
std::cout << "i:" << i << std::endl;
det.setCounterMask(fixedMask[i]);
{
// pump probe
std::ostringstream oss;
caller.call("pumpprobe", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "pumpprobe 1\n");
REQUIRE(det.getDAC(defs::VTH1, 0, {0})
.tsquash("inconsistent vth2 dac value") ==
disabledDacValue);
REQUIRE(det.getDAC(defs::VTH2, 0, {0})
.tsquash("inconsistent vth2 dac value") ==
fixedVthDacVal);
REQUIRE(det.getDAC(defs::VTH3, 0, {0})
.tsquash("inconsistent vth2 dac value") ==
disabledDacValue);
}
// interpolation and pump probe
REQUIRE_THROWS(caller.call("interpolation", {"1"}, -1, PUT));
{
// none
std::ostringstream oss;
caller.call("pumpprobe", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "pumpprobe 0\n");
REQUIRE(det.getCounterMask().tsquash(
"inconsistent counter mask") == fixedMask[i]);
REQUIRE(
det.getDAC(defs::VTH1, 0, {0})
.tsquash("inconsistent vth1 dac value") ==
(fixedMask[i] & 0x1 ? fixedVthDacVal : disabledDacValue));
REQUIRE(
det.getDAC(defs::VTH2, 0, {0})
.tsquash("inconsistent vth2 dac value") ==
(fixedMask[i] & 0x2 ? fixedVthDacVal : disabledDacValue));
REQUIRE(
det.getDAC(defs::VTH3, 0, {0})
.tsquash("inconsistent vth3 dac value") ==
(fixedMask[i] & 0x4 ? fixedVthDacVal : disabledDacValue));
}
}
{
std::ostringstream oss;
caller.call("pumpprobe", {}, -1, GET, oss);
REQUIRE(oss.str() == "pumpprobe 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setCounterMask(prev_mask[i], {i});
det.setPumpProbe(prev_val[i], {i});
det.setInterpolation(prev_interpolation[i], {i});
det.setDAC(defs::VTH1, prev_vth1DacVal[i], 0, {i});
det.setDAC(defs::VTH2, prev_vth2DacVal[i], 0, {i});
det.setDAC(defs::VTH3, prev_vth3DacVal[i], 0, {i});
}
} else {
REQUIRE_THROWS(caller.call("pumpprobe", {}, -1, GET));
}
}
TEST_CASE("Caller::apulse", "[.cmdcall]") {
Detector det;
Caller caller(&det);
if (det.getDetectorType().squash() == defs::MYTHEN3) {
auto prev_val = det.getAnalogPulsing();
{
std::ostringstream oss;
caller.call("apulse", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "apulse 1\n");
}
{
std::ostringstream oss;
caller.call("apulse", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "apulse 0\n");
}
{
std::ostringstream oss;
caller.call("apulse", {}, -1, GET, oss);
REQUIRE(oss.str() == "apulse 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setAnalogPulsing(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("apulse", {}, -1, GET));
}
}
TEST_CASE("Caller::dpulse", "[.cmdcall]") {
Detector det;
Caller caller(&det);
if (det.getDetectorType().squash() == defs::MYTHEN3) {
auto prev_val = det.getDigitalPulsing();
{
std::ostringstream oss;
caller.call("dpulse", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "dpulse 1\n");
}
{
std::ostringstream oss;
caller.call("dpulse", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "dpulse 0\n");
}
{
std::ostringstream oss;
caller.call("dpulse", {}, -1, GET, oss);
REQUIRE(oss.str() == "dpulse 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setDigitalPulsing(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("dpulse", {}, -1, GET));
}
}
} // namespace sls

View File

@@ -0,0 +1,412 @@
// 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/sls_detector_defs.h"
#include <sstream>
#include "sls/Result.h"
#include "sls/ToString.h"
#include "sls/versionAPI.h"
#include "test-Caller-global.h"
#include "tests/globals.h"
namespace sls {
using test::GET;
using test::PUT;
/* Pattern */
TEST_CASE("Caller::patfname", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MYTHEN3) {
REQUIRE_THROWS(caller.call("patfname", {}, -1, PUT));
REQUIRE_NOTHROW(caller.call("patfname", {}, -1, GET));
} else {
REQUIRE_THROWS(caller.call("patfname", {}, -1, GET));
}
}
TEST_CASE("Caller::pattern", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MYTHEN3) {
// no proper test for put
REQUIRE_THROWS(caller.call("pattern", {}, -1, GET));
} else {
REQUIRE_THROWS(caller.call("pattern", {}, -1, GET));
}
}
TEST_CASE("Caller::savepattern", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MYTHEN3) {
REQUIRE_THROWS(
caller.call("savepattern", {"/tmp/pattern.txt"}, -1, GET));
if (det.size() == 1) {
REQUIRE_NOTHROW(
caller.call("savepattern", {"/tmp/pattern.txt"}, -1, PUT));
}
} else {
REQUIRE_THROWS(
caller.call("savepattern", {"/tmp/pattern.txt"}, -1, PUT));
}
}
TEST_CASE("Caller::defaultpattern", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::MYTHEN3) {
REQUIRE_THROWS(caller.call("defaultpattern", {}, -1, GET));
REQUIRE_NOTHROW(caller.call("defaultpattern", {}, -1, PUT));
} else {
REQUIRE_THROWS(caller.call("defaultpattern", {}, -1, GET));
REQUIRE_THROWS(caller.call("defaultpattern", {}, -1, PUT));
}
}
TEST_CASE("Caller::patioctrl", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD) {
auto prev_val = det.getPatternIOControl();
{
std::ostringstream oss;
caller.call("patioctrl", {"0xc15004808d0a21a4"}, -1, PUT, oss);
REQUIRE(oss.str() == "patioctrl 0xc15004808d0a21a4\n");
}
{
std::ostringstream oss;
caller.call("patioctrl", {"0xaadf0"}, -1, PUT, oss);
REQUIRE(oss.str() == "patioctrl 0x00000000000aadf0\n");
}
{
std::ostringstream oss;
caller.call("patioctrl", {}, -1, GET, oss);
REQUIRE(oss.str() == "patioctrl 0x00000000000aadf0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setPatternIOControl(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("patioctrl", {}, -1, GET));
}
}
TEST_CASE("Caller::patword", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MYTHEN3) {
int addr = 0x23;
std::string saddr = ToStringHex(addr, 4);
auto prev_val = det.getPatternWord(addr);
{
std::ostringstream oss;
caller.call("patword", {saddr, "0xc15004808d0a21a4"}, -1, PUT, oss);
REQUIRE(oss.str() ==
"patword [" + saddr + ", 0xc15004808d0a21a4]\n");
}
{
std::ostringstream oss;
caller.call("patword", {saddr, "0xaadf0"}, -1, PUT, oss);
REQUIRE(oss.str() ==
"patword [" + saddr + ", 0x00000000000aadf0]\n");
}
{
std::ostringstream oss;
caller.call("patword", {saddr}, -1, GET, oss);
REQUIRE(oss.str() ==
"patword [" + saddr + ", 0x00000000000aadf0]\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setPatternWord(addr, prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("patword", {"0x23"}, -1, GET));
}
}
TEST_CASE("Caller::patlimits", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MYTHEN3) {
auto prev_val = det.getPatternLoopAddresses(-1);
{
std::ostringstream oss;
caller.call("patlimits", {"0x20", "0x5c"}, -1, PUT, oss);
REQUIRE(oss.str() == "patlimits [0x0020, 0x005c]\n");
}
{
std::ostringstream oss;
caller.call("patlimits", {}, -1, GET, oss);
REQUIRE(oss.str() == "patlimits [0x0020, 0x005c]\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setPatternLoopAddresses(-1, prev_val[i][0], prev_val[i][1],
{i});
}
} else {
REQUIRE_THROWS(caller.call("patlimits", {}, -1, GET));
}
}
TEST_CASE("Caller::patloop", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MYTHEN3) {
for (int iLoop = 0; iLoop != MAX_PATTERN_LEVELS; ++iLoop) {
// m3 only has 3 levels
if (det_type == defs::MYTHEN3 && iLoop >= 3) {
continue;
}
auto prev_val = det.getPatternLoopAddresses(iLoop);
std::string sLoop = ToString(iLoop);
if (iLoop < 3) {
std::string deprecatedCmd = "patloop" + sLoop;
{ // depreciated
std::ostringstream oss;
caller.call(deprecatedCmd, {"0x20", "0x5c"}, -1, PUT, oss);
REQUIRE(oss.str() == deprecatedCmd + " [0x0020, 0x005c]\n");
}
{ // depreciated
std::ostringstream oss;
caller.call(deprecatedCmd, {}, -1, GET, oss);
REQUIRE(oss.str() == deprecatedCmd + " [0x0020, 0x005c]\n");
}
}
{
std::ostringstream oss;
caller.call("patloop", {sLoop, "0x20", "0x5c"}, -1, PUT, oss);
REQUIRE(oss.str() ==
"patloop " + sLoop + " [0x0020, 0x005c]\n");
}
{
std::ostringstream oss;
caller.call("patloop", {sLoop}, -1, GET, oss);
REQUIRE(oss.str() ==
"patloop " + sLoop + " [0x0020, 0x005c]\n");
}
for (int iDet = 0; iDet != det.size(); ++iDet) {
det.setPatternLoopAddresses(iLoop, prev_val[iDet][0],
prev_val[iDet][1], {iDet});
}
}
} else {
REQUIRE_THROWS(caller.call("patloop", {"0"}, -1, GET));
}
}
TEST_CASE("Caller::patnloop", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MYTHEN3) {
for (int iLoop = 0; iLoop != MAX_PATTERN_LEVELS; ++iLoop) {
// m3 only has 3 levels
if (det_type == defs::MYTHEN3 && iLoop >= 3) {
continue;
}
auto prev_val = det.getPatternLoopCycles(iLoop);
std::string sLoop = ToString(iLoop);
if (iLoop < 3) {
std::string deprecatedCmd = "patnloop" + sLoop;
{ // depreciated
std::ostringstream oss;
caller.call(deprecatedCmd, {"5"}, -1, PUT, oss);
REQUIRE(oss.str() == deprecatedCmd + " 5\n");
}
{ // depreciated
std::ostringstream oss;
caller.call(deprecatedCmd, {}, -1, GET, oss);
REQUIRE(oss.str() == deprecatedCmd + " 5\n");
}
}
{
std::ostringstream oss;
caller.call("patnloop", {sLoop, "5"}, -1, PUT, oss);
REQUIRE(oss.str() == "patnloop " + sLoop + " 5\n");
}
{
std::ostringstream oss;
caller.call("patnloop", {sLoop}, -1, GET, oss);
REQUIRE(oss.str() == "patnloop " + sLoop + " 5\n");
}
for (int iDet = 0; iDet != det.size(); ++iDet) {
det.setPatternLoopCycles(iLoop, prev_val[iDet], {iDet});
}
}
} else {
REQUIRE_THROWS(caller.call("patnloop", {"0"}, -1, GET));
}
}
TEST_CASE("Caller::patwait", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MYTHEN3) {
for (int iLoop = 0; iLoop != MAX_PATTERN_LEVELS; ++iLoop) {
// m3 only has 3 levels
if (det_type == defs::MYTHEN3 && iLoop >= 3) {
continue;
}
auto prev_val = det.getPatternWaitAddr(iLoop);
std::string sLoop = ToString(iLoop);
if (iLoop < 3) {
std::string deprecatedCmd = "patwait" + sLoop;
{ // depreciated
std::ostringstream oss;
caller.call(deprecatedCmd, {"0x5c"}, -1, PUT, oss);
REQUIRE(oss.str() == deprecatedCmd + " 0x005c\n");
}
{ // depreciated
std::ostringstream oss;
caller.call(deprecatedCmd, {}, -1, GET, oss);
REQUIRE(oss.str() == deprecatedCmd + " 0x005c\n");
}
}
{
std::ostringstream oss;
caller.call("patwait", {sLoop, "0x5c"}, -1, PUT, oss);
REQUIRE(oss.str() == "patwait " + sLoop + " 0x005c\n");
}
{
std::ostringstream oss;
caller.call("patwait", {sLoop}, -1, GET, oss);
REQUIRE(oss.str() == "patwait " + sLoop + " 0x005c\n");
}
for (int iDet = 0; iDet != det.size(); ++iDet) {
det.setPatternWaitAddr(iLoop, prev_val[iDet], {iDet});
}
}
} else {
REQUIRE_THROWS(caller.call("patwait", {"0"}, -1, GET));
}
}
TEST_CASE("Caller::patwaittime", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MYTHEN3) {
for (int iLoop = 0; iLoop != MAX_PATTERN_LEVELS; ++iLoop) {
// m3 only has 3 levels
if (det_type == defs::MYTHEN3 && iLoop >= 3) {
continue;
}
auto prev_val = det.getPatternWaitTime(iLoop);
std::string sLoop = ToString(iLoop);
if (iLoop < 3) {
std::string deprecatedCmd = "patwaittime" + sLoop;
{ // depreciated
std::ostringstream oss;
caller.call(deprecatedCmd, {"8589936640"}, -1, PUT, oss);
REQUIRE(oss.str() == deprecatedCmd + " 8589936640\n");
}
{ // depreciated
std::ostringstream oss;
caller.call(deprecatedCmd, {}, -1, GET, oss);
REQUIRE(oss.str() == deprecatedCmd + " 8589936640\n");
}
}
{
std::ostringstream oss;
caller.call("patwaittime", {sLoop, "8589936640"}, -1, PUT, oss);
REQUIRE(oss.str() == "patwaittime " + sLoop + " 8589936640\n");
}
{
std::ostringstream oss;
caller.call("patwaittime", {sLoop}, -1, GET, oss);
REQUIRE(oss.str() == "patwaittime " + sLoop + " 8589936640\n");
}
for (int iDet = 0; iDet != det.size(); ++iDet) {
det.setPatternWaitTime(iLoop, prev_val[iDet], {iDet});
}
}
} else {
REQUIRE_THROWS(caller.call("patwaittime", {"0"}, -1, GET));
}
}
TEST_CASE("Caller::patmask", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MYTHEN3) {
auto prev_val = det.getPatternMask();
{
std::ostringstream oss;
caller.call("patmask", {"0x842f020204200dc0"}, -1, PUT, oss);
REQUIRE(oss.str() == "patmask 0x842f020204200dc0\n");
}
{
std::ostringstream oss;
caller.call("patmask", {}, -1, GET, oss);
REQUIRE(oss.str() == "patmask 0x842f020204200dc0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setPatternMask(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("patmask", {}, -1, GET));
}
}
TEST_CASE("Caller::patsetbit", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MYTHEN3) {
auto prev_val = det.getPatternBitMask();
{
std::ostringstream oss;
caller.call("patsetbit", {"0x842f020204200dc0"}, -1, PUT, oss);
REQUIRE(oss.str() == "patsetbit 0x842f020204200dc0\n");
}
{
std::ostringstream oss;
caller.call("patsetbit", {}, -1, GET, oss);
REQUIRE(oss.str() == "patsetbit 0x842f020204200dc0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setPatternBitMask(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("patsetbit", {}, -1, GET));
}
}
TEST_CASE("Caller::patternstart", "[.cmdcall]") {
Detector det;
Caller caller(&det);
REQUIRE_THROWS(caller.call("patternstart", {}, -1, GET));
auto det_type = det.getDetectorType().squash();
if (det_type == defs::MYTHEN3) {
REQUIRE_NOTHROW(caller.call("patternstart", {}, -1, PUT));
} else {
REQUIRE_THROWS(caller.call("patternstart", {}, -1, PUT));
}
}
} // namespace sls

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff