adding config for tests

This commit is contained in:
Erik Frojdh 2019-04-23 17:37:02 +02:00
parent 72091f47d9
commit 02fd4b356e
9 changed files with 258 additions and 91 deletions

View File

@ -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';

View File

@ -14,9 +14,32 @@
#define VERBOSE
// Header holding all configurations for different detectors
#include "config.h"
#include "tests/config.h"
TEST_CASE("single EIGER detector no receiver basic set and get", "[.integration]") {
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;
@ -48,9 +71,12 @@ TEST_CASE("single EIGER detector no receiver basic set and get", "[.integration]
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);
@ -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;
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);
if (type == dt::EIGER) {
auto subtime = 200;
d.setTimer(slsDetectorDefs::timerIndex::SUBFRAME_ACQUISITION_TIME, subtime);
CHECK(d.setTimer(slsDetectorDefs::timerIndex::SUBFRAME_ACQUISITION_TIME) == subtime);
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,15 +257,16 @@ 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;
@ -277,7 +319,6 @@ TEST_CASE("Eiger Dynamic Range with effect on rate correction and clock divider"
CHECK(m.getRateCorrection() == 0);
}
TEST_CASE("Chiptestboard Loading Patterns", "[.ctbintegration]") {
SingleDetectorConfig c;
@ -315,24 +356,29 @@ TEST_CASE("Chiptestboard Loading Patterns", "[.ctbintegration]") {
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_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_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;

View File

@ -1,11 +1,78 @@
// #include "catch.hpp"
// #include "multiSlsDetector.h"
#include "catch.hpp"
// #include <iostream>
// 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);
#include "multiSlsDetector.h"
#include "string_utils.h"
// }
#include "tests/globals.h"
#include <iostream>
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 get dacs", "[.integration][.multi]"){
multiSlsDetector d(0, true, true);
d.setHostname(hostname.c_str());
switch(type){
case dt::EIGER:
d.setDAC(3500, di::E_Vrf, 0);
CHECK(d.setDAC(-1, di::E_Vrf, 0) == 3500);
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(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);
auto th = 1000;
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);
break;
}
d.freeSharedMemory();
}
TEST_CASE("Timers", "[.integration][.multi]") {
multiSlsDetector d(0, true, true);
d.setHostname(hostname.c_str());
int n_frames = 3;
d.setNumberOfFrames(n_frames);
CHECK(d.setNumberOfFrames() == n_frames);
double exptime = 1;
d.setExposureTime(exptime, true);
CHECK(d.setExposureTime(-1, true) == exptime);
d.freeSharedMemory();
}

View File

@ -292,6 +292,8 @@ class slsDetector : public virtual slsDetectorDefs{
int64_t getId(idMode mode);
int sendToDetector(int fnum, void* args, size_t args_size, void* retval, size_t retval_size);
int64_t getReceiverSoftwareVersion() const;
/**

View File

@ -1826,16 +1826,13 @@ int slsDetector::getDataBytesInclGapPixels() {
int slsDetector::setDAC(int val, dacIndex index, int mV) {
int fnum = F_SET_DAC;
int ret = FAIL;
int args[3]{static_cast<int>(index), mV, val};
int args[]{static_cast<int>(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));
ret = sendToDetector(fnum, args, sizeof(args), &retval, sizeof(retval));
FILE_LOG(logDEBUG1) << "Dac index " << index << ": " << retval
<< (mV != 0 ? "mV" : "dac units");
}
@ -1845,6 +1842,15 @@ int slsDetector::setDAC(int val, dacIndex index, int mV) {
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);
return client.sendCommandThenRead(fnum, args, args_size, retval, retval_size);
}
int slsDetector::getADC(dacIndex index) {
int fnum = F_GET_ADC;
int arg = static_cast<int>(index);
@ -1870,10 +1876,10 @@ 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));
// auto client = DetectorSocket(detector_shm()->hostname,
// detector_shm()->controlPort);
// ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval,sizeof(retval));
FILE_LOG(logDEBUG1) << "Timing Mode: " << retval;
}
if (ret == FORCE_UPDATE) {

View File

@ -1,5 +1,6 @@
include_directories(
${PROJECT_SOURCE_DIR}/catch
include
)
set(SLS_TEST_SOURCES

View File

@ -1,5 +1,8 @@
#pragma once
#include <string>
#include "sls_detector_defs.h"
struct SingleDetectorConfig {
slsDetectorDefs::detectorType type_enum =
slsDetectorDefs::detectorType::CHIPTESTBOARD;

View File

@ -0,0 +1,6 @@
#include "sls_detector_defs.h"
using dt = slsDetectorDefs::detectorType;
using di = slsDetectorDefs::dacIndex;
extern std::string hostname;
extern std::string detector_type;
extern dt type;

View File

@ -1,3 +1,38 @@
// tests-main.cpp
#define CATCH_CONFIG_MAIN
// #define CATCH_CONFIG_MAIN
// #include "catch.hpp"
#define CATCH_CONFIG_RUNNER
#include "catch.hpp"
#include "sls_detector_defs.h"
#include "tests/config.h"
#include <string>
// 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();
}