From e996068328c2eb0f871d0c1c2e705612bc9c66b9 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Wed, 27 Nov 2019 13:39:06 +0100 Subject: [PATCH] more tests --- CMakeLists.txt | 8 +- slsDetectorSoftware/src/CmdLineApp.cpp | 7 +- slsDetectorSoftware/src/CmdProxy.cpp | 5 +- slsDetectorSoftware/src/CmdProxy.h | 2 +- .../tests/test-CmdProxy-eiger.cpp | 180 ++++++++++++------ .../tests/test-CmdProxy-rx.cpp | 15 +- slsDetectorSoftware/tests/test-CmdProxy.cpp | 81 +++----- 7 files changed, 159 insertions(+), 139 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19cb805c2..c42193f4d 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,10 +106,10 @@ endif() if(SLS_USE_SANITIZER) - # target_compile_options(slsProjectOptions INTERFACE -fsanitize=address,undefined -fno-omit-frame-pointer) - # target_link_libraries(slsProjectOptions INTERFACE -fsanitize=address,undefined) - target_compile_options(slsProjectOptions INTERFACE -fsanitize=thread) - target_link_libraries(slsProjectOptions INTERFACE -fsanitize=thread) + target_compile_options(slsProjectOptions INTERFACE -fsanitize=address,undefined -fno-omit-frame-pointer) + target_link_libraries(slsProjectOptions INTERFACE -fsanitize=address,undefined) + # target_compile_options(slsProjectOptions INTERFACE -fsanitize=thread) + # target_link_libraries(slsProjectOptions INTERFACE -fsanitize=thread) endif() #rapidjson diff --git a/slsDetectorSoftware/src/CmdLineApp.cpp b/slsDetectorSoftware/src/CmdLineApp.cpp index 1d05ee7b2..a4244b061 100644 --- a/slsDetectorSoftware/src/CmdLineApp.cpp +++ b/slsDetectorSoftware/src/CmdLineApp.cpp @@ -60,13 +60,8 @@ int main(int argc, char *argv[]) { //How big should this try block be? sls::Detector det(parser.multi_id()); sls::CmdProxy proxy(&det); - auto cmd = proxy.Call(parser.command(), parser.arguments(), + proxy.Call(parser.command(), parser.arguments(), parser.detector_id(), action); - // TODO! move this check into CmdProxy - if (!cmd.empty()) { - std::cout << cmd - << " Unknown command, use list to list all commands\n"; - } } catch (const sls::RuntimeError &e) { // OK to catch and do nothing since this will print the error message // and command line app will anyway exit diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index e8ead3b7b..76367c1b8 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -25,7 +25,7 @@ std::ostream &operator<<(std::ostream &os, return os; } -std::string CmdProxy::Call(const std::string &command, +void CmdProxy::Call(const std::string &command, const std::vector &arguments, int detector_id, int action, std::ostream &os) { cmd = command; @@ -37,9 +37,8 @@ std::string CmdProxy::Call(const std::string &command, auto it = functions.find(cmd); if (it != functions.end()) { os << ((*this).*(it->second))(action); - return {}; } else { - return cmd; + throw sls::RuntimeError(cmd + " Unknown command, use list to list all commands"); } } diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index ff56339c4..3f1501321 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -416,7 +416,7 @@ class CmdProxy { public: explicit CmdProxy(Detector *ptr) : det(ptr) {} - std::string Call(const std::string &command, + void Call(const std::string &command, const std::vector &arguments, int detector_id = -1, int action = -1, std::ostream &os = std::cout); diff --git a/slsDetectorSoftware/tests/test-CmdProxy-eiger.cpp b/slsDetectorSoftware/tests/test-CmdProxy-eiger.cpp index e1ed94f71..ba8b0754e 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-eiger.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-eiger.cpp @@ -2,6 +2,7 @@ #include "Detector.h" #include "catch.hpp" #include "sls_detector_defs.h" +#include #include #include "tests/globals.h" @@ -12,26 +13,84 @@ using sls::Detector; using test::GET; using test::PUT; -// TEST_CASE("tengiga", "[.cmd][.eiger][.ctb]") { -// if (test::type == slsDetectorDefs::EIGER || test::type == -// slsDetectorDefs::CHIPTESTBOARD) { -// { -// REQUIRE_NOTHROW(multiSlsDetectorClient("tengiga 1", PUT)); -// std::ostringstream oss; -// REQUIRE_NOTHROW(multiSlsDetectorClient("0:tengiga", GET, nullptr, -// oss)); REQUIRE(oss.str() == "tengiga 1\n"); -// } -// { -// REQUIRE_NOTHROW(multiSlsDetectorClient("tengiga 0", PUT)); -// std::ostringstream oss; -// REQUIRE_NOTHROW(multiSlsDetectorClient("0:tengiga", GET, nullptr, -// oss)); REQUIRE(oss.str() == "tengiga 0\n"); -// } +TEST_CASE("dr", "[.cmd][.eiger]") { + Detector det; + CmdProxy proxy(&det); + + auto det_type = det.getDetectorType().squash(); + if (det_type == defs::EIGER) { + // The only detector currently supporting setting dr + // is EIGER? + auto dr = det.getDynamicRange().squash(); + std::array vals{4, 8, 16, 32}; + for (const auto val : vals) { + std::ostringstream oss1, oss2; + proxy.Call("dr", {std::to_string(val)}, -1, PUT, oss1); + REQUIRE(oss1.str() == "dr " + std::to_string(val) + '\n'); + proxy.Call("dr", {}, -1, GET, oss2); + REQUIRE(oss2.str() == "dr " + std::to_string(val) + '\n'); + } + det.setDynamicRange(dr); + } else { + // For the other detectors we should get an error message + // except for dr 16 + REQUIRE_THROWS(proxy.Call("dr", {"4"}, -1, PUT)); + REQUIRE_THROWS(proxy.Call("dr", {"8"}, -1, PUT)); + REQUIRE_THROWS(proxy.Call("dr", {"32"}, -1, PUT)); + + std::ostringstream oss1, oss2; + proxy.Call("dr", {"16"}, -1, PUT, oss1); + REQUIRE(oss1.str() == "dr 16\n"); + proxy.Call("dr", {"16"}, -1, PUT, oss2); + REQUIRE(oss2.str() == "dr 16\n"); + } +} + +// TEST_CASE("subexptime", "[.cmd][.eiger]") { +// if (test::type == slsDetectorDefs::EIGER) { +// std::string s; +// std::ostringstream oss; +// REQUIRE_NOTHROW(multiSlsDetectorClient("subexptime", GET, nullptr, +// oss)); s = oss.str(); REQUIRE_NOTHROW(multiSlsDetectorClient(s, +// PUT)); // } else { -// REQUIRE_THROWS(multiSlsDetectorClient("tengiga", GET)); +// REQUIRE_THROWS(multiSlsDetectorClient("subexptime", GET)); // } // } +// TEST_CASE("subdeadtime", "[.cmd][.eiger]") { +// if (test::type == slsDetectorDefs::EIGER) { +// std::string s; +// std::ostringstream oss; +// REQUIRE_NOTHROW(multiSlsDetectorClient("subdeadtime", GET, nullptr, +// oss)); s = oss.str(); REQUIRE_NOTHROW(multiSlsDetectorClient(s, +// PUT)); +// } else { +// REQUIRE_THROWS(multiSlsDetectorClient("subdeadtime", GET)); +// } +// } + +TEST_CASE("tengiga", "[.cmd][.eiger][.ctb]") { + Detector det; + CmdProxy proxy(&det); + + auto det_type = det.getDetectorType().squash(); + if (det_type == defs::EIGER || det_type == defs::CHIPTESTBOARD){ + auto tengiga = det.getTenGiga(); + det.setTenGiga(false); + + std::ostringstream oss1, oss2; + proxy.Call("tengiga", {"1"}, -1, PUT, oss1); + REQUIRE(oss1.str() == "tengiga 1\n"); + proxy.Call("tengiga", {}, -1, GET, oss2); + REQUIRE(oss2.str() == "tengiga 1\n"); + + for (int i = 0; i!=det.size(); ++i){ + det.setTenGiga(tengiga[i], {i}); + } + } +} + TEST_CASE("quad", "[.cmd]") { // TODO! set and get once available in virtual detector Detector det; @@ -142,7 +201,6 @@ TEST_CASE("Setting and reading back EIGER dacs", "[.cmd]") { // REQUIRE(oss.str() == "trigger successful\n"); // } - // auto currentfnum = det.getStartingFrameNumber().tsquash( // "inconsistent frame nr in test"); @@ -154,49 +212,49 @@ TEST_CASE("Setting and reading back EIGER dacs", "[.cmd]") { // REQUIRE(oss.str() == "timing auto\n"); // } // } - // if(test::type != slsDetectorDefs::EIGER) { - // REQUIRE_THROWS(multiSlsDetectorClient("trigger", PUT)); - // } else { - // // trigger - // { - // std::ostringstream oss; - // REQUIRE_NOTHROW(multiSlsDetectorClient("timing trigger", PUT, - // nullptr, oss)); REQUIRE(oss.str() == "timing trigger\n"); - // } - // int startingfnum = 0; - // { - // std::ostringstream oss; - // REQUIRE_NOTHROW(multiSlsDetectorClient("startingfnum", GET, - // nullptr, oss)); std::string s = (oss.str()).erase (0, - // strlen("startingfnum ")); startingfnum = std::stoi(s); - // } - // { - // std::ostringstream oss; - // REQUIRE_NOTHROW(multiSlsDetectorClient("start", PUT, nullptr, - // oss)); REQUIRE(oss.str() == "start successful\n"); - // } - // { - // std::ostringstream oss; - // REQUIRE_NOTHROW(multiSlsDetectorClient("status", GET, - // nullptr, oss)); REQUIRE(oss.str() != "status idle\n"); - // REQUIRE(oss.str() - // != "status stopped\n"); - // } - // { - // std::ostringstream oss; - // REQUIRE_NOTHROW(multiSlsDetectorClient("trigger", PUT, - // nullptr, oss)); REQUIRE(oss.str() == "trigger successful\n"); - // } - // REQUIRE_NOTHROW(multiSlsDetectorClient("stop", PUT)); - // int currentfnum = 0; - // { - // std::ostringstream oss; - // REQUIRE_NOTHROW(multiSlsDetectorClient("startingfnum", GET, - // nullptr, oss)); std::string s = (oss.str()).erase (0, - // strlen("startingfnum ")); currentfnum = std::stoi(s); - // } - // REQUIRE((startingfnum + 1) == currentfnum); +// if(test::type != slsDetectorDefs::EIGER) { +// REQUIRE_THROWS(multiSlsDetectorClient("trigger", PUT)); +// } else { +// // trigger +// { +// std::ostringstream oss; +// REQUIRE_NOTHROW(multiSlsDetectorClient("timing trigger", PUT, +// nullptr, oss)); REQUIRE(oss.str() == "timing trigger\n"); +// } +// int startingfnum = 0; +// { +// std::ostringstream oss; +// REQUIRE_NOTHROW(multiSlsDetectorClient("startingfnum", GET, +// nullptr, oss)); std::string s = (oss.str()).erase (0, +// strlen("startingfnum ")); startingfnum = std::stoi(s); +// } +// { +// std::ostringstream oss; +// REQUIRE_NOTHROW(multiSlsDetectorClient("start", PUT, nullptr, +// oss)); REQUIRE(oss.str() == "start successful\n"); +// } +// { +// std::ostringstream oss; +// REQUIRE_NOTHROW(multiSlsDetectorClient("status", GET, +// nullptr, oss)); REQUIRE(oss.str() != "status idle\n"); +// REQUIRE(oss.str() +// != "status stopped\n"); +// } +// { +// std::ostringstream oss; +// REQUIRE_NOTHROW(multiSlsDetectorClient("trigger", PUT, +// nullptr, oss)); REQUIRE(oss.str() == "trigger successful\n"); +// } +// REQUIRE_NOTHROW(multiSlsDetectorClient("stop", PUT)); +// int currentfnum = 0; +// { +// std::ostringstream oss; +// REQUIRE_NOTHROW(multiSlsDetectorClient("startingfnum", GET, +// nullptr, oss)); std::string s = (oss.str()).erase (0, +// strlen("startingfnum ")); currentfnum = std::stoi(s); +// } +// REQUIRE((startingfnum + 1) == currentfnum); - // REQUIRE_NOTHROW(multiSlsDetectorClient("timing auto", PUT)); - // } +// REQUIRE_NOTHROW(multiSlsDetectorClient("timing auto", PUT)); +// } // } diff --git a/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp b/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp index 32c346032..d7ceaf74e 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp @@ -61,14 +61,15 @@ TEST_CASE("rx_framescaught", "[.cmd]") { REQUIRE(oss.str() == "rx_framescaught 0\n"); } + // Currently disabled may activate if we have a stable env // Now take one frame and see that we caught it - det.setNumberOfFrames(1); - det.acquire(); - { - std::ostringstream oss; - proxy.Call("rx_framescaught", {}, -1, GET, oss); - REQUIRE(oss.str() == "rx_framescaught 1\n"); - } + // det.setNumberOfFrames(1); + // det.acquire(); + // { + // std::ostringstream oss; + // proxy.Call("rx_framescaught", {}, -1, GET, oss); + // REQUIRE(oss.str() == "rx_framescaught 1\n"); + // } } TEST_CASE("rx_status", "[.cmd]") { diff --git a/slsDetectorSoftware/tests/test-CmdProxy.cpp b/slsDetectorSoftware/tests/test-CmdProxy.cpp index d40f8cb73..fc32cf92b 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy.cpp @@ -14,6 +14,12 @@ using sls::Detector; using test::GET; using test::PUT; +TEST_CASE("Unknown command", "[.cmd]"){ + Detector det; + CmdProxy proxy(&det); + REQUIRE_THROWS(proxy.Call("vsaevrreavv", {}, -1, PUT)); +} + // TEST_CASE("vchip", "[.cmd]") { // int prev_val = 0; @@ -3100,66 +3106,27 @@ TEST_CASE("stopport", "[.cmd]") { // oss)); s = oss.str(); REQUIRE_NOTHROW(multiSlsDetectorClient(s, PUT)); // } -// TEST_CASE("subdeadtime", "[.cmd][.eiger]") { -// if (test::type == slsDetectorDefs::EIGER) { -// std::string s; -// std::ostringstream oss; -// REQUIRE_NOTHROW(multiSlsDetectorClient("subdeadtime", GET, nullptr, -// oss)); s = oss.str(); REQUIRE_NOTHROW(multiSlsDetectorClient(s, -// PUT)); -// } else { -// REQUIRE_THROWS(multiSlsDetectorClient("subdeadtime", GET)); -// } -// } -// TEST_CASE("subexptime", "[.cmd][.eiger]") { -// if (test::type == slsDetectorDefs::EIGER) { -// std::string s; -// std::ostringstream oss; -// REQUIRE_NOTHROW(multiSlsDetectorClient("subexptime", GET, nullptr, -// oss)); s = oss.str(); REQUIRE_NOTHROW(multiSlsDetectorClient(s, -// PUT)); -// } else { -// REQUIRE_THROWS(multiSlsDetectorClient("subexptime", GET)); -// } -// } -// TEST_CASE("dr", "[.cmd][.eiger]") { -// if (test::type == slsDetectorDefs::EIGER) { -// int vals[4] = {4, 8, 16, 32}; -// for (int i = 0; i < 4; ++i) { -// REQUIRE_NOTHROW(multiSlsDetectorClient("dr " + -// std::to_string(vals[i]), PUT)); std::ostringstream oss; -// REQUIRE_NOTHROW(multiSlsDetectorClient("dr", GET, nullptr, oss)); -// REQUIRE(oss.str() == "dr " + std::to_string(vals[i]) + '\n'); -// } -// } else { -// REQUIRE_THROWS(multiSlsDetectorClient("dr 4", PUT)); -// REQUIRE_THROWS(multiSlsDetectorClient("dr 8", PUT)); -// REQUIRE_THROWS(multiSlsDetectorClient("dr 32", PUT)); -// REQUIRE_NOTHROW(multiSlsDetectorClient("dr 16", PUT)); -// { -// std::ostringstream oss; -// REQUIRE_NOTHROW(multiSlsDetectorClient("dr", GET, nullptr, oss)); -// REQUIRE(oss.str() == "dr " + std::to_string(16) + '\n'); -// } -// } -// } -// TEST_CASE("zmqip", "[.cmd]") { -// std::string s; -// { -// std::ostringstream oss; -// REQUIRE_NOTHROW(multiSlsDetectorClient("0:zmqip", GET, nullptr, -// oss)); s = oss.str(); -// } -// { -// REQUIRE_NOTHROW(multiSlsDetectorClient(s, PUT)); -// std::ostringstream oss; -// REQUIRE_NOTHROW(multiSlsDetectorClient("0:zmqip", GET, nullptr, -// oss)); REQUIRE(oss.str() == s); -// } -// } + + + +TEST_CASE("zmqip", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + std::ostringstream oss1, oss2; + auto zmqip = det.getClientZmqIp(); + proxy.Call("zmqip", {}, 0, GET, oss1); + REQUIRE(oss1.str() == "zmqip " + zmqip[0].str() + '\n'); + + proxy.Call("zmqip", {zmqip[0].str()}, 0, PUT, oss2); + REQUIRE(oss2.str() == "zmqip " + zmqip[0].str() + '\n'); + + for (int i = 0; i!=det.size(); ++i){ + det.setRxZmqIP(zmqip[i], {i}); + } +} // TEST_CASE("zmqport", "[.cmd]") { // multiSlsDetector d;