integration test

This commit is contained in:
Erik Frojdh 2019-04-11 11:29:34 +02:00
parent 04146e683c
commit d00fd70d6d
9 changed files with 123 additions and 86 deletions

View File

@ -45,5 +45,5 @@ deploy:
provider: script provider: script
script: find $HOME/miniconda/conda-bld/${TRAVIS_OS_NAME}-64 -name "*.tar.bz2" -exec anaconda -t $CONDA_TOKEN upload --force {} \; script: find $HOME/miniconda/conda-bld/${TRAVIS_OS_NAME}-64 -name "*.tar.bz2" -exec anaconda -t $CONDA_TOKEN upload --force {} \;
on: on:
all_branches: true branch: refactor

View File

@ -63,20 +63,20 @@ outputs:
- {{compiler('cxx')}} - {{compiler('cxx')}}
- python {{ python }} - python {{ python }}
- setuptools - setuptools
- sls_detector_lib - sls_detector_lib=refactor
- pyzmq - pyzmq
- pybind11 2.2 - pybind11 2.2
host: host:
- python - python
- pybind11 2.2 - pybind11 2.2
- pyzmq - pyzmq
- sls_detector_lib - sls_detector_lib=refactor
- libstdcxx-ng - libstdcxx-ng
- libgcc-ng - libgcc-ng
run: run:
- python - python
- numpy - numpy
- sls_detector_lib - sls_detector_lib=refactor
- pyzmq - pyzmq
- libstdcxx-ng - libstdcxx-ng
- libgcc-ng - libgcc-ng

View File

@ -1,43 +1,48 @@
MESSAGE( STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR} ) # MESSAGE( STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR} )
MESSAGE( STATUS "PROJECT_SOURCE_DIR: " ${PROJECT_SOURCE_DIR} ) # MESSAGE( STATUS "PROJECT_SOURCE_DIR: " ${PROJECT_SOURCE_DIR} )
include_directories( # include_directories(
${PROJECT_SOURCE_DIR}/catch # ${PROJECT_SOURCE_DIR}/catch
# )
target_sources(tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/test-integrationMulti.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test-integrationDectector.cpp
) )
if(SLS_USE_TESTS) # if(SLS_USE_TESTS)
set(TEST_SOURCES # set(TEST_SOURCES
src/test-slsDetector.cpp # src/test-slsDetector.cpp
src/test.cpp # src/test.cpp
) # )
add_executable(detector_test ${TEST_SOURCES}) # add_executable(detector_test ${TEST_SOURCES})
target_link_libraries(detector_test # target_link_libraries(detector_test
slsDetectorShared # slsDetectorShared
slsProjectOptions # slsProjectOptions
slsProjectWarnings # slsProjectWarnings
slsSupportLib # slsSupportLib
pthread # pthread
rt # rt
) # )
set_target_properties(detector_test PROPERTIES # set_target_properties(detector_test PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin # RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
) # )
add_executable(a src/a.cpp) # add_executable(a src/a.cpp)
target_link_libraries(a # target_link_libraries(a
slsProjectOptions # slsProjectOptions
slsProjectWarnings # slsProjectWarnings
slsDetectorShared # slsDetectorShared
slsSupportLib # slsSupportLib
pthread # pthread
rt # rt
) # )
set_target_properties(a PROPERTIES # set_target_properties(a PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin # RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
) # )
endif() # endif()

View File

@ -0,0 +1,9 @@
#pragma once
#include <string>
struct SingleDetectorConfig {
slsDetectorDefs::detectorType type_enum =
slsDetectorDefs::detectorType::EIGER;
const std::string hostname = "beb083";
const std::string type_string = "Eiger";
const std::string my_ip = "129.129.205.242";
};

View File

