#include "catch.hpp" #include "ClientSocket.h" #include "logger.h" #include "multiSlsDetector.h" #include "slsDetector.h" #include "sls_detector_defs.h" #include "Timer.h" #include "sls_detector_funcs.h" #include #include #define VERBOSE // Header holding all configurations for different detectors #include "tests/config.h" #include "tests/globals.h" // using dt = slsDetectorDefs::detectorType; // extern std::string hostname; // extern std::string detector_type; // extern dt type; TEST_CASE("Single detector no receiver", "[.integration][.single]") { 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); CHECK(d.setDetectorType() == type); d.freeSharedMemory(); } TEST_CASE("Set control port then create a new object with this control port", "[.integration][.single]") { /* TODO! 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 */ int old_cport = DEFAULT_PORTNO; int old_sport = DEFAULT_PORTNO + 1; int new_cport = 1993; int new_sport = 2000; { slsDetector d(type); d.setHostname(hostname); d.setOnline(true); CHECK(d.getControlPort() == old_cport); d.setControlPort(new_cport); CHECK(d.getStopPort() == old_sport); d.setStopPort(new_sport); d.freeSharedMemory(); } { slsDetector d(type); d.setHostname(hostname); d.setControlPort(new_cport); d.setStopPort(new_sport); CHECK(d.getControlPort() == new_cport); CHECK(d.getStopPort() == new_sport); d.setOnline(true); // Reset standard ports d.setControlPort(old_cport); d.setStopPort(old_sport); d.freeSharedMemory(); } slsDetector d(type); d.setHostname(hostname); d.setOnline(true); CHECK(d.getStopPort() == DEFAULT_PORTNO + 1); 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 auto type = slsDetector::getTypeFromDetector(c.hostname); CHECK(type == c.type_enum); // Create slsDetector of said type and set hostname and detector online slsDetector d(type); CHECK(d.getDetectorTypeAsEnum() == type); CHECK(d.getDetectorTypeAsString() == c.type_string); d.setHostname(c.hostname); CHECK(d.getHostname() == c.hostname); d.setOnline(true); CHECK(d.getOnlineFlag() == true); CHECK(d.getReceiverOnline() == false); CHECK(d.checkDetectorVersionCompatibility() == slsDetectorDefs::OK); // 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 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.getNChans() == 256 * 256); CHECK(d.getNChans(slsDetectorDefs::dimension::X) == 256); CHECK(d.getNChans(slsDetectorDefs::dimension::Y) == 256); // CHECK(d.getNChans(slsDetectorDefs::dimension::Z) == 1); CHECK(d.getNChips() == 4); CHECK(d.getNChips(slsDetectorDefs::dimension::X) == 4); CHECK(d.getNChips(slsDetectorDefs::dimension::Y) == 1); // CHECK(d.getNChips(slsDetectorDefs::dimension::Z) == 1); d.freeSharedMemory(); } TEST_CASE("Locking mechanism and last ip", "[.integration][.single]") { slsDetector d(type); d.setHostname(hostname); d.setOnline(true); // 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 auto t = 1300000000; d.setTimer(slsDetectorDefs::timerIndex::ACQUISITION_TIME, t); CHECK(d.setTimer(slsDetectorDefs::timerIndex::ACQUISITION_TIME) == t); // unlock again and free d.lockServer(0); CHECK(d.lockServer() == 0); CHECK(d.getLastClientIP() == my_ip); d.freeSharedMemory(); } TEST_CASE("Set settings", "[.integration][.single]"){ slsDetector d(type); d.setHostname(hostname); d.setOnline(true); CHECK(d.setSettings(defs::STANDARD) == defs::STANDARD); } 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) // */ // PROGRESS, /**< fraction of measurement elapsed - only get! */ // MEASUREMENTS_NUMBER, // FRAMES_FROM_START, // FRAMES_FROM_START_PG, // SAMPLES, // SUBFRAME_ACQUISITION_TIME, /**< subframe exposure time */ // STORAGE_CELL_NUMBER, /** list = m.getReceiverDbitList(); list.clear(); for (int i = 0; i < 10; ++i) list.push_back(i); m.setReceiverDbitList(list); CHECK(m.getReceiverDbitList().size() == 10); list.push_back(64); CHECK_THROWS_AS(m.setReceiverDbitList(list), sls::RuntimeError); CHECK_THROWS_WITH(m.setReceiverDbitList(list), Catch::Matchers::Contains("be between 0 and 63")); list.clear(); for (int i = 0; i < 65; ++i) list.push_back(i); CHECK(list.size() == 65); CHECK_THROWS_WITH(m.setReceiverDbitList(list), Catch::Matchers::Contains("be greater than 64")); list.clear(); m.setReceiverDbitList(list); CHECK(m.getReceiverDbitList().empty()); // adcinvert m.setADCInvert(0); CHECK(m.getADCInvert() == 0); m.setADCInvert(5); CHECK(m.getADCInvert() == 5); m.setADCInvert(-1); CHECK(m.getADCInvert() == -1); // ext sampling reg m.setExternalSamplingSource(0); CHECK(m.getExternalSamplingSource() == 0); m.setExternalSamplingSource(62); CHECK(m.getExternalSamplingSource() == 62); CHECK_THROWS_WITH(m.setExternalSamplingSource(64), Catch::Matchers::Contains("be 0-63")); CHECK(m.getExternalSamplingSource() == 62); m.setExternalSampling(1); CHECK(m.getExternalSampling() == 1); m.setExternalSampling(0); CHECK(m.getExternalSampling() == 0); m.setExternalSampling(1); CHECK(m.getExternalSampling() == 1); CHECK(m.readRegister(0x7b) == 0x1003E); }