slsDetectorPackage/slsDetectorSoftware/tests/test-CmdProxy-pattern.cpp
Erik Fröjdh 2f2fe4dd47
Release of 5.1.0 (#237)
* Setting pattern from memory (#218)

* ToString accepts c-style arrays

* fixed patwait time bug in validation

* Introduced pattern class

* compile for servers too

* Python binding for Pattern

* added scanParameters in Python

* slsReceiver: avoid potential memory leak around Implementation::generalData

* additional constructors for scanPrameters in python

* bugfix: avoid potentital memory leak in receiver if called outside constructor context

* added scanParameters in Python

* additional constructors for scanPrameters in python

* M3defaultpattern (#227)

* default pattern for m3 and moench including Python bindings

* M3settings (#228)

* some changes to compile on RH7 and in the server to load the default chip status register at startup

* Updated mythen3DeectorServer_developer executable with correct initialization at startup

Co-authored-by: Erik Frojdh <erik.frojdh@gmail.com>
Co-authored-by: Anna Bergamaschi <anna.bergamaschi@psi.ch>

* Pattern.h as a public header files (#229)

* fixed buffer overflow but caused by using global instead of local enum

* replacing out of range trimbits with edge values

* replacing dac values that are out of range after interpolation

* updated pybind11 to 2.6.2

* Mythen3 improved synchronization (#231)

Disabling scans for multi module Mythen3, since there is no feedback of the detectors being ready
startDetector first starts the slaves then the master
acquire firs calls startDetector for the slaves then acquire on the master
getMaster to read back from hardware which one is master

* New server for JF to go with the new FW (#232)

* Modified Jungfrau speed settings for HW1.0 - FW fix version 1.1.1, compilation date 210218

* Corrected bug. DBIT clk phase is implemented in both HW version 1.0 and 2.0. Previous version did not update the DBIT phase shift on the configuration of a speed.

* fix for m3 scan with single module

* m3 fw version

* m3 server

* bugfix for bottom when setting quad

* new strategy for finding zmq based on cppzmq



Co-authored-by: Dhanya Thattil <dhanya.thattil@psi.ch>
Co-authored-by: Dhanya Thattil <33750417+thattil@users.noreply.github.com>
Co-authored-by: Alejandro Homs Puron <ahoms@esrf.fr>
Co-authored-by: Anna Bergamaschi <anna.bergamaschi@psi.ch>
Co-authored-by: Xiaoqiang Wang <xiaoqiangwang@gmail.com>
Co-authored-by: lopez_c <carlos.lopez-cuenca@psi.ch>
2021-03-22 14:43:11 +01:00

529 lines
17 KiB
C++

#include "CmdProxy.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-CmdProxy-global.h"
#include "tests/globals.h"
using sls::CmdProxy;
using sls::Detector;
using test::GET;
using test::PUT;
/* Pattern */
TEST_CASE("pattern", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH ||
det_type == defs::MYTHEN3) {
// no proper test for put
REQUIRE_THROWS(proxy.Call("pattern", {}, -1, GET));
} else {
REQUIRE_THROWS(proxy.Call("pattern", {}, -1, GET));
}
}
TEST_CASE("savepattern", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH ||
det_type == defs::MYTHEN3) {
REQUIRE_THROWS(
proxy.Call("savepattern", {"/tmp/pattern.txt"}, -1, GET));
REQUIRE_NOTHROW(
proxy.Call("savepattern", {"/tmp/pattern.txt"}, -1, PUT));
} else {
REQUIRE_THROWS(
proxy.Call("savepattern", {"/tmp/pattern.txt"}, -1, PUT));
}
}
TEST_CASE("defaultpattern", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::MOENCH || det_type == defs::MYTHEN3) {
REQUIRE_THROWS(proxy.Call("defaultpattern", {}, -1, GET));
REQUIRE_NOTHROW(proxy.Call("defaultpattern", {}, -1, PUT));
} else {
REQUIRE_THROWS(proxy.Call("defaultpattern", {}, -1, GET));
REQUIRE_NOTHROW(proxy.Call("defaultpattern", {}, -1, PUT));
}
}
TEST_CASE("patioctrl", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH) {
auto prev_val = det.getPatternIOControl();
{
std::ostringstream oss;
proxy.Call("patioctrl", {"0xc15004808d0a21a4"}, -1, PUT, oss);
REQUIRE(oss.str() == "patioctrl 0xc15004808d0a21a4\n");
}
{
std::ostringstream oss;
proxy.Call("patioctrl", {"0xaadf0"}, -1, PUT, oss);
REQUIRE(oss.str() == "patioctrl 0x00000000000aadf0\n");
}
{
std::ostringstream oss;
proxy.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(proxy.Call("patioctrl", {}, -1, GET));
}
}
TEST_CASE("patword", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH ||
det_type == defs::MYTHEN3) {
int addr = 0x23;
std::string saddr = sls::ToStringHex(addr, 4);
auto prev_val = det.getPatternWord(addr);
{
std::ostringstream oss;
proxy.Call("patword", {saddr, "0xc15004808d0a21a4"}, -1, PUT, oss);
REQUIRE(oss.str() ==
"patword [" + saddr + ", 0xc15004808d0a21a4]\n");
}
{
std::ostringstream oss;
proxy.Call("patword", {saddr, "0xaadf0"}, -1, PUT, oss);
REQUIRE(oss.str() ==
"patword [" + saddr + ", 0x00000000000aadf0]\n");
}
{
std::ostringstream oss;
proxy.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(proxy.Call("patword", {"0x23"}, -1, GET));
}
}
TEST_CASE("patlimits", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH ||
det_type == defs::MYTHEN3) {
auto prev_val = det.getPatternLoopAddresses(-1);
{
std::ostringstream oss;
proxy.Call("patlimits", {"0x20", "0x5c"}, -1, PUT, oss);
REQUIRE(oss.str() == "patlimits [0x0020, 0x005c]\n");
}
{
std::ostringstream oss;
proxy.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(proxy.Call("patlimits", {}, -1, GET));
}
}
TEST_CASE("patloop0", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH ||
det_type == defs::MYTHEN3) {
auto prev_val = det.getPatternLoopAddresses(0);
{
std::ostringstream oss;
proxy.Call("patloop0", {"0x20", "0x5c"}, -1, PUT, oss);
REQUIRE(oss.str() == "patloop0 [0x0020, 0x005c]\n");
}
{
std::ostringstream oss;
proxy.Call("patloop0", {}, -1, GET, oss);
REQUIRE(oss.str() == "patloop0 [0x0020, 0x005c]\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setPatternLoopAddresses(0, prev_val[i][0], prev_val[i][1], {i});
}
} else {
REQUIRE_THROWS(proxy.Call("patloop0", {}, -1, GET));
}
}
TEST_CASE("patloop1", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH ||
det_type == defs::MYTHEN3) {
auto prev_val = det.getPatternLoopAddresses(1);
{
std::ostringstream oss;
proxy.Call("patloop1", {"0x20", "0x5c"}, -1, PUT, oss);
REQUIRE(oss.str() == "patloop1 [0x0020, 0x005c]\n");
}
{
std::ostringstream oss;
proxy.Call("patloop1", {}, -1, GET, oss);
REQUIRE(oss.str() == "patloop1 [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(proxy.Call("patloop1", {}, -1, GET));
}
}
TEST_CASE("patloop2", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH ||
det_type == defs::MYTHEN3) {
auto prev_val = det.getPatternLoopAddresses(2);
{
std::ostringstream oss;
proxy.Call("patloop2", {"0x20", "0x5c"}, -1, PUT, oss);
REQUIRE(oss.str() == "patloop2 [0x0020, 0x005c]\n");
}
{
std::ostringstream oss;
proxy.Call("patloop2", {}, -1, GET, oss);
REQUIRE(oss.str() == "patloop2 [0x0020, 0x005c]\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setPatternLoopAddresses(2, prev_val[i][0], prev_val[i][1], {i});
}
} else {
REQUIRE_THROWS(proxy.Call("patloop2", {}, -1, GET));
}
}
TEST_CASE("patnloop0", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH ||
det_type == defs::MYTHEN3) {
auto prev_val = det.getPatternLoopCycles(0);
{
std::ostringstream oss;
proxy.Call("patnloop0", {"5"}, -1, PUT, oss);
REQUIRE(oss.str() == "patnloop0 5\n");
}
{
std::ostringstream oss;
proxy.Call("patnloop0", {}, -1, GET, oss);
REQUIRE(oss.str() == "patnloop0 5\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setPatternLoopCycles(0, prev_val[i], {i});
}
} else {
REQUIRE_THROWS(proxy.Call("patnloop0", {}, -1, GET));
}
}
TEST_CASE("patnloop1", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH ||
det_type == defs::MYTHEN3) {
auto prev_val = det.getPatternLoopCycles(1);
{
std::ostringstream oss;
proxy.Call("patnloop1", {"5"}, -1, PUT, oss);
REQUIRE(oss.str() == "patnloop1 5\n");
}
{
std::ostringstream oss;
proxy.Call("patnloop1", {}, -1, GET, oss);
REQUIRE(oss.str() == "patnloop1 5\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setPatternLoopCycles(1, prev_val[i], {i});
}
} else {
REQUIRE_THROWS(proxy.Call("patnloop1", {}, -1, GET));
}
}
TEST_CASE("patnloop2", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH ||
det_type == defs::MYTHEN3) {
auto prev_val = det.getPatternLoopCycles(2);
{
std::ostringstream oss;
proxy.Call("patnloop2", {"5"}, -1, PUT, oss);
REQUIRE(oss.str() == "patnloop2 5\n");
}
{
std::ostringstream oss;
proxy.Call("patnloop2", {}, -1, GET, oss);
REQUIRE(oss.str() == "patnloop2 5\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setPatternLoopCycles(2, prev_val[i], {i});
}
} else {
REQUIRE_THROWS(proxy.Call("patnloop2", {}, -1, GET));
}
}
TEST_CASE("patwait0", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH ||
det_type == defs::MYTHEN3) {
auto prev_val = det.getPatternWaitAddr(0);
{
std::ostringstream oss;
proxy.Call("patwait0", {"0x5c"}, -1, PUT, oss);
REQUIRE(oss.str() == "patwait0 0x005c\n");
}
{
std::ostringstream oss;
proxy.Call("patwait0", {}, -1, GET, oss);
REQUIRE(oss.str() == "patwait0 0x005c\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setPatternWaitAddr(0, prev_val[i], {i});
}
} else {
REQUIRE_THROWS(proxy.Call("patwait0", {}, -1, GET));
}
}
TEST_CASE("patwait1", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH ||
det_type == defs::MYTHEN3) {
auto prev_val = det.getPatternWaitAddr(1);
{
std::ostringstream oss;
proxy.Call("patwait1", {"0x5c"}, -1, PUT, oss);
REQUIRE(oss.str() == "patwait1 0x005c\n");
}
{
std::ostringstream oss;
proxy.Call("patwait1", {}, -1, GET, oss);
REQUIRE(oss.str() == "patwait1 0x005c\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setPatternWaitAddr(1, prev_val[i], {i});
}
} else {
REQUIRE_THROWS(proxy.Call("patwait1", {}, -1, GET));
}
}
TEST_CASE("patwait2", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH ||
det_type == defs::MYTHEN3) {
auto prev_val = det.getPatternWaitAddr(2);
{
std::ostringstream oss;
proxy.Call("patwait2", {"0x5c"}, -1, PUT, oss);
REQUIRE(oss.str() == "patwait2 0x005c\n");
}
{
std::ostringstream oss;
proxy.Call("patwait2", {}, -1, GET, oss);
REQUIRE(oss.str() == "patwait2 0x005c\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setPatternWaitAddr(2, prev_val[i], {i});
}
} else {
REQUIRE_THROWS(proxy.Call("patwait2", {}, -1, GET));
}
}
TEST_CASE("patwaittime0", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH ||
det_type == defs::MYTHEN3) {
auto prev_val = det.getPatternWaitTime(0);
{
std::ostringstream oss;
proxy.Call("patwaittime0", {"8589936640"}, -1, PUT, oss);
REQUIRE(oss.str() == "patwaittime0 8589936640\n");
}
{
std::ostringstream oss;
proxy.Call("patwaittime0", {}, -1, GET, oss);
REQUIRE(oss.str() == "patwaittime0 8589936640\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setPatternWaitTime(0, prev_val[i], {i});
}
} else {
REQUIRE_THROWS(proxy.Call("patwaittime0", {}, -1, GET));
}
}
TEST_CASE("patwaittime1", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH ||
det_type == defs::MYTHEN3) {
auto prev_val = det.getPatternWaitTime(1);
{
std::ostringstream oss;
proxy.Call("patwaittime1", {"8589936640"}, -1, PUT, oss);
REQUIRE(oss.str() == "patwaittime1 8589936640\n");
}
{
std::ostringstream oss;
proxy.Call("patwaittime1", {}, -1, GET, oss);
REQUIRE(oss.str() == "patwaittime1 8589936640\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setPatternWaitTime(1, prev_val[i], {i});
}
} else {
REQUIRE_THROWS(proxy.Call("patwaittime1", {}, -1, GET));
}
}
TEST_CASE("patwaittime2", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH ||
det_type == defs::MYTHEN3) {
auto prev_val = det.getPatternWaitTime(2);
{
std::ostringstream oss;
proxy.Call("patwaittime2", {"8589936640"}, -1, PUT, oss);
REQUIRE(oss.str() == "patwaittime2 8589936640\n");
}
{
std::ostringstream oss;
proxy.Call("patwaittime2", {}, -1, GET, oss);
REQUIRE(oss.str() == "patwaittime2 8589936640\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setPatternWaitTime(2, prev_val[i], {i});
}
} else {
REQUIRE_THROWS(proxy.Call("patwaittime2", {}, -1, GET));
}
}
TEST_CASE("patmask", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH ||
det_type == defs::MYTHEN3) {
auto prev_val = det.getPatternMask();
{
std::ostringstream oss;
proxy.Call("patmask", {"0x842f020204200dc0"}, -1, PUT, oss);
REQUIRE(oss.str() == "patmask 0x842f020204200dc0\n");
}
{
std::ostringstream oss;
proxy.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(proxy.Call("patmask", {}, -1, GET));
}
}
TEST_CASE("patsetbit", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH ||
det_type == defs::MYTHEN3) {
auto prev_val = det.getPatternBitMask();
{
std::ostringstream oss;
proxy.Call("patsetbit", {"0x842f020204200dc0"}, -1, PUT, oss);
REQUIRE(oss.str() == "patsetbit 0x842f020204200dc0\n");
}
{
std::ostringstream oss;
proxy.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(proxy.Call("patsetbit", {}, -1, GET));
}
}
TEST_CASE("patternstart", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
REQUIRE_THROWS(proxy.Call("patternstart", {}, -1, GET));
auto det_type = det.getDetectorType().squash();
if (det_type == defs::MYTHEN3) {
REQUIRE_NOTHROW(proxy.Call("patternstart", {}, -1, PUT));
} else {
REQUIRE_THROWS(proxy.Call("patternstart", {}, -1, PUT));
}
}