mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-10-14 18:10:25 +02:00
Build and Deploy on local RHEL9 / build (push) Successful in 2m0s
Build on RHEL9 docker image / build (push) Successful in 5m5s
Build and Deploy on local RHEL8 / build (push) Successful in 5m9s
Build on RHEL8 docker image / build (push) Successful in 5m29s
Run Simulator Tests on local RHEL9 / build (push) Successful in 20m40s
Run Simulator Tests on local RHEL8 / build (push) Successful in 24m2s
* refactored test_dac_caller * fix for the changes so that dacname works
131 lines
4.5 KiB
C++
131 lines
4.5 KiB
C++
// SPDX-License-Identifier: LGPL-3.0-or-other
|
|
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
|
#include "test-Caller-global.h"
|
|
#include "Caller.h"
|
|
#include "GeneralData.h"
|
|
#include "sls/Detector.h"
|
|
#include "sls/logger.h"
|
|
#include "tests/globals.h"
|
|
|
|
#include "catch.hpp"
|
|
#include <regex>
|
|
|
|
namespace sls {
|
|
int chipVersionToX10(const std::string &chipVersion) {
|
|
static const std::regex versionRegex(R"(v?\s*([0-9]+)\.([0-9]+))",
|
|
std::regex::icase);
|
|
std::smatch match;
|
|
if (!std::regex_search(chipVersion, match, versionRegex)) {
|
|
throw sls::RuntimeError("Could not parse chip version: " + chipVersion);
|
|
}
|
|
return std::stoi(match[1].str()) * 10 + std::stoi(match[2].str());
|
|
}
|
|
|
|
namespace acq = sls::test::acquire;
|
|
|
|
using test::GET;
|
|
using test::PUT;
|
|
void test_valid_port_caller(const std::string &command,
|
|
const std::vector<std::string> &arguments,
|
|
int detector_id, int action) {
|
|
Detector det;
|
|
Caller caller(&det);
|
|
|
|
std::vector<std::string> arg(arguments);
|
|
if (arg.empty())
|
|
arg.push_back("0");
|
|
|
|
int test_values[3] = {77797, -1, 0};
|
|
for (int i = 0; i != 3; ++i) {
|
|
int port_number = test_values[i];
|
|
arg[arg.size() - 1] = std::to_string(port_number);
|
|
REQUIRE_THROWS(caller.call(command, arg, detector_id, action));
|
|
/*REQUIRE_THROWS_WITH(proxy.Call(command, arguments, detector_id,
|
|
action), "Invalid port range. Must be between 1 - 65535.");*/
|
|
}
|
|
}
|
|
|
|
void test_dac(defs::dacIndex index, std::string dacname, int dacvalue,
|
|
bool mV) {
|
|
Detector det;
|
|
Caller caller(&det);
|
|
auto value = std::to_string(dacvalue);
|
|
auto previous = det.getDAC(index, false);
|
|
{
|
|
std::ostringstream oss;
|
|
std::vector<std::string> args = {dacname, value};
|
|
if (mV)
|
|
args.push_back("mV");
|
|
std::cout << "args:" << ToString(args) << std::endl;
|
|
caller.call("dac", args, -1, PUT, oss);
|
|
REQUIRE(oss.str() == std::string("dac ") + dacname + " " + value +
|
|
(mV ? " mV\n" : "\n"));
|
|
}
|
|
{
|
|
std::ostringstream oss;
|
|
std::vector<std::string> args = {dacname};
|
|
if (mV)
|
|
args.push_back("mV");
|
|
caller.call("dac", args, -1, GET, oss);
|
|
{
|
|
std::ostringstream oss_expected;
|
|
oss_expected << "dac " << dacname << " " << value
|
|
<< (mV ? " mV" : "") << '\n';
|
|
REQUIRE(oss.str() == oss_expected.str());
|
|
}
|
|
}
|
|
// Reset all dacs to previous value
|
|
for (int i = 0; i != det.size(); ++i) {
|
|
det.setDAC(index, previous[i], false, {i});
|
|
}
|
|
}
|
|
|
|
void test_dac_caller(defs::dacIndex index, int dacvalue, bool mV) {
|
|
std::string dacname = sls::ToString(index);
|
|
// ctb: use only the index for dacname
|
|
// so that cli output is not 'dac dac 0'
|
|
if (index <= defs::DAC_17) {
|
|
dacname = std::to_string(static_cast<int>(index));
|
|
}
|
|
test_dac(index, dacname, dacvalue, mV);
|
|
}
|
|
|
|
void test_dacname_caller(std::string dacname, int dacvalue, bool mV) {
|
|
Detector det;
|
|
auto detType = det.getDetectorType().squash(defs::GENERIC);
|
|
REQUIRE((detType == defs::CHIPTESTBOARD ||
|
|
detType == defs::XILINX_CHIPTESTBOARD));
|
|
auto index = det.getDacIndex(dacname);
|
|
test_dac(index, dacname, dacvalue, mV);
|
|
}
|
|
|
|
void test_onchip_dac_caller(defs::dacIndex index, const std::string &dacname,
|
|
int dacvalue) {
|
|
Detector det;
|
|
Caller caller(&det);
|
|
REQUIRE_THROWS(caller.call(dacname, {}, -1, GET));
|
|
REQUIRE_THROWS(
|
|
caller.call(dacname, {"10", "0x0"}, -1, PUT)); // chip index (-1 to 9)
|
|
REQUIRE_THROWS(
|
|
caller.call(dacname, {"-1", "0x400"}, -1, PUT)); // max val is 0x3ff
|
|
|
|
int chipIndex = -1; // for now, it is -1 only
|
|
auto prev_val = det.getOnChipDAC(index, chipIndex);
|
|
auto dacValueStr = ToStringHex(dacvalue);
|
|
auto chipIndexStr = std::to_string(chipIndex);
|
|
std::ostringstream oss_set, oss_get;
|
|
caller.call(dacname, {chipIndexStr, dacValueStr}, -1, PUT, oss_set);
|
|
REQUIRE(oss_set.str() ==
|
|
dacname + " " + chipIndexStr + " " + dacValueStr + "\n");
|
|
caller.call(dacname, {chipIndexStr}, -1, GET, oss_get);
|
|
REQUIRE(oss_get.str() ==
|
|
dacname + " " + chipIndexStr + " " + dacValueStr + "\n");
|
|
|
|
// Reset all dacs to previous value
|
|
for (int i = 0; i != det.size(); ++i) {
|
|
det.setOnChipDAC(index, chipIndex, prev_val[i], {i});
|
|
}
|
|
}
|
|
|
|
} // namespace sls
|