more of sendToDetector

This commit is contained in:
Erik Frojdh
2019-04-24 14:39:08 +02:00
parent 834b1e58ea
commit dbf927901f
5 changed files with 230 additions and 331 deletions

View File

@ -4,9 +4,19 @@
#include "tests/globals.h"
#include <iostream>
TEST_CASE("Set and get dacs", "[.eigerintegration][cli]") {
multiSlsDetector d(0, true, true);
d.setHostname(hostname.c_str());
class MultiDetectorFixture {
protected:
multiSlsDetector d;
public:
MultiDetectorFixture() : d(0, true, true) {
d.setHostname(hostname.c_str());
}
~MultiDetectorFixture() { d.freeSharedMemory(); }
};
TEST_CASE_METHOD(MultiDetectorFixture, "Set and get dacs",
"[.eigerintegration][cli]") {
auto th = 1000;
// set and read back each individual dac of EIGER
@ -64,14 +74,10 @@ TEST_CASE("Set and get dacs", "[.eigerintegration][cli]") {
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());
TEST_CASE_METHOD(MultiDetectorFixture, "Read temperatures",
"[.eigerintegration][cli]") {
std::vector<di> tempindex{di::TEMPERATURE_FPGA, di::TEMPERATURE_FPGA2,
di::TEMPERATURE_FPGA3};
for (auto index : tempindex) {
@ -83,19 +89,15 @@ TEST_CASE("Read temperatures", "[.eigerintegration][cli]") {
}
}
int to_time(uint32_t reg){
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
uint32_t exponent = (reg & 0b111) + 1;
return clocks * pow(10, exponent);
}
TEST_CASE("Read/write register", "[.eigerintegration][cli]"){
multiSlsDetector d(0, true, true);
d.setHostname(hostname.c_str());
TEST_CASE_METHOD(MultiDetectorFixture, "Read/write register",
"[.eigerintegration][cli]") {
d.setTimer(ti::MEASUREMENTS_NUMBER, 1);
d.setNumberOfFrames(1);
d.setExposureTime(10000);
d.acquire();
@ -103,5 +105,83 @@ TEST_CASE("Read/write register", "[.eigerintegration][cli]"){
d.writeRegister(0x4, 500);
CHECK(d.readRegister(0x4) == 500);
}
}
TEST_CASE_METHOD(MultiDetectorFixture, "Set dynamic range",
"[.eigerintegration][cli]") {
std::vector<int> dynamic_range{4, 8, 16, 32};
for (auto dr : dynamic_range) {
d.setDynamicRange(dr);
CHECK(d.setDynamicRange() == dr);
}
}
TEST_CASE_METHOD(MultiDetectorFixture, "Set clock divider",
"[.eigerintegration][cli]") {
for (int i = 0; i != 3; ++i) {
d.setSpeed(sv::CLOCK_DIVIDER, i);
CHECK(d.setSpeed(sv::CLOCK_DIVIDER) == i);
}
}
TEST_CASE_METHOD(MultiDetectorFixture, "Get time left",
"[.eigerintegration][cli]") {
CHECK_THROWS(d.getTimeLeft(ti::PROGRESS));
}
TEST_CASE_METHOD(MultiDetectorFixture, "Get ID", "[.eigerintegration][cli]") {
std::string hn = hostname;
hn.erase(std::remove(begin(hn), end(hn), 'b'), end(hn));
hn.erase(std::remove(begin(hn), end(hn), 'e'), end(hn));
auto hostnames = sls::split(hn, '+');
CHECK(hostnames.size() == d.getNumberOfDetectors());
for (int i = 0; i != d.getNumberOfDetectors(); ++i) {
CHECK(d.getId(defs::DETECTOR_SERIAL_NUMBER, 0) ==
std::stoi(hostnames[0]));
}
}
TEST_CASE_METHOD(MultiDetectorFixture, "Lock server",
"[.eigerintegration][cli]") {
d.lockServer(1);
CHECK(d.lockServer() == 1);
d.lockServer(0);
CHECK(d.lockServer() == 0);
}
TEST_CASE_METHOD(MultiDetectorFixture, "Settings", "[.eigerintegration][cli]") {
CHECK(d.setSettings(defs::STANDARD) == defs::STANDARD);
}
TEST_CASE_METHOD(MultiDetectorFixture, "Set readout flags",
"[.eigerintegration][cli]") {
d.setReadOutFlags(defs::PARALLEL);
CHECK((d.setReadOutFlags() & defs::PARALLEL));
d.setReadOutFlags(defs::NONPARALLEL);
CHECK_FALSE((d.setReadOutFlags() & defs::PARALLEL));
CHECK((d.setReadOutFlags() & defs::NONPARALLEL));
}
TEST_CASE_METHOD(MultiDetectorFixture, "Flow control 10gbe",
"[.eigerintegration][cli]") {
d.setFlowControl10G(1);
CHECK(d.setFlowControl10G() == 1);
d.setFlowControl10G(0);
CHECK(d.setFlowControl10G() == 0);
}
TEST_CASE_METHOD(MultiDetectorFixture, "activate", "[.eigerintegration][cli]") {
d.activate(0);
CHECK(d.activate() == 0);
d.activate(1);
CHECK(d.activate() == 1);
}
TEST_CASE_METHOD(MultiDetectorFixture, "all trimbits", "[.eigerintegration][cli]") {
d.setAllTrimbits(32);
CHECK(d.setAllTrimbits(-1) == 32);
}

View File

@ -15,13 +15,14 @@
// 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;
// using dt = slsDetectorDefs::detectorType;
// extern std::string hostname;
// extern std::string detector_type;
// extern dt type;
TEST_CASE("Single detector no receiver", "[.integration][cli]") {
TEST_CASE("Single detector no receiver", "[.integration][.single]") {
auto t = slsDetector::getTypeFromDetector(hostname);
CHECK(t == type);
@ -35,9 +36,57 @@ TEST_CASE("Single detector no receiver", "[.integration][cli]") {
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
@ -91,63 +140,11 @@ TEST_CASE("single EIGER detector no receiver basic set and get",
d.freeSharedMemory();
}
TEST_CASE("Set control port then create a new object with this control port",
"[.integration]") {
/*
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;
SingleDetectorConfig c;
{
auto type = slsDetector::getTypeFromDetector(c.hostname);
CHECK(type == c.type_enum);
slsDetector d(type);
d.setHostname(c.hostname);
d.setOnline(true);
CHECK(d.getControlPort() == old_cport);
d.setControlPort(new_cport);
CHECK(d.getStopPort() == old_sport);
d.setStopPort(new_sport);
d.freeSharedMemory();
}
{
auto type = slsDetector::getTypeFromDetector(c.hostname, new_cport);
CHECK(type == c.type_enum);
slsDetector d(type);
d.setHostname(c.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();
}
auto type = slsDetector::getTypeFromDetector(c.hostname);
CHECK(type == c.type_enum);
TEST_CASE("Locking mechanism and last ip", "[.integration][.single]") {
slsDetector d(type);
d.setHostname(c.hostname);
d.setOnline(true);
CHECK(d.getStopPort() == DEFAULT_PORTNO + 1);
d.freeSharedMemory();
}
TEST_CASE("Locking mechanism and last ip", "[.integration]") {
SingleDetectorConfig c;
auto type = slsDetector::getTypeFromDetector(c.hostname);
slsDetector d(type);
d.setHostname(c.hostname);
d.setHostname(hostname);
d.setOnline(true);
// Check that detector server is unlocked then lock
@ -164,10 +161,18 @@ TEST_CASE("Locking mechanism and last ip", "[.integration]") {
d.lockServer(0);
CHECK(d.lockServer() == 0);
CHECK(d.getLastClientIP() == c.my_ip);
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,