mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-20 02:40:03 +02:00
tests add to namespace sls (#466)
* tests add to namespace sls * fixed for tests * finish up namespace sls for tests
This commit is contained in:
parent
8656eeec25
commit
d61741c28b
@ -6,6 +6,8 @@
|
|||||||
#include "tests/globals.h"
|
#include "tests/globals.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
class MultiDetectorFixture {
|
class MultiDetectorFixture {
|
||||||
protected:
|
protected:
|
||||||
DetectorImpl d;
|
DetectorImpl d;
|
||||||
@ -136,7 +138,7 @@ TEST_CASE_METHOD(MultiDetectorFixture, "Get ID", "[.eigerintegration][cli]") {
|
|||||||
std::string hn = test::hostname;
|
std::string hn = test::hostname;
|
||||||
hn.erase(std::remove(begin(hn), end(hn), 'b'), end(hn));
|
hn.erase(std::remove(begin(hn), end(hn), 'b'), end(hn));
|
||||||
hn.erase(std::remove(begin(hn), end(hn), 'e'), end(hn));
|
hn.erase(std::remove(begin(hn), end(hn), 'e'), end(hn));
|
||||||
auto hostnames = sls::split(hn, '+');
|
auto hostnames = split(hn, '+');
|
||||||
CHECK(hostnames.size() == d.getNumberOfDetectors());
|
CHECK(hostnames.size() == d.getNumberOfDetectors());
|
||||||
for (int i = 0; i != d.getNumberOfDetectors(); ++i) {
|
for (int i = 0; i != d.getNumberOfDetectors(); ++i) {
|
||||||
CHECK(d.getId(defs::DETECTOR_SERIAL_NUMBER, 0) ==
|
CHECK(d.getId(defs::DETECTOR_SERIAL_NUMBER, 0) ==
|
||||||
@ -198,3 +200,5 @@ TEST_CASE_METHOD(MultiDetectorFixture, "rate correction",
|
|||||||
d.setRateCorrection(200);
|
d.setRateCorrection(200);
|
||||||
CHECK(d.getRateCorrection() == 200);
|
CHECK(d.getRateCorrection() == 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
// extern std::string detector_type;
|
// extern std::string detector_type;
|
||||||
// extern dt type;
|
// extern dt type;
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
TEST_CASE("Single detector no receiver", "[.integration][.single]") {
|
TEST_CASE("Single detector no receiver", "[.integration][.single]") {
|
||||||
auto t = Module::getTypeFromDetector(test::hostname);
|
auto t = Module::getTypeFromDetector(test::hostname);
|
||||||
CHECK(t == test::type);
|
CHECK(t == test::type);
|
||||||
@ -283,14 +285,14 @@ TEST_CASE(
|
|||||||
CHECK(m.getRateCorrection() == ratecorr);
|
CHECK(m.getRateCorrection() == ratecorr);
|
||||||
|
|
||||||
// ratecorr fail with dr 4 or 8
|
// ratecorr fail with dr 4 or 8
|
||||||
CHECK_THROWS_AS(m.setDynamicRange(8), sls::RuntimeError);
|
CHECK_THROWS_AS(m.setDynamicRange(8), RuntimeError);
|
||||||
CHECK(m.getRateCorrection() == 0);
|
CHECK(m.getRateCorrection() == 0);
|
||||||
m.setDynamicRange(16);
|
m.setDynamicRange(16);
|
||||||
m.setDynamicRange(16);
|
m.setDynamicRange(16);
|
||||||
m.setRateCorrection(ratecorr);
|
m.setRateCorrection(ratecorr);
|
||||||
m.setDynamicRange(16);
|
m.setDynamicRange(16);
|
||||||
m.setRateCorrection(ratecorr);
|
m.setRateCorrection(ratecorr);
|
||||||
CHECK_THROWS_AS(m.setDynamicRange(4), sls::RuntimeError);
|
CHECK_THROWS_AS(m.setDynamicRange(4), RuntimeError);
|
||||||
CHECK(m.getRateCorrection() == 0);
|
CHECK(m.getRateCorrection() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -329,11 +331,11 @@ TEST_CASE("Chiptestboard Loading Patterns", "[.ctbintegration]") {
|
|||||||
m.setPatternWord(addr, word);
|
m.setPatternWord(addr, word);
|
||||||
CHECK(m.setPatternWord(addr, -1) == word);
|
CHECK(m.setPatternWord(addr, -1) == word);
|
||||||
addr = MAX_ADDR;
|
addr = MAX_ADDR;
|
||||||
CHECK_THROWS_AS(m.setPatternWord(addr, word), sls::RuntimeError);
|
CHECK_THROWS_AS(m.setPatternWord(addr, word), RuntimeError);
|
||||||
CHECK_THROWS_WITH(m.setPatternWord(addr, word),
|
CHECK_THROWS_WITH(m.setPatternWord(addr, word),
|
||||||
Catch::Matchers::Contains("be between 0 and"));
|
Catch::Matchers::Contains("be between 0 and"));
|
||||||
addr = -1;
|
addr = -1;
|
||||||
CHECK_THROWS_AS(m.setPatternWord(addr, word), sls::RuntimeError);
|
CHECK_THROWS_AS(m.setPatternWord(addr, word), RuntimeError);
|
||||||
CHECK_THROWS_WITH(m.setPatternWord(addr, word),
|
CHECK_THROWS_WITH(m.setPatternWord(addr, word),
|
||||||
Catch::Matchers::Contains("be between 0 and"));
|
Catch::Matchers::Contains("be between 0 and"));
|
||||||
|
|
||||||
@ -408,7 +410,7 @@ TEST_CASE("Chiptestboard Dbit offset, list, sampling, advinvert",
|
|||||||
CHECK(m.getReceiverDbitList().size() == 10);
|
CHECK(m.getReceiverDbitList().size() == 10);
|
||||||
|
|
||||||
list.push_back(64);
|
list.push_back(64);
|
||||||
CHECK_THROWS_AS(m.setReceiverDbitList(list), sls::RuntimeError);
|
CHECK_THROWS_AS(m.setReceiverDbitList(list), RuntimeError);
|
||||||
CHECK_THROWS_WITH(m.setReceiverDbitList(list),
|
CHECK_THROWS_WITH(m.setReceiverDbitList(list),
|
||||||
Catch::Matchers::Contains("be between 0 and 63"));
|
Catch::Matchers::Contains("be between 0 and 63"));
|
||||||
|
|
||||||
@ -476,7 +478,7 @@ TEST_CASE("Eiger or Jungfrau nextframenumber",
|
|||||||
CHECK(m.acquire() == slsDetectorDefs::OK);
|
CHECK(m.acquire() == slsDetectorDefs::OK);
|
||||||
CHECK(m.getReceiverCurrentFrameIndex() == val);
|
CHECK(m.getReceiverCurrentFrameIndex() == val);
|
||||||
|
|
||||||
CHECK_THROWS_AS(m.setNextFrameNumber(0), sls::RuntimeError);
|
CHECK_THROWS_AS(m.setNextFrameNumber(0), RuntimeError);
|
||||||
|
|
||||||
if (m.getDetectorTypeAsString() == "Eiger") {
|
if (m.getDetectorTypeAsString() == "Eiger") {
|
||||||
val = 281474976710655;
|
val = 281474976710655;
|
||||||
@ -511,8 +513,10 @@ TEST_CASE("Eiger partialread", "[.eigerintegration][partialread]") {
|
|||||||
m.setDynamicRange(8);
|
m.setDynamicRange(8);
|
||||||
m.setPartialReadout(256);
|
m.setPartialReadout(256);
|
||||||
CHECK(m.getPartialReadout() == 256);
|
CHECK(m.getPartialReadout() == 256);
|
||||||
CHECK_THROWS_AS(m.setPartialReadout(1), sls::RuntimeError);
|
CHECK_THROWS_AS(m.setPartialReadout(1), RuntimeError);
|
||||||
CHECK(m.getPartialReadout() == 256);
|
CHECK(m.getPartialReadout() == 256);
|
||||||
CHECK_THROWS_AS(m.setPartialReadout(0), sls::RuntimeError);
|
CHECK_THROWS_AS(m.setPartialReadout(0), RuntimeError);
|
||||||
m.setPartialReadout(256);
|
m.setPartialReadout(256);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -6,10 +6,12 @@
|
|||||||
#include "tests/globals.h"
|
#include "tests/globals.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
using namespace Catch::literals;
|
using namespace Catch::literals;
|
||||||
|
|
||||||
TEST_CASE("Initialize a multi detector", "[.integration][.multi]") {
|
TEST_CASE("Initialize a multi detector", "[.integration][.multi]") {
|
||||||
auto hostnames = sls::split(test::hostname, '+');
|
auto hostnames = split(test::hostname, '+');
|
||||||
|
|
||||||
DetectorImpl d(0, true, true);
|
DetectorImpl d(0, true, true);
|
||||||
d.setHostname(test::hostname.c_str());
|
d.setHostname(test::hostname.c_str());
|
||||||
@ -102,3 +104,6 @@ TEST_CASE("Set and read timers", "[.integration][.multi]") {
|
|||||||
|
|
||||||
d.freeSharedMemory();
|
d.freeSharedMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
|
||||||
|
@ -21,4 +21,9 @@ target_sources(tests PRIVATE
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/test-CtbConfig.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/test-CtbConfig.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(tests PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../src>")
|
target_include_directories(tests
|
||||||
|
PUBLIC
|
||||||
|
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../src>"
|
||||||
|
PRIVATE
|
||||||
|
${SLS_INTERNAL_RAPIDJSON_DIR}
|
||||||
|
)
|
@ -9,8 +9,9 @@
|
|||||||
// help for all docs
|
// help for all docs
|
||||||
// command for all depreciated commands
|
// command for all depreciated commands
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
using vs = std::vector<std::string>;
|
using vs = std::vector<std::string>;
|
||||||
using sls::CmdParser;
|
|
||||||
|
|
||||||
SCENARIO("Construction", "[support]") {
|
SCENARIO("Construction", "[support]") {
|
||||||
GIVEN("A default constructed CmdParser") {
|
GIVEN("A default constructed CmdParser") {
|
||||||
@ -407,3 +408,5 @@ TEST_CASE("Parse a command in the form 0-1:command") {
|
|||||||
REQUIRE(p.detector_id() == 5);
|
REQUIRE(p.detector_id() == 5);
|
||||||
REQUIRE(p.command() == "exptime");
|
REQUIRE(p.command() == "exptime");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
@ -12,8 +12,8 @@
|
|||||||
#include "test-CmdProxy-global.h"
|
#include "test-CmdProxy-global.h"
|
||||||
#include "tests/globals.h"
|
#include "tests/globals.h"
|
||||||
|
|
||||||
using sls::CmdProxy;
|
namespace sls {
|
||||||
using sls::Detector;
|
|
||||||
using test::GET;
|
using test::GET;
|
||||||
using test::PUT;
|
using test::PUT;
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ TEST_CASE("samples", "[.cmd]") {
|
|||||||
|
|
||||||
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH) {
|
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH) {
|
||||||
auto prev_asamples = det.getNumberOfAnalogSamples();
|
auto prev_asamples = det.getNumberOfAnalogSamples();
|
||||||
sls::Result<int> prev_dsamples = 0;
|
Result<int> prev_dsamples = 0;
|
||||||
if (det_type == defs::CHIPTESTBOARD) {
|
if (det_type == defs::CHIPTESTBOARD) {
|
||||||
prev_dsamples = det.getNumberOfDigitalSamples();
|
prev_dsamples = det.getNumberOfDigitalSamples();
|
||||||
}
|
}
|
||||||
@ -866,3 +866,5 @@ TEST_CASE("led", "[.cmd]") {
|
|||||||
REQUIRE_THROWS(proxy.Call("led", {}, -1, GET));
|
REQUIRE_THROWS(proxy.Call("led", {}, -1, GET));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
#include "test-CmdProxy-global.h"
|
#include "test-CmdProxy-global.h"
|
||||||
#include "tests/globals.h"
|
#include "tests/globals.h"
|
||||||
|
|
||||||
using sls::CmdProxy;
|
namespace sls {
|
||||||
using sls::Detector;
|
|
||||||
using test::GET;
|
using test::GET;
|
||||||
using test::PUT;
|
using test::PUT;
|
||||||
|
|
||||||
@ -658,3 +658,5 @@ TEST_CASE("top", "[.cmd]") {
|
|||||||
REQUIRE_THROWS(proxy.Call("top", {"1"}, -1, PUT));
|
REQUIRE_THROWS(proxy.Call("top", {"1"}, -1, PUT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
#include "sls/Detector.h"
|
#include "sls/Detector.h"
|
||||||
#include "tests/globals.h"
|
#include "tests/globals.h"
|
||||||
|
|
||||||
using sls::CmdProxy;
|
namespace sls {
|
||||||
using sls::Detector;
|
|
||||||
using test::GET;
|
using test::GET;
|
||||||
using test::PUT;
|
using test::PUT;
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ void test_onchip_dac(defs::dacIndex index, const std::string &dacname,
|
|||||||
|
|
||||||
int chipIndex = -1; // for now, it is -1 only
|
int chipIndex = -1; // for now, it is -1 only
|
||||||
auto prev_val = det.getOnChipDAC(index, chipIndex);
|
auto prev_val = det.getOnChipDAC(index, chipIndex);
|
||||||
auto dacValueStr = sls::ToStringHex(dacvalue);
|
auto dacValueStr = ToStringHex(dacvalue);
|
||||||
auto chipIndexStr = std::to_string(chipIndex);
|
auto chipIndexStr = std::to_string(chipIndex);
|
||||||
std::ostringstream oss_set, oss_get;
|
std::ostringstream oss_set, oss_get;
|
||||||
proxy.Call(dacname, {chipIndexStr, dacValueStr}, -1, PUT, oss_set);
|
proxy.Call(dacname, {chipIndexStr, dacValueStr}, -1, PUT, oss_set);
|
||||||
@ -67,3 +67,5 @@ void test_onchip_dac(defs::dacIndex index, const std::string &dacname,
|
|||||||
det.setOnChipDAC(index, chipIndex, prev_val[i], {i});
|
det.setOnChipDAC(index, chipIndex, prev_val[i], {i});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -3,7 +3,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "sls/sls_detector_defs.h"
|
#include "sls/sls_detector_defs.h"
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
void test_dac(slsDetectorDefs::dacIndex index, const std::string &dacname,
|
void test_dac(slsDetectorDefs::dacIndex index, const std::string &dacname,
|
||||||
int dacvalue);
|
int dacvalue);
|
||||||
void test_onchip_dac(slsDetectorDefs::dacIndex index,
|
void test_onchip_dac(slsDetectorDefs::dacIndex index,
|
||||||
const std::string &dacname, int dacvalue);
|
const std::string &dacname, int dacvalue);
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
#include "test-CmdProxy-global.h"
|
#include "test-CmdProxy-global.h"
|
||||||
#include "tests/globals.h"
|
#include "tests/globals.h"
|
||||||
|
|
||||||
using sls::CmdProxy;
|
namespace sls {
|
||||||
using sls::Detector;
|
|
||||||
using test::GET;
|
using test::GET;
|
||||||
using test::PUT;
|
using test::PUT;
|
||||||
|
|
||||||
@ -155,3 +155,5 @@ TEST_CASE("exptimel", "[.cmd]") {
|
|||||||
REQUIRE_THROWS(proxy.Call("exptimel", {}, -1, GET));
|
REQUIRE_THROWS(proxy.Call("exptimel", {}, -1, GET));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
#include "test-CmdProxy-global.h"
|
#include "test-CmdProxy-global.h"
|
||||||
#include "tests/globals.h"
|
#include "tests/globals.h"
|
||||||
|
|
||||||
using sls::CmdProxy;
|
namespace sls {
|
||||||
using sls::Detector;
|
|
||||||
using test::GET;
|
using test::GET;
|
||||||
using test::PUT;
|
using test::PUT;
|
||||||
|
|
||||||
@ -467,7 +467,7 @@ TEST_CASE("burstmode", "[.cmd]") {
|
|||||||
|
|
||||||
if (det_type == defs::GOTTHARD2) {
|
if (det_type == defs::GOTTHARD2) {
|
||||||
auto burst = det.getBurstMode();
|
auto burst = det.getBurstMode();
|
||||||
auto burststr = sls::ToString(burst);
|
auto burststr = ToString(burst);
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
proxy.Call("burstmode", {"burst_internal"}, -1, PUT, oss);
|
proxy.Call("burstmode", {"burst_internal"}, -1, PUT, oss);
|
||||||
@ -744,3 +744,5 @@ TEST_CASE("badchannels", "[.cmd]") {
|
|||||||
REQUIRE_THROWS(proxy.Call("badchannels", {}, -1, GET));
|
REQUIRE_THROWS(proxy.Call("badchannels", {}, -1, GET));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -10,8 +10,8 @@
|
|||||||
#include "test-CmdProxy-global.h"
|
#include "test-CmdProxy-global.h"
|
||||||
#include "tests/globals.h"
|
#include "tests/globals.h"
|
||||||
|
|
||||||
using sls::CmdProxy;
|
namespace sls {
|
||||||
using sls::Detector;
|
|
||||||
using test::GET;
|
using test::GET;
|
||||||
using test::PUT;
|
using test::PUT;
|
||||||
|
|
||||||
@ -538,3 +538,5 @@ TEST_CASE("filtercells", "[.cmd]") {
|
|||||||
REQUIRE_THROWS(proxy.Call("filtercells", {"0"}, -1, PUT));
|
REQUIRE_THROWS(proxy.Call("filtercells", {"0"}, -1, PUT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
#include "test-CmdProxy-global.h"
|
#include "test-CmdProxy-global.h"
|
||||||
#include "tests/globals.h"
|
#include "tests/globals.h"
|
||||||
|
|
||||||
using sls::CmdProxy;
|
namespace sls {
|
||||||
using sls::Detector;
|
|
||||||
using test::GET;
|
using test::GET;
|
||||||
using test::PUT;
|
using test::PUT;
|
||||||
|
|
||||||
@ -108,3 +108,5 @@ TEST_CASE("Setting and reading back MOENCH dacs", "[.cmd][.dacs]") {
|
|||||||
REQUIRE_THROWS(proxy.Call("dac", {"vcom_adc2"}, -1, GET));
|
REQUIRE_THROWS(proxy.Call("dac", {"vcom_adc2"}, -1, GET));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
#include "test-CmdProxy-global.h"
|
#include "test-CmdProxy-global.h"
|
||||||
#include "tests/globals.h"
|
#include "tests/globals.h"
|
||||||
|
|
||||||
using sls::CmdProxy;
|
namespace sls {
|
||||||
using sls::Detector;
|
|
||||||
using test::GET;
|
using test::GET;
|
||||||
using test::PUT;
|
using test::PUT;
|
||||||
|
|
||||||
@ -216,9 +216,9 @@ TEST_CASE("counters", "[.cmd]") {
|
|||||||
REQUIRE(oss_set2.str() == "counters [0, 2]\n");
|
REQUIRE(oss_set2.str() == "counters [0, 2]\n");
|
||||||
// put back old value
|
// put back old value
|
||||||
proxy.Call("counters", list_str, -1, PUT, oss_set3);
|
proxy.Call("counters", list_str, -1, PUT, oss_set3);
|
||||||
REQUIRE(oss_set3.str() == "counters " + sls::ToString(list_str) + "\n");
|
REQUIRE(oss_set3.str() == "counters " + ToString(list_str) + "\n");
|
||||||
proxy.Call("counters", {}, -1, GET, oss_get);
|
proxy.Call("counters", {}, -1, GET, oss_get);
|
||||||
REQUIRE(oss_get.str() == "counters " + sls::ToString(list_str) + "\n");
|
REQUIRE(oss_get.str() == "counters " + ToString(list_str) + "\n");
|
||||||
} else {
|
} else {
|
||||||
REQUIRE_THROWS(proxy.Call("counters", {}, -1, GET));
|
REQUIRE_THROWS(proxy.Call("counters", {}, -1, GET));
|
||||||
}
|
}
|
||||||
@ -349,7 +349,7 @@ TEST_CASE("gatedelay", "[.cmd]") {
|
|||||||
auto prev_val = det.getExptimeForAllGates().tsquash(
|
auto prev_val = det.getExptimeForAllGates().tsquash(
|
||||||
"inconsistent gatedelay to test");
|
"inconsistent gatedelay to test");
|
||||||
if (prev_val[0] != prev_val[1] || prev_val[1] != prev_val[2]) {
|
if (prev_val[0] != prev_val[1] || prev_val[1] != prev_val[2]) {
|
||||||
throw sls::RuntimeError("inconsistent gatedelay for all gates");
|
throw RuntimeError("inconsistent gatedelay for all gates");
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
@ -611,3 +611,5 @@ TEST_CASE("dpulse", "[.cmd]") {
|
|||||||
REQUIRE_THROWS(proxy.Call("dpulse", {}, -1, GET));
|
REQUIRE_THROWS(proxy.Call("dpulse", {}, -1, GET));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
#include "test-CmdProxy-global.h"
|
#include "test-CmdProxy-global.h"
|
||||||
#include "tests/globals.h"
|
#include "tests/globals.h"
|
||||||
|
|
||||||
using sls::CmdProxy;
|
namespace sls {
|
||||||
using sls::Detector;
|
|
||||||
using test::GET;
|
using test::GET;
|
||||||
using test::PUT;
|
using test::PUT;
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ TEST_CASE("patword", "[.cmd]") {
|
|||||||
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH ||
|
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH ||
|
||||||
det_type == defs::MYTHEN3) {
|
det_type == defs::MYTHEN3) {
|
||||||
int addr = 0x23;
|
int addr = 0x23;
|
||||||
std::string saddr = sls::ToStringHex(addr, 4);
|
std::string saddr = ToStringHex(addr, 4);
|
||||||
auto prev_val = det.getPatternWord(addr);
|
auto prev_val = det.getPatternWord(addr);
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
@ -529,3 +529,5 @@ TEST_CASE("patternstart", "[.cmd]") {
|
|||||||
REQUIRE_THROWS(proxy.Call("patternstart", {}, -1, PUT));
|
REQUIRE_THROWS(proxy.Call("patternstart", {}, -1, PUT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
#include "sls/versionAPI.h"
|
#include "sls/versionAPI.h"
|
||||||
#include "tests/globals.h"
|
#include "tests/globals.h"
|
||||||
|
|
||||||
using sls::CmdProxy;
|
namespace sls {
|
||||||
using sls::Detector;
|
|
||||||
using test::GET;
|
using test::GET;
|
||||||
using test::PUT;
|
using test::PUT;
|
||||||
|
|
||||||
@ -449,7 +449,7 @@ TEST_CASE("rx_roi", "[.cmd]") {
|
|||||||
REQUIRE_THROWS(proxy.Call("rx_roi", {"5", "10"}, -1, PUT));
|
REQUIRE_THROWS(proxy.Call("rx_roi", {"5", "10"}, -1, PUT));
|
||||||
} else {
|
} else {
|
||||||
auto prev_val = det.getRxROI();
|
auto prev_val = det.getRxROI();
|
||||||
defs::xy detsize = det.getDetectrSize();
|
defs::xy detsize = det.getDetectorSize();
|
||||||
|
|
||||||
// 1d
|
// 1d
|
||||||
if (det_type == defs::GOTTHARD || det_type == defs::GOTTHARD2 ||
|
if (det_type == defs::GOTTHARD || det_type == defs::GOTTHARD2 ||
|
||||||
@ -991,3 +991,5 @@ TEST_CASE("rx_jsonpara", "[.cmd][.rx]") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Insignificant */
|
/* Insignificant */
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
#include "tests/globals.h"
|
#include "tests/globals.h"
|
||||||
|
|
||||||
using sls::CmdProxy;
|
namespace sls {
|
||||||
using sls::Detector;
|
|
||||||
using test::GET;
|
using test::GET;
|
||||||
using test::PUT;
|
using test::PUT;
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ TEST_CASE("type", "[.cmd]") {
|
|||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
proxy.Call("type", {}, -1, GET, oss);
|
proxy.Call("type", {}, -1, GET, oss);
|
||||||
auto ans = oss.str().erase(0, strlen("type "));
|
auto ans = oss.str().erase(0, strlen("type "));
|
||||||
REQUIRE(ans == sls::ToString(dt) + '\n');
|
REQUIRE(ans == ToString(dt) + '\n');
|
||||||
// REQUIRE(dt == test::type);
|
// REQUIRE(dt == test::type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,7 +339,7 @@ TEST_CASE("threshold", "[.cmd]") {
|
|||||||
for (int i = 0; i != det.size(); ++i) {
|
for (int i = 0; i != det.size(); ++i) {
|
||||||
if (prev_threshold[i][0] >= 0) {
|
if (prev_threshold[i][0] >= 0) {
|
||||||
std::cout
|
std::cout
|
||||||
<< "prev cvalues:" << sls::ToString(prev_threshold[i])
|
<< "prev cvalues:" << ToString(prev_threshold[i])
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
det.setThresholdEnergy(prev_threshold[i], prev_settings,
|
det.setThresholdEnergy(prev_threshold[i], prev_settings,
|
||||||
true, {i});
|
true, {i});
|
||||||
@ -684,7 +684,7 @@ TEST_CASE("exptime", "[.cmd][.time]") {
|
|||||||
auto t =
|
auto t =
|
||||||
det.getExptimeForAllGates().tsquash("inconsistent exptime to test");
|
det.getExptimeForAllGates().tsquash("inconsistent exptime to test");
|
||||||
if (t[0] != t[1] || t[1] != t[2]) {
|
if (t[0] != t[1] || t[1] != t[2]) {
|
||||||
throw sls::RuntimeError("inconsistent exptime for all gates");
|
throw RuntimeError("inconsistent exptime for all gates");
|
||||||
}
|
}
|
||||||
prev_val = t[0];
|
prev_val = t[0];
|
||||||
}
|
}
|
||||||
@ -1867,7 +1867,7 @@ TEST_CASE("defaultdac", "[.cmd]") {
|
|||||||
if (it == defs::VTHRESHOLD) {
|
if (it == defs::VTHRESHOLD) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto dacname = sls::ToString(it);
|
auto dacname = ToString(it);
|
||||||
auto prev_val = det.getDefaultDac(it);
|
auto prev_val = det.getDefaultDac(it);
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
@ -1889,7 +1889,7 @@ TEST_CASE("defaultdac", "[.cmd]") {
|
|||||||
std::vector<defs::dacIndex> daclist = {
|
std::vector<defs::dacIndex> daclist = {
|
||||||
defs::VREF_PRECH, defs::VREF_DS, defs::VREF_COMP};
|
defs::VREF_PRECH, defs::VREF_DS, defs::VREF_COMP};
|
||||||
for (auto it : daclist) {
|
for (auto it : daclist) {
|
||||||
auto dacname = sls::ToString(it);
|
auto dacname = ToString(it);
|
||||||
auto prev_val = det.getDefaultDac(it, defs::GAIN0);
|
auto prev_val = det.getDefaultDac(it, defs::GAIN0);
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
@ -2044,7 +2044,7 @@ TEST_CASE("start", "[.cmd]") {
|
|||||||
auto t =
|
auto t =
|
||||||
det.getExptimeForAllGates().tsquash("inconsistent exptime to test");
|
det.getExptimeForAllGates().tsquash("inconsistent exptime to test");
|
||||||
if (t[0] != t[1] || t[1] != t[2]) {
|
if (t[0] != t[1] || t[1] != t[2]) {
|
||||||
throw sls::RuntimeError("inconsistent exptime for all gates");
|
throw RuntimeError("inconsistent exptime for all gates");
|
||||||
}
|
}
|
||||||
prev_val = t[0];
|
prev_val = t[0];
|
||||||
}
|
}
|
||||||
@ -2083,7 +2083,7 @@ TEST_CASE("stop", "[.cmd]") {
|
|||||||
auto t =
|
auto t =
|
||||||
det.getExptimeForAllGates().tsquash("inconsistent exptime to test");
|
det.getExptimeForAllGates().tsquash("inconsistent exptime to test");
|
||||||
if (t[0] != t[1] || t[1] != t[2]) {
|
if (t[0] != t[1] || t[1] != t[2]) {
|
||||||
throw sls::RuntimeError("inconsistent exptime for all gates");
|
throw RuntimeError("inconsistent exptime for all gates");
|
||||||
}
|
}
|
||||||
prev_val = t[0];
|
prev_val = t[0];
|
||||||
}
|
}
|
||||||
@ -2126,7 +2126,7 @@ TEST_CASE("status", "[.cmd]") {
|
|||||||
auto t =
|
auto t =
|
||||||
det.getExptimeForAllGates().tsquash("inconsistent exptime to test");
|
det.getExptimeForAllGates().tsquash("inconsistent exptime to test");
|
||||||
if (t[0] != t[1] || t[1] != t[2]) {
|
if (t[0] != t[1] || t[1] != t[2]) {
|
||||||
throw sls::RuntimeError("inconsistent exptime for all gates");
|
throw RuntimeError("inconsistent exptime for all gates");
|
||||||
}
|
}
|
||||||
prev_val = t[0];
|
prev_val = t[0];
|
||||||
}
|
}
|
||||||
@ -2265,29 +2265,29 @@ TEST_CASE("scan", "[.cmd]") {
|
|||||||
|
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
proxy.Call("scan", {sls::ToString(ind), "500", "1500", "500"}, -1, PUT,
|
proxy.Call("scan", {ToString(ind), "500", "1500", "500"}, -1, PUT,
|
||||||
oss);
|
oss);
|
||||||
CHECK(oss.str() ==
|
CHECK(oss.str() ==
|
||||||
"scan [" + sls::ToString(ind) + ", 500, 1500, 500]\n");
|
"scan [" + ToString(ind) + ", 500, 1500, 500]\n");
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
proxy.Call("scan", {}, -1, GET, oss);
|
proxy.Call("scan", {}, -1, GET, oss);
|
||||||
CHECK(oss.str() == "scan [enabled\ndac " + sls::ToString(ind) +
|
CHECK(oss.str() == "scan [enabled\ndac " + ToString(ind) +
|
||||||
"\nstart 500\nstop 1500\nstep "
|
"\nstart 500\nstop 1500\nstep "
|
||||||
"500\nsettleTime 1ms\n]\n");
|
"500\nsettleTime 1ms\n]\n");
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
proxy.Call("scan", {sls::ToString(ind), "500", "1500", "500", "2s"}, -1,
|
proxy.Call("scan", {ToString(ind), "500", "1500", "500", "2s"}, -1,
|
||||||
PUT, oss);
|
PUT, oss);
|
||||||
CHECK(oss.str() ==
|
CHECK(oss.str() ==
|
||||||
"scan [" + sls::ToString(ind) + ", 500, 1500, 500, 2s]\n");
|
"scan [" + ToString(ind) + ", 500, 1500, 500, 2s]\n");
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
proxy.Call("scan", {}, -1, GET, oss);
|
proxy.Call("scan", {}, -1, GET, oss);
|
||||||
CHECK(oss.str() == "scan [enabled\ndac " + sls::ToString(ind) +
|
CHECK(oss.str() == "scan [enabled\ndac " + ToString(ind) +
|
||||||
"\nstart 500\nstop 1500\nstep "
|
"\nstart 500\nstop 1500\nstep "
|
||||||
"500\nsettleTime 2s\n]\n");
|
"500\nsettleTime 2s\n]\n");
|
||||||
}
|
}
|
||||||
@ -2303,17 +2303,17 @@ TEST_CASE("scan", "[.cmd]") {
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
proxy.Call("scan", {sls::ToString(ind), "1500", "500", "-500"}, -1, PUT,
|
proxy.Call("scan", {ToString(ind), "1500", "500", "-500"}, -1, PUT,
|
||||||
oss);
|
oss);
|
||||||
CHECK(oss.str() ==
|
CHECK(oss.str() ==
|
||||||
"scan [" + sls::ToString(ind) + ", 1500, 500, -500]\n");
|
"scan [" + ToString(ind) + ", 1500, 500, -500]\n");
|
||||||
}
|
}
|
||||||
CHECK_THROWS(proxy.Call(
|
CHECK_THROWS(proxy.Call(
|
||||||
"scan", {sls::ToString(notImplementedInd), "500", "1500", "500"}, -1,
|
"scan", {ToString(notImplementedInd), "500", "1500", "500"}, -1,
|
||||||
PUT));
|
PUT));
|
||||||
CHECK_THROWS(proxy.Call("scan", {sls::ToString(ind), "500", "1500", "-500"},
|
CHECK_THROWS(proxy.Call("scan", {ToString(ind), "500", "1500", "-500"},
|
||||||
-1, PUT));
|
-1, PUT));
|
||||||
CHECK_THROWS(proxy.Call("scan", {sls::ToString(ind), "1500", "500", "500"},
|
CHECK_THROWS(proxy.Call("scan", {ToString(ind), "1500", "500", "500"},
|
||||||
-1, PUT));
|
-1, PUT));
|
||||||
|
|
||||||
if (det_type == defs::MYTHEN3 || defs::EIGER) {
|
if (det_type == defs::MYTHEN3 || defs::EIGER) {
|
||||||
@ -2491,7 +2491,7 @@ TEST_CASE("udp_srcip2", "[.cmd]") {
|
|||||||
REQUIRE(oss.str() == "udp_srcip2 129.129.205.12\n");
|
REQUIRE(oss.str() == "udp_srcip2 129.129.205.12\n");
|
||||||
}
|
}
|
||||||
for (int i = 0; i != det.size(); ++i) {
|
for (int i = 0; i != det.size(); ++i) {
|
||||||
if (prev_val[i] != sls::IpAddr{"0.0.0.0"})
|
if (prev_val[i] != IpAddr{"0.0.0.0"})
|
||||||
det.setSourceUDPIP2(prev_val[i], {i});
|
det.setSourceUDPIP2(prev_val[i], {i});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -2846,7 +2846,7 @@ TEST_CASE("reg", "[.cmd]") {
|
|||||||
auto det_type = det.getDetectorType().squash();
|
auto det_type = det.getDetectorType().squash();
|
||||||
if (det_type != defs::EIGER) {
|
if (det_type != defs::EIGER) {
|
||||||
uint32_t addr = 0x64;
|
uint32_t addr = 0x64;
|
||||||
std::string saddr = sls::ToStringHex(addr);
|
std::string saddr = ToStringHex(addr);
|
||||||
auto prev_val = det.readRegister(addr);
|
auto prev_val = det.readRegister(addr);
|
||||||
{
|
{
|
||||||
std::ostringstream oss1, oss2;
|
std::ostringstream oss1, oss2;
|
||||||
@ -2889,7 +2889,7 @@ TEST_CASE("setbit", "[.cmd]") {
|
|||||||
auto det_type = det.getDetectorType().squash();
|
auto det_type = det.getDetectorType().squash();
|
||||||
if (det_type != defs::EIGER) {
|
if (det_type != defs::EIGER) {
|
||||||
uint32_t addr = 0x64;
|
uint32_t addr = 0x64;
|
||||||
std::string saddr = sls::ToStringHex(addr);
|
std::string saddr = ToStringHex(addr);
|
||||||
auto prev_val = det.readRegister(addr);
|
auto prev_val = det.readRegister(addr);
|
||||||
{
|
{
|
||||||
std::ostringstream oss1, oss2;
|
std::ostringstream oss1, oss2;
|
||||||
@ -2911,7 +2911,7 @@ TEST_CASE("clearbit", "[.cmd]") {
|
|||||||
auto det_type = det.getDetectorType().squash();
|
auto det_type = det.getDetectorType().squash();
|
||||||
if (det_type != defs::EIGER) {
|
if (det_type != defs::EIGER) {
|
||||||
uint32_t addr = 0x64;
|
uint32_t addr = 0x64;
|
||||||
std::string saddr = sls::ToStringHex(addr);
|
std::string saddr = ToStringHex(addr);
|
||||||
auto prev_val = det.readRegister(addr);
|
auto prev_val = det.readRegister(addr);
|
||||||
{
|
{
|
||||||
std::ostringstream oss1, oss2;
|
std::ostringstream oss1, oss2;
|
||||||
@ -2933,7 +2933,7 @@ TEST_CASE("getbit", "[.cmd]") {
|
|||||||
auto det_type = det.getDetectorType().squash();
|
auto det_type = det.getDetectorType().squash();
|
||||||
if (det_type != defs::EIGER) {
|
if (det_type != defs::EIGER) {
|
||||||
uint32_t addr = 0x64;
|
uint32_t addr = 0x64;
|
||||||
std::string saddr = sls::ToStringHex(addr);
|
std::string saddr = ToStringHex(addr);
|
||||||
auto prev_val = det.readRegister(addr);
|
auto prev_val = det.readRegister(addr);
|
||||||
{
|
{
|
||||||
std::ostringstream oss1, oss2;
|
std::ostringstream oss1, oss2;
|
||||||
@ -3162,3 +3162,5 @@ TEST_CASE("user", "[.cmd]") {
|
|||||||
REQUIRE_THROWS(proxy.Call("user", {}, -1, PUT));
|
REQUIRE_THROWS(proxy.Call("user", {}, -1, PUT));
|
||||||
REQUIRE_NOTHROW(proxy.Call("user", {}, -1, GET));
|
REQUIRE_NOTHROW(proxy.Call("user", {}, -1, GET));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
|
|
||||||
#include "SharedMemory.h"
|
#include "SharedMemory.h"
|
||||||
#include "CtbConfig.h"
|
#include "CtbConfig.h"
|
||||||
using namespace sls;
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
TEST_CASE("Default construction"){
|
TEST_CASE("Default construction"){
|
||||||
static_assert(sizeof(CtbConfig) == 360); // 18*20
|
static_assert(sizeof(CtbConfig) == 360); // 18*20
|
||||||
@ -57,3 +57,5 @@ TEST_CASE("Move CtbConfig "){
|
|||||||
CtbConfig c2(std::move(c1));
|
CtbConfig c2(std::move(c1));
|
||||||
REQUIRE(c2.getDacName(3) == "yetanothername");
|
REQUIRE(c2.getDacName(3) == "yetanothername");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -4,19 +4,21 @@
|
|||||||
#include "SharedMemory.h"
|
#include "SharedMemory.h"
|
||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
using dt = slsDetectorDefs::detectorType;
|
using dt = slsDetectorDefs::detectorType;
|
||||||
TEST_CASE("Construction with a defined detector type") {
|
TEST_CASE("Construction with a defined detector type") {
|
||||||
sls::Module m(dt::EIGER);
|
Module m(dt::EIGER);
|
||||||
REQUIRE(m.getDetectorType() == dt::EIGER);
|
REQUIRE(m.getDetectorType() == dt::EIGER);
|
||||||
m.freeSharedMemory(); // clean up
|
m.freeSharedMemory(); // clean up
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Read back detector type from shm") {
|
TEST_CASE("Read back detector type from shm") {
|
||||||
// Create specific detector in order to create shm
|
// Create specific detector in order to create shm
|
||||||
sls::Module m(dt::JUNGFRAU);
|
Module m(dt::JUNGFRAU);
|
||||||
|
|
||||||
// New detector that reads type from shm
|
// New detector that reads type from shm
|
||||||
sls::Module m2;
|
Module m2;
|
||||||
REQUIRE(m2.getDetectorType() == dt::JUNGFRAU);
|
REQUIRE(m2.getDetectorType() == dt::JUNGFRAU);
|
||||||
|
|
||||||
// Now both objects point to the same shm so we can only
|
// Now both objects point to the same shm so we can only
|
||||||
@ -25,13 +27,13 @@ TEST_CASE("Read back detector type from shm") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Is shm fixed pattern shm compatible") {
|
TEST_CASE("Is shm fixed pattern shm compatible") {
|
||||||
sls::Module m(dt::JUNGFRAU);
|
Module m(dt::JUNGFRAU);
|
||||||
|
|
||||||
// Should be true since we just created the shm
|
// Should be true since we just created the shm
|
||||||
REQUIRE(m.isFixedPatternSharedMemoryCompatible() == true);
|
REQUIRE(m.isFixedPatternSharedMemoryCompatible() == true);
|
||||||
|
|
||||||
// Set shm version to 0
|
// Set shm version to 0
|
||||||
sls::SharedMemory<sls::sharedModule> shm(0, 0);
|
SharedMemory<sharedModule> shm(0, 0);
|
||||||
REQUIRE(shm.exists() == true);
|
REQUIRE(shm.exists() == true);
|
||||||
shm.openSharedMemory(true);
|
shm.openSharedMemory(true);
|
||||||
shm()->shmversion = 0;
|
shm()->shmversion = 0;
|
||||||
@ -43,19 +45,21 @@ TEST_CASE("Is shm fixed pattern shm compatible") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Get default control port") {
|
TEST_CASE("Get default control port") {
|
||||||
sls::Module m(dt::MYTHEN3);
|
Module m(dt::MYTHEN3);
|
||||||
REQUIRE(m.getControlPort() == 1952);
|
REQUIRE(m.getControlPort() == 1952);
|
||||||
m.freeSharedMemory();
|
m.freeSharedMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Get default stop port") {
|
TEST_CASE("Get default stop port") {
|
||||||
sls::Module m(dt::GOTTHARD2);
|
Module m(dt::GOTTHARD2);
|
||||||
REQUIRE(m.getStopPort() == 1953);
|
REQUIRE(m.getStopPort() == 1953);
|
||||||
m.freeSharedMemory();
|
m.freeSharedMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Get default receiver TCP port") {
|
TEST_CASE("Get default receiver TCP port") {
|
||||||
sls::Module m(dt::MYTHEN3);
|
Module m(dt::MYTHEN3);
|
||||||
REQUIRE(m.getReceiverPort() == 1954);
|
REQUIRE(m.getReceiverPort() == 1954);
|
||||||
m.freeSharedMemory();
|
m.freeSharedMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
#include "sls/Pattern.h"
|
#include "sls/Pattern.h"
|
||||||
|
|
||||||
using sls::Pattern;
|
namespace sls {
|
||||||
|
|
||||||
TEST_CASE("Pattern is default constructable and has zeroed fields") {
|
TEST_CASE("Pattern is default constructable and has zeroed fields") {
|
||||||
Pattern p;
|
Pattern p;
|
||||||
@ -27,3 +27,5 @@ TEST_CASE("Compare patterns") {
|
|||||||
p1.data()->word[500] = 1;
|
p1.data()->word[500] = 1;
|
||||||
REQUIRE_FALSE(p == p1);
|
REQUIRE_FALSE(p == p1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -6,10 +6,10 @@
|
|||||||
#include "sls/TypeTraits.h"
|
#include "sls/TypeTraits.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using sls::Result;
|
namespace sls {
|
||||||
|
|
||||||
TEST_CASE("Result looks and behaves like a standard container") {
|
TEST_CASE("Result looks and behaves like a standard container") {
|
||||||
REQUIRE(sls::is_container<Result<int>>::value == true);
|
REQUIRE(is_container<Result<int>>::value == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Default construction is possible and gives an empty result") {
|
TEST_CASE("Default construction is possible and gives an empty result") {
|
||||||
@ -195,3 +195,5 @@ TEST_CASE("String conversions") {
|
|||||||
REQUIRE(ToString(res4) ==
|
REQUIRE(ToString(res4) ==
|
||||||
"[{one: 1}, {one: 1, three: 3, two: 2}, {one: 1}]");
|
"[{one: 1}, {one: 1, three: 3, two: 2}, {one: 1}]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -7,14 +7,14 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
struct Data {
|
struct Data {
|
||||||
int x;
|
int x;
|
||||||
double y;
|
double y;
|
||||||
char mess[50];
|
char mess[50];
|
||||||
};
|
};
|
||||||
|
|
||||||
using namespace sls;
|
|
||||||
|
|
||||||
constexpr int shm_id = 10;
|
constexpr int shm_id = 10;
|
||||||
|
|
||||||
TEST_CASE("Create SharedMemory read and write", "[detector]") {
|
TEST_CASE("Create SharedMemory read and write", "[detector]") {
|
||||||
@ -26,7 +26,7 @@ TEST_CASE("Create SharedMemory read and write", "[detector]") {
|
|||||||
|
|
||||||
shm()->x = 3;
|
shm()->x = 3;
|
||||||
shm()->y = 5.7;
|
shm()->y = 5.7;
|
||||||
sls::strcpy_safe(shm()->mess, "Some string");
|
strcpy_safe(shm()->mess, "Some string");
|
||||||
|
|
||||||
CHECK(shm()->x == 3);
|
CHECK(shm()->x == 3);
|
||||||
CHECK(shm()->y == 5.7);
|
CHECK(shm()->y == 5.7);
|
||||||
@ -168,8 +168,6 @@ TEST_CASE("map int64 to int32 throws"){
|
|||||||
REQUIRE_THROWS(shm2.openSharedMemory(true));
|
REQUIRE_THROWS(shm2.openSharedMemory(true));
|
||||||
|
|
||||||
shm.removeSharedMemory();
|
shm.removeSharedMemory();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -238,7 +238,7 @@
|
|||||||
// CHECK(d.getReceiverDbitList().size() == 10);
|
// CHECK(d.getReceiverDbitList().size() == 10);
|
||||||
|
|
||||||
// list.push_back(64);
|
// list.push_back(64);
|
||||||
// CHECK_THROWS_AS(d.setReceiverDbitList(list), sls::RuntimeError);
|
// CHECK_THROWS_AS(d.setReceiverDbitList(list), RuntimeError);
|
||||||
// CHECK_THROWS_WITH(d.setReceiverDbitList(list),
|
// CHECK_THROWS_WITH(d.setReceiverDbitList(list),
|
||||||
// Catch::Matchers::Contains("be between 0 and 63"));
|
// Catch::Matchers::Contains("be between 0 and 63"));
|
||||||
|
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
#include "sls/CircularFifo.h"
|
#include "sls/CircularFifo.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using sls::CircularFifo;
|
namespace sls {
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE("Empty buffer") {
|
TEST_CASE("Empty buffer") {
|
||||||
CircularFifo<char> fifo(0);
|
CircularFifo<char> fifo(0);
|
||||||
@ -51,3 +52,5 @@ TEST_CASE("Push pop") {
|
|||||||
CHECK(fifo.isEmpty() == true);
|
CHECK(fifo.isEmpty() == true);
|
||||||
CHECK(fifo.isFull() == false);
|
CHECK(fifo.isFull() == false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -8,9 +8,11 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
std::vector<char> server() {
|
std::vector<char> server() {
|
||||||
std::cout << "starting server\n";
|
std::cout << "starting server\n";
|
||||||
auto server = sls::ServerSocket(1950);
|
auto server = ServerSocket(1950);
|
||||||
auto s = server.accept();
|
auto s = server.accept();
|
||||||
std::vector<char> buffer(100, '\0');
|
std::vector<char> buffer(100, '\0');
|
||||||
s.Receive(buffer.data(), buffer.size());
|
s.Receive(buffer.data(), buffer.size());
|
||||||
@ -33,7 +35,7 @@ TEST_CASE("The server recive the same message as we send", "[support]") {
|
|||||||
|
|
||||||
auto s = std::async(std::launch::async, server);
|
auto s = std::async(std::launch::async, server);
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
auto client = sls::DetectorSocket("localhost", 1950);
|
auto client = DetectorSocket("localhost", 1950);
|
||||||
client.Send(sent_message.data(), sent_message.size());
|
client.Send(sent_message.data(), sent_message.size());
|
||||||
client.Receive(received_message.data(), received_message.size());
|
client.Receive(received_message.data(), received_message.size());
|
||||||
client.close();
|
client.close();
|
||||||
@ -45,5 +47,7 @@ TEST_CASE("The server recive the same message as we send", "[support]") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("throws on no server", "[support]") {
|
TEST_CASE("throws on no server", "[support]") {
|
||||||
CHECK_THROWS(sls::DetectorSocket("localhost", 1950));
|
CHECK_THROWS(DetectorSocket("localhost", 1950));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -7,10 +7,11 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
using sls::StaticVector;
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
TEST_CASE("StaticVector is a container") {
|
TEST_CASE("StaticVector is a container") {
|
||||||
REQUIRE(sls::is_container<StaticVector<int, 7>>::value == true);
|
REQUIRE(is_container<StaticVector<int, 7>>::value == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Comparing StaticVector containers") {
|
TEST_CASE("Comparing StaticVector containers") {
|
||||||
@ -317,15 +318,15 @@ SCENARIO("Converting to vector", "[support]") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("sls::StaticVector") {
|
TEST_CASE("StaticVector") {
|
||||||
sls::StaticVector<int, 5> vec;
|
StaticVector<int, 5> vec;
|
||||||
vec.push_back(3);
|
vec.push_back(3);
|
||||||
vec.push_back(8);
|
vec.push_back(8);
|
||||||
REQUIRE(sls::ToString(vec) == "[3, 8]");
|
REQUIRE(ToString(vec) == "[3, 8]");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("sls::StaticVector stream") {
|
TEST_CASE("StaticVector stream") {
|
||||||
sls::StaticVector<int, 5> vec;
|
StaticVector<int, 5> vec;
|
||||||
vec.push_back(33);
|
vec.push_back(33);
|
||||||
vec.push_back(85667);
|
vec.push_back(85667);
|
||||||
vec.push_back(2);
|
vec.push_back(2);
|
||||||
@ -333,3 +334,5 @@ TEST_CASE("sls::StaticVector stream") {
|
|||||||
oss << vec;
|
oss << vec;
|
||||||
REQUIRE(oss.str() == "[33, 85667, 2]");
|
REQUIRE(oss.str() == "[33, 85667, 2]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -6,9 +6,11 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
TEST_CASE("Time 1s restart then time 2s", "[.timer]") {
|
TEST_CASE("Time 1s restart then time 2s", "[.timer]") {
|
||||||
auto sleep_duration = std::chrono::seconds(1);
|
auto sleep_duration = std::chrono::seconds(1);
|
||||||
auto t = sls::Timer();
|
auto t = Timer();
|
||||||
std::this_thread::sleep_for(sleep_duration);
|
std::this_thread::sleep_for(sleep_duration);
|
||||||
REQUIRE(t.elapsed_s() == Approx(1).epsilon(0.01));
|
REQUIRE(t.elapsed_s() == Approx(1).epsilon(0.01));
|
||||||
|
|
||||||
@ -19,7 +21,9 @@ TEST_CASE("Time 1s restart then time 2s", "[.timer]") {
|
|||||||
|
|
||||||
TEST_CASE("Return ms", "[.timer]") {
|
TEST_CASE("Return ms", "[.timer]") {
|
||||||
auto sleep_duration = std::chrono::milliseconds(1300);
|
auto sleep_duration = std::chrono::milliseconds(1300);
|
||||||
auto t = sls::Timer();
|
auto t = Timer();
|
||||||
std::this_thread::sleep_for(sleep_duration);
|
std::this_thread::sleep_for(sleep_duration);
|
||||||
REQUIRE(t.elapsed_ms() == Approx(1300).epsilon(0.5));
|
REQUIRE(t.elapsed_ms() == Approx(1300).epsilon(0.5));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -12,11 +12,8 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// using namespace sls;
|
namespace sls {
|
||||||
using sls::defs;
|
|
||||||
using sls::StringTo;
|
|
||||||
using sls::ToString;
|
|
||||||
using sls::ToStringHex;
|
|
||||||
using namespace sls::time;
|
using namespace sls::time;
|
||||||
|
|
||||||
TEST_CASE("Integer conversions", "[support]") {
|
TEST_CASE("Integer conversions", "[support]") {
|
||||||
@ -91,9 +88,9 @@ TEST_CASE("Array") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Convert types with str method") {
|
TEST_CASE("Convert types with str method") {
|
||||||
sls::IpAddr addr;
|
IpAddr addr;
|
||||||
REQUIRE(ToString(addr) == "0.0.0.0");
|
REQUIRE(ToString(addr) == "0.0.0.0");
|
||||||
REQUIRE(ToString(sls::IpAddr{}) == "0.0.0.0");
|
REQUIRE(ToString(IpAddr{}) == "0.0.0.0");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("String to string", "[support]") {
|
TEST_CASE("String to string", "[support]") {
|
||||||
@ -325,39 +322,41 @@ TEST_CASE("Printing c style arrays of double") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Print a member of patternParameters") {
|
TEST_CASE("Print a member of patternParameters") {
|
||||||
auto pat = sls::make_unique<sls::patternParameters>();
|
auto pat = make_unique<patternParameters>();
|
||||||
pat->limits[0] = 4;
|
pat->limits[0] = 4;
|
||||||
pat->limits[1] = 100;
|
pat->limits[1] = 100;
|
||||||
REQUIRE(ToString(pat->limits) == "[4, 100]");
|
REQUIRE(ToString(pat->limits) == "[4, 100]");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("streamingInterface") {
|
TEST_CASE("streamingInterface") {
|
||||||
REQUIRE(ToString(sls::defs::streamingInterface::NONE) == "none");
|
REQUIRE(ToString(defs::streamingInterface::NONE) == "none");
|
||||||
REQUIRE(ToString(sls::defs::streamingInterface::ETHERNET_10GB) == "10gbe");
|
REQUIRE(ToString(defs::streamingInterface::ETHERNET_10GB) == "10gbe");
|
||||||
REQUIRE(ToString(sls::defs::streamingInterface::LOW_LATENCY_LINK) == "lll");
|
REQUIRE(ToString(defs::streamingInterface::LOW_LATENCY_LINK) == "lll");
|
||||||
REQUIRE(ToString(sls::defs::streamingInterface::LOW_LATENCY_LINK |
|
REQUIRE(ToString(defs::streamingInterface::LOW_LATENCY_LINK |
|
||||||
sls::defs::streamingInterface::ETHERNET_10GB) ==
|
defs::streamingInterface::ETHERNET_10GB) ==
|
||||||
"lll, 10gbe");
|
"lll, 10gbe");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Speed level
|
// Speed level
|
||||||
TEST_CASE("speedLevel to string") {
|
TEST_CASE("speedLevel to string") {
|
||||||
REQUIRE(ToString(sls::defs::speedLevel::FULL_SPEED) == "full_speed");
|
REQUIRE(ToString(defs::speedLevel::FULL_SPEED) == "full_speed");
|
||||||
REQUIRE(ToString(sls::defs::speedLevel::HALF_SPEED) == "half_speed");
|
REQUIRE(ToString(defs::speedLevel::HALF_SPEED) == "half_speed");
|
||||||
REQUIRE(ToString(sls::defs::speedLevel::QUARTER_SPEED) == "quarter_speed");
|
REQUIRE(ToString(defs::speedLevel::QUARTER_SPEED) == "quarter_speed");
|
||||||
REQUIRE(ToString(sls::defs::speedLevel::G2_108MHZ) == "108");
|
REQUIRE(ToString(defs::speedLevel::G2_108MHZ) == "108");
|
||||||
REQUIRE(ToString(sls::defs::speedLevel::G2_144MHZ) == "144");
|
REQUIRE(ToString(defs::speedLevel::G2_144MHZ) == "144");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("string to speedLevel") {
|
TEST_CASE("string to speedLevel") {
|
||||||
REQUIRE(StringTo<sls::defs::speedLevel>("full_speed") ==
|
REQUIRE(StringTo<defs::speedLevel>("full_speed") ==
|
||||||
sls::defs::speedLevel::FULL_SPEED);
|
defs::speedLevel::FULL_SPEED);
|
||||||
REQUIRE(StringTo<sls::defs::speedLevel>("half_speed") ==
|
REQUIRE(StringTo<defs::speedLevel>("half_speed") ==
|
||||||
sls::defs::speedLevel::HALF_SPEED);
|
defs::speedLevel::HALF_SPEED);
|
||||||
REQUIRE(StringTo<sls::defs::speedLevel>("quarter_speed") ==
|
REQUIRE(StringTo<defs::speedLevel>("quarter_speed") ==
|
||||||
sls::defs::speedLevel::QUARTER_SPEED);
|
defs::speedLevel::QUARTER_SPEED);
|
||||||
REQUIRE(StringTo<sls::defs::speedLevel>("108") ==
|
REQUIRE(StringTo<defs::speedLevel>("108") ==
|
||||||
sls::defs::speedLevel::G2_108MHZ);
|
defs::speedLevel::G2_108MHZ);
|
||||||
REQUIRE(StringTo<sls::defs::speedLevel>("144") ==
|
REQUIRE(StringTo<defs::speedLevel>("144") ==
|
||||||
sls::defs::speedLevel::G2_144MHZ);
|
defs::speedLevel::G2_144MHZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
// Dummy classes only used here for testing
|
// Dummy classes only used here for testing
|
||||||
class DummyWithStr {
|
class DummyWithStr {
|
||||||
public:
|
public:
|
||||||
@ -19,35 +21,37 @@ class DummyNoStr {
|
|||||||
std::string somethingelse();
|
std::string somethingelse();
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_CASE("sls::is_container") {
|
TEST_CASE("is_container") {
|
||||||
|
|
||||||
CHECK(sls::is_container<std::vector<int>>::value == true);
|
CHECK(is_container<std::vector<int>>::value == true);
|
||||||
CHECK(sls::is_container<std::array<double, 3>>::value == true);
|
CHECK(is_container<std::array<double, 3>>::value == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Check for str() method") {
|
TEST_CASE("Check for str() method") {
|
||||||
REQUIRE(sls::has_str<DummyWithStr>::value == true);
|
REQUIRE(has_str<DummyWithStr>::value == true);
|
||||||
REQUIRE(sls::has_str<DummyNoStr>::value == false);
|
REQUIRE(has_str<DummyNoStr>::value == false);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Check for str() on ostream") {
|
TEST_CASE("Check for str() on ostream") {
|
||||||
REQUIRE(sls::has_str<std::ostringstream>::value == true);
|
REQUIRE(has_str<std::ostringstream>::value == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("sls::is_duration") {
|
TEST_CASE("is_duration") {
|
||||||
REQUIRE(sls::is_duration<std::chrono::nanoseconds>::value == true);
|
REQUIRE(is_duration<std::chrono::nanoseconds>::value == true);
|
||||||
REQUIRE(sls::is_duration<std::chrono::seconds>::value == true);
|
REQUIRE(is_duration<std::chrono::seconds>::value == true);
|
||||||
REQUIRE(sls::is_duration<std::chrono::hours>::value == true);
|
REQUIRE(is_duration<std::chrono::hours>::value == true);
|
||||||
|
|
||||||
REQUIRE(sls::is_duration<int>::value == false);
|
REQUIRE(is_duration<int>::value == false);
|
||||||
REQUIRE(sls::is_duration<std::vector<int>>::value == false);
|
REQUIRE(is_duration<std::vector<int>>::value == false);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("initializer list") {
|
TEST_CASE("initializer list") {
|
||||||
REQUIRE(sls::is_light_container<std::initializer_list<int>>::value == true);
|
REQUIRE(is_light_container<std::initializer_list<int>>::value == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Check for emplace back") {
|
TEST_CASE("Check for emplace back") {
|
||||||
// we know vector should have this its the type trait that is tested
|
// we know vector should have this its the type trait that is tested
|
||||||
REQUIRE(sls::has_emplace_back<std::vector<int>>::value == true);
|
REQUIRE(has_emplace_back<std::vector<int>>::value == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
constexpr int default_port = 50001;
|
constexpr int default_port = 50001;
|
||||||
|
|
||||||
int open_socket(int port) {
|
int open_socket(int port) {
|
||||||
@ -31,16 +33,16 @@ int open_socket(int port) {
|
|||||||
|
|
||||||
const std::string portname = std::to_string(port);
|
const std::string portname = std::to_string(port);
|
||||||
if (getaddrinfo(host, portname.c_str(), &hints, &res)) {
|
if (getaddrinfo(host, portname.c_str(), &hints, &res)) {
|
||||||
throw sls::RuntimeError("Failed at getaddrinfo with " +
|
throw RuntimeError("Failed at getaddrinfo with " +
|
||||||
std::string(host));
|
std::string(host));
|
||||||
}
|
}
|
||||||
int fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
int fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
throw sls::RuntimeError("Failed to create UDP RX socket");
|
throw RuntimeError("Failed to create UDP RX socket");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connect(fd, res->ai_addr, res->ai_addrlen)) {
|
if (connect(fd, res->ai_addr, res->ai_addrlen)) {
|
||||||
throw sls::RuntimeError("Failed to connect socket");
|
throw RuntimeError("Failed to connect socket");
|
||||||
}
|
}
|
||||||
freeaddrinfo(res);
|
freeaddrinfo(res);
|
||||||
return fd;
|
return fd;
|
||||||
@ -49,7 +51,7 @@ int open_socket(int port) {
|
|||||||
TEST_CASE("Get packet size returns the packet size we set in the constructor") {
|
TEST_CASE("Get packet size returns the packet size we set in the constructor") {
|
||||||
constexpr int port = 50001;
|
constexpr int port = 50001;
|
||||||
constexpr ssize_t packet_size = 8000;
|
constexpr ssize_t packet_size = 8000;
|
||||||
sls::UdpRxSocket s{port, packet_size};
|
UdpRxSocket s{port, packet_size};
|
||||||
CHECK(s.getPacketSize() == packet_size);
|
CHECK(s.getPacketSize() == packet_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +62,7 @@ TEST_CASE("Receive data from a vector") {
|
|||||||
ssize_t packet_size =
|
ssize_t packet_size =
|
||||||
sizeof(decltype(data_to_send)::value_type) * data_to_send.size();
|
sizeof(decltype(data_to_send)::value_type) * data_to_send.size();
|
||||||
|
|
||||||
sls::UdpRxSocket udpsock{port, packet_size};
|
UdpRxSocket udpsock{port, packet_size};
|
||||||
|
|
||||||
int fd = open_socket(port);
|
int fd = open_socket(port);
|
||||||
auto n = write(fd, data_to_send.data(), packet_size);
|
auto n = write(fd, data_to_send.data(), packet_size);
|
||||||
@ -74,13 +76,13 @@ TEST_CASE("Receive data from a vector") {
|
|||||||
TEST_CASE("Shutdown socket without hanging when waiting for data") {
|
TEST_CASE("Shutdown socket without hanging when waiting for data") {
|
||||||
constexpr int port = 50001;
|
constexpr int port = 50001;
|
||||||
constexpr ssize_t packet_size = 8000;
|
constexpr ssize_t packet_size = 8000;
|
||||||
sls::UdpRxSocket s{port, packet_size};
|
UdpRxSocket s{port, packet_size};
|
||||||
char buff[packet_size];
|
char buff[packet_size];
|
||||||
|
|
||||||
// Start a thread and wait for package
|
// Start a thread and wait for package
|
||||||
// if the socket is left open we would block
|
// if the socket is left open we would block
|
||||||
std::future<bool> ret =
|
std::future<bool> ret =
|
||||||
std::async(&sls::UdpRxSocket::ReceivePacket, &s, (char *)&buff);
|
std::async(&UdpRxSocket::ReceivePacket, &s, (char *)&buff);
|
||||||
|
|
||||||
s.Shutdown();
|
s.Shutdown();
|
||||||
auto r = ret.get();
|
auto r = ret.get();
|
||||||
@ -90,7 +92,7 @@ TEST_CASE("Shutdown socket without hanging when waiting for data") {
|
|||||||
|
|
||||||
TEST_CASE("Too small packet") {
|
TEST_CASE("Too small packet") {
|
||||||
constexpr int port = 50001;
|
constexpr int port = 50001;
|
||||||
sls::UdpRxSocket s(port, 2 * sizeof(uint32_t));
|
UdpRxSocket s(port, 2 * sizeof(uint32_t));
|
||||||
auto fd = open_socket(port);
|
auto fd = open_socket(port);
|
||||||
uint32_t val = 10;
|
uint32_t val = 10;
|
||||||
write(fd, &val, sizeof(val));
|
write(fd, &val, sizeof(val));
|
||||||
@ -103,8 +105,10 @@ TEST_CASE("Receive an int to an external buffer") {
|
|||||||
int to_send = 5;
|
int to_send = 5;
|
||||||
int received = -1;
|
int received = -1;
|
||||||
auto fd = open_socket(default_port);
|
auto fd = open_socket(default_port);
|
||||||
sls::UdpRxSocket s(default_port, sizeof(int));
|
UdpRxSocket s(default_port, sizeof(int));
|
||||||
write(fd, &to_send, sizeof(to_send));
|
write(fd, &to_send, sizeof(to_send));
|
||||||
CHECK(s.ReceivePacket(reinterpret_cast<char *>(&received)));
|
CHECK(s.ReceivePacket(reinterpret_cast<char *>(&received)));
|
||||||
CHECK(received == to_send);
|
CHECK(received == to_send);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
#include "sls/ZmqSocket.h"
|
#include "sls/ZmqSocket.h"
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE("Throws when cannot create socket") {
|
TEST_CASE("Throws when cannot create socket") {
|
||||||
REQUIRE_THROWS(ZmqSocket("sdiasodjajpvv", 5076001));
|
REQUIRE_THROWS(ZmqSocket("sdiasodjajpvv", 5076001));
|
||||||
}
|
}
|
||||||
@ -114,3 +117,5 @@ TEST_CASE("Send header and data") {
|
|||||||
REQUIRE(data[i] == received_data[i]);
|
REQUIRE(data[i] == received_data[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} //namespace
|
@ -4,25 +4,27 @@
|
|||||||
#include "sls/bit_utils.h"
|
#include "sls/bit_utils.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
TEST_CASE("Get set bits from 0") {
|
TEST_CASE("Get set bits from 0") {
|
||||||
auto vec = sls::getSetBits(0);
|
auto vec = getSetBits(0);
|
||||||
REQUIRE(vec.empty());
|
REQUIRE(vec.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Get set bits from 1") {
|
TEST_CASE("Get set bits from 1") {
|
||||||
auto vec = sls::getSetBits(1);
|
auto vec = getSetBits(1);
|
||||||
REQUIRE(vec.size() == 1);
|
REQUIRE(vec.size() == 1);
|
||||||
REQUIRE(vec[0] == 0);
|
REQUIRE(vec[0] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Get set bits from 2") {
|
TEST_CASE("Get set bits from 2") {
|
||||||
auto vec = sls::getSetBits(2ul);
|
auto vec = getSetBits(2ul);
|
||||||
REQUIRE(vec.size() == 1);
|
REQUIRE(vec.size() == 1);
|
||||||
REQUIRE(vec[0] == 1);
|
REQUIRE(vec[0] == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Get set bits from 3") {
|
TEST_CASE("Get set bits from 3") {
|
||||||
auto vec = sls::getSetBits(3u);
|
auto vec = getSetBits(3u);
|
||||||
REQUIRE(vec.size() == 2);
|
REQUIRE(vec.size() == 2);
|
||||||
REQUIRE(vec[0] == 0);
|
REQUIRE(vec[0] == 0);
|
||||||
REQUIRE(vec[1] == 1);
|
REQUIRE(vec[1] == 1);
|
||||||
@ -30,12 +32,14 @@ TEST_CASE("Get set bits from 3") {
|
|||||||
|
|
||||||
TEST_CASE("All bits set") {
|
TEST_CASE("All bits set") {
|
||||||
uint8_t val = -1;
|
uint8_t val = -1;
|
||||||
auto vec = sls::getSetBits(val);
|
auto vec = getSetBits(val);
|
||||||
REQUIRE(vec == std::vector<int>{0, 1, 2, 3, 4, 5, 6, 7});
|
REQUIRE(vec == std::vector<int>{0, 1, 2, 3, 4, 5, 6, 7});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Get set bits from 523") {
|
TEST_CASE("Get set bits from 523") {
|
||||||
// 0b1000001011 == 523
|
// 0b1000001011 == 523
|
||||||
auto vec = sls::getSetBits(523);
|
auto vec = getSetBits(523);
|
||||||
REQUIRE(vec == std::vector<int>{0, 1, 3, 9});
|
REQUIRE(vec == std::vector<int>{0, 1, 3, 9});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using namespace sls;
|
namespace sls {
|
||||||
|
|
||||||
TEST_CASE("Equality of an empty vector", "[support]") {
|
TEST_CASE("Equality of an empty vector", "[support]") {
|
||||||
std::vector<int> v;
|
std::vector<int> v;
|
||||||
@ -64,36 +64,36 @@ TEST_CASE("A vector of double with different values", "[support]") {
|
|||||||
|
|
||||||
TEST_CASE("Sum of empty vector", "[support]") {
|
TEST_CASE("Sum of empty vector", "[support]") {
|
||||||
std::vector<float> v;
|
std::vector<float> v;
|
||||||
REQUIRE(sls::sum(v) == Approx(0));
|
REQUIRE(sum(v) == Approx(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Sum of vector", "[support]") {
|
TEST_CASE("Sum of vector", "[support]") {
|
||||||
std::vector<double> v{1.2, 2., 4.2, 4, 1.13};
|
std::vector<double> v{1.2, 2., 4.2, 4, 1.13};
|
||||||
REQUIRE(sls::sum(v) == Approx(12.53));
|
REQUIRE(sum(v) == Approx(12.53));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Minus one if different", "[support]") {
|
TEST_CASE("Minus one if different", "[support]") {
|
||||||
std::vector<double> v;
|
std::vector<double> v;
|
||||||
REQUIRE(v.empty());
|
REQUIRE(v.empty());
|
||||||
double d = -1;
|
double d = -1;
|
||||||
REQUIRE(sls::minusOneIfDifferent(v) == d);
|
REQUIRE(minusOneIfDifferent(v) == d);
|
||||||
|
|
||||||
SECTION("single element") {
|
SECTION("single element") {
|
||||||
v.push_back(7.3);
|
v.push_back(7.3);
|
||||||
REQUIRE(v.size() == 1);
|
REQUIRE(v.size() == 1);
|
||||||
REQUIRE(sls::minusOneIfDifferent(v) == Approx(7.3));
|
REQUIRE(minusOneIfDifferent(v) == Approx(7.3));
|
||||||
}
|
}
|
||||||
SECTION("different elements") {
|
SECTION("different elements") {
|
||||||
v.push_back(7.3);
|
v.push_back(7.3);
|
||||||
v.push_back(1.0);
|
v.push_back(1.0);
|
||||||
v.push_back(62.1);
|
v.push_back(62.1);
|
||||||
REQUIRE(sls::minusOneIfDifferent(v) == Approx(-1.0));
|
REQUIRE(minusOneIfDifferent(v) == Approx(-1.0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("minus one does not have side effects", "[support]") {
|
TEST_CASE("minus one does not have side effects", "[support]") {
|
||||||
std::vector<int> v{1, 1, 1};
|
std::vector<int> v{1, 1, 1};
|
||||||
int i = sls::minusOneIfDifferent(v);
|
int i = minusOneIfDifferent(v);
|
||||||
REQUIRE(i == 1);
|
REQUIRE(i == 1);
|
||||||
i = 5;
|
i = 5;
|
||||||
REQUIRE(v[0] == 1);
|
REQUIRE(v[0] == 1);
|
||||||
@ -135,3 +135,5 @@ TEST_CASE("compare a vector of arrays", "[support]") {
|
|||||||
std::vector<std::array<uint64_t, 3>> vec1{{5, 90, 8}, {5, 6, 8}, {5, 6, 8}};
|
std::vector<std::array<uint64_t, 3>> vec1{{5, 90, 8}, {5, 6, 8}, {5, 6, 8}};
|
||||||
CHECK(minusOneIfDifferent(vec1) == arr);
|
CHECK(minusOneIfDifferent(vec1) == arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -7,10 +7,12 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
TEST_CASE("Get size of empty file") {
|
TEST_CASE("Get size of empty file") {
|
||||||
char fname[] = "temfile_XXXXXX";
|
char fname[] = "temfile_XXXXXX";
|
||||||
std::ifstream ifs(fname);
|
std::ifstream ifs(fname);
|
||||||
auto size = sls::getFileSize(ifs);
|
auto size = getFileSize(ifs);
|
||||||
REQUIRE(size <= 0); // -1 or zero
|
REQUIRE(size <= 0); // -1 or zero
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,7 +24,9 @@ TEST_CASE("Get size of file with data") {
|
|||||||
write(fh, data.data(), n_bytes);
|
write(fh, data.data(), n_bytes);
|
||||||
|
|
||||||
std::ifstream ifs(fname);
|
std::ifstream ifs(fname);
|
||||||
auto size = sls::getFileSize(ifs);
|
auto size = getFileSize(ifs);
|
||||||
REQUIRE(size == n_bytes);
|
REQUIRE(size == n_bytes);
|
||||||
REQUIRE(ifs.tellg() == 0); // getting size resets pos!
|
REQUIRE(ifs.tellg() == 0); // getting size resets pos!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using sls::Logger;
|
namespace sls {
|
||||||
|
|
||||||
TEST_CASE("LogLevel to string") {
|
TEST_CASE("LogLevel to string") {
|
||||||
CHECK(Logger::ToString(logERROR) == "ERROR");
|
CHECK(Logger::ToString(logERROR) == "ERROR");
|
||||||
@ -49,3 +49,5 @@ TEST_CASE("Test output") {
|
|||||||
auto pos = r.find("This should be printed");
|
auto pos = r.find("This should be printed");
|
||||||
CHECK(pos != std::string::npos);
|
CHECK(pos != std::string::npos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include "sls/sls_detector_exceptions.h"
|
#include "sls/sls_detector_exceptions.h"
|
||||||
#include "sls/string_utils.h"
|
#include "sls/string_utils.h"
|
||||||
|
|
||||||
using namespace sls;
|
namespace sls {
|
||||||
|
|
||||||
TEST_CASE("Convert mac address using classes", "[support]") {
|
TEST_CASE("Convert mac address using classes", "[support]") {
|
||||||
|
|
||||||
@ -128,3 +128,5 @@ TEST_CASE("udp dst struct basic properties") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO!(Erik) Look up a real hostname and verify the IP
|
// TODO!(Erik) Look up a real hostname and verify the IP
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
#include "sls/sls_detector_defs.h"
|
#include "sls/sls_detector_defs.h"
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
using dt = slsDetectorDefs::detectorType;
|
using dt = slsDetectorDefs::detectorType;
|
||||||
|
|
||||||
TEST_CASE("sls_detector_module default construction", "[support][new]") {
|
TEST_CASE("sls_detector_module default construction", "[support][new]") {
|
||||||
@ -76,3 +78,5 @@ TEST_CASE("compare two scanParameters") {
|
|||||||
p0.enable = 1;
|
p0.enable = 1;
|
||||||
CHECK_FALSE(p0 == p1);
|
CHECK_FALSE(p0 == p1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
#include "sls/string_utils.h"
|
#include "sls/string_utils.h"
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
TEST_CASE("copy a string") {
|
TEST_CASE("copy a string") {
|
||||||
|
|
||||||
char src[10] = "hej";
|
char src[10] = "hej";
|
||||||
@ -14,7 +16,7 @@ TEST_CASE("copy a string") {
|
|||||||
|
|
||||||
char dst[20];
|
char dst[20];
|
||||||
|
|
||||||
sls::strcpy_safe(dst, src);
|
strcpy_safe(dst, src);
|
||||||
REQUIRE(dst[0] == 'h');
|
REQUIRE(dst[0] == 'h');
|
||||||
REQUIRE(dst[1] == 'e');
|
REQUIRE(dst[1] == 'e');
|
||||||
REQUIRE(dst[2] == 'j');
|
REQUIRE(dst[2] == 'j');
|
||||||
@ -26,7 +28,7 @@ TEST_CASE("copy a string") {
|
|||||||
TEST_CASE("copy a long string") {
|
TEST_CASE("copy a long string") {
|
||||||
auto src = "some very very long sting that does not fit";
|
auto src = "some very very long sting that does not fit";
|
||||||
char dst[3];
|
char dst[3];
|
||||||
sls::strcpy_safe(dst, src);
|
strcpy_safe(dst, src);
|
||||||
REQUIRE(dst[0] == 's');
|
REQUIRE(dst[0] == 's');
|
||||||
REQUIRE(dst[1] == 'o');
|
REQUIRE(dst[1] == 'o');
|
||||||
REQUIRE(dst[2] == '\0');
|
REQUIRE(dst[2] == '\0');
|
||||||
@ -35,7 +37,7 @@ TEST_CASE("copy a long string") {
|
|||||||
|
|
||||||
TEST_CASE("split a string with end delimiter") {
|
TEST_CASE("split a string with end delimiter") {
|
||||||
std::string s("abra+kadabra+");
|
std::string s("abra+kadabra+");
|
||||||
auto r = sls::split(s, '+');
|
auto r = split(s, '+');
|
||||||
REQUIRE(r.size() == 2);
|
REQUIRE(r.size() == 2);
|
||||||
REQUIRE(r[0] == "abra");
|
REQUIRE(r[0] == "abra");
|
||||||
REQUIRE(r[1] == "kadabra");
|
REQUIRE(r[1] == "kadabra");
|
||||||
@ -43,7 +45,7 @@ TEST_CASE("split a string with end delimiter") {
|
|||||||
|
|
||||||
TEST_CASE("split a string without end delimiter") {
|
TEST_CASE("split a string without end delimiter") {
|
||||||
std::string s("abra+kadabra+filibom");
|
std::string s("abra+kadabra+filibom");
|
||||||
auto r = sls::split(s, '+');
|
auto r = split(s, '+');
|
||||||
REQUIRE(r.size() == 3);
|
REQUIRE(r.size() == 3);
|
||||||
REQUIRE(r[0] == "abra");
|
REQUIRE(r[0] == "abra");
|
||||||
REQUIRE(r[1] == "kadabra");
|
REQUIRE(r[1] == "kadabra");
|
||||||
@ -52,58 +54,60 @@ TEST_CASE("split a string without end delimiter") {
|
|||||||
|
|
||||||
TEST_CASE("Remove char from string") {
|
TEST_CASE("Remove char from string") {
|
||||||
char str[] = "sometest";
|
char str[] = "sometest";
|
||||||
sls::removeChar(str, 'e');
|
removeChar(str, 'e');
|
||||||
REQUIRE(std::string(str) == "somtst");
|
REQUIRE(std::string(str) == "somtst");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Remove char from empty string") {
|
TEST_CASE("Remove char from empty string") {
|
||||||
char str[50] = {};
|
char str[50] = {};
|
||||||
sls::removeChar(str, 'e');
|
removeChar(str, 'e');
|
||||||
REQUIRE(std::string(str).empty());
|
REQUIRE(std::string(str).empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Many characters in a row") {
|
TEST_CASE("Many characters in a row") {
|
||||||
char str[] = "someeequitellll::ongstring";
|
char str[] = "someeequitellll::ongstring";
|
||||||
sls::removeChar(str, 'l');
|
removeChar(str, 'l');
|
||||||
REQUIRE(std::string(str) == "someeequite::ongstring");
|
REQUIRE(std::string(str) == "someeequite::ongstring");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Check is string is integer") {
|
TEST_CASE("Check is string is integer") {
|
||||||
|
|
||||||
REQUIRE(sls::is_int("75"));
|
REQUIRE(is_int("75"));
|
||||||
REQUIRE(sls::is_int("11675"));
|
REQUIRE(is_int("11675"));
|
||||||
REQUIRE_FALSE(sls::is_int("7.5"));
|
REQUIRE_FALSE(is_int("7.5"));
|
||||||
REQUIRE_FALSE(sls::is_int("hej"));
|
REQUIRE_FALSE(is_int("hej"));
|
||||||
REQUIRE_FALSE(sls::is_int("7a"));
|
REQUIRE_FALSE(is_int("7a"));
|
||||||
REQUIRE_FALSE(sls::is_int(""));
|
REQUIRE_FALSE(is_int(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Replace substring in string") {
|
TEST_CASE("Replace substring in string") {
|
||||||
std::string s = "this string should be replaced";
|
std::string s = "this string should be replaced";
|
||||||
auto r = sls::replace_first(&s, "string ", "");
|
auto r = replace_first(&s, "string ", "");
|
||||||
REQUIRE(r == true);
|
REQUIRE(r == true);
|
||||||
REQUIRE(s == "this should be replaced");
|
REQUIRE(s == "this should be replaced");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Replace --help in command") {
|
TEST_CASE("Replace --help in command") {
|
||||||
std::string s = "sls_detector_get --help exptime";
|
std::string s = "sls_detector_get --help exptime";
|
||||||
auto r = sls::replace_first(&s, " --help", "");
|
auto r = replace_first(&s, " --help", "");
|
||||||
REQUIRE(r == true);
|
REQUIRE(r == true);
|
||||||
REQUIRE(s == "sls_detector_get exptime");
|
REQUIRE(s == "sls_detector_get exptime");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Replace -h in command") {
|
TEST_CASE("Replace -h in command") {
|
||||||
std::string s = "sls_detector_get -h exptime";
|
std::string s = "sls_detector_get -h exptime";
|
||||||
auto r = sls::replace_first(&s, " -h", "");
|
auto r = replace_first(&s, " -h", "");
|
||||||
REQUIRE(r == true);
|
REQUIRE(r == true);
|
||||||
REQUIRE(s == "sls_detector_get exptime");
|
REQUIRE(s == "sls_detector_get exptime");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("replace --help") {
|
TEST_CASE("replace --help") {
|
||||||
std::string s = "list --help";
|
std::string s = "list --help";
|
||||||
auto r = sls::replace_first(&s, " --help", "");
|
auto r = replace_first(&s, " --help", "");
|
||||||
REQUIRE(r == true);
|
REQUIRE(r == true);
|
||||||
REQUIRE(s == "list");
|
REQUIRE(s == "list");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TEST_CASE("concat things not being strings")
|
// TEST_CASE("concat things not being strings")
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include "sls/sls_detector_defs.h"
|
#include "sls/sls_detector_defs.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
struct SingleDetectorConfig {
|
struct SingleDetectorConfig {
|
||||||
slsDetectorDefs::detectorType type_enum =
|
slsDetectorDefs::detectorType type_enum =
|
||||||
slsDetectorDefs::detectorType::EIGER;
|
slsDetectorDefs::detectorType::EIGER;
|
||||||
@ -11,3 +13,5 @@ struct SingleDetectorConfig {
|
|||||||
const std::string type_string = "Eiger";
|
const std::string type_string = "Eiger";
|
||||||
const std::string my_ip = "129.129.205.171";
|
const std::string my_ip = "129.129.205.171";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "sls/sls_detector_defs.h"
|
#include "sls/sls_detector_defs.h"
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
using dt = slsDetectorDefs::detectorType;
|
using dt = slsDetectorDefs::detectorType;
|
||||||
using di = slsDetectorDefs::dacIndex;
|
using di = slsDetectorDefs::dacIndex;
|
||||||
using defs = slsDetectorDefs;
|
using defs = slsDetectorDefs;
|
||||||
@ -15,3 +18,5 @@ extern decltype(defs::GET_ACTION) GET;
|
|||||||
extern decltype(defs::PUT_ACTION) PUT;
|
extern decltype(defs::PUT_ACTION) PUT;
|
||||||
|
|
||||||
} // namespace test
|
} // namespace test
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -2,6 +2,11 @@
|
|||||||
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
enum class func_id { read_data, read_int, read_half_data, combined };
|
enum class func_id { read_data, read_int, read_half_data, combined };
|
||||||
constexpr size_t MB = 1048576;
|
constexpr size_t MB = 1048576;
|
||||||
constexpr size_t DATA_SIZE = 50 * MB;
|
constexpr size_t DATA_SIZE = 50 * MB;
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
@ -32,13 +32,13 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
std::cout << "Sending to: " << hostname << ":" << port << "\n";
|
std::cout << "Sending to: " << hostname << ":" << port << "\n";
|
||||||
|
|
||||||
auto data = sls::make_unique<char[]>(DATA_SIZE);
|
auto data = sls::make_unique<char[]>(sls::DATA_SIZE);
|
||||||
|
|
||||||
// Many connections sending small amounts
|
// Many connections sending small amounts
|
||||||
for (int i = 0; i != 100; ++i) {
|
for (int i = 0; i != 100; ++i) {
|
||||||
std::cout << "Sending: " << i << "\n";
|
std::cout << "Sending: " << i << "\n";
|
||||||
auto socket = sls::ClientSocket("test", hostname, port);
|
auto socket = sls::ClientSocket("test", hostname, port);
|
||||||
std::cout << "Sent: " << socket.Send(func_id::read_int) << " bytes\n";
|
std::cout << "Sent: " << socket.Send(sls::func_id::read_int) << " bytes\n";
|
||||||
std::cout << "Sent: " << socket.Send(i) << " bytes\n";
|
std::cout << "Sent: " << socket.Send(i) << " bytes\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,24 +46,24 @@ int main(int argc, char **argv) {
|
|||||||
for (int i = 0; i != 5; ++i) {
|
for (int i = 0; i != 5; ++i) {
|
||||||
std::cout << "Sending data\n";
|
std::cout << "Sending data\n";
|
||||||
auto socket = sls::ClientSocket("test", hostname, port);
|
auto socket = sls::ClientSocket("test", hostname, port);
|
||||||
std::cout << "Sent: " << socket.Send(func_id::read_data) << " bytes\n";
|
std::cout << "Sent: " << socket.Send(sls::func_id::read_data) << " bytes\n";
|
||||||
std::cout << "Sent: " << socket.Send(data.get(), DATA_SIZE)
|
std::cout << "Sent: " << socket.Send(data.get(), sls::DATA_SIZE)
|
||||||
<< " bytes\n";
|
<< " bytes\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send too little data
|
// Send too little data
|
||||||
{
|
{
|
||||||
auto socket = sls::ClientSocket("test", hostname, port);
|
auto socket = sls::ClientSocket("test", hostname, port);
|
||||||
std::cout << "Sent: " << socket.Send(func_id::read_data) << " bytes\n";
|
std::cout << "Sent: " << socket.Send(sls::func_id::read_data) << " bytes\n";
|
||||||
std::cout << "Sent: " << socket.Send(data.get(), DATA_SIZE / 2)
|
std::cout << "Sent: " << socket.Send(data.get(), sls::DATA_SIZE / 2)
|
||||||
<< " bytes\n";
|
<< " bytes\n";
|
||||||
}
|
}
|
||||||
// Send too much data
|
// Send too much data
|
||||||
try {
|
try {
|
||||||
auto socket = sls::ClientSocket("test", hostname, port);
|
auto socket = sls::ClientSocket("test", hostname, port);
|
||||||
std::cout << "Sent: " << socket.Send(func_id::read_half_data)
|
std::cout << "Sent: " << socket.Send(sls::func_id::read_half_data)
|
||||||
<< " bytes\n";
|
<< " bytes\n";
|
||||||
std::cout << "Sent: " << socket.Send(data.get(), DATA_SIZE)
|
std::cout << "Sent: " << socket.Send(data.get(), sls::DATA_SIZE)
|
||||||
<< " bytes\n";
|
<< " bytes\n";
|
||||||
} catch (const sls::SocketError &e) {
|
} catch (const sls::SocketError &e) {
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ int main(int argc, char **argv) {
|
|||||||
for (int i = 0; i != 10; ++i) {
|
for (int i = 0; i != 10; ++i) {
|
||||||
std::cout << "Sending: " << i << "\n";
|
std::cout << "Sending: " << i << "\n";
|
||||||
auto socket = sls::ClientSocket("test", hostname, port);
|
auto socket = sls::ClientSocket("test", hostname, port);
|
||||||
std::cout << "Sent: " << socket.Send(func_id::read_int) << " bytes\n";
|
std::cout << "Sent: " << socket.Send(sls::func_id::read_int) << " bytes\n";
|
||||||
std::cout << "Sent: " << socket.Send(i) << " bytes\n";
|
std::cout << "Sent: " << socket.Send(i) << " bytes\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ int main(int argc, char **argv) {
|
|||||||
double b = 18.3;
|
double b = 18.3;
|
||||||
float c = -1.2;
|
float c = -1.2;
|
||||||
auto socket = sls::ClientSocket("test", hostname, port);
|
auto socket = sls::ClientSocket("test", hostname, port);
|
||||||
int s = socket.SendAll(func_id::combined, a, b, c);
|
int s = socket.SendAll(sls::func_id::combined, a, b, c);
|
||||||
std::cout << "send all: " << s << "\n";
|
std::cout << "send all: " << s << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
// For hashing of enum with C++11, not needed in 14
|
// For hashing of enum with C++11, not needed in 14
|
||||||
struct EnumClassHash {
|
struct EnumClassHash {
|
||||||
template <typename T> std::size_t operator()(T t) const {
|
template <typename T> std::size_t operator()(T t) const {
|
||||||
@ -25,14 +27,14 @@ using func_ptr = void (*)(Interface &);
|
|||||||
********************************************/
|
********************************************/
|
||||||
|
|
||||||
void read_data(Interface &socket) {
|
void read_data(Interface &socket) {
|
||||||
auto data = sls::make_unique<char[]>(DATA_SIZE);
|
auto data = sls::make_unique<char[]>(sls::DATA_SIZE);
|
||||||
std::cout << "Read: " << socket.Receive(data.get(), DATA_SIZE)
|
std::cout << "Read: " << socket.Receive(data.get(), sls::DATA_SIZE)
|
||||||
<< " bytes into buffer\n";
|
<< " bytes into buffer\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_half_data(Interface &socket) {
|
void read_half_data(Interface &socket) {
|
||||||
auto data = sls::make_unique<char[]>(DATA_SIZE);
|
auto data = sls::make_unique<char[]>(sls::DATA_SIZE);
|
||||||
std::cout << "Read: " << socket.Receive(data.get(), DATA_SIZE / 2)
|
std::cout << "Read: " << socket.Receive(data.get(), sls::DATA_SIZE / 2)
|
||||||
<< " bytes into buffer\n";
|
<< " bytes into buffer\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,11 +51,13 @@ void read_combined(Interface &socket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Map from int to function pointer, in this case probably a map would be faster
|
// Map from int to function pointer, in this case probably a map would be faster
|
||||||
std::unordered_map<func_id, func_ptr, EnumClassHash> fmap{
|
std::unordered_map<sls::func_id, func_ptr, EnumClassHash> fmap{
|
||||||
{func_id::read_data, &read_data},
|
{sls::func_id::read_data, &read_data},
|
||||||
{func_id::read_int, &read_int},
|
{sls::func_id::read_int, &read_int},
|
||||||
{func_id::read_half_data, &read_half_data},
|
{sls::func_id::read_half_data, &read_half_data},
|
||||||
{func_id::combined, &read_combined}};
|
{sls::func_id::combined, &read_combined}};
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
std::cout << "Starting test server...\n";
|
std::cout << "Starting test server...\n";
|
||||||
@ -73,9 +77,9 @@ int main(int argc, char **argv) {
|
|||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
auto socket = server.accept();
|
auto socket = server.accept();
|
||||||
auto fnum = socket.Receive<func_id>();
|
auto fnum = socket.Receive<sls::func_id>();
|
||||||
std::cout << "Calling func: " << (int)fnum << "\n";
|
std::cout << "Calling func: " << (int)fnum << "\n";
|
||||||
(*fmap[fnum])(socket); // call mapped function
|
(*sls::fmap[fnum])(socket); // call mapped function
|
||||||
|
|
||||||
} catch (const sls::RuntimeError &e) {
|
} catch (const sls::RuntimeError &e) {
|
||||||
// Do nothing, error is printed when the exeption is created
|
// Do nothing, error is printed when the exeption is created
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "tests/config.h"
|
#include "tests/config.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
// using namespace Catch::clara;
|
// using namespace Catch::clara;
|
||||||
using Opt = Catch::clara::Opt;
|
using Opt = Catch::clara::Opt;
|
||||||
using dt = slsDetectorDefs::detectorType;
|
using dt = slsDetectorDefs::detectorType;
|
||||||
@ -23,18 +24,19 @@ dt type;
|
|||||||
auto GET = slsDetectorDefs::GET_ACTION;
|
auto GET = slsDetectorDefs::GET_ACTION;
|
||||||
auto PUT = slsDetectorDefs::PUT_ACTION;
|
auto PUT = slsDetectorDefs::PUT_ACTION;
|
||||||
} // namespace test
|
} // namespace test
|
||||||
|
} // namespace sls
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
test::my_ip = "undefined";
|
sls::test::my_ip = "undefined";
|
||||||
|
|
||||||
Catch::Session session;
|
Catch::Session session;
|
||||||
auto cli =
|
auto cli =
|
||||||
session.cli() |
|
session.cli() |
|
||||||
Opt(test::hostname, "hostname")["-hn"]["--hostname"](
|
sls::Opt(sls::test::hostname, "hostname")["-hn"]["--hostname"](
|
||||||
"Detector hostname for integration tests") |
|
"Detector hostname for integration tests") |
|
||||||
Opt(test::detector_type, "detector_type")["-dt"]["--detector_type"](
|
sls::Opt(sls::test::detector_type, "detector_type")["-dt"]["--detector_type"](
|
||||||
"Detector type for integration tests") |
|
"Detector type for integration tests") |
|
||||||
Opt(test::my_ip, "my_ip")["-hip"]["--host_ip"]("Host ip address");
|
sls::Opt(sls::test::my_ip, "my_ip")["-hip"]["--host_ip"]("Host ip address");
|
||||||
|
|
||||||
session.cli(cli);
|
session.cli(cli);
|
||||||
|
|
||||||
@ -43,10 +45,10 @@ int main(int argc, char *argv[]) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
test::type = slsDetectorDefs::GENERIC;
|
sls::test::type = slsDetectorDefs::GENERIC;
|
||||||
if (!test::detector_type.empty()) {
|
if (!sls::test::detector_type.empty()) {
|
||||||
test::type =
|
sls::test::type =
|
||||||
sls::StringTo<slsDetectorDefs::detectorType>(test::detector_type);
|
sls::StringTo<slsDetectorDefs::detectorType>(sls::test::detector_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
return session.run();
|
return session.run();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user