diff --git a/integrationTests/CMakeLists.txt b/integrationTests/CMakeLists.txt index df8f9aa07..5bfc62e07 100755 --- a/integrationTests/CMakeLists.txt +++ b/integrationTests/CMakeLists.txt @@ -10,6 +10,7 @@ target_sources(tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test-integrationMulti.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-integrationDectector.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test-eigerIntegration.cpp ) # if(SLS_USE_TESTS) diff --git a/integrationTests/a.cpp b/integrationTests/a.cpp index 40cc3044a..216fc41a8 100644 --- a/integrationTests/a.cpp +++ b/integrationTests/a.cpp @@ -36,9 +36,10 @@ std::ostream &operator<<(std::ostream &out, const ROI &r) { int main() { - int ret[]{0,0,0}; - for (auto i: ret) - std::cout << i << "\n"; + std::cout << "nullptr: " << sizeof(nullptr) << "\n"; + // int ret[]{0,0,0}; + // for (auto i: ret) + // std::cout << i << "\n"; // uint32_t imageSize = 101; // uint32_t packetSize = 100; // std::cout << "a: " << std::ceil((double)imageSize / (double)packetSize) <<'\n'; diff --git a/integrationTests/test-eigerIntegration.cpp b/integrationTests/test-eigerIntegration.cpp new file mode 100644 index 000000000..bd19151d7 --- /dev/null +++ b/integrationTests/test-eigerIntegration.cpp @@ -0,0 +1,107 @@ +#include "catch.hpp" +#include "multiSlsDetector.h" +#include "string_utils.h" +#include "tests/globals.h" +#include + +TEST_CASE("Set and get dacs", "[.eigerintegration][cli]") { + multiSlsDetector d(0, true, true); + d.setHostname(hostname.c_str()); + auto th = 1000; + + // set and read back each individual dac of EIGER + d.setDAC(0, di::E_SvP, 0); + CHECK(d.setDAC(-1, di::E_SvP, 0) == 0); + d.setDAC(4000, di::E_SvN, 0); + CHECK(d.setDAC(-1, di::E_SvN, 0) == 4000); + d.setDAC(2000, di::E_Vtr, 0); + CHECK(d.setDAC(-1, di::E_Vtr, 0) == 2000); + d.setDAC(3500, di::E_Vrf, 0); + CHECK(d.setDAC(-1, di::E_Vrf, 0) == 3500); + d.setDAC(1400, di::E_Vrs, 0); + CHECK(d.setDAC(-1, di::E_Vrs, 0) == 1400); + d.setDAC(2556, di::E_Vtgstv, 0); + CHECK(d.setDAC(-1, di::E_Vtgstv, 0) == 2556); + d.setDAC(1500, di::E_Vcmp_ll, 0); + CHECK(d.setDAC(-1, di::E_Vcmp_ll, 0) == 1500); + d.setDAC(1400, di::E_Vcmp_lr, 0); + CHECK(d.setDAC(-1, di::E_Vcmp_lr, 0) == 1400); + d.setDAC(4000, di::E_cal, 0); + CHECK(d.setDAC(-1, di::E_cal, 0) == 4000); + d.setDAC(1300, di::E_Vcmp_rl, 0); + CHECK(d.setDAC(-1, di::E_Vcmp_rl, 0) == 1300); + d.setDAC(1200, di::E_Vcmp_rr, 0); + CHECK(d.setDAC(-1, di::E_Vcmp_rr, 0) == 1200); + d.setDAC(1100, di::E_rxb_rb, 0); + CHECK(d.setDAC(-1, di::E_rxb_rb, 0) == 1100); + d.setDAC(1100, di::E_rxb_lb, 0); + CHECK(d.setDAC(-1, di::E_rxb_lb, 0) == 1100); + d.setDAC(1500, di::E_Vcp, 0); + CHECK(d.setDAC(-1, di::E_Vcp, 0) == 1500); + d.setDAC(2000, di::E_Vcn, 0); + CHECK(d.setDAC(-1, di::E_Vcn, 0) == 2000); + d.setDAC(1550, di::E_Vis, 0); + CHECK(d.setDAC(-1, di::E_Vis, 0) == 1550); + d.setDAC(660, di::IO_DELAY, 0); + CHECK(d.setDAC(-1, di::IO_DELAY, 0) == 660); + + // setting threshold sets all individual vcmp + d.setDAC(th, di::THRESHOLD, 0); + CHECK(d.setDAC(-1, di::THRESHOLD, 0) == th); + CHECK(d.setDAC(-1, di::E_Vcmp_ll, 0) == th); + CHECK(d.setDAC(-1, di::E_Vcmp_lr, 0) == th); + CHECK(d.setDAC(-1, di::E_Vcmp_rl, 0) == th); + CHECK(d.setDAC(-1, di::E_Vcmp_rr, 0) == th); + + // different values gives -1 + if (d.getNumberOfDetectors() > 1) { + d.setDAC(1600, di::E_Vcmp_ll, 0, 0); + d.setDAC(1700, di::E_Vcmp_ll, 0, 1); + CHECK(d.setDAC(-1, di::E_Vcmp_ll, 0, 0) == 1600); + CHECK(d.setDAC(-1, di::E_Vcmp_ll, 0, 1) == 1700); + CHECK(d.setDAC(-1, di::E_Vcmp_ll, 0) == -1); + CHECK(d.setDAC(-1, di::THRESHOLD, 0) == -1); + CHECK(d.setDAC(-1, di::THRESHOLD, 0, 0) == -1); + CHECK(d.setDAC(-1, di::THRESHOLD, 0, 1) == -1); + } + + d.freeSharedMemory(); +} + +TEST_CASE("Read temperatures", "[.eigerintegration][cli]") { + multiSlsDetector d(0, true, true); + d.setHostname(hostname.c_str()); + + std::vector tempindex{di::TEMPERATURE_FPGA, di::TEMPERATURE_FPGA2, + di::TEMPERATURE_FPGA3}; + for (auto index : tempindex) { + for (int i = 0; i != d.getNumberOfDetectors(); ++i) { + double temp = static_cast(d.getADC(index, 0)) / 1000; + CHECK(temp > 20); + CHECK(temp < 60); + } + } +} + +int to_time(uint32_t reg){ + uint32_t clocks = reg >> 3; + uint32_t exponent = (reg & 0b111)+1; + return clocks*pow(10, exponent); + // clocks = register >> 3 + // exponent = register & 0b111 + // return clocks*10**exponent / 100e6 +} + +TEST_CASE("Read/write register", "[.eigerintegration][cli]"){ + multiSlsDetector d(0, true, true); + d.setHostname(hostname.c_str()); + + d.setNumberOfFrames(1); + d.setExposureTime(10000); + d.acquire(); + CHECK(to_time(d.readRegister(0x4, 0)) == 10000); + + d.writeRegister(0x4, 500); + CHECK(d.readRegister(0x4) == 500); + +} \ No newline at end of file diff --git a/integrationTests/test-integrationDectector.cpp b/integrationTests/test-integrationDectector.cpp index 6d4805752..e596933be 100755 --- a/integrationTests/test-integrationDectector.cpp +++ b/integrationTests/test-integrationDectector.cpp @@ -13,18 +13,41 @@ #include #define VERBOSE -//Header holding all configurations for different detectors -#include "config.h" +// Header holding all configurations for different detectors +#include "tests/config.h" -TEST_CASE("single EIGER detector no receiver basic set and get", "[.integration]") { - //TODO! this test should take command line arguments for config +using dt = slsDetectorDefs::detectorType; +extern std::string hostname; +extern std::string detector_type; +extern dt type; + +TEST_CASE("Single detector no receiver", "[.integration][cli]") { + auto t = slsDetector::getTypeFromDetector(hostname); + CHECK(t == type); + + slsDetector d(t); + CHECK(d.getDetectorTypeAsEnum() == t); + CHECK(d.getDetectorTypeAsString() == detector_type); + + d.setHostname(hostname); + CHECK(d.getHostname() == hostname); + + d.setOnline(true); + CHECK(d.getOnlineFlag() == true); + + d.freeSharedMemory(); +} + +TEST_CASE("single EIGER detector no receiver basic set and get", + "[.integration][eiger]") { + // TODO! this test should take command line arguments for config SingleDetectorConfig c; - //Read type by connecting to the detector + // Read type by connecting to the detector auto type = slsDetector::getTypeFromDetector(c.hostname); CHECK(type == c.type_enum); - //Create slsDetector of said type and set hostname and detector online + // Create slsDetector of said type and set hostname and detector online slsDetector d(type); CHECK(d.getDetectorTypeAsEnum() == type); CHECK(d.getDetectorTypeAsString() == c.type_string); @@ -38,19 +61,22 @@ TEST_CASE("single EIGER detector no receiver basic set and get", "[.integration] CHECK(d.getReceiverOnline() == false); CHECK(d.checkDetectorVersionCompatibility() == slsDetectorDefs::OK); - //Setting and reading exposure time + // Setting and reading exposure time auto t = 1000000000; d.setTimer(slsDetectorDefs::timerIndex::ACQUISITION_TIME, t); CHECK(d.setTimer(slsDetectorDefs::timerIndex::ACQUISITION_TIME) == t); - //size of an eiger half module with and without gap pixels + // size of an eiger half module with and without gap pixels CHECK(d.getTotalNumberOfChannels() == 256 * 256 * 4); CHECK(d.getTotalNumberOfChannels(slsDetectorDefs::dimension::X) == 1024); CHECK(d.getTotalNumberOfChannels(slsDetectorDefs::dimension::Y) == 256); // CHECK(d.getTotalNumberOfChannels(slsDetectorDefs::dimension::Z) == 1); - CHECK(d.getTotalNumberOfChannelsInclGapPixels(slsDetectorDefs::dimension::X) == 1024); - CHECK(d.getTotalNumberOfChannelsInclGapPixels(slsDetectorDefs::dimension::Y) == 256); - // CHECK(d.getTotalNumberOfChannelsInclGapPixels(slsDetectorDefs::dimension::Z) == 1); + CHECK(d.getTotalNumberOfChannelsInclGapPixels( + slsDetectorDefs::dimension::X) == 1024); + CHECK(d.getTotalNumberOfChannelsInclGapPixels( + slsDetectorDefs::dimension::Y) == 256); + // CHECK(d.getTotalNumberOfChannelsInclGapPixels(slsDetectorDefs::dimension::Z) + // == 1); CHECK(d.getNChans() == 256 * 256); CHECK(d.getNChans(slsDetectorDefs::dimension::X) == 256); @@ -69,7 +95,7 @@ TEST_CASE("Set control port then create a new object with this control port", "[.integration]") { /* TODO! - Standard port but should not be hardcoded + Standard port but should not be hardcoded Is this the best way to initialize the detectors Using braces to make the object go out of scope */ @@ -102,7 +128,7 @@ TEST_CASE("Set control port then create a new object with this control port", d.setOnline(true); - //Reset standard ports + // Reset standard ports d.setControlPort(old_cport); d.setStopPort(old_sport); d.freeSharedMemory(); @@ -124,17 +150,17 @@ TEST_CASE("Locking mechanism and last ip", "[.integration]") { d.setHostname(c.hostname); d.setOnline(true); - //Check that detector server is unlocked then lock + // Check that detector server is unlocked then lock CHECK(d.lockServer() == 0); d.lockServer(1); CHECK(d.lockServer() == 1); - //Can we still access the detector while it's locked + // Can we still access the detector while it's locked auto t = 1300000000; d.setTimer(slsDetectorDefs::timerIndex::ACQUISITION_TIME, t); CHECK(d.setTimer(slsDetectorDefs::timerIndex::ACQUISITION_TIME) == t); - //unlock again and free + // unlock again and free d.lockServer(0); CHECK(d.lockServer() == 0); @@ -142,15 +168,17 @@ TEST_CASE("Locking mechanism and last ip", "[.integration]") { d.freeSharedMemory(); } -TEST_CASE("Excersise all possible set timer functions", "[.integration]") { - // FRAME_NUMBER, /**< number of real time frames: total number of acquisitions is number or frames*number of cycles */ - // ACQUISITION_TIME, /**< exposure time */ - // FRAME_PERIOD, /**< period between exposures */ - // DELAY_AFTER_TRIGGER, /**< delay between trigger and start of exposure or readout (in triggered mode) */ - // GATES_NUMBER, /**< number of gates per frame (in gated mode) */ - // CYCLES_NUMBER, /**< number of cycles: total number of acquisitions is number or frames*number of cycles */ +TEST_CASE("Timer functions", "[.integration][cli]") { + // FRAME_NUMBER, /**< number of real time frames: total number of + // acquisitions is number or frames*number of cycles */ ACQUISITION_TIME, + // /**< exposure time */ FRAME_PERIOD, /**< period between exposures */ + // DELAY_AFTER_TRIGGER, /**< delay between trigger and start of exposure or + // readout (in triggered mode) */ GATES_NUMBER, /**< number of gates per + // frame (in gated mode) */ CYCLES_NUMBER, /**< number of cycles: total + // number of acquisitions is number or frames*number of cycles */ // ACTUAL_TIME, /**< Actual time of the detector's internal timer */ - // MEASUREMENT_TIME, /**< Time of the measurement from the detector (fifo) */ + // MEASUREMENT_TIME, /**< Time of the measurement from the detector (fifo) + // */ // PROGRESS, /**< fraction of measurement elapsed - only get! */ // MEASUREMENTS_NUMBER, @@ -163,43 +191,56 @@ TEST_CASE("Excersise all possible set timer functions", "[.integration]") { // MEASURED_PERIOD, /**< measured period */ // MEASURED_SUBPERIOD, /**< measured subperiod */ // MAX_TIMERS - SingleDetectorConfig c; - auto type = slsDetector::getTypeFromDetector(c.hostname); + slsDetector d(type); - d.setHostname(c.hostname); + d.setHostname(hostname); d.setOnline(true); - //Number of frames - auto frames = 10; + // Number of frames + auto frames = 5; d.setTimer(slsDetectorDefs::timerIndex::FRAME_NUMBER, frames); CHECK(d.setTimer(slsDetectorDefs::timerIndex::FRAME_NUMBER) == frames); - auto t = 10000000; - d.setTimer(slsDetectorDefs::timerIndex::ACQUISITION_TIME, t); - CHECK(d.setTimer(slsDetectorDefs::timerIndex::ACQUISITION_TIME) == t); + auto exptime = 2000000000; + d.setTimer(slsDetectorDefs::timerIndex::ACQUISITION_TIME, exptime); + CHECK(d.setTimer(slsDetectorDefs::timerIndex::ACQUISITION_TIME) == exptime); - auto period = 1000000000; + auto period = 2000000000; d.setTimer(slsDetectorDefs::timerIndex::FRAME_PERIOD, period); CHECK(d.setTimer(slsDetectorDefs::timerIndex::FRAME_PERIOD) == period); - // not implemented for EIGER - // auto delay = 10000; - // d.setTimer(slsDetectorDefs::timerIndex::DELAY_AFTER_TRIGGER, delay); - // CHECK(d.setTimer(slsDetectorDefs::timerIndex::DELAY_AFTER_TRIGGER) == delay); + if (type != dt::EIGER) { + auto delay = 10000; + d.setTimer(slsDetectorDefs::timerIndex::DELAY_AFTER_TRIGGER, delay); + CHECK(d.setTimer(slsDetectorDefs::timerIndex::DELAY_AFTER_TRIGGER) == + delay); + } - // auto gates = 1; - // d.setTimer(slsDetectorDefs::timerIndex::GATES_NUMBER, gates); - // CHECK(d.setTimer(slsDetectorDefs::timerIndex::GATES_NUMBER) == gates); + if (type != dt::EIGER) { + auto gates = 1; + d.setTimer(slsDetectorDefs::timerIndex::GATES_NUMBER, gates); + CHECK(d.setTimer(slsDetectorDefs::timerIndex::GATES_NUMBER) == gates); + } auto cycles = 2; d.setTimer(slsDetectorDefs::timerIndex::CYCLES_NUMBER, cycles); CHECK(d.setTimer(slsDetectorDefs::timerIndex::CYCLES_NUMBER) == cycles); - auto subtime = 200; - d.setTimer(slsDetectorDefs::timerIndex::SUBFRAME_ACQUISITION_TIME, subtime); - CHECK(d.setTimer(slsDetectorDefs::timerIndex::SUBFRAME_ACQUISITION_TIME) == subtime); + if (type == dt::EIGER) { + auto subtime = 200; + d.setTimer(slsDetectorDefs::timerIndex::SUBFRAME_ACQUISITION_TIME, + subtime); + CHECK(d.setTimer( + slsDetectorDefs::timerIndex::SUBFRAME_ACQUISITION_TIME) == + subtime); + } + // for (int i =0; i!=frames; ++i) + d.startAndReadAll(); d.freeSharedMemory(); + + // If we add a timer we should add tests for the timer + CHECK(slsDetectorDefs::MAX_TIMERS == 19); } // TEST_CASE("Aquire", "[.integration][eiger]"){ @@ -216,26 +257,27 @@ TEST_CASE("Excersise all possible set timer functions", "[.integration]") { // d.setTimer(slsDetectorDefs::timerIndex::FRAME_PERIOD, period); // d.startAndReadAll(); - - -// auto rperiod = d.getTimeLeft(slsDetectorDefs::timerIndex::MEASURED_PERIOD); +// auto rperiod = +// d.getTimeLeft(slsDetectorDefs::timerIndex::MEASURED_PERIOD); // CHECK(rperiod == 0.1); // d.freeSharedMemory(); // } -TEST_CASE("Eiger Dynamic Range with effect on rate correction and clock divider", "[.eigerintegration]") { +TEST_CASE( + "Eiger Dynamic Range with effect on rate correction and clock divider", + "[.eigerintegration]") { SingleDetectorConfig c; - + int ratecorr = 125; // pick up multi detector from shm id 0 multiSlsDetector m(0); // ensure eiger detector type, hostname and online - REQUIRE(m.getDetectorTypeAsEnum()==c.type_enum); - REQUIRE(m.getHostname()==c.hostname); - REQUIRE(m.setOnline(true)==slsDetectorDefs::ONLINE_FLAG); + REQUIRE(m.getDetectorTypeAsEnum() == c.type_enum); + REQUIRE(m.getHostname() == c.hostname); + REQUIRE(m.setOnline(true) == slsDetectorDefs::ONLINE_FLAG); // starting state with rate correction off CHECK(m.setRateCorrection(0) == 0); @@ -267,27 +309,26 @@ TEST_CASE("Eiger Dynamic Range with effect on rate correction and clock divider" // ratecorr fail with dr 4 or 8 CHECK_THROWS_AS(m.setDynamicRange(8), sls::NonCriticalError); - CHECK(m.getRateCorrection()==0); + CHECK(m.getRateCorrection() == 0); m.setDynamicRange(16); m.setDynamicRange(16); m.setRateCorrection(ratecorr); m.setDynamicRange(16); m.setRateCorrection(ratecorr); CHECK_THROWS_AS(m.setDynamicRange(4), sls::NonCriticalError); - CHECK(m.getRateCorrection()==0); + CHECK(m.getRateCorrection() == 0); } - TEST_CASE("Chiptestboard Loading Patterns", "[.ctbintegration]") { SingleDetectorConfig c; - - // pick up multi detector from shm id 0 + + // pick up multi detector from shm id 0 multiSlsDetector m(0); // ensure ctb detector type, hostname and online - REQUIRE(m.getDetectorTypeAsEnum()==c.type_enum); - REQUIRE(m.getHostname()==c.hostname); - REQUIRE(m.setOnline(true)==slsDetectorDefs::ONLINE_FLAG); + REQUIRE(m.getDetectorTypeAsEnum() == c.type_enum); + REQUIRE(m.getHostname() == c.hostname); + REQUIRE(m.setOnline(true) == slsDetectorDefs::ONLINE_FLAG); uint64_t word = 0; int addr = 0; @@ -314,25 +355,30 @@ TEST_CASE("Chiptestboard Loading Patterns", "[.ctbintegration]") { m.setPatternWord(addr, word); CHECK(m.setPatternWord(addr, -1) == word); addr = MAX_ADDR; - CHECK_THROWS_AS(m.setPatternWord(addr, word), sls::NonCriticalError); - CHECK_THROWS_WITH(m.setPatternWord(addr, word), Catch::Matchers::Contains( "be between 0 and" )); + CHECK_THROWS_AS(m.setPatternWord(addr, word), sls::NonCriticalError); + CHECK_THROWS_WITH(m.setPatternWord(addr, word), + Catch::Matchers::Contains("be between 0 and")); addr = -1; - CHECK_THROWS_AS(m.setPatternWord(addr, word), sls::NonCriticalError); - CHECK_THROWS_WITH(m.setPatternWord(addr, word), Catch::Matchers::Contains( "be between 0 and" )); + CHECK_THROWS_AS(m.setPatternWord(addr, word), sls::NonCriticalError); + CHECK_THROWS_WITH(m.setPatternWord(addr, word), + Catch::Matchers::Contains("be between 0 and")); addr = 0x2FF; for (level = 0; level < 3; ++level) { CHECK(m.setPatternWaitAddr(level, addr) == addr); CHECK(m.setPatternWaitAddr(level, -1) == addr); } - CHECK_THROWS_WITH(m.setPatternWaitAddr(-1, addr), Catch::Matchers::Contains( "be between 0 and" )); - CHECK_THROWS_WITH(m.setPatternWaitAddr(0, MAX_ADDR), Catch::Matchers::Contains( "be between 0 and" )); + CHECK_THROWS_WITH(m.setPatternWaitAddr(-1, addr), + Catch::Matchers::Contains("be between 0 and")); + CHECK_THROWS_WITH(m.setPatternWaitAddr(0, MAX_ADDR), + Catch::Matchers::Contains("be between 0 and")); for (level = 0; level < 3; ++level) { CHECK(m.setPatternWaitTime(level, word) == word); CHECK(m.setPatternWaitTime(level, -1) == word); } - CHECK_THROWS_WITH(m.setPatternWaitTime(-1, word), Catch::Matchers::Contains( "be between 0 and" )); + CHECK_THROWS_WITH(m.setPatternWaitTime(-1, word), + Catch::Matchers::Contains("be between 0 and")); { int startaddr = addr; @@ -354,6 +400,6 @@ TEST_CASE("Chiptestboard Loading Patterns", "[.ctbintegration]") { CHECK_THROWS_WITH(m.setPatternLoops(-1, startaddr, MAX_ADDR, nloops), Catch::Matchers::Contains("be less than")); CHECK_THROWS_WITH(m.setPatternLoops(-1, MAX_ADDR, stopaddr, nloops), - Catch::Matchers::Contains("be less than")); + Catch::Matchers::Contains("be less than")); } } \ No newline at end of file diff --git a/integrationTests/test-integrationMulti.cpp b/integrationTests/test-integrationMulti.cpp index ca16cae56..580d5723c 100755 --- a/integrationTests/test-integrationMulti.cpp +++ b/integrationTests/test-integrationMulti.cpp @@ -1,11 +1,110 @@ -// #include "catch.hpp" -// #include "multiSlsDetector.h" +#include "catch.hpp" +#include "multiSlsDetector.h" +#include "string_utils.h" +#include "tests/globals.h" +#include -// #include -// TEST_CASE("Initialize a detector") { -// multiSlsDetector det(0, true, true); -// std::cout << "Size: " << det.getNumberOfDetectors() << std::endl; -// std::cout << "Hostname: " << det.getHostname() << std::endl; -// REQUIRE(false); - -// } \ No newline at end of file +using namespace Catch::literals; + +TEST_CASE("Initialize a multi detector", "[.integration][.multi]") { + auto hostnames = sls::split(hostname, '+'); + + multiSlsDetector d(0, true, true); + d.setHostname(hostname.c_str()); + REQUIRE(d.setOnline() == true); // get! + + CHECK(d.getHostname() == hostname); + for (size_t i = 0; i != hostnames.size(); ++i) { + CHECK(d.getHostname(i) == hostnames[i]); + } + + CHECK(d.getDetectorTypeAsEnum() == type); + CHECK(d.getDetectorTypeAsString() == detector_type); + + CHECK(d.getNumberOfDetectors() == hostnames.size()); + d.freeSharedMemory(); +} + + + +TEST_CASE("Set and read timers", "[.integration][.multi]") { + + multiSlsDetector d(0, true, true); + d.setHostname(hostname.c_str()); + + // FRAME_NUMBER + int n_frames = 3; + d.setNumberOfFrames(n_frames); + CHECK(d.setNumberOfFrames() == n_frames); + + // ACQUISITION_TIME + double exptime = 0.3; + d.setExposureTime(exptime, true); + CHECK(d.setExposureTime(-1, true) == Approx(exptime)); + CHECK(d.setExposureTime(-1) == Approx(exptime * 1E9)); + + // FRAME_PERIOD, + double period = 0.5; + d.setExposurePeriod(period, true); + CHECK(d.setExposurePeriod(-1, true) == Approx(period)); + CHECK(d.setExposurePeriod(-1) == Approx(period * 1E9)); + + // DELAY_AFTER_TRIGGER, + // GATES_NUMBER, + // CYCLES_NUMBER, + // ACTUAL_TIME + // MEASUREMENT_TIME + + // PROGRESS, /**< fraction of measurement elapsed - only get! */ + // MEASUREMENTS_NUMBER, + + int measurements = 2; + d.setTimer(ti::MEASUREMENTS_NUMBER, measurements); + CHECK(d.setTimer(ti::MEASUREMENTS_NUMBER, -1) == measurements); + + // FRAMES_FROM_START, + // FRAMES_FROM_START_PG, + // SAMPLES, + + // SUBFRAME_ACQUISITION_TIME, /**< subframe exposure time */ + double subframe_exposure = 2000000; // ns + if (type == dt::EIGER) { + d.setSubFrameExposureTime(subframe_exposure); + CHECK(d.setSubFrameExposureTime(-1) == Approx(subframe_exposure)); + } + + // STORAGE_CELL_NUMBER, /**(index), mV, val}; + int args[]{static_cast(index), mV, val}; int retval = -1; FILE_LOG(logDEBUG1) << "Setting DAC " << index << " to " << val << (mV != 0 ? "mV" : "dac units"); if (detector_shm()->onlineFlag == ONLINE_FLAG) { - auto client = DetectorSocket(detector_shm()->hostname, - detector_shm()->controlPort); - ret = client.sendCommandThenRead(fnum, args, sizeof(args), &retval, - sizeof(retval)); + sendToDetector(fnum, args, sizeof(args), &retval, sizeof(retval)); FILE_LOG(logDEBUG1) << "Dac index " << index << ": " << retval << (mV != 0 ? "mV" : "dac units"); } + return retval; +} + + +int slsDetector::sendToDetector(int fnum, void* args, size_t args_size, void* retval, size_t retval_size) +{ + auto client = DetectorSocket(detector_shm()->hostname, + detector_shm()->controlPort); + auto ret = client.sendCommandThenRead(fnum, args, args_size, retval, retval_size); + client.close(); if (ret == FORCE_UPDATE) { updateDetector(); } - return retval; + return ret; } int slsDetector::getADC(dacIndex index) { @@ -1852,10 +1858,7 @@ int slsDetector::getADC(dacIndex index) { FILE_LOG(logDEBUG1) << "Getting ADC " << index; if (detector_shm()->onlineFlag == ONLINE_FLAG) { - auto client = DetectorSocket(detector_shm()->hostname, - detector_shm()->controlPort); - client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval, - sizeof(retval)); + sendToDetector(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); FILE_LOG(logDEBUG1) << "ADC (" << index << "): " << retval; } return retval; @@ -1870,10 +1873,7 @@ slsDetector::setExternalCommunicationMode(externalCommunicationMode pol) { FILE_LOG(logDEBUG1) << "Setting communication to mode " << pol; if (detector_shm()->onlineFlag == ONLINE_FLAG) { - auto client = DetectorSocket(detector_shm()->hostname, - detector_shm()->controlPort); - ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval, - sizeof(retval)); + ret = sendToDetector(fnum, &arg, sizeof(arg), &retval,sizeof(retval)); FILE_LOG(logDEBUG1) << "Timing Mode: " << retval; } if (ret == FORCE_UPDATE) { @@ -1952,45 +1952,30 @@ int slsDetector::setReadOutFlags(readOutFlags flag) { uint32_t slsDetector::writeRegister(uint32_t addr, uint32_t val) { int fnum = F_WRITE_REGISTER; - int ret = FAIL; uint32_t args[]{addr, val}; uint32_t retval = -1; FILE_LOG(logDEBUG1) << "Writing to register 0x" << std::hex << addr << "data: 0x" << std::hex << val << std::dec; if (detector_shm()->onlineFlag == ONLINE_FLAG) { - auto client = DetectorSocket(detector_shm()->hostname, - detector_shm()->controlPort); - ret = client.sendCommandThenRead(fnum, args, sizeof(args), &retval, - sizeof(retval)); + sendToDetector(fnum, args, sizeof(args), &retval, sizeof(retval)); FILE_LOG(logDEBUG1) << "Register 0x" << std::hex << addr << ": 0x" << std::hex << retval << std::dec; } - if (ret == FORCE_UPDATE) { - updateDetector(); - } return retval; } uint32_t slsDetector::readRegister(uint32_t addr) { int fnum = F_READ_REGISTER; - int ret = FAIL; - uint32_t arg = addr; uint32_t retval = -1; FILE_LOG(logDEBUG1) << "Reading register 0x" << std::hex << addr << std::dec; if (detector_shm()->onlineFlag == ONLINE_FLAG) { - auto client = DetectorSocket(detector_shm()->hostname, - detector_shm()->controlPort); - ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval, - sizeof(retval)); + sendToDetector(fnum, &addr, sizeof(addr), &retval, sizeof(retval)); FILE_LOG(logDEBUG1) << "Register 0x" << std::hex << addr << ": 0x" << std::hex << retval << std::dec; } - if (ret == FORCE_UPDATE) { - updateDetector(); - } return retval; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 61415ddc3..b8366739e 100755 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,6 @@ include_directories( ${PROJECT_SOURCE_DIR}/catch + include ) set(SLS_TEST_SOURCES diff --git a/integrationTests/config.h b/tests/include/tests/config.h similarity index 90% rename from integrationTests/config.h rename to tests/include/tests/config.h index cb8357b40..c62ddd3f9 100644 --- a/integrationTests/config.h +++ b/tests/include/tests/config.h @@ -1,5 +1,8 @@ #pragma once #include +#include "sls_detector_defs.h" + + struct SingleDetectorConfig { slsDetectorDefs::detectorType type_enum = slsDetectorDefs::detectorType::CHIPTESTBOARD; diff --git a/tests/include/tests/globals.h b/tests/include/tests/globals.h new file mode 100644 index 000000000..32967b76b --- /dev/null +++ b/tests/include/tests/globals.h @@ -0,0 +1,8 @@ +#include "sls_detector_defs.h" +using dt = slsDetectorDefs::detectorType; +using di = slsDetectorDefs::dacIndex; +using ti = slsDetectorDefs::timerIndex; +using ro = slsDetectorDefs::readOutFlags; +extern std::string hostname; +extern std::string detector_type; +extern dt type; \ No newline at end of file diff --git a/tests/test.cpp b/tests/test.cpp index 8daed99c4..857f447b6 100755 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -1,3 +1,38 @@ // tests-main.cpp -#define CATCH_CONFIG_MAIN -#include "catch.hpp" \ No newline at end of file +// #define CATCH_CONFIG_MAIN +// #include "catch.hpp" + +#define CATCH_CONFIG_RUNNER +#include "catch.hpp" +#include "sls_detector_defs.h" +#include "tests/config.h" +#include + +// using namespace Catch::clara; +using Opt = Catch::clara::Opt; +using dt = slsDetectorDefs::detectorType; + +std::string hostname; +std::string detector_type; +dt type; + +int main(int argc, char *argv[]) { + Catch::Session session; + + auto cli = session.cli() | + Opt(hostname, "hostname")["-hn"]["--hostname"]( + "Detector hostname for integration tests") | + Opt(detector_type, "detector_type")["-dt"]["--detector_type"]( + "Detector type for integration tests"); + + session.cli(cli); + + auto ret = session.applyCommandLine(argc, argv); + if (ret) { + return ret; + } + + type = slsDetectorDefs::detectorTypeToEnum(detector_type); + + return session.run(); +} \ No newline at end of file