tests add to namespace sls (#464)

This commit is contained in:
Dhanya Thattil 2022-05-20 15:41:37 +02:00 committed by GitHub
parent c7ba79644a
commit f5745fcf18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
44 changed files with 350 additions and 228 deletions

View File

@ -6,6 +6,8 @@
#include "tests/globals.h"
#include <iostream>
namespace sls {
class MultiDetectorFixture {
protected:
DetectorImpl d;
@ -136,7 +138,7 @@ TEST_CASE_METHOD(MultiDetectorFixture, "Get ID", "[.eigerintegration][cli]") {
std::string hn = test::hostname;
hn.erase(std::remove(begin(hn), end(hn), 'b'), end(hn));
hn.erase(std::remove(begin(hn), end(hn), 'e'), end(hn));
auto hostnames = sls::split(hn, '+');
auto hostnames = split(hn, '+');
CHECK(hostnames.size() == d.getNumberOfDetectors());
for (int i = 0; i != d.getNumberOfDetectors(); ++i) {
CHECK(d.getId(defs::DETECTOR_SERIAL_NUMBER, 0) ==
@ -198,3 +200,5 @@ TEST_CASE_METHOD(MultiDetectorFixture, "rate correction",
d.setRateCorrection(200);
CHECK(d.getRateCorrection() == 200);
}
} // namespace sls

View File

@ -24,6 +24,8 @@
// extern std::string detector_type;
// extern dt type;
namespace sls {
TEST_CASE("Single detector no receiver", "[.integration][.single]") {
auto t = Module::getTypeFromDetector(test::hostname);
CHECK(t == test::type);
@ -283,14 +285,14 @@ TEST_CASE(
CHECK(m.getRateCorrection() == ratecorr);
// 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);
m.setDynamicRange(16);
m.setDynamicRange(16);
m.setRateCorrection(ratecorr);
m.setDynamicRange(16);
m.setRateCorrection(ratecorr);
CHECK_THROWS_AS(m.setDynamicRange(4), sls::RuntimeError);
CHECK_THROWS_AS(m.setDynamicRange(4), RuntimeError);
CHECK(m.getRateCorrection() == 0);
}
@ -329,11 +331,11 @@ TEST_CASE("Chiptestboard Loading Patterns", "[.ctbintegration]") {
m.setPatternWord(addr, word);
CHECK(m.setPatternWord(addr, -1) == word);
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),
Catch::Matchers::Contains("be between 0 and"));
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),
Catch::Matchers::Contains("be between 0 and"));
@ -408,7 +410,7 @@ TEST_CASE("Chiptestboard Dbit offset, list, sampling, advinvert",
CHECK(m.getReceiverDbitList().size() == 10);
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),
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.getReceiverCurrentFrameIndex() == val);
CHECK_THROWS_AS(m.setNextFrameNumber(0), sls::RuntimeError);
CHECK_THROWS_AS(m.setNextFrameNumber(0), RuntimeError);
if (m.getDetectorTypeAsString() == "Eiger") {
val = 281474976710655;
@ -511,8 +513,10 @@ TEST_CASE("Eiger partialread", "[.eigerintegration][partialread]") {
m.setDynamicRange(8);
m.setPartialReadout(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_THROWS_AS(m.setPartialReadout(0), sls::RuntimeError);
CHECK_THROWS_AS(m.setPartialReadout(0), RuntimeError);
m.setPartialReadout(256);
}
} // namespace sls

View File

@ -6,10 +6,12 @@
#include "tests/globals.h"
#include <iostream>
namespace sls {
using namespace Catch::literals;
TEST_CASE("Initialize a multi detector", "[.integration][.multi]") {
auto hostnames = sls::split(test::hostname, '+');
auto hostnames = split(test::hostname, '+');
DetectorImpl d(0, true, true);
d.setHostname(test::hostname.c_str());
@ -102,3 +104,6 @@ TEST_CASE("Set and read timers", "[.integration][.multi]") {
d.freeSharedMemory();
}
} // namespace sls

View File

@ -21,4 +21,9 @@ target_sources(tests PRIVATE
${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}
)

View File

@ -9,8 +9,9 @@
// help for all docs
// command for all depreciated commands
namespace sls {
using vs = std::vector<std::string>;
using sls::CmdParser;
SCENARIO("Construction", "[support]") {
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.command() == "exptime");
}
} // namespace sls

View File

@ -12,8 +12,8 @@
#include "test-CmdProxy-global.h"
#include "tests/globals.h"
using sls::CmdProxy;
using sls::Detector;
namespace sls {
using test::GET;
using test::PUT;
@ -141,7 +141,7 @@ TEST_CASE("samples", "[.cmd]") {
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH) {
auto prev_asamples = det.getNumberOfAnalogSamples();
sls::Result<int> prev_dsamples = 0;
Result<int> prev_dsamples = 0;
if (det_type == defs::CHIPTESTBOARD) {
prev_dsamples = det.getNumberOfDigitalSamples();
}
@ -866,3 +866,5 @@ TEST_CASE("led", "[.cmd]") {
REQUIRE_THROWS(proxy.Call("led", {}, -1, GET));
}
}
} // namespace sls

View File

@ -12,8 +12,8 @@
#include "test-CmdProxy-global.h"
#include "tests/globals.h"
using sls::CmdProxy;
using sls::Detector;
namespace sls {
using test::GET;
using test::PUT;
@ -658,3 +658,5 @@ TEST_CASE("top", "[.cmd]") {
REQUIRE_THROWS(proxy.Call("top", {"1"}, -1, PUT));
}
}
} // namespace sls

View File

@ -6,8 +6,8 @@
#include "sls/Detector.h"
#include "tests/globals.h"
using sls::CmdProxy;
using sls::Detector;
namespace sls {
using test::GET;
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
auto prev_val = det.getOnChipDAC(index, chipIndex);
auto dacValueStr = sls::ToStringHex(dacvalue);
auto dacValueStr = ToStringHex(dacvalue);
auto chipIndexStr = std::to_string(chipIndex);
std::ostringstream oss_set, oss_get;
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});
}
}
} // namespace sls

