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:
Dhanya Thattil
2022-05-23 16:17:32 +02:00
committed by GitHub
parent 8656eeec25
commit d61741c28b
44 changed files with 360 additions and 236 deletions

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") {
@ -406,4 +407,6 @@ TEST_CASE("Parse a command in the form 0-1:command") {
REQUIRE(p.multi_id() == 3);
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();
}
@ -865,4 +865,6 @@ TEST_CASE("led", "[.cmd]") {
} else {
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;
@ -657,4 +657,6 @@ TEST_CASE("top", "[.cmd]") {
REQUIRE_THROWS(proxy.Call("top", {}, -1, GET));
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);
@ -66,4 +66,6 @@ void test_onchip_dac(defs::dacIndex index, const std::string &dacname,
for (int i = 0; i != det.size(); ++i) {
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;
@ -154,4 +154,6 @@ TEST_CASE("exptimel", "[.cmd]") {
} else {
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);
@ -743,4 +743,6 @@ TEST_CASE("badchannels", "[.cmd]") {
} else {
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;
@ -610,4 +610,6 @@ TEST_CASE("dpulse", "[.cmd]") {
} else {
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;
@ -528,4 +528,6 @@ TEST_CASE("patternstart", "[.cmd]") {
} else {
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
@ -56,4 +56,6 @@ TEST_CASE("Move CtbConfig "){
c1.setDacName(3, "yetanothername");
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"));