diff --git a/slsDetectorSoftware/tests/CMakeLists.txt b/slsDetectorSoftware/tests/CMakeLists.txt index 25ad51248..699eac1e5 100755 --- a/slsDetectorSoftware/tests/CMakeLists.txt +++ b/slsDetectorSoftware/tests/CMakeLists.txt @@ -4,6 +4,7 @@ target_sources(tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test-CmdProxy.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-CmdProxy-rx.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-CmdProxy-eiger.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test-CmdProxy-jungfrau.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-Result.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-CmdLineParser.cpp ) diff --git a/slsDetectorSoftware/tests/test-CmdProxy-eiger.cpp b/slsDetectorSoftware/tests/test-CmdProxy-eiger.cpp index 8addbfd9d..e09a59e45 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-eiger.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-eiger.cpp @@ -66,6 +66,7 @@ TEST_CASE("Setting and reading back EIGER dacs", "[.cmd]") { SECTION("vcp") { test_dac(defs::VCP, "vcp", 1400); } SECTION("vcn") { test_dac(defs::VCN, "vcn", 1400); } SECTION("vis") { test_dac(defs::VIS, "vis", 1400); } + SECTION("iodelay") { test_dac(defs::IO_DELAY, "iodelay", 1400); } SECTION("vthreshold") { // Read out individual vcmp to be able to reset after // the test is done @@ -75,7 +76,6 @@ TEST_CASE("Setting and reading back EIGER dacs", "[.cmd]") { auto vcmp_rr = det.getDAC(defs::VCMP_RR, false); auto vcp = det.getDAC(defs::VCP, false); - { std::ostringstream oss; proxy.Call("vthreshold", {"1234"}, -1, PUT, oss); @@ -87,7 +87,6 @@ TEST_CASE("Setting and reading back EIGER dacs", "[.cmd]") { REQUIRE(oss.str() == "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}); @@ -100,62 +99,84 @@ TEST_CASE("Setting and reading back EIGER dacs", "[.cmd]") { } } -// TEST_CASE("trigger", "[.cmd][.eiger]") { -// if(test::type != slsDetectorDefs::EIGER) { -// REQUIRE_THROWS(multiSlsDetectorClient("trigger", PUT)); +// TEST_CASE("trigger", "[.cmd]") { +// Detector det; +// CmdProxy proxy(&det); +// auto det_type = det.getDetectorType().squash(); +// if (det_type != defs::EIGER) { +// proxy.Call("trigger", {}, -1, 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)); -// } -// } - -// TEST_CASE("quad", "[.cmd][.eiger]") { -// if (test::type == slsDetectorDefs::EIGER) { // { // std::ostringstream oss; -// REQUIRE_NOTHROW(multiSlsDetectorClient("quad", GET, nullptr, -// oss)); REQUIRE(oss.str() == "quad 0\n"); +// proxy.Call("timing", {"trigger"}, -1, PUT, oss); +// REQUIRE(oss.str() == "timing trigger\n"); +// } +// auto startingfnum = det.getStartingFrameNumber().tsquash( +// "inconsistent frame nr in test"); +// det.startDetector(); + +// { +// std::ostringstream oss; +// proxy.Call("trigger", {}, -1, PUT, oss); +// REQUIRE(oss.str() == "trigger successful\n"); +// } + + +// auto currentfnum = det.getStartingFrameNumber().tsquash( +// "inconsistent frame nr in test"); + +// REQUIRE(startingfnum +1 == currentfnum); +// det.stopDetector(); +// { +// std::ostringstream oss; +// proxy.Call("timing", {"auto"}, -1, PUT, oss); +// REQUIRE(oss.str() == "timing auto\n"); // } -// REQUIRE_NOTHROW(multiSlsDetectorClient("quad 0", PUT)); -// } else { -// REQUIRE_THROWS(multiSlsDetectorClient("quad", GET)); // } + // 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)); + // } // } diff --git a/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp b/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp new file mode 100644 index 000000000..8e2c7bffa --- /dev/null +++ b/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp @@ -0,0 +1,241 @@ +#include "CmdProxy.h" +#include "Detector.h" +#include "catch.hpp" +#include "sls_detector_defs.h" +#include + +#include "tests/globals.h" +#include "versionAPI.h" + +using sls::CmdProxy; +using sls::Detector; +using test::GET; +using test::PUT; + +TEST_CASE("powerchip", "[.cmd][!mayfail]") { + // TODO! this test currently fails with the + // virtual detecto server + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + + if (det_type == defs::JUNGFRAU) { + auto pc = det.getPowerChip(); + { + std::ostringstream oss; + proxy.Call("powerchip", {"1"}, -1, PUT, oss); + REQUIRE(oss.str() == "powerchip 1\n"); + } + { + std::ostringstream oss; + proxy.Call("powerchip", {"0"}, -1, PUT, oss); + REQUIRE(oss.str() == "powerchip 0\n"); + } + { + std::ostringstream oss; + proxy.Call("powerchip", {}, -1, GET, oss); + REQUIRE(oss.str() == "powerchip 0\n"); + } + for (int i = 0; i != det.size(); ++i) { + det.setPowerChip(pc[i], {i}); + } + } else { + REQUIRE_THROWS(proxy.Call("powerchip", {}, -1, GET)); + } +} + +TEST_CASE("nframes", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + if (det_type == defs::JUNGFRAU || det_type == defs::CHIPTESTBOARD) { + auto nframes = det.getNumberOfFramesFromStart().squash(); + std::ostringstream oss; + proxy.Call("nframes", {}, -1, GET, oss); + REQUIRE(oss.str() == "nframes " + std::to_string(nframes) + "\n"); + + } else { + REQUIRE_THROWS(proxy.Call("nframes", {}, -1, GET)); + } +} + +TEST_CASE("now", "[.cmd]") { + // TODO! can we test this? + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + if (det_type == defs::JUNGFRAU || det_type == defs::CHIPTESTBOARD) { + std::ostringstream oss; + proxy.Call("now", {}, -1, GET, oss); + + // Get only + REQUIRE_THROWS(proxy.Call("now", {"2019"}, -1, PUT)); + } else { + REQUIRE_THROWS(proxy.Call("now", {}, -1, GET)); + } +} + +TEST_CASE("timestamp", "[.cmd]") { + // TODO! can we test this? + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + if (det_type == defs::JUNGFRAU || det_type == defs::CHIPTESTBOARD) { + std::ostringstream oss; + proxy.Call("timestamp", {}, -1, GET, oss); + + // Get only + REQUIRE_THROWS(proxy.Call("timestamp", {"2019"}, -1, PUT)); + } else { + REQUIRE_THROWS(proxy.Call("timestamp", {}, -1, GET)); + } +} + +TEST_CASE("adcreg", "[.cmd]") { + //TODO! what is a safe value to use? + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + if (det_type == defs::JUNGFRAU || det_type == defs::CHIPTESTBOARD || + det_type == defs::GOTTHARD) { + std::ostringstream oss; + proxy.Call("adcreg", {"0x0", "0"}, -1, PUT, oss); + REQUIRE(oss.str() == "adcreg [0x0, 0]\n"); + // This is a put only command + REQUIRE_THROWS(proxy.Call("adcreg", {}, -1, GET)); + } else { + REQUIRE_THROWS(proxy.Call("adcreg", {"0x0", "0"}, -1, PUT)); + REQUIRE_THROWS(proxy.Call("adcreg", {}, -1, GET)); + } +} + +TEST_CASE("bustest", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + if (det_type == defs::JUNGFRAU || det_type == defs::CHIPTESTBOARD || + det_type == defs::GOTTHARD) { + std::ostringstream oss; + proxy.Call("bustest", {}, -1, PUT, oss); + REQUIRE(oss.str() == "bustest successful\n"); + REQUIRE_THROWS(proxy.Call("bustest", {}, -1, GET)); + } else { + REQUIRE_THROWS(proxy.Call("bustest", {}, -1, GET)); + REQUIRE_THROWS(proxy.Call("bustest", {}, -1, PUT)); + } +} + +TEST_CASE("firmwaretest", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + if (det_type == defs::JUNGFRAU || det_type == defs::CHIPTESTBOARD || + det_type == defs::GOTTHARD) { + std::ostringstream oss; + proxy.Call("firmwaretest", {}, -1, PUT, oss); + REQUIRE(oss.str() == "firmwaretest successful\n"); + REQUIRE_THROWS(proxy.Call("firmwaretest", {}, -1, GET)); + } else { + REQUIRE_THROWS(proxy.Call("firmwaretest", {}, -1, GET)); + REQUIRE_THROWS(proxy.Call("firmwaretest", {}, -1, PUT)); + } +} + +TEST_CASE("resetfpga", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + if (det_type == defs::JUNGFRAU || det_type == defs::CHIPTESTBOARD) { + std::ostringstream oss; + proxy.Call("resetfpga", {}, -1, PUT, oss); + REQUIRE(oss.str() == "resetfpga successful\n"); + REQUIRE_THROWS(proxy.Call("resetfpga", {}, -1, GET)); + } else { + REQUIRE_THROWS(proxy.Call("resetfpga", {}, -1, GET)); + REQUIRE_THROWS(proxy.Call("resetfpga", {}, -1, PUT)); + } +} + +// TEST_CASE("resetfpga", "[.cmd][.ctb][.jungfrau]") { +// if (test::type == slsDetectorDefs::JUNGFRAU || test::type == +// slsDetectorDefs::CHIPTESTBOARD) { +// ;//REQUIRE_NOTHROW(multiSlsDetectorClient("resetfpga", PUT)); +// } else { +// REQUIRE_THROWS(multiSlsDetectorClient("resetfpga", GET)); +// } +// } + + + +// void test_dac(defs::dacIndex index, const std::string &dacname, int dacvalue) +// { +// Detector det; +// CmdProxy proxy(&det); +// std::ostringstream oss_set, oss_get; +// auto dacstr = std::to_string(dacvalue); +// auto previous = det.getDAC(index, false); +// proxy.Call(dacname, {dacstr}, -1, PUT, oss_set); +// REQUIRE(oss_set.str() == dacname + " " + dacstr + "\n"); +// proxy.Call(dacname, {}, -1, GET, oss_get); +// REQUIRE(oss_set.str() == dacname + " " + dacstr + "\n"); +// // Reset all dacs to previous value +// for (int i = 0; i != det.size(); ++i) { +// det.setDAC(index, previous[i], false, {i}); +// } +// } + +// TEST_CASE("Setting and reading back EIGER dacs", "[.cmd]") { +// // 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; +// CmdProxy proxy(&det); +// auto det_type = det.getDetectorType().squash(); +// if (det_type == defs::EIGER) { +// SECTION("vsvp") { test_dac(defs::SVP, "vsvp", 5); } +// SECTION("vtr") { test_dac(defs::VRF, "vtr", 1200); } +// SECTION("vrf") { test_dac(defs::VRF, "vrf", 1500); } +// SECTION("vrs") { test_dac(defs::VRF, "vrs", 1510); } +// SECTION("vsvn") { test_dac(defs::SVN, "vsvn", 3800); } +// SECTION("vtgstv") { test_dac(defs::VTGSTV, "vtgstv", 2550); } +// SECTION("vcmp_ll") { test_dac(defs::VCMP_LL, "vcmp_ll", 1400); } +// SECTION("vcmp_lr") { test_dac(defs::VCMP_LR, "vcmp_lr", 1400); } +// SECTION("vcal") { test_dac(defs::CAL, "vcal", 1400); } +// SECTION("vcmp_rl") { test_dac(defs::VCMP_RL, "vcmp_rl", 1400); } +// SECTION("rxb_rb") { test_dac(defs::RXB_RB, "rxb_rb", 1400); } +// SECTION("rxb_lb") { test_dac(defs::RXB_LB, "rxb_lb", 1400); } +// SECTION("vcmp_rr") { test_dac(defs::VCMP_RR, "vcmp_rr", 1400); } +// SECTION("vcp") { test_dac(defs::VCP, "vcp", 1400); } +// SECTION("vcn") { test_dac(defs::VCN, "vcn", 1400); } +// SECTION("vis") { test_dac(defs::VIS, "vis", 1400); } +// SECTION("iodelay") { test_dac(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; +// proxy.Call("vthreshold", {"1234"}, -1, PUT, oss); +// REQUIRE(oss.str() == "vthreshold 1234\n"); +// } +// { +// std::ostringstream oss; +// proxy.Call("vthreshold", {}, -1, GET, oss); +// REQUIRE(oss.str() == "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_ll[i], false, {i}); +// det.setDAC(defs::VCMP_RL, vcmp_ll[i], false, {i}); +// det.setDAC(defs::VCMP_RR, vcmp_ll[i], false, {i}); +// det.setDAC(defs::VCP, vcp[i], false, {i}); +// } +// } +// } +// } diff --git a/slsDetectorSoftware/tests/test-CmdProxy.cpp b/slsDetectorSoftware/tests/test-CmdProxy.cpp index 188075f91..f0cf1dcf3 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy.cpp @@ -1386,32 +1386,9 @@ TEST_CASE("user", "[.cmd]") { REQUIRE_THROWS(proxy.Call("user", {}, -1, PUT)); } -// TEST_CASE("now", "[.cmd]") { -// if (test::type == slsDetectorDefs::JUNGFRAU || test::type == -// slsDetectorDefs::CHIPTESTBOARD) { -// REQUIRE_NOTHROW(multiSlsDetectorClient("now", GET)); -// } else { -// REQUIRE_THROWS(multiSlsDetectorClient("now", GET)); -// } -// } -// TEST_CASE("timestamp", "[.cmd]") { -// if (test::type == slsDetectorDefs::JUNGFRAU || test::type == -// slsDetectorDefs::CHIPTESTBOARD) { -// REQUIRE_NOTHROW(multiSlsDetectorClient("timestamp", GET)); -// } else { -// REQUIRE_THROWS(multiSlsDetectorClient("timestamp", GET)); -// } -// } -// TEST_CASE("nframes", "[.cmd]") { -// if (test::type == slsDetectorDefs::JUNGFRAU || test::type == -// slsDetectorDefs::CHIPTESTBOARD) { -// REQUIRE_NOTHROW(multiSlsDetectorClient("nframes", GET)); -// } else { -// REQUIRE_THROWS(multiSlsDetectorClient("nframes", GET)); -// } -// } + // TEST_CASE("execcommand", "[.cmd]") { // REQUIRE_NOTHROW(multiSlsDetectorClient("execcommand ls", PUT)); @@ -1451,16 +1428,7 @@ TEST_CASE("stopport", "[.cmd]") { REQUIRE(port == 1953); } -// TEST_CASE("adcreg", "[.cmd]") { -// if (test::type == slsDetectorDefs::JUNGFRAU || test::type == -// slsDetectorDefs::CHIPTESTBOARD || test::type == -// slsDetectorDefs::GOTTHARD) { -// REQUIRE_THROWS(multiSlsDetectorClient("adcreg 0x34", PUT)); -// REQUIRE_THROWS(multiSlsDetectorClient("adcreg", GET)); -// } else { -// REQUIRE_THROWS(multiSlsDetectorClient("adcreg 0x45 0x3", PUT)); -// } -// } + // TEST_CASE("bustest", "[.cmd]") { // if (test::type == slsDetectorDefs::JUNGFRAU || test::type == @@ -2773,27 +2741,7 @@ TEST_CASE("stopport", "[.cmd]") { // } // } -// TEST_CASE("powerchip", "[.cmd][.jungfrau]") { -// if (test::type == slsDetectorDefs::JUNGFRAU) { -// { -// std::ostringstream oss; -// REQUIRE_NOTHROW(multiSlsDetectorClient("powerchip 1", PUT, -// nullptr, oss)); REQUIRE(oss.str() == "powerchip 1\n"); -// } -// { -// std::ostringstream oss; -// REQUIRE_NOTHROW(multiSlsDetectorClient("powerchip 0", PUT, -// nullptr, oss)); REQUIRE(oss.str() == "powerchip 0\n"); -// } -// { -// std::ostringstream oss; -// REQUIRE_NOTHROW(multiSlsDetectorClient("powerchip", GET, nullptr, -// oss)); REQUIRE(oss.str() == "powerchip 0\n"); -// } -// } else { -// REQUIRE_THROWS(multiSlsDetectorClient("powerchip", GET)); -// } -// } + // TEST_CASE("temp_", "[.cmd][.jungfrau]") { // if (test::type == slsDetectorDefs::JUNGFRAU) {