View File

@ -3,7 +3,12 @@
#pragma once
#include "sls/sls_detector_defs.h"
namespace sls {
void test_dac(slsDetectorDefs::dacIndex index, const std::string &dacname,
int dacvalue);
void test_onchip_dac(slsDetectorDefs::dacIndex index,
const std::string &dacname, int dacvalue);
} // namespace sls

View File

@ -12,8 +12,8 @@
#include "test-CmdProxy-global.h"
#include "tests/globals.h"
using sls::CmdProxy;
using sls::Detector;
namespace sls {
using test::GET;
using test::PUT;
@ -155,3 +155,5 @@ TEST_CASE("exptimel", "[.cmd]") {
REQUIRE_THROWS(proxy.Call("exptimel", {}, -1, GET));
}
}
} // namespace sls

View File

@ -12,8 +12,8 @@
#include "test-CmdProxy-global.h"
#include "tests/globals.h"
using sls::CmdProxy;
using sls::Detector;
namespace sls {
using test::GET;
using test::PUT;
@ -467,7 +467,7 @@ TEST_CASE("burstmode", "[.cmd]") {
if (det_type == defs::GOTTHARD2) {
auto burst = det.getBurstMode();
auto burststr = sls::ToString(burst);
auto burststr = ToString(burst);
{
std::ostringstream oss;
proxy.Call("burstmode", {"burst_internal"}, -1, PUT, oss);
@ -744,3 +744,5 @@ TEST_CASE("badchannels", "[.cmd]") {
REQUIRE_THROWS(proxy.Call("badchannels", {}, -1, GET));
}
}
} // namespace sls

View File

@ -10,8 +10,8 @@
#include "test-CmdProxy-global.h"
#include "tests/globals.h"
using sls::CmdProxy;
using sls::Detector;
namespace sls {
using test::GET;
using test::PUT;
@ -538,3 +538,5 @@ TEST_CASE("filtercells", "[.cmd]") {
REQUIRE_THROWS(proxy.Call("filtercells", {"0"}, -1, PUT));
}
}
} // namespace sls

View File

@ -12,8 +12,8 @@
#include "test-CmdProxy-global.h"
#include "tests/globals.h"
using sls::CmdProxy;
using sls::Detector;
namespace sls {
using test::GET;
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));
}
}
} // namespace sls

View File

@ -12,8 +12,8 @@
#include "test-CmdProxy-global.h"
#include "tests/globals.h"
using sls::CmdProxy;
using sls::Detector;
namespace sls {
using test::GET;
using test::PUT;
@ -216,9 +216,9 @@ TEST_CASE("counters", "[.cmd]") {
REQUIRE(oss_set2.str() == "counters [0, 2]\n");
// put back old value
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);
REQUIRE(oss_get.str() == "counters " + sls::ToString(list_str) + "\n");
REQUIRE(oss_get.str() == "counters " + ToString(list_str) + "\n");
} else {
REQUIRE_THROWS(proxy.Call("counters", {}, -1, GET));
}
@ -349,7 +349,7 @@ TEST_CASE("gatedelay", "[.cmd]") {
auto prev_val = det.getExptimeForAllGates().tsquash(
"inconsistent gatedelay to test");
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;
@ -611,3 +611,5 @@ TEST_CASE("dpulse", "[.cmd]") {
REQUIRE_THROWS(proxy.Call("dpulse", {}, -1, GET));
}
}
} // namespace sls

View File

