mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-28 09:10:01 +02:00
* 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>
413 lines
14 KiB
C++
413 lines
14 KiB
C++
// SPDX-License-Identifier: LGPL-3.0-or-other
|
|
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
|
#include "Caller.h"
|
|
#include "catch.hpp"
|
|
#include "sls/Detector.h"
|
|
#include "sls/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
|