@ -12,25 +12,24 @@
#include <vector> #include <vector>
#define VERBOSE #define VERBOSE
auto type_enum = slsDetectorDefs::detectorType::EIGER; //Header holding all configurations for different detectors
const std::string hostname = "beb083"; #include "config.h"
const std::string type_string = "Eiger";
const std::string my_ip = "129.129.205.242";
TEST_CASE("single EIGER detector no receiver basic set and get") { TEST_CASE("single EIGER detector no receiver basic set and get", "[.integration]") {
//TODO! this test should take command line arguments for config //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(hostname); auto type = slsDetector::getTypeFromDetector(c.hostname);
CHECK(type == type_enum); 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); slsDetector d(type);
CHECK(d.getDetectorTypeAsEnum() == type); CHECK(d.getDetectorTypeAsEnum() == type);
CHECK(d.getDetectorTypeAsString() == type_string); CHECK(d.getDetectorTypeAsString() == c.type_string);
d.setHostname(hostname); d.setHostname(c.hostname);
CHECK(d.getHostname() == hostname); CHECK(d.getHostname() == c.hostname);
d.setOnline(true); d.setOnline(true);
CHECK(d.getOnlineFlag() == true); CHECK(d.getOnlineFlag() == true);
@ -65,7 +64,8 @@ TEST_CASE("single EIGER detector no receiver basic set and get") {
d.freeSharedMemory(); d.freeSharedMemory();
} }
TEST_CASE("Set control port then create a new object with this control port") { TEST_CASE("Set control port then create a new object with this control port",
"[.integration]") {
/* /*
TODO! TODO!
Standard port but should not be hardcoded Standard port but should not be hardcoded
@ -76,12 +76,12 @@ TEST_CASE("Set control port then create a new object with this control port") {
int old_sport = DEFAULT_PORTNO + 1; int old_sport = DEFAULT_PORTNO + 1;
int new_cport = 1993; int new_cport = 1993;
int new_sport = 2000; int new_sport = 2000;
SingleDetectorConfig c;
{ {
auto type = slsDetector::getTypeFromDetector(hostname); auto type = slsDetector::getTypeFromDetector(c.hostname);
CHECK(type == type_enum); CHECK(type == c.type_enum);
slsDetector d(type); slsDetector d(type);
d.setHostname(hostname); d.setHostname(c.hostname);
d.setOnline(true); d.setOnline(true);
CHECK(d.getControlPort() == old_cport); CHECK(d.getControlPort() == old_cport);
d.setControlPort(new_cport); d.setControlPort(new_cport);
@ -90,10 +90,10 @@ TEST_CASE("Set control port then create a new object with this control port") {
d.freeSharedMemory(); d.freeSharedMemory();
} }
{ {
auto type = slsDetector::getTypeFromDetector(hostname, new_cport); auto type = slsDetector::getTypeFromDetector(c.hostname, new_cport);
CHECK(type == type_enum); CHECK(type == c.type_enum);
slsDetector d(type); slsDetector d(type);
d.setHostname(hostname); d.setHostname(c.hostname);
d.setControlPort(new_cport); d.setControlPort(new_cport);
d.setStopPort(new_sport); d.setStopPort(new_sport);
CHECK(d.getControlPort() == new_cport); CHECK(d.getControlPort() == new_cport);
@ -107,18 +107,20 @@ TEST_CASE("Set control port then create a new object with this control port") {
d.freeSharedMemory(); d.freeSharedMemory();
} }
auto type = slsDetector::getTypeFromDetector(hostname); auto type = slsDetector::getTypeFromDetector(c.hostname);
CHECK(type == type_enum); CHECK(type == c.type_enum);
slsDetector d(type); slsDetector d(type);
d.setHostname(hostname); d.setHostname(c.hostname);
d.setOnline(true); d.setOnline(true);
CHECK(d.getStopPort() == DEFAULT_PORTNO + 1); CHECK(d.getStopPort() == DEFAULT_PORTNO + 1);
d.freeSharedMemory();
} }
TEST_CASE("Locking mechanism and last ip") { TEST_CASE("Locking mechanism and last ip", "[.integration]") {
auto type = slsDetector::getTypeFromDetector(hostname); SingleDetectorConfig c;
auto type = slsDetector::getTypeFromDetector(c.hostname);
slsDetector d(type); slsDetector d(type);
d.setHostname(hostname); d.setHostname(c.hostname);
d.setOnline(true); d.setOnline(true);
//Check that detector server is unlocked then lock //Check that detector server is unlocked then lock
@ -126,19 +128,20 @@ TEST_CASE("Locking mechanism and last ip") {
d.lockServer(1); d.lockServer(1);
CHECK(d.lockServer() == 1); CHECK(d.lockServer() == 1);
//Can we do things while it is locked //Can we still access the detector while it's locked
auto t = 1300000000; auto t = 1300000000;
d.setTimer(slsDetectorDefs::timerIndex::ACQUISITION_TIME, t); d.setTimer(slsDetectorDefs::timerIndex::ACQUISITION_TIME, t);
CHECK(d.setTimer(slsDetectorDefs::timerIndex::ACQUISITION_TIME) == t); CHECK(d.setTimer(slsDetectorDefs::timerIndex::ACQUISITION_TIME) == t);
//unlock again //unlock again and free
d.lockServer(0); d.lockServer(0);
CHECK(d.lockServer() == 0); CHECK(d.lockServer() == 0);
CHECK(d.getLastClientIP() == my_ip); CHECK(d.getLastClientIP() == c.my_ip);
d.freeSharedMemory();
} }
TEST_CASE("Excersise all possible set timer functions") { 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 */ // FRAME_NUMBER, /**< number of real time frames: total number of acquisitions is number or frames*number of cycles */
// ACQUISITION_TIME, /**< exposure time */ // ACQUISITION_TIME, /**< exposure time */
// FRAME_PERIOD, /**< period between exposures */ // FRAME_PERIOD, /**< period between exposures */
@ -159,10 +162,10 @@ TEST_CASE("Excersise all possible set timer functions") {
// MEASURED_PERIOD, /**< measured period */ // MEASURED_PERIOD, /**< measured period */
// MEASURED_SUBPERIOD, /**< measured subperiod */ // MEASURED_SUBPERIOD, /**< measured subperiod */
// MAX_TIMERS // MAX_TIMERS
SingleDetectorConfig c;
auto type = slsDetector::getTypeFromDetector(hostname); auto type = slsDetector::getTypeFromDetector(c.hostname);
slsDetector d(type); slsDetector d(type);
d.setHostname(hostname); d.setHostname(c.hostname);
d.setOnline(true); d.setOnline(true);
//Number of frames //Number of frames
@ -194,6 +197,28 @@ TEST_CASE("Excersise all possible set timer functions") {
auto subtime = 200; auto subtime = 200;
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); CHECK(d.setTimer(slsDetectorDefs::timerIndex::SUBFRAME_ACQUISITION_TIME) == subtime);
d.freeSharedMemory();
} }
// TEST_CASE() // TEST_CASE("Aquire", "[.integration][eiger]"){
// SingleDetectorConfig c;
// auto type = slsDetector::getTypeFromDetector(c.hostname);
// slsDetector d(type);
// d.setHostname(c.hostname);
// d.setOnline(true);
// auto period = 1000000000;
// auto exptime = 100000000;
// d.setTimer(slsDetectorDefs::timerIndex::FRAME_NUMBER, 5);
// d.setTimer(slsDetectorDefs::timerIndex::ACQUISITION_TIME, exptime);
// d.setTimer(slsDetectorDefs::timerIndex::FRAME_PERIOD, period);
// d.startAndReadAll();
// auto rperiod = d.getTimeLeft(slsDetectorDefs::timerIndex::MEASURED_PERIOD);
// CHECK(rperiod == 0.1);
// d.freeSharedMemory();
// }

View File

@ -845,7 +845,7 @@ int slsDetector::execCommand(const std::string &cmd) {
if (detector_shm()->onlineFlag == ONLINE_FLAG) { if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort); auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, arg, sizeof(arg), retval, sizeof(retval)); ret = client.sendCommandThenRead(fnum, arg, sizeof(arg), retval, sizeof(retval));
if (strlen(retval)) { if (strlen(retval) != 0u) {
FILE_LOG(logINFO) << "Detector " << detId << " returned:\n" << retval; FILE_LOG(logINFO) << "Detector " << detId << " returned:\n" << retval;
} }
} }
@ -871,7 +871,7 @@ int slsDetector::updateDetectorNoWait(sls::ClientSocket &client) {
if ((detector_shm()->myDetectorType != CHIPTESTBOARD) && if ((detector_shm()->myDetectorType != CHIPTESTBOARD) &&
(detector_shm()->myDetectorType != MOENCH)) { (detector_shm()->myDetectorType != MOENCH)) {
n += client.receiveData(&i32, sizeof(i32)); n += client.receiveData(&i32, sizeof(i32));
detector_shm()->currentSettings = (detectorSettings)i32; detector_shm()->currentSettings = static_cast<detectorSettings>(i32);
} }
// threshold // threshold
@ -925,7 +925,7 @@ int slsDetector::updateDetectorNoWait(sls::ClientSocket &client) {
if (detector_shm()->myDetectorType == EIGER || if (detector_shm()->myDetectorType == EIGER ||
detector_shm()->myDetectorType == CHIPTESTBOARD) { detector_shm()->myDetectorType == CHIPTESTBOARD) {
n += client.receiveData(&i32, sizeof(i32)); n += client.receiveData(&i32, sizeof(i32));
detector_shm()->roFlags = (readOutFlags)i32; detector_shm()->roFlags = static_cast<readOutFlags>(i32);
} }
// samples // samples
@ -965,7 +965,7 @@ int slsDetector::updateDetectorNoWait(sls::ClientSocket &client) {
updateTotalNumberOfChannels(); updateTotalNumberOfChannels();
} }
if (!n) { if (n == 0) {
FILE_LOG(logERROR) << "Could not update detector, received 0 bytes"; FILE_LOG(logERROR) << "Could not update detector, received 0 bytes";
} }
@ -2973,7 +2973,7 @@ int slsDetector::writeAdcRegister(int addr, int val) {
return ret; return ret;
} }
int slsDetector::activate(int const enable) { int slsDetector::activate(int enable) {
int fnum = F_ACTIVATE; int fnum = F_ACTIVATE;
int ret = FAIL; int ret = FAIL;
int arg = enable; int arg = enable;
@ -3400,7 +3400,7 @@ int slsDetector::powerChip(int ival) {
FILE_LOG(logDEBUG1) << "Power chip: " << retval; FILE_LOG(logDEBUG1) << "Power chip: " << retval;
} }
if (ret == FORCE_UPDATE) { if (ret == FORCE_UPDATE) {
ret = updateDetector(); updateDetector();
} }
return retval; return retval;
} }
@ -3418,7 +3418,7 @@ int slsDetector::setAutoComparatorDisableMode(int ival) {
FILE_LOG(logDEBUG1) << "Auto comp disable: " << retval; FILE_LOG(logDEBUG1) << "Auto comp disable: " << retval;
} }
if (ret == FORCE_UPDATE) { if (ret == FORCE_UPDATE) {
ret = updateDetector(); updateDetector();
} }
return retval; return retval;
} }
@ -3430,7 +3430,7 @@ int slsDetector::getChanRegs(double *retval) {
if (myMod != nullptr) { if (myMod != nullptr) {
// the original array has 0 initialized // the original array has 0 initialized
if (myMod->chanregs) { if (myMod->chanregs != nullptr) {
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
retval[i] = (double)(myMod->chanregs[i] & TRIMBITMASK); retval[i] = (double)(myMod->chanregs[i] & TRIMBITMASK);
} }
@ -3529,7 +3529,7 @@ int64_t slsDetector::getRateCorrection() {
FILE_LOG(logDEBUG1) << "Rate correction: " << retval; FILE_LOG(logDEBUG1) << "Rate correction: " << retval;
} }
if (ret == FORCE_UPDATE) { if (ret == FORCE_UPDATE) {
ret = updateDetector(); updateDetector();
} }
return retval; return retval;
} }
@ -3549,20 +3549,18 @@ void slsDetector::printReceiverConfiguration(TLogLevel level) {
int slsDetector::setReceiverOnline(int value) { int slsDetector::setReceiverOnline(int value) {
if (value != GET_ONLINE_FLAG) { if (value != GET_ONLINE_FLAG) {
// no receiver // no receiver
if (!strcmp(detector_shm()->receiver_hostname, "none")) { if (strcmp(detector_shm()->receiver_hostname, "none") == 0) {
detector_shm()->receiverOnlineFlag = OFFLINE_FLAG; detector_shm()->receiverOnlineFlag = OFFLINE_FLAG;
} else { } else {
detector_shm()->receiverOnlineFlag = OFFLINE_FLAG; detector_shm()->receiverOnlineFlag = OFFLINE_FLAG;
// set online // set online
if (value == ONLINE_FLAG) { if (value == ONLINE_FLAG) {
// connect and set offline flag // connect and set offline flag
auto receiver = ReceiverSocket(detector_shm()->receiver_hostname, auto receiver = ReceiverSocket(detector_shm()->receiver_hostname,
detector_shm()->receiverTCPPort); detector_shm()->receiverTCPPort);
receiver.close(); receiver.close();
detector_shm()->receiverOnlineFlag = ONLINE_FLAG; detector_shm()->receiverOnlineFlag = ONLINE_FLAG;
// check for version compatibility
if (detector_shm()->receiverAPIVersion == 0) { if (detector_shm()->receiverAPIVersion == 0) {
checkReceiverVersionCompatibility(); checkReceiverVersionCompatibility();
} }
@ -3600,7 +3598,7 @@ int slsDetector::lockReceiver(int lock) {
FILE_LOG(logDEBUG1) << "Receiver Lock: " << retval; FILE_LOG(logDEBUG1) << "Receiver Lock: " << retval;
} }
if (ret == FORCE_UPDATE) { if (ret == FORCE_UPDATE) {
ret = updateCachedReceiverVariables(); updateCachedReceiverVariables();
} }
return retval; return retval;
} }
@ -3618,7 +3616,7 @@ std::string slsDetector::getReceiverLastClientIP() {
FILE_LOG(logDEBUG1) << "Last client IP to receiver: " << retval; FILE_LOG(logDEBUG1) << "Last client IP to receiver: " << retval;
} }
if (ret == FORCE_UPDATE) { if (ret == FORCE_UPDATE) {
ret = updateCachedReceiverVariables(); updateCachedReceiverVariables();
} }
return retval; return retval;
} }
@ -3690,7 +3688,7 @@ int slsDetector::updateCachedReceiverVariables() const {
// file format // file format
n += receiver.receiveData(&i32, sizeof(i32)); n += receiver.receiveData(&i32, sizeof(i32));
detector_shm()->rxFileFormat = (fileFormat)i32; detector_shm()->rxFileFormat = static_cast<fileFormat>(i32);
// frames per file // frames per file
n += receiver.receiveData(&i32, sizeof(i32)); n += receiver.receiveData(&i32, sizeof(i32));
@ -3698,7 +3696,7 @@ int slsDetector::updateCachedReceiverVariables() const {
// frame discard policy // frame discard policy
n += receiver.receiveData(&i32, sizeof(i32)); n += receiver.receiveData(&i32, sizeof(i32));
detector_shm()->receiver_frameDiscardMode = (frameDiscardPolicy)i32; detector_shm()->receiver_frameDiscardMode = static_cast<frameDiscardPolicy>(i32);
// frame padding // frame padding
n += receiver.receiveData(&i32, sizeof(i32)); n += receiver.receiveData(&i32, sizeof(i32));