@ -12,8 +12,8 @@
#include "test-CmdProxy-global.h"
#include "tests/globals.h"
using sls::CmdProxy;
using sls::Detector;
namespace sls {
using test::GET;
using test::PUT;
@ -99,7 +99,7 @@ TEST_CASE("patword", "[.cmd]") {
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH ||
det_type == defs::MYTHEN3) {
int addr = 0x23;
std::string saddr = sls::ToStringHex(addr, 4);
std::string saddr = ToStringHex(addr, 4);
auto prev_val = det.getPatternWord(addr);
{
std::ostringstream oss;
@ -529,3 +529,5 @@ TEST_CASE("patternstart", "[.cmd]") {
REQUIRE_THROWS(proxy.Call("patternstart", {}, -1, PUT));
}
}
} // namespace sls

View File

@ -9,8 +9,8 @@
#include "sls/versionAPI.h"
#include "tests/globals.h"
using sls::CmdProxy;
using sls::Detector;
namespace sls {
using test::GET;
using test::PUT;
@ -449,7 +449,7 @@ TEST_CASE("rx_roi", "[.cmd]") {
REQUIRE_THROWS(proxy.Call("rx_roi", {"5", "10"}, -1, PUT));
} else {
auto prev_val = det.getRxROI();
defs::xy detsize = det.getDetectrSize();
defs::xy detsize = det.getDetectorSize();
// 1d
if (det_type == defs::GOTTHARD || det_type == defs::GOTTHARD2 ||
@ -991,3 +991,5 @@ TEST_CASE("rx_jsonpara", "[.cmd][.rx]") {
}
/* Insignificant */
} // namespace sls

View File

@ -11,8 +11,8 @@
#include "tests/globals.h"
using sls::CmdProxy;
using sls::Detector;
namespace sls {
using test::GET;
using test::PUT;
@ -152,7 +152,7 @@ TEST_CASE("type", "[.cmd]") {
std::ostringstream oss;
proxy.Call("type", {}, -1, GET, oss);
auto ans = oss.str().erase(0, strlen("type "));
REQUIRE(ans == sls::ToString(dt) + '\n');
REQUIRE(ans == ToString(dt) + '\n');
// REQUIRE(dt == test::type);
}
@ -339,7 +339,7 @@ TEST_CASE("threshold", "[.cmd]") {
for (int i = 0; i != det.size(); ++i) {
if (prev_threshold[i][0] >= 0) {
std::cout
<< "prev cvalues:" << sls::ToString(prev_threshold[i])
<< "prev cvalues:" << ToString(prev_threshold[i])
<< std::endl;
det.setThresholdEnergy(prev_threshold[i], prev_settings,
true, {i});
@ -684,7 +684,7 @@ TEST_CASE("exptime", "[.cmd][.time]") {
auto t =
det.getExptimeForAllGates().tsquash("inconsistent exptime to test");
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];
}
@ -1867,7 +1867,7 @@ TEST_CASE("defaultdac", "[.cmd]") {
if (it == defs::VTHRESHOLD) {
continue;
}
auto dacname = sls::ToString(it);
auto dacname = ToString(it);
auto prev_val = det.getDefaultDac(it);
{
std::ostringstream oss;
@ -1889,7 +1889,7 @@ TEST_CASE("defaultdac", "[.cmd]") {
std::vector<defs::dacIndex> daclist = {
defs::VREF_PRECH, defs::VREF_DS, defs::VREF_COMP};
for (auto it : daclist) {
auto dacname = sls::ToString(it);
auto dacname = ToString(it);
auto prev_val = det.getDefaultDac(it, defs::GAIN0);
{
std::ostringstream oss;
@ -2044,7 +2044,7 @@ TEST_CASE("start", "[.cmd]") {
auto t =
det.getExptimeForAllGates().tsquash("inconsistent exptime to test");
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];
}
@ -2083,7 +2083,7 @@ TEST_CASE("stop", "[.cmd]") {
auto t =
det.getExptimeForAllGates().tsquash("inconsistent exptime to test");
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];
}
@ -2126,7 +2126,7 @@ TEST_CASE("status", "[.cmd]") {
auto t =
det.getExptimeForAllGates().tsquash("inconsistent exptime to test");
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];
}
@ -2265,29 +2265,29 @@ TEST_CASE("scan", "[.cmd]") {
{
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);
CHECK(oss.str() ==
"scan [" + sls::ToString(ind) + ", 500, 1500, 500]\n");
"scan [" + ToString(ind) + ", 500, 1500, 500]\n");
}
{
std::ostringstream 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 "
"500\nsettleTime 1ms\n]\n");
}
{
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);
CHECK(oss.str() ==
"scan [" + sls::ToString(ind) + ", 500, 1500, 500, 2s]\n");
"scan [" + ToString(ind) + ", 500, 1500, 500, 2s]\n");
}
{
std::ostringstream 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 "
"500\nsettleTime 2s\n]\n");
}
@ -2303,17 +2303,17 @@ TEST_CASE("scan", "[.cmd]") {
}
{
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);
CHECK(oss.str() ==
"scan [" + sls::ToString(ind) + ", 1500, 500, -500]\n");
"scan [" + ToString(ind) + ", 1500, 500, -500]\n");
}
CHECK_THROWS(proxy.Call(
"scan", {sls::ToString(notImplementedInd), "500", "1500", "500"}, -1,
"scan", {ToString(notImplementedInd), "500", "1500", "500"}, -1,
PUT));
CHECK_THROWS(proxy.Call("scan", {sls::ToString(ind), "500", "1500", "-500"},
CHECK_THROWS(proxy.Call("scan", {ToString(ind), "500", "1500", "-500"},
-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));
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");
}
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});
}
} else {
@ -2846,7 +2846,7 @@ TEST_CASE("reg", "[.cmd]") {
auto det_type = det.getDetectorType().squash();
if (det_type != defs::EIGER) {
uint32_t addr = 0x64;
std::string saddr = sls::ToStringHex(addr);
std::string saddr = ToStringHex(addr);
auto prev_val = det.readRegister(addr);
{
std::ostringstream oss1, oss2;
@ -2889,7 +2889,7 @@ TEST_CASE("setbit", "[.cmd]") {
auto det_type = det.getDetectorType().squash();
if (det_type != defs::EIGER) {
uint32_t addr = 0x64;
std::string saddr = sls::ToStringHex(addr);
std::string saddr = ToStringHex(addr);
auto prev_val = det.readRegister(addr);
{
std::ostringstream oss1, oss2;
@ -2911,7 +2911,7 @@ TEST_CASE("clearbit", "[.cmd]") {
auto det_type = det.getDetectorType().squash();
if (det_type != defs::EIGER) {
uint32_t addr = 0x64;
std::string saddr = sls::ToStringHex(addr);
std::string saddr = ToStringHex(addr);
auto prev_val = det.readRegister(addr);
{
std::ostringstream oss1, oss2;
@ -2933,7 +2933,7 @@ TEST_CASE("getbit", "[.cmd]") {
auto det_type = det.getDetectorType().squash();
if (det_type != defs::EIGER) {
uint32_t addr = 0x64;
std::string saddr = sls::ToStringHex(addr);
std::string saddr = ToStringHex(addr);
auto prev_val = det.readRegister(addr);
{
std::ostringstream oss1, oss2;
@ -3162,3 +3162,5 @@ TEST_CASE("user", "[.cmd]") {
REQUIRE_THROWS(proxy.Call("user", {}, -1, PUT));
REQUIRE_NOTHROW(proxy.Call("user", {}, -1, GET));
}
} // namespace sls

View File

@ -5,9 +5,9 @@
#include "SharedMemory.h"
#include "CtbConfig.h"
using namespace sls;
#include <fstream>
namespace sls {
TEST_CASE("Default construction"){
static_assert(sizeof(CtbConfig) == 360); // 18*20
@ -57,3 +57,5 @@ TEST_CASE("Move CtbConfig "){
CtbConfig c2(std::move(c1));
REQUIRE(c2.getDacName(3) == "yetanothername");
}
} // namespace sls

View File

@ -4,19 +4,21 @@
#include "SharedMemory.h"
#include "catch.hpp"
namespace sls {
using dt = slsDetectorDefs::detectorType;
TEST_CASE("Construction with a defined detector type") {
sls::Module m(dt::EIGER);
Module m(dt::EIGER);
REQUIRE(m.getDetectorType() == dt::EIGER);
m.freeSharedMemory(); // clean up
}
TEST_CASE("Read back detector type from 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
sls::Module m2;
Module m2;
REQUIRE(m2.getDetectorType() == dt::JUNGFRAU);
// 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") {
sls::Module m(dt::JUNGFRAU);
Module m(dt::JUNGFRAU);
// Should be true since we just created the shm
REQUIRE(m.isFixedPatternSharedMemoryCompatible() == true);
// Set shm version to 0
sls::SharedMemory<sls::sharedModule> shm(0, 0);
SharedMemory<sharedModule> shm(0, 0);
REQUIRE(shm.exists() == true);
shm.openSharedMemory(true);
shm()->shmversion = 0;
@ -43,19 +45,21 @@ TEST_CASE("Is shm fixed pattern shm compatible") {
}
TEST_CASE("Get default control port") {
sls::Module m(dt::MYTHEN3);
Module m(dt::MYTHEN3);
REQUIRE(m.getControlPort() == 1952);
m.freeSharedMemory();
}
TEST_CASE("Get default stop port") {
sls::Module m(dt::GOTTHARD2);
Module m(dt::GOTTHARD2);
REQUIRE(m.getStopPort() == 1953);
m.freeSharedMemory();
}
TEST_CASE("Get default receiver TCP port") {
sls::Module m(dt::MYTHEN3);
Module m(dt::MYTHEN3);
REQUIRE(m.getReceiverPort() == 1954);
m.freeSharedMemory();
}
} // namespace sls

View File

@ -3,7 +3,7 @@
#include "catch.hpp"
#include "sls/Pattern.h"
using sls::Pattern;
namespace sls {
TEST_CASE("Pattern is default constructable and has zeroed fields") {
Pattern p;
@ -27,3 +27,5 @@ TEST_CASE("Compare patterns") {
p1.data()->word[500] = 1;
REQUIRE_FALSE(p == p1);
}
} // namespace sls

View File

@ -6,10 +6,10 @@
#include "sls/TypeTraits.h"
#include <string>
using sls::Result;
namespace sls {
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") {
@ -195,3 +195,5 @@ TEST_CASE("String conversions") {
REQUIRE(ToString(res4) ==
"[{one: 1}, {one: 1, three: 3, two: 2}, {one: 1}]");
}
} // namespace sls

View File

@ -7,14 +7,14 @@
#include <iostream>
namespace sls {
struct Data {
int x;
double y;
char mess[50];
};
using namespace sls;
constexpr int shm_id = 10;
TEST_CASE("Create SharedMemory read and write", "[detector]") {
@ -26,7 +26,7 @@ TEST_CASE("Create SharedMemory read and write", "[detector]") {
shm()->x = 3;
shm()->y = 5.7;
sls::strcpy_safe(shm()->mess, "Some string");
strcpy_safe(shm()->mess, "Some string");
CHECK(shm()->x == 3);
CHECK(shm()->y == 5.7);
@ -168,8 +168,6 @@ TEST_CASE("map int64 to int32 throws"){
REQUIRE_THROWS(shm2.openSharedMemory(true));
shm.removeSharedMemory();
}
} // namespace sls

View File

@ -238,7 +238,7 @@
// CHECK(d.getReceiverDbitList().size() == 10);
// 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),
// Catch::Matchers::Contains("be between 0 and 63"));

View File

@ -4,7 +4,8 @@
#include "sls/CircularFifo.h"
#include <vector>
using sls::CircularFifo;
namespace sls {
TEST_CASE("Empty buffer") {
CircularFifo<char> fifo(0);
@ -51,3 +52,5 @@ TEST_CASE("Push pop") {
CHECK(fifo.isEmpty() == true);
CHECK(fifo.isFull() == false);
}
} // namespace sls

View File

@ -8,9 +8,11 @@
#include <iostream>
#include <thread>
namespace sls {
std::vector<char> server() {
std::cout << "starting server\n";
auto server = sls::ServerSocket(1950);
auto server = ServerSocket(1950);
auto s = server.accept();
std::vector<char> buffer(100, '\0');
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);
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.Receive(received_message.data(), received_message.size());
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]") {
CHECK_THROWS(sls::DetectorSocket("localhost", 1950));
CHECK_THROWS(DetectorSocket("localhost", 1950));
}
} // namespace sls

View File

@ -7,10 +7,11 @@
#include <array>
#include <sstream>
#include <vector>
using sls::StaticVector;
namespace sls {
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") {
@ -317,15 +318,15 @@ SCENARIO("Converting to vector", "[support]") {
}
}
TEST_CASE("sls::StaticVector") {
sls::StaticVector<int, 5> vec;
TEST_CASE("StaticVector") {
StaticVector<int, 5> vec;
vec.push_back(3);
vec.push_back(8);
REQUIRE(sls::ToString(vec) == "[3, 8]");
REQUIRE(ToString(vec) == "[3, 8]");
}
TEST_CASE("sls::StaticVector stream") {
sls::StaticVector<int, 5> vec;
TEST_CASE("StaticVector stream") {
StaticVector<int, 5> vec;
vec.push_back(33);
vec.push_back(85667);
vec.push_back(2);
@ -333,3 +334,5 @@ TEST_CASE("sls::StaticVector stream") {
oss << vec;
REQUIRE(oss.str() == "[33, 85667, 2]");
}
} // namespace sls

View File

@ -6,9 +6,11 @@
#include <chrono>
#include <thread>
namespace sls {
TEST_CASE("Time 1s restart then time 2s", "[.timer]") {
auto sleep_duration = std::chrono::seconds(1);
auto t = sls::Timer();
auto t = Timer();
std::this_thread::sleep_for(sleep_duration);
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]") {
auto sleep_duration = std::chrono::milliseconds(1300);
auto t = sls::Timer();
auto t = Timer();
std::this_thread::sleep_for(sleep_duration);
REQUIRE(t.elapsed_ms() == Approx(1300).epsilon(0.5));
}
} // namespace sls

View File

@ -12,11 +12,8 @@
#include <sstream>
#include <vector>
// using namespace sls;
using sls::defs;
using sls::StringTo;
using sls::ToString;
using sls::ToStringHex;
namespace sls {
using namespace sls::time;
TEST_CASE("Integer conversions", "[support]") {
@ -91,9 +88,9 @@ TEST_CASE("Array") {
}
TEST_CASE("Convert types with str method") {
sls::IpAddr addr;
IpAddr addr;
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]") {
@ -325,39 +322,41 @@ TEST_CASE("Printing c style arrays of double") {
}
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[1] = 100;
REQUIRE(ToString(pat->limits) == "[4, 100]");
}
TEST_CASE("streamingInterface") {
REQUIRE(ToString(sls::defs::streamingInterface::NONE) == "none");
REQUIRE(ToString(sls::defs::streamingInterface::ETHERNET_10GB) == "10gbe");
REQUIRE(ToString(sls::defs::streamingInterface::LOW_LATENCY_LINK) == "lll");
REQUIRE(ToString(sls::defs::streamingInterface::LOW_LATENCY_LINK |
sls::defs::streamingInterface::ETHERNET_10GB) ==
REQUIRE(ToString(defs::streamingInterface::NONE) == "none");
REQUIRE(ToString(defs::streamingInterface::ETHERNET_10GB) == "10gbe");
REQUIRE(ToString(defs::streamingInterface::LOW_LATENCY_LINK) == "lll");
REQUIRE(ToString(defs::streamingInterface::LOW_LATENCY_LINK |
defs::streamingInterface::ETHERNET_10GB) ==
"lll, 10gbe");
}
// Speed level
TEST_CASE("speedLevel to string") {
REQUIRE(ToString(sls::defs::speedLevel::FULL_SPEED) == "full_speed");
REQUIRE(ToString(sls::defs::speedLevel::HALF_SPEED) == "half_speed");
REQUIRE(ToString(sls::defs::speedLevel::QUARTER_SPEED) == "quarter_speed");
REQUIRE(ToString(sls::defs::speedLevel::G2_108MHZ) == "108");
REQUIRE(ToString(sls::defs::speedLevel::G2_144MHZ) == "144");
REQUIRE(ToString(defs::speedLevel::FULL_SPEED) == "full_speed");
REQUIRE(ToString(defs::speedLevel::HALF_SPEED) == "half_speed");
REQUIRE(ToString(defs::speedLevel::QUARTER_SPEED) == "quarter_speed");
REQUIRE(ToString(defs::speedLevel::G2_108MHZ) == "108");
REQUIRE(ToString(defs::speedLevel::G2_144MHZ) == "144");
}
TEST_CASE("string to speedLevel") {
REQUIRE(StringTo<sls::defs::speedLevel>("full_speed") ==
sls::defs::speedLevel::FULL_SPEED);
REQUIRE(StringTo<sls::defs::speedLevel>("half_speed") ==
sls::defs::speedLevel::HALF_SPEED);
REQUIRE(StringTo<sls::defs::speedLevel>("quarter_speed") ==
sls::defs::speedLevel::QUARTER_SPEED);
REQUIRE(StringTo<sls::defs::speedLevel>("108") ==
sls::defs::speedLevel::G2_108MHZ);
REQUIRE(StringTo<sls::defs::speedLevel>("144") ==
sls::defs::speedLevel::G2_144MHZ);
REQUIRE(StringTo<defs::speedLevel>("full_speed") ==
defs::speedLevel::FULL_SPEED);
REQUIRE(StringTo<defs::speedLevel>("half_speed") ==
defs::speedLevel::HALF_SPEED);
REQUIRE(StringTo<defs::speedLevel>("quarter_speed") ==
defs::speedLevel::QUARTER_SPEED);
REQUIRE(StringTo<defs::speedLevel>("108") ==
defs::speedLevel::G2_108MHZ);
REQUIRE(StringTo<defs::speedLevel>("144") ==
defs::speedLevel::G2_144MHZ);
}
} // namespace sls

View File

@ -8,6 +8,8 @@
#include <sstream>
#include <vector>
namespace sls {
// Dummy classes only used here for testing
class DummyWithStr {
public:
@ -19,35 +21,37 @@ class DummyNoStr {
std::string somethingelse();
};
TEST_CASE("sls::is_container") {
TEST_CASE("is_container") {
CHECK(sls::is_container<std::vector<int>>::value == true);
CHECK(sls::is_container<std::array<double, 3>>::value == true);
CHECK(is_container<std::vector<int>>::value == true);
CHECK(is_container<std::array<double, 3>>::value == true);
}
TEST_CASE("Check for str() method") {
REQUIRE(sls::has_str<DummyWithStr>::value == true);
REQUIRE(sls::has_str<DummyNoStr>::value == false);
REQUIRE(has_str<DummyWithStr>::value == true);
REQUIRE(has_str<DummyNoStr>::value == false);
}
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") {
REQUIRE(sls::is_duration<std::chrono::nanoseconds>::value == true);
REQUIRE(sls::is_duration<std::chrono::seconds>::value == true);
REQUIRE(sls::is_duration<std::chrono::hours>::value == true);
TEST_CASE("is_duration") {
REQUIRE(is_duration<std::chrono::nanoseconds>::value == true);
REQUIRE(is_duration<std::chrono::seconds>::value == true);
REQUIRE(is_duration<std::chrono::hours>::value == true);
REQUIRE(sls::is_duration<int>::value == false);
REQUIRE(sls::is_duration<std::vector<int>>::value == false);
REQUIRE(is_duration<int>::value == false);
REQUIRE(is_duration<std::vector<int>>::value == false);
}
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") {
// 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

View File

@ -15,6 +15,8 @@
#include <unistd.h>
#include <vector>
namespace sls {
constexpr int default_port = 50001;
int open_socket(int port) {
@ -31,16 +33,16 @@ int open_socket(int port) {
const std::string portname = std::to_string(port);
if (getaddrinfo(host, portname.c_str(), &hints, &res)) {
throw sls::RuntimeError("Failed at getaddrinfo with " +
throw RuntimeError("Failed at getaddrinfo with " +
std::string(host));
}
int fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
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)) {
throw sls::RuntimeError("Failed to connect socket");
throw RuntimeError("Failed to connect socket");
}
freeaddrinfo(res);
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") {
constexpr int port = 50001;
constexpr ssize_t packet_size = 8000;
sls::UdpRxSocket s{port, packet_size};
UdpRxSocket s{port, packet_size};
CHECK(s.getPacketSize() == packet_size);
}
@ -60,7 +62,7 @@ TEST_CASE("Receive data from a vector") {
ssize_t packet_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);
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") {
constexpr int port = 50001;
constexpr ssize_t packet_size = 8000;
sls::UdpRxSocket s{port, packet_size};
UdpRxSocket s{port, packet_size};
char buff[packet_size];
// Start a thread and wait for package
// if the socket is left open we would block
std::future<bool> ret =
std::async(&sls::UdpRxSocket::ReceivePacket, &s, (char *)&buff);
std::async(&UdpRxSocket::ReceivePacket, &s, (char *)&buff);
s.Shutdown();
auto r = ret.get();
@ -90,7 +92,7 @@ TEST_CASE("Shutdown socket without hanging when waiting for data") {
TEST_CASE("Too small packet") {
constexpr int port = 50001;
sls::UdpRxSocket s(port, 2 * sizeof(uint32_t));
UdpRxSocket s(port, 2 * sizeof(uint32_t));
auto fd = open_socket(port);
uint32_t val = 10;
write(fd, &val, sizeof(val));
@ -103,8 +105,10 @@ TEST_CASE("Receive an int to an external buffer") {
int to_send = 5;
int received = -1;
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));
CHECK(s.ReceivePacket(reinterpret_cast<char *>(&received)));
CHECK(received == to_send);
}
} // namespace sls

View File

@ -3,6 +3,9 @@
#include "catch.hpp"
#include "sls/ZmqSocket.h"
namespace sls {
TEST_CASE("Throws when cannot create socket") {
REQUIRE_THROWS(ZmqSocket("sdiasodjajpvv", 5076001));
}
@ -114,3 +117,5 @@ TEST_CASE("Send header and data") {
REQUIRE(data[i] == received_data[i]);
}
}
} //namespace

View File

@ -4,25 +4,27 @@
#include "sls/bit_utils.h"
#include <vector>
namespace sls {
TEST_CASE("Get set bits from 0") {
auto vec = sls::getSetBits(0);
auto vec = getSetBits(0);
REQUIRE(vec.empty());
}
TEST_CASE("Get set bits from 1") {
auto vec = sls::getSetBits(1);
auto vec = getSetBits(1);
REQUIRE(vec.size() == 1);
REQUIRE(vec[0] == 0);
}
TEST_CASE("Get set bits from 2") {
auto vec = sls::getSetBits(2ul);
auto vec = getSetBits(2ul);
REQUIRE(vec.size() == 1);
REQUIRE(vec[0] == 1);
}
TEST_CASE("Get set bits from 3") {
auto vec = sls::getSetBits(3u);
auto vec = getSetBits(3u);
REQUIRE(vec.size() == 2);
REQUIRE(vec[0] == 0);
REQUIRE(vec[1] == 1);
@ -30,12 +32,14 @@ TEST_CASE("Get set bits from 3") {
TEST_CASE("All bits set") {
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});
}
TEST_CASE("Get set bits from 523") {
// 0b1000001011 == 523
auto vec = sls::getSetBits(523);
auto vec = getSetBits(523);
REQUIRE(vec == std::vector<int>{0, 1, 3, 9});
}
} // namespace sls

View File

@ -6,7 +6,7 @@
#include <string>
#include <vector>
using namespace sls;
namespace sls {
TEST_CASE("Equality of an empty vector", "[support]") {
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]") {
std::vector<float> v;
REQUIRE(sls::sum(v) == Approx(0));
REQUIRE(sum(v) == Approx(0));
}
TEST_CASE("Sum of vector", "[support]") {
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]") {
std::vector<double> v;
REQUIRE(v.empty());
double d = -1;
REQUIRE(sls::minusOneIfDifferent(v) == d);
REQUIRE(minusOneIfDifferent(v) == d);
SECTION("single element") {
v.push_back(7.3);
REQUIRE(v.size() == 1);
REQUIRE(sls::minusOneIfDifferent(v) == Approx(7.3));
REQUIRE(minusOneIfDifferent(v) == Approx(7.3));
}
SECTION("different elements") {
v.push_back(7.3);
v.push_back(1.0);
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]") {
std::vector<int> v{1, 1, 1};
int i = sls::minusOneIfDifferent(v);
int i = minusOneIfDifferent(v);
REQUIRE(i == 1);
i = 5;
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}};
CHECK(minusOneIfDifferent(vec1) == arr);
}
} // namespace sls

View File

@ -7,10 +7,12 @@
#include <unistd.h>
#include <vector>
namespace sls {
TEST_CASE("Get size of empty file") {
char fname[] = "temfile_XXXXXX";
std::ifstream ifs(fname);
auto size = sls::getFileSize(ifs);
auto size = getFileSize(ifs);
REQUIRE(size <= 0); // -1 or zero
}
@ -22,7 +24,9 @@ TEST_CASE("Get size of file with data") {
write(fh, data.data(), n_bytes);
std::ifstream ifs(fname);
auto size = sls::getFileSize(ifs);
auto size = getFileSize(ifs);
REQUIRE(size == n_bytes);
REQUIRE(ifs.tellg() == 0); // getting size resets pos!
}
} // namespace sls

View File

@ -6,7 +6,7 @@
#include <fstream>
#include <iostream>
using sls::Logger;
namespace sls {
TEST_CASE("LogLevel to string") {
CHECK(Logger::ToString(logERROR) == "ERROR");
@ -49,3 +49,5 @@ TEST_CASE("Test output") {
auto pos = r.find("This should be printed");
CHECK(pos != std::string::npos);
}
} // namespace sls

View File

@ -10,7 +10,7 @@
#include "sls/sls_detector_exceptions.h"
#include "sls/string_utils.h"
using namespace sls;
namespace sls {
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
} // namespace sls

View File

@ -3,6 +3,8 @@
#include "catch.hpp"
#include "sls/sls_detector_defs.h"
namespace sls {
using dt = slsDetectorDefs::detectorType;
TEST_CASE("sls_detector_module default construction", "[support][new]") {
@ -76,3 +78,5 @@ TEST_CASE("compare two scanParameters") {
p0.enable = 1;
CHECK_FALSE(p0 == p1);
}
} // namespace sls

View File

@ -7,6 +7,8 @@
#include "sls/string_utils.h"
namespace sls {
TEST_CASE("copy a string") {
char src[10] = "hej";
@ -14,7 +16,7 @@ TEST_CASE("copy a string") {
char dst[20];
sls::strcpy_safe(dst, src);
strcpy_safe(dst, src);
REQUIRE(dst[0] == 'h');
REQUIRE(dst[1] == 'e');
REQUIRE(dst[2] == 'j');
@ -26,7 +28,7 @@ TEST_CASE("copy a string") {
TEST_CASE("copy a long string") {
auto src = "some very very long sting that does not fit";
char dst[3];
sls::strcpy_safe(dst, src);
strcpy_safe(dst, src);
REQUIRE(dst[0] == 's');
REQUIRE(dst[1] == 'o');
REQUIRE(dst[2] == '\0');
@ -35,7 +37,7 @@ TEST_CASE("copy a long string") {
TEST_CASE("split a string with end delimiter") {
std::string s("abra+kadabra+");
auto r = sls::split(s, '+');
auto r = split(s, '+');
REQUIRE(r.size() == 2);
REQUIRE(r[0] == "abra");
REQUIRE(r[1] == "kadabra");
@ -43,7 +45,7 @@ TEST_CASE("split a string with end delimiter") {
TEST_CASE("split a string without end delimiter") {
std::string s("abra+kadabra+filibom");
auto r = sls::split(s, '+');
auto r = split(s, '+');
REQUIRE(r.size() == 3);
REQUIRE(r[0] == "abra");
REQUIRE(r[1] == "kadabra");
@ -52,58 +54,60 @@ TEST_CASE("split a string without end delimiter") {
TEST_CASE("Remove char from string") {
char str[] = "sometest";
sls::removeChar(str, 'e');
removeChar(str, 'e');
REQUIRE(std::string(str) == "somtst");
}
TEST_CASE("Remove char from empty string") {
char str[50] = {};
sls::removeChar(str, 'e');
removeChar(str, 'e');
REQUIRE(std::string(str).empty());
}
TEST_CASE("Many characters in a row") {
char str[] = "someeequitellll::ongstring";
sls::removeChar(str, 'l');
removeChar(str, 'l');
REQUIRE(std::string(str) == "someeequite::ongstring");
}
TEST_CASE("Check is string is integer") {
REQUIRE(sls::is_int("75"));
REQUIRE(sls::is_int("11675"));
REQUIRE_FALSE(sls::is_int("7.5"));
REQUIRE_FALSE(sls::is_int("hej"));
REQUIRE_FALSE(sls::is_int("7a"));
REQUIRE_FALSE(sls::is_int(""));
REQUIRE(is_int("75"));
REQUIRE(is_int("11675"));
REQUIRE_FALSE(is_int("7.5"));
REQUIRE_FALSE(is_int("hej"));
REQUIRE_FALSE(is_int("7a"));
REQUIRE_FALSE(is_int(""));
}
TEST_CASE("Replace substring in string") {
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(s == "this should be replaced");
}
TEST_CASE("Replace --help in command") {
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(s == "sls_detector_get exptime");
}
TEST_CASE("Replace -h in command") {
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(s == "sls_detector_get exptime");
}
TEST_CASE("replace --help") {
std::string s = "list --help";
auto r = sls::replace_first(&s, " --help", "");
auto r = replace_first(&s, " --help", "");
REQUIRE(r == true);
REQUIRE(s == "list");
}
// TEST_CASE("concat things not being strings")
} // namespace sls

View File

@ -4,6 +4,8 @@
#include "sls/sls_detector_defs.h"
#include <string>
namespace sls {
struct SingleDetectorConfig {
slsDetectorDefs::detectorType type_enum =
slsDetectorDefs::detectorType::EIGER;
@ -11,3 +13,5 @@ struct SingleDetectorConfig {
const std::string type_string = "Eiger";
const std::string my_ip = "129.129.205.171";
};
} // namespace sls

View File

@ -2,6 +2,9 @@
// Copyright (C) 2021 Contributors to the SLS Detector Package
#pragma once
#include "sls/sls_detector_defs.h"
namespace sls {
using dt = slsDetectorDefs::detectorType;
using di = slsDetectorDefs::dacIndex;
using defs = slsDetectorDefs;
@ -15,3 +18,5 @@ extern decltype(defs::GET_ACTION) GET;
extern decltype(defs::PUT_ACTION) PUT;
} // namespace test
} // namespace sls

View File

@ -2,6 +2,11 @@
// Copyright (C) 2021 Contributors to the SLS Detector Package
#pragma once
#include <cstdint>
namespace sls {
enum class func_id { read_data, read_int, read_half_data, combined };
constexpr size_t MB = 1048576;
constexpr size_t DATA_SIZE = 50 * MB;
} // namespace sls

View File

@ -32,13 +32,13 @@ int main(int argc, char **argv) {
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
for (int i = 0; i != 100; ++i) {
std::cout << "Sending: " << i << "\n";
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";
}
@ -46,24 +46,24 @@ int main(int argc, char **argv) {
for (int i = 0; i != 5; ++i) {
std::cout << "Sending data\n";
auto socket = sls::ClientSocket("test", hostname, port);
std::cout << "Sent: " << socket.Send(func_id::read_data) << " bytes\n";
std::cout << "Sent: " << socket.Send(data.get(), DATA_SIZE)
std::cout << "Sent: " << socket.Send(sls::func_id::read_data) << " bytes\n";
std::cout << "Sent: " << socket.Send(data.get(), sls::DATA_SIZE)
<< " bytes\n";
}
// Send too little data
{
auto socket = sls::ClientSocket("test", hostname, port);
std::cout << "Sent: " << socket.Send(func_id::read_data) << " bytes\n";
std::cout << "Sent: " << socket.Send(data.get(), DATA_SIZE / 2)
std::cout << "Sent: " << socket.Send(sls::func_id::read_data) << " bytes\n";
std::cout << "Sent: " << socket.Send(data.get(), sls::DATA_SIZE / 2)
<< " bytes\n";
}
// Send too much data
try {
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";
std::cout << "Sent: " << socket.Send(data.get(), DATA_SIZE)
std::cout << "Sent: " << socket.Send(data.get(), sls::DATA_SIZE)
<< " bytes\n";
} catch (const sls::SocketError &e) {
}
@ -71,7 +71,7 @@ int main(int argc, char **argv) {
for (int i = 0; i != 10; ++i) {
std::cout << "Sending: " << i << "\n";
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";
}
@ -81,7 +81,7 @@ int main(int argc, char **argv) {
double b = 18.3;
float c = -1.2;
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";
}
}

View File

@ -25,14 +25,14 @@ using func_ptr = void (*)(Interface &);
********************************************/
void read_data(Interface &socket) {
auto data = sls::make_unique<char[]>(DATA_SIZE);
std::cout << "Read: " << socket.Receive(data.get(), DATA_SIZE)
auto data = sls::make_unique<char[]>(sls::DATA_SIZE);
std::cout << "Read: " << socket.Receive(data.get(), sls::DATA_SIZE)
<< " bytes into buffer\n";
}
void read_half_data(Interface &socket) {
auto data = sls::make_unique<char[]>(DATA_SIZE);
std::cout << "Read: " << socket.Receive(data.get(), DATA_SIZE / 2)
auto data = sls::make_unique<char[]>(sls::DATA_SIZE);
std::cout << "Read: " << socket.Receive(data.get(), sls::DATA_SIZE / 2)
<< " bytes into buffer\n";
}
@ -49,11 +49,11 @@ void read_combined(Interface &socket) {
}
// Map from int to function pointer, in this case probably a map would be faster
std::unordered_map<func_id, func_ptr, EnumClassHash> fmap{
{func_id::read_data, &read_data},
{func_id::read_int, &read_int},
{func_id::read_half_data, &read_half_data},
{func_id::combined, &read_combined}};
std::unordered_map<sls::func_id, func_ptr, EnumClassHash> fmap{
{sls::func_id::read_data, &read_data},
{sls::func_id::read_int, &read_int},
{sls::func_id::read_half_data, &read_half_data},
{sls::func_id::combined, &read_combined}};
int main(int argc, char **argv) {
std::cout << "Starting test server...\n";
@ -73,7 +73,7 @@ int main(int argc, char **argv) {
while (true) {
try {
auto socket = server.accept();
auto fnum = socket.Receive<func_id>();
auto fnum = socket.Receive<sls::func_id>();
std::cout << "Calling func: " << (int)fnum << "\n";
(*fmap[fnum])(socket); // call mapped function

View File

@ -11,6 +11,8 @@
#include "tests/config.h"
#include <string>
namespace sls {
// using namespace Catch::clara;
using Opt = Catch::clara::Opt;
using dt = slsDetectorDefs::detectorType;
@ -46,8 +48,10 @@ int main(int argc, char *argv[]) {
test::type = slsDetectorDefs::GENERIC;
if (!test::detector_type.empty()) {
test::type =
sls::StringTo<slsDetectorDefs::detectorType>(test::detector_type);
StringTo<slsDetectorDefs::detectorType>(test::detector_type);
}
return session.run();
}
} // namespace sls