wip, acq test
Run Simulator Tests on local RHEL9 / build (push) Failing after 55s
Build on RHEL9 docker image / build (push) Failing after 1m42s
Build on RHEL8 docker image / build (push) Failing after 1m52s
Run Simulator Tests on local RHEL8 / build (push) Failing after 2m26s

This commit is contained in:
2026-05-22 12:24:26 +02:00
parent b45349998b
commit c35ec170f6
8 changed files with 306 additions and 506 deletions
@@ -8,11 +8,17 @@
#include "test-Caller-global.h"
#include "tests/globals.h"
#include "acquire/Acquire.h"
#include "acquire/CTBState.h"
#include "acquire/FileState.h"
#include <filesystem>
#include <sstream>
namespace sls {
namespace acq = sls::test::acquire;
using test::GET;
using test::PUT;
@@ -33,7 +39,7 @@ TEST_CASE("jungfrau_or_moench_acquire_check_file_size",
"inconsistent number of udp interfaces");
int num_frames_to_acquire = 2;
create_files_for_acquire(det, caller, num_frames_to_acquire);
acq::run(det, num_frames_to_acquire);
// check file size (assuming local pc)
{
@@ -43,9 +49,9 @@ TEST_CASE("jungfrau_or_moench_acquire_check_file_size",
size_t expected_image_size = (par.nChanX * par.nChanY * par.nChipX *
par.nChipY * bytes_per_pixel) /
num_udp_interfaces;
testFileInfo test_file_info;
test_acquire_binary_file_size(test_file_info, num_frames_to_acquire,
expected_image_size);
REQUIRE_NOTHROW(test_acquire_binary_file_size(
acq::default_file_state(), num_frames_to_acquire,
expected_image_size));
}
}
}
@@ -65,7 +71,7 @@ TEST_CASE("eiger_acquire_check_file_size",
"Eiger detector must have dynamic range 16 to test");
}
int num_frames_to_acquire = 2;
create_files_for_acquire(det, caller, num_frames_to_acquire);
acq::run(det, num_frames_to_acquire);
// check file size (assuming local pc)
{
@@ -75,9 +81,9 @@ TEST_CASE("eiger_acquire_check_file_size",
int bytes_per_pixel = (dynamic_range / 8);
size_t expected_image_size =
par.nChanX * par.nChanY * num_chips * bytes_per_pixel;
testFileInfo test_file_info;
test_acquire_binary_file_size(test_file_info, num_frames_to_acquire,
expected_image_size);
REQUIRE_NOTHROW(test_acquire_binary_file_size(
acq::default_file_state(), num_frames_to_acquire,
expected_image_size));
}
}
}
@@ -99,7 +105,7 @@ TEST_CASE("mythen3_acquire_check_file_size",
}
int num_counters = __builtin_popcount(counter_mask);
int num_frames_to_acquire = 2;
create_files_for_acquire(det, caller, num_frames_to_acquire);
acq::run(det, num_frames_to_acquire);
// check file size (assuming local pc)
{
@@ -109,9 +115,9 @@ TEST_CASE("mythen3_acquire_check_file_size",
size_t expected_image_size = num_channels_per_counter *
num_counters * par.nChipX *
bytes_per_pixel;
testFileInfo test_file_info;
test_acquire_binary_file_size(test_file_info, num_frames_to_acquire,
expected_image_size);
REQUIRE_NOTHROW(test_acquire_binary_file_size(
acq::default_file_state(), num_frames_to_acquire,
expected_image_size));
}
}
}
@@ -126,7 +132,7 @@ TEST_CASE("gotthard2_acquire_check_file_size",
if (det_type == defs::GOTTHARD2) {
int num_frames_to_acquire = 2;
create_files_for_acquire(det, caller, num_frames_to_acquire);
acq::run(det, num_frames_to_acquire);
// check file size (assuming local pc)
{
@@ -134,26 +140,24 @@ TEST_CASE("gotthard2_acquire_check_file_size",
int bytes_per_pixel = det.getDynamicRange().squash() / 8;
size_t expected_image_size =
par.nChanX * par.nChipX * bytes_per_pixel;
testFileInfo test_file_info;
test_acquire_binary_file_size(test_file_info, num_frames_to_acquire,
expected_image_size);
REQUIRE_NOTHROW(test_acquire_binary_file_size(
acq::default_file_state(), num_frames_to_acquire,
expected_image_size));
}
}
}
void test_ctb_file_size_with_acquire(Detector &det, Caller &caller,
int64_t num_frames,
const testCtbAcquireInfo &test_info,
void test_ctb_file_size_with_acquire(Detector &det, int64_t num_frames,
const CTBState &test_info,
bool isXilinxCtb) {
create_files_for_acquire(det, caller, num_frames, test_info);
acq::run(det, num_frames, test_info);
// check file size (assuming local pc)
uint64_t expected_image_size =
calculate_ctb_image_size(test_info, isXilinxCtb).first;
testFileInfo test_file_info;
REQUIRE_NOTHROW(test_acquire_binary_file_size(test_file_info, num_frames,
expected_image_size));
REQUIRE_NOTHROW(test_acquire_binary_file_size(
acq::default_file_state(), num_frames, expected_image_size));
}
// disable for xilinx_ctb as it requires higher maximum receive buffer size
@@ -168,122 +172,95 @@ TEST_CASE("ctb_acquire_check_file_size",
if (det_type == defs::CHIPTESTBOARD ||
det_type == defs::XILINX_CHIPTESTBOARD) {
bool isXilinxCtb = (det_type == defs::XILINX_CHIPTESTBOARD);
bool isAltera = (det_type == defs::CHIPTESTBOARD);
int num_frames_to_acquire = 2;
// all the test cases
{
testCtbAcquireInfo test_ctb_config{};
test_ctb_config.readout_mode = defs::ANALOG_AND_DIGITAL;
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, caller, num_frames_to_acquire, test_ctb_config,
isXilinxCtb));
}
{
testCtbAcquireInfo test_ctb_config{};
test_ctb_config.readout_mode = defs::ANALOG_AND_DIGITAL;
test_ctb_config.dbit_offset = 16;
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, caller, num_frames_to_acquire, test_ctb_config,
isXilinxCtb));
}
{
testCtbAcquireInfo test_ctb_config{};
test_ctb_config.readout_mode = defs::ANALOG_AND_DIGITAL;
test_ctb_config.dbit_reorder = true;
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, caller, num_frames_to_acquire, test_ctb_config,
isXilinxCtb));
}
{
testCtbAcquireInfo test_ctb_config{};
test_ctb_config.readout_mode = defs::ANALOG_AND_DIGITAL;
test_ctb_config.dbit_offset = 16;
test_ctb_config.dbit_reorder = true;
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, caller, num_frames_to_acquire, test_ctb_config,
isXilinxCtb));
}
{
testCtbAcquireInfo test_ctb_config{};
test_ctb_config.readout_mode = defs::ANALOG_AND_DIGITAL;
test_ctb_config.dbit_offset = 16;
test_ctb_config.dbit_list.clear();
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, caller, num_frames_to_acquire, test_ctb_config,
isXilinxCtb));
}
{
testCtbAcquireInfo test_ctb_config{};
test_ctb_config.readout_mode = defs::ANALOG_AND_DIGITAL;
test_ctb_config.dbit_offset = 16;
test_ctb_config.dbit_list.clear();
test_ctb_config.dbit_reorder = true;
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, caller, num_frames_to_acquire, test_ctb_config,
isXilinxCtb));
}
{
testCtbAcquireInfo test_ctb_config{};
test_ctb_config.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, caller, num_frames_to_acquire, test_ctb_config,
isXilinxCtb));
}
{
testCtbAcquireInfo test_ctb_config{};
test_ctb_config.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
test_ctb_config.dbit_offset = 16;
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, caller, num_frames_to_acquire, test_ctb_config,
isXilinxCtb));
}
{
testCtbAcquireInfo test_ctb_config{};
test_ctb_config.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
test_ctb_config.dbit_list.clear();
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, caller, num_frames_to_acquire, test_ctb_config,
isXilinxCtb));
}
{
testCtbAcquireInfo test_ctb_config{};
test_ctb_config.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
test_ctb_config.dbit_offset = 16;
test_ctb_config.dbit_list.clear();
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, caller, num_frames_to_acquire, test_ctb_config,
isXilinxCtb));
}
{
testCtbAcquireInfo test_ctb_config{};
test_ctb_config.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
test_ctb_config.dbit_offset = 16;
test_ctb_config.dbit_list.clear();
test_ctb_config.dbit_reorder = true;
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, caller, num_frames_to_acquire, test_ctb_config,
isXilinxCtb));
}
{
testCtbAcquireInfo test_ctb_config{};
test_ctb_config.readout_mode = defs::TRANSCEIVER_ONLY;
test_ctb_config.dbit_offset = 16;
test_ctb_config.dbit_list.clear();
test_ctb_config.dbit_reorder = true;
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, caller, num_frames_to_acquire, test_ctb_config,
isXilinxCtb));
}
{
testCtbAcquireInfo test_ctb_config{};
test_ctb_config.readout_mode = defs::ANALOG_ONLY;
test_ctb_config.dbit_offset = 16;
test_ctb_config.dbit_list.clear();
test_ctb_config.dbit_reorder = true;
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, caller, num_frames_to_acquire, test_ctb_config,
isXilinxCtb));
}
acq::CTBState ctb_state = acq::default_ctb_state(isAltera);
ctb_state.readout_mode = defs::ANALOG_AND_DIGITAL;
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, num_frames_to_acquire, ctb_state, isXilinxCtb));
ctb_state = acq::default_ctb_state(isAltera);
ctb_state.readout_mode = defs::ANALOG_AND_DIGITAL;
ctb_state.dbit_offset = 16;
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, num_frames_to_acquire, ctb_state, isXilinxCtb));
ctb_state = acq::default_ctb_state(isAltera);
ctb_state.readout_mode = defs::ANALOG_AND_DIGITAL;
ctb_state.dbit_reorder = true;
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, num_frames_to_acquire, ctb_state, isXilinxCtb));
ctb_state = acq::default_ctb_state(isAltera);
ctb_state.readout_mode = defs::ANALOG_AND_DIGITAL;
ctb_state.dbit_offset = 16;
ctb_state.dbit_reorder = true;
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, num_frames_to_acquire, ctb_state, isXilinxCtb));
ctb_state = acq::default_ctb_state(isAltera);
ctb_state.readout_mode = defs::ANALOG_AND_DIGITAL;
ctb_state.dbit_offset = 16;
ctb_state.dbit_list.clear();
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, num_frames_to_acquire, ctb_state, isXilinxCtb));
ctb_state = acq::default_ctb_state(isAltera);
ctb_state.readout_mode = defs::ANALOG_AND_DIGITAL;
ctb_state.dbit_offset = 16;
ctb_state.dbit_list.clear();
ctb_state.dbit_reorder = true;
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, num_frames_to_acquire, ctb_state, isXilinxCtb));
ctb_state = acq::default_ctb_state(isAltera);
ctb_state.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, num_frames_to_acquire, ctb_state, isXilinxCtb));
ctb_state = acq::default_ctb_state(isAltera);
ctb_state.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
ctb_state.dbit_offset = 16;
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, num_frames_to_acquire, ctb_state, isXilinxCtb));
ctb_state = acq::default_ctb_state(isAltera);
ctb_state.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
ctb_state.dbit_list.clear();
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, num_frames_to_acquire, ctb_state, isXilinxCtb));
ctb_state = acq::default_ctb_state(isAltera);
ctb_state.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
ctb_state.dbit_offset = 16;
ctb_state.dbit_list.clear();
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, num_frames_to_acquire, ctb_state, isXilinxCtb));
ctb_state = acq::default_ctb_state(isAltera);
ctb_state.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
ctb_state.dbit_offset = 16;
ctb_state.dbit_list.clear();
ctb_state.dbit_reorder = true;
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, num_frames_to_acquire, ctb_state, isXilinxCtb));
ctb_state = acq::default_ctb_state(isAltera);
ctb_state.readout_mode = defs::TRANSCEIVER_ONLY;
ctb_state.dbit_offset = 16;
ctb_state.dbit_list.clear();
ctb_state.dbit_reorder = true;
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, num_frames_to_acquire, ctb_state, isXilinxCtb));
ctb_state = acq::default_ctb_state(isAltera);
ctb_state.readout_mode = defs::ANALOG_ONLY;
ctb_state.dbit_offset = 16;
ctb_state.dbit_list.clear();
ctb_state.dbit_reorder = true;
REQUIRE_NOTHROW(test_ctb_file_size_with_acquire(
det, num_frames_to_acquire, ctb_state, isXilinxCtb));
}
}
@@ -98,28 +98,7 @@ void test_onchip_dac_caller(defs::dacIndex index, const std::string &dacname,
}
}
testFileInfo get_file_state(const Detector &det) {
return testFileInfo{
det.getFilePath().tsquash("Inconsistent file path"),
det.getFileNamePrefix().tsquash("Inconsistent file prefix"),
det.getAcquisitionIndex().tsquash(
"Inconsistent file acquisition index"),
det.getFileWrite().tsquash("Inconsistent file write state"),
det.getFileOverWrite().tsquash("Inconsistent file overwrite state"),
det.getFileFormat().tsquash("Inconsistent file format")};
}
void set_file_state(Detector &det, const testFileInfo &file_info) {
if (!file_info.file_path.empty())
det.setFilePath(file_info.file_path);
det.setFileNamePrefix(file_info.file_prefix);
det.setAcquisitionIndex(file_info.file_acq_index);
det.setFileWrite(file_info.file_write);
det.setFileOverWrite(file_info.file_overwrite);
det.setFileFormat(file_info.file_format);
}
void test_acquire_binary_file_size(const testFileInfo &file_info,
void test_acquire_binary_file_size(const acq::FileState &file_info,
uint64_t num_frames_to_acquire,
uint64_t expected_image_size) {
assert(file_info.file_format == defs::BINARY);
@@ -133,127 +112,8 @@ void test_acquire_binary_file_size(const testFileInfo &file_info,
REQUIRE(actual_file_size == expected_file_size);
}
void test_acquire_with_receiver(Caller &caller, const Detector &det) {
REQUIRE_NOTHROW(caller.call("rx_start", {}, -1, PUT));
REQUIRE_NOTHROW(caller.call("start", {}, -1, PUT));
bool idle = false;
while (!idle) {
std::ostringstream oss;
REQUIRE_NOTHROW(caller.call("status", {}, -1, GET));
auto statusList = det.getDetectorStatus();
if (statusList.any(defs::ERROR)) {
throw std::runtime_error("error status while acquiring");
}
if (statusList.contains_only(defs::IDLE, defs::STOPPED)) {
idle = true;
}
}
REQUIRE_NOTHROW(caller.call("rx_stop", {}, -1, PUT));
}
void create_files_for_acquire(
Detector &det, Caller &caller, int64_t num_frames,
const std::optional<testCtbAcquireInfo> &test_info) {
// save previous state
testFileInfo prev_file_info = get_file_state(det);
auto prev_num_frames = det.getNumberOfFrames().tsquash(
"Inconsistent number of frames to acquire");
std::optional<testCtbAcquireInfo> prev_ctb_config_info{};
if (test_info) {
prev_ctb_config_info = get_ctb_config_state(det);
}
// set state for acquire
testFileInfo test_file_info;
set_file_state(det, test_file_info);
det.setNumberOfFrames(num_frames);
if (test_info) {
set_ctb_config_state(det, *test_info);
}
// acquire and get num frames caught
REQUIRE_NOTHROW(test_acquire_with_receiver(caller, det));
// TODO: maybe there should not be REQUIRE statements in void function at
// all, but traceback should be handled
{
auto frames_caught = det.getFramesCaught()[0][0];
REQUIRE(frames_caught == num_frames);
}
// hdf5
#ifdef HDF5C
test_file_info.file_format = defs::HDF5;
test_file_info.file_acq_index = 0;
set_file_state(det, test_file_info);
// acquire and get num frames caught
test_acquire_with_receiver(caller, det);
{
auto frames_caught = det.getFramesCaught()[0][0];
REQUIRE(frames_caught == num_frames);
}
#endif
// restore previous state
// file
set_file_state(det, prev_file_info);
det.setNumberOfFrames(prev_num_frames);
if (test_info) {
set_ctb_config_state(det, *prev_ctb_config_info);
}
}
testCtbAcquireInfo get_ctb_config_state(const Detector &det) {
testCtbAcquireInfo ctb_config_info{
det.getReadoutMode().tsquash("inconsistent readout mode to test"),
true,
det.getNumberOfAnalogSamples().tsquash(
"inconsistent number of analog samples to test"),
det.getNumberOfDigitalSamples().tsquash(
"inconsistent number of digital samples to test"),
det.getNumberOfTransceiverSamples().tsquash(
"inconsistent number of transceiver samples to test"),
0,
det.getTenGigaADCEnableMask().tsquash(
"inconsistent ten giga adc enable mask to test"),
det.getRxDbitOffset().tsquash("inconsistent rx dbit offset to test"),
det.getRxDbitList().tsquash("inconsistent rx dbit list to test"),
det.getRxDbitReorder().tsquash("inconsistent rx dbit reorder to test"),
det.getTransceiverEnableMask().tsquash(
"inconsistent transceiver mask to test")};
if (det.getDetectorType().tsquash("inconsistent detector type to test") ==
slsDetectorDefs::CHIPTESTBOARD) {
ctb_config_info.ten_giga =
det.getTenGiga().tsquash("inconsistent ten giga enable to test");
ctb_config_info.adc_enable_1g = det.getADCEnableMask().tsquash(
"inconsistent adc enable mask to test");
}
return ctb_config_info;
}
void set_ctb_config_state(Detector &det,
const testCtbAcquireInfo &ctb_config_info) {
det.setReadoutMode(ctb_config_info.readout_mode);
if (det.getDetectorType().tsquash("inconsistent detector type to test") ==
slsDetectorDefs::CHIPTESTBOARD) {
det.setTenGiga(ctb_config_info.ten_giga);
det.setADCEnableMask(ctb_config_info.adc_enable_1g);
}
det.setNumberOfAnalogSamples(ctb_config_info.num_adc_samples);
det.setNumberOfDigitalSamples(ctb_config_info.num_dbit_samples);
det.setNumberOfTransceiverSamples(ctb_config_info.num_trans_samples);
det.setTenGigaADCEnableMask(ctb_config_info.adc_enable_10g);
det.setRxDbitOffset(ctb_config_info.dbit_offset);
det.setRxDbitList(ctb_config_info.dbit_list);
det.setRxDbitReorder(ctb_config_info.dbit_reorder);
det.setTransceiverEnableMask(ctb_config_info.transceiver_mask);
}
std::pair<uint64_t, int>
calculate_ctb_image_size(const testCtbAcquireInfo &test_info,
bool isXilinxCtb) {
calculate_ctb_image_size(const acq::CTBState &test_info, bool isXilinxCtb) {
// test_info.print(); // for debugging
sls::CtbImageInputs inputs{};
@@ -8,70 +8,16 @@
#include "sls/logger.h"
#include "sls/sls_detector_defs.h"
#include "acquire/Acquire.h"
#include <chrono>
#include <filesystem>
#include <optional>
#include <thread>
namespace sls {
struct testFileInfo {
std::string file_path{"/tmp"};
std::string file_prefix{"sls_test"};
int64_t file_acq_index{0};
bool file_write{true};
bool file_overwrite{true};
slsDetectorDefs::fileFormat file_format{slsDetectorDefs::BINARY};
std::string getMasterFileNamePrefix() const {
return file_path + "/" + file_prefix + "_master_" +
std::to_string(file_acq_index);
}
std::string getVirtualFileName() const {
return file_path + "/" + file_prefix + "_virtual_" +
std::to_string(file_acq_index) + ".h5";
}
inline void print() const {
LOG(logINFO) << "File Info: "
<< "\n\tFile Path: " << file_path
<< "\n\tFile Prefix: " << file_prefix
<< "\n\tFile Acquisition Index: " << file_acq_index
<< "\n\tFile Write: " << file_write
<< "\n\tFile Overwrite: " << file_overwrite
<< "\n\tFile Format: " << ToString(file_format)
<< "\n\tMaster Filename: " << getMasterFileNamePrefix()
<< "\n\tVirtual Filename: " << getVirtualFileName();
}
};
struct testCtbAcquireInfo {
defs::readoutMode readout_mode{defs::ANALOG_AND_DIGITAL};
bool ten_giga{false};
int num_adc_samples{5000};
int num_dbit_samples{6000};
int num_trans_samples{288};
uint32_t adc_enable_1g{0xFFFFFF00};
uint32_t adc_enable_10g{0xFF00FFFF};
int dbit_offset{0};
std::vector<int> dbit_list{0, 12, 2, 43};
bool dbit_reorder{false};
uint32_t transceiver_mask{0x3};
inline void print() const {
LOG(logINFO) << "CTB Acquire Info: "
<< "\n\tReadout Mode: " << ToString(readout_mode)
<< "\n\tTen Giga: " << ten_giga
<< "\n\tADC Enable 1G: " << std::hex << adc_enable_1g
<< std::dec << "\n\tADC Enable 10G: " << std::hex
<< adc_enable_10g << std::dec
<< "\n\tNumber of Analog Samples: " << num_adc_samples
<< "\n\tNumber of Digital Samples: " << num_dbit_samples
<< "\n\tNumber of Transceiver Samples: "
<< num_trans_samples << "\n\tDBIT Offset: " << dbit_offset
<< "\n\tDBIT Reorder: " << dbit_reorder
<< "\n\tDBIT List: " << ToString(dbit_list)
<< "\n\tTransceiver Mask: " << std::hex << transceiver_mask
<< std::dec << std::endl;
}
};
namespace acq = sls::test::acquire;
void test_valid_port_caller(const std::string &command,
const std::vector<std::string> &arguments,
@@ -82,20 +28,11 @@ void test_dac_caller(slsDetectorDefs::dacIndex index,
void test_onchip_dac_caller(slsDetectorDefs::dacIndex index,
const std::string &dacname, int dacvalue);
testFileInfo get_file_state(const Detector &det);
void set_file_state(Detector &det, const testFileInfo &file_info);
void test_acquire_binary_file_size(const testFileInfo &file_info,
void test_acquire_binary_file_size(const acq::FileState &file_info,
uint64_t num_frames_to_acquire,
uint64_t expected_image_size);
void create_files_for_acquire(
Detector &det, Caller &caller, int64_t num_frames = 1,
const std::optional<testCtbAcquireInfo> &test_info = std::nullopt);
testCtbAcquireInfo get_ctb_config_state(const Detector &det);
void set_ctb_config_state(Detector &det,
const testCtbAcquireInfo &ctb_config_info);
std::pair<uint64_t, int>
calculate_ctb_image_size(const testCtbAcquireInfo &test_info, bool isXilinxCtb);
calculate_ctb_image_size(const acq::CTBState &test_info, bool isXilinxCtb);
} // namespace sls
@@ -5,6 +5,8 @@
#ifdef HDF5C
#include "master_file/ReadersH5.h"
#endif
#include "acquire/Acquire.h"
#include "acquire/FileState.h"
#include "master_file/Checker.h"
#include "Caller.h"
@@ -31,14 +33,8 @@
namespace sls {
using test::GET;
using test::PUT;
using namespace rapidjson;
namespace mf = test::master_file;
#ifdef HDF5C
#endif
namespace mf = sls::test::master_file;
namespace acq = sls::test::acquire;
inline bool operator==(sls::ns lhs, sls::ns rhs) {
return lhs.count() == rhs.count();
@@ -221,7 +217,6 @@ void test_master_file_total_frames(const Detector &det, CheckerT &checker) {
auto burst_mode = det.getBurstMode().tsquash("Inconsistent burst mode");
auto numBursts =
det.getNumberOfBursts().tsquash("Inconsistent number of bursts");
// auto
if (timing_mode == defs::AUTO_TIMING) {
// burst mode, repeats = #bursts
if (burst_mode == defs::BURST_INTERNAL ||
@@ -232,9 +227,8 @@ void test_master_file_total_frames(const Detector &det, CheckerT &checker) {
else {
repeats = 1;
}
}
// trigger
else {
} else {
// trigger
// continuous, numFrames is limited
if (burst_mode == defs::CONTINUOUS_INTERNAL ||
burst_mode == defs::CONTINUOUS_EXTERNAL) {
@@ -713,7 +707,7 @@ void test_master_file_metadata(const Detector &det, CheckerT &checker) {
}
}
Document parse_binary_master_attributes(std::string file_path) {
rapidjson::Document parse_binary_master_attributes(std::string file_path) {
REQUIRE(std::filesystem::exists(file_path) == true);
std::ifstream file(file_path);
REQUIRE(file.is_open());
@@ -721,7 +715,7 @@ Document parse_binary_master_attributes(std::string file_path) {
buffer << file.rdbuf();
std::string json_str = buffer.str();
Document doc;
rapidjson::Document doc;
ParseResult result = doc.Parse(json_str.c_str());
if (!result) {
std::cout << "JSON parse error: " << GetParseError_En(result.Code())
@@ -741,43 +735,22 @@ TEST_CASE("check_master_file_attributes",
"[.detectorintegration][.disable_check_data_file]") {
Detector det;
Caller caller(&det);
auto det_type =
det.getDetectorType().tsquash("Inconsistent detector types to test");
int64_t num_frames = 1;
switch (det_type) {
case defs::JUNGFRAU:
case defs::EIGER:
case defs::MOENCH:
case defs::MYTHEN3:
case defs::GOTTHARD2:
create_files_for_acquire(det, caller, num_frames);
break;
case defs::CHIPTESTBOARD:
case defs::XILINX_CHIPTESTBOARD: {
testCtbAcquireInfo test_ctb_config{};
create_files_for_acquire(det, caller, num_frames, test_ctb_config);
} break;
default:
throw sls::RuntimeError("Unsupported detector type for this test");
}
testFileInfo file_info;
std::string master_file_prefix = file_info.getMasterFileNamePrefix();
acq::run(det, num_frames);
std::string master_file_prefix =
get_master_file_name_prefix(acq::default_file_state());
// binary
std::string fname =
master_file_prefix + ".json"; // /tmp/sls_test_master_0.json
// binary (/tmp/sls_test_master_0.json)
std::string fname = master_file_prefix + ".json";
auto doc = parse_binary_master_attributes(fname);
mf::Checker<mf::JsonContext> checker(mf::JsonContext{doc});
test_master_file_metadata(det, checker);
test_master_file_frames_in_file(checker, num_frames);
// hdf5
// hdf5 (/tmp/sls_test_master_0.h5)
#ifdef HDF5C
fname = master_file_prefix + ".h5"; // /tmp/sls_test_master_0.h5
fname = master_file_prefix + ".h5";
try {
mf::Checker<mf::H5Context> checker(mf::H5Context{fname});
test_master_file_metadata(det, checker);
+41 -47
View File
@@ -2,68 +2,62 @@
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include "Acquire.h"
#include "CTBState.h"
#include "FileState.h"
#include "catch.hpp"
#include <chrono>
#include <thread>
namespace sls::test::acquire {
void wait_until_idle(const Detector &det) {
bool idle = false;
while (!idle) {
auto statusList = det.getDetectorStatus();
if (statusList.any(defs::ERROR)) {
throw std::runtime_error("error status during acquisition");
}
if (statusList.contains_only(defs::IDLE, defs::STOPPED)) {
idle = true;
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
void wait_until_idle(const Detector &det) {
bool idle = false;
while (!idle) {
auto statusList = det.getDetectorStatus();
if (statusList.any(defs::ERROR)) {
throw RuntimeError("error status during acquisition");
}
}
void acquire(Detector &det) {
det.startReceiver();
det.startDetector();
wait_until_idle(det);
det.stopReceiver();
}
void run(Detector &det, int64_t num_frames, const FileState& file_state, const std::optional<CTBState>& ctb_state) {
FileStateGuard file_guard(det);
CTBStateGuard ctb_guard(det);
if (ctb_state) {
set_ctb_state(det, ctb_state.value());
if (statusList.contains_only(defs::IDLE, defs::STOPPED)) {
idle = true;
}
// frames
auto prev_frames = det.getNumberOfFrames().tsquash(
"Inconsistent number of frames to acquire");
det.setNumberOfFrames(num_frames);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
void run_acquisition(Detector &det) {
det.startReceiver();
det.startDetector();
wait_until_idle(det);
det.stopReceiver();
}
void run(Detector &det, int64_t num_frames, const CTBState &ctb_state,
const FileState &file_state) {
FrameGuard frame_guard(det, num_frames);
CTBStateGuard ctb_guard(det, ctb_state);
{
// binary
auto bin_state = file_state;
bin_state.file_format = defs::BINARY;
set_file_state(det, bin_state);
auto binary_state = file_state;
binary_state.file_format = defs::BINARY;
FileStateGuard file_guard(det, binary_state);
acquire(det);
{
auto frames_caught = det.getFramesCaught()[0][0];
REQUIRE(frames_caught == num_frames);
}
auto frames_caught = det.getFramesCaught()[0][0];
REQUIRE(frames_caught == num_frames);
}
// hdf5
#ifdef HDF5C
{
// hdf5
auto h5_state = file_state;
h5_state.file_format = defs::HDF5;
set_file_state(det, h5_state);
acquire(det);
{
auto frames_caught = det.getFramesCaught()[0][0];
REQUIRE(frames_caught == num_frames);
}
#endif
// restore previous state
det.setNumberOfFrames(prev_frames);
FileStateGuard file_guard(det, h5_state);
acquire(det);
auto frames_caught = det.getFramesCaught()[0][0];
REQUIRE(frames_caught == num_frames);
}
#endif
}
} // namespace sls::test::acquire
+23 -8
View File
@@ -3,16 +3,31 @@
#pragma once
#include "FileState.h"
#include "CTBState.h"
#include "sls/Detector.h"
#include <optional>
class FileState;
class CTBState;
class Detector;
namespace sls::test::acquire {
void wait_until_idle(const Detector &det);
void acquire(Detector &det);
void run(Detector &det, int64_t num_frames = 1, const FileState& file_state = default_file_state(), const std::optional<CTBState>& ctb_state = std::nullopt);
void wait_until_idle(const Detector &det);
void run_acquisition(Detector &det);
void run(Detector &det, int64_t num_frames = 1,
const CTBState &ctb_state = default_ctb_state(),
const FileState &file_state = default_file_state());
class FrameGuard {
public:
FrameGuard(Detector &det, int64_t new_frames)
: det(det), prev(det.getNumberOfFrames().tsquash(
"Inconsistent number of frames")) {
det.setNumberOfFrames(new_frames);
}
~FrameGuard() { det.setNumberOfFrames(prev); }
private:
Detector &det;
int64_t prev;
};
} // namespace sls::test::acquire
+66 -38
View File
@@ -4,6 +4,9 @@
#include "sls/Detector.h"
#include <cstdint>
#include <vector>
namespace sls::test::acquire {
struct CTBState {
@@ -20,42 +23,46 @@ struct CTBState {
uint32_t transceiver_mask;
};
inline CTBState default_ctb_state() {
return {
defs::ANALOG_AND_DIGITAL,
false,
5000,
6000,
288,
0xFFFFFF00,
0xFF00FFFF,
0,
{0, 12, 2, 43},
false,
0x3
};
inline CTBState default_ctb_state(bool isAltera) {
return {defs::ANALOG_AND_DIGITAL,
isAltera ? false : true,
5000,
6000,
288,
0xFFFFFF00,
0xFF00FFFF,
0,
{0, 12, 2, 43},
false,
0x3};
}
inline CTBState get_ctb_state(const Detector& det) {
inline CTBState get_ctb_state(const Detector &det, bool isAltera) {
return CTBState{
det.getReadoutMode().tsquash("Inconsistent readout mode"),
true, // always true for xilinx, det.getTenGiga() for ctb
det.getNumberOfAnalogSamples().tsquash("Inconsistent number of analog samples"),
det.getNumberOfDigitalSamples().tsquash("Inconsistent number of digital samples"),
det.getNumberOfTransceiverSamples().tsquash("Inconsistent number of transceiver samples"),
0, // always 0 for xilinx, det.getTenGigaADCEnableMask() for ctb
det.getTenGigaADCEnableMask().tsquash("Inconsistent ten giga adc enable mask"),
isAltera ? det.getTenGiga().tsquash("Inconsisten ten giga enable")
: true,
det.getNumberOfAnalogSamples().tsquash(
"Inconsistent number of analog samples"),
det.getNumberOfDigitalSamples().tsquash(
"Inconsistent number of digital samples"),
det.getNumberOfTransceiverSamples().tsquash(
"Inconsistent number of transceiver samples"),
isAltera
? det.getADCEnableMask().tsquash("Inconsistent adc enable mask")
: 0,
det.getTenGigaADCEnableMask().tsquash(
"Inconsistent ten giga adc enable mask"),
det.getRxDbitOffset().tsquash("Inconsistent rx dbit offset"),
det.getRxDbitList().tsquash("Inconsistent rx dbit list"),
det.getRxDbitReorder().tsquash("Inconsistent rx dbit reorder"),
det.getTransceiverEnableMask().tsquash("Inconsistent transceiver mask")
};
det.getTransceiverEnableMask().tsquash(
"Inconsistent transceiver mask")};
}
inline void set_ctb_state(Detector& det, const CTBState& s) {
inline void set_ctb_state(Detector &det, const CTBState &s, bool isAltera) {
det.setReadoutMode(s.readout_mode);
if (det.getDetectorType().tsquash("inconsistent detector type") ==
slsDetectorDefs::CHIPTESTBOARD) {
if (isAltera) {
det.setTenGiga(s.ten_giga);
det.setADCEnableMask(s.adc_enable_1g);
}
@@ -69,23 +76,44 @@ inline void set_ctb_state(Detector& det, const CTBState& s) {
det.setTransceiverEnableMask(s.transceiver_mask);
}
inline void print_ctb_state(const CTBState &s) {
LOG(logINFO) << "CTB State:"
<< "\n Readout Mode: " << ToString(s.readout_mode)
<< "\n Ten Giga: " << s.ten_giga
<< "\n Num ADC Samples: " << s.num_adc_samples
<< "\n Num DBIT Samples: " << s.num_dbit_samples
<< "\n Num Trans Samples: " << s.num_trans_samples
<< "\n ADC Enable 1G: " << ToStringHex(s.adc_enable_1g)
<< "\n ADC Enable 10G: " << ToStringHex(s.adc_enable_10g)
<< "\n DBIT Offset: " << s.dbit_offset
<< "\n DBIT List: " << ToString(s.dbit_list)
<< "\n DBIT Reorder: " << s.dbit_reorder
<< "\n Transceiver Mask: " << ToStringHex(s.transceiver_mask);
}
class CTBStateGuard {
public:
explicit CTBStateGuard(Detector& det) : det(det), saved_(get_ctb_state(det)) {}
public:
explicit CTBStateGuard(Detector &det, const CTBState &new_state)
: det(det) {
auto type = det.getDetectorType().squash(defs::GENERIC);
isAltera = (type == defs::CHIPTESTBOARD);
active =
(type == defs::CHIPTESTBOARD || type == defs::XILINX_CHIPTESTBOARD);
if (active) {
saved_ = get_ctb_state(det, isAltera);
set_ctb_state(det, new_state, isAltera);
}
}
~CTBStateGuard() {
set_ctb_state(det, saved_);
if (active)
set_ctb_state(det, saved_, isAltera);
}
private:
Detector& det;
private:
Detector &det;
bool active{false};
bool isAltera{false};
CTBState saved_;
static bool is_ctb(const Detector& det) {
auto type = det.getDetectorType().tsquash("");
return type == defs::CHIPTESTBOARD ||
type == defs::XILINX_CHIPTESTBOARD;
}
};
} // namespace sls::test::acquire
+40 -24
View File
@@ -4,6 +4,8 @@
#include "sls/Detector.h"
#include <string>
namespace sls::test::acquire {
struct FileState {
@@ -12,32 +14,25 @@ struct FileState {
int64_t file_acq_index;
bool file_write;
bool file_overwrite;
slsDetectorDefs::fileFormat file_format;
slsDetectorDefs::fileFormat file_format;
};
inline FileState default_file_state() {
return {
"/tmp",
"sls_test",
0,
true,
true,
slsDetectorDefs::BINARY
};
return {"/tmp", "sls_test", 0, true, true, slsDetectorDefs::BINARY};
}
inline FileState get_file_state(const Detector& det) {
inline FileState get_file_state(const Detector &det) {
return FileState{
det.getFilePath().tsquash("Inconsistent file path"),
det.getFileNamePrefix().tsquash("Inconsistent file prefix"),
det.getAcquisitionIndex().tsquash("Inconsistent file acquisition index"),
det.getAcquisitionIndex().tsquash(
"Inconsistent file acquisition index"),
det.getFileWrite().tsquash("Inconsistent file write"),
det.getFileOverWrite().tsquash("Inconsistent file overwrite"),
det.getFileFormat().tsquash("Inconsistent file format")
};
det.getFileFormat().tsquash("Inconsistent file format")};
}
inline void set_file_state(Detector& det, const FileState& s) {
inline void set_file_state(Detector &det, const FileState &s) {
det.setFilePath(s.file_path);
det.setFileNamePrefix(s.file_prefix);
det.setAcquisitionIndex(s.file_acq_index);
@@ -46,17 +41,38 @@ inline void set_file_state(Detector& det, const FileState& s) {
det.setFileFormat(s.file_format);
}
class FileStateGuard {
public:
explicit FileStateGuard(Detector& det) : det(det), saved_(get_file_state(det)) {}
~FileStateGuard() {
set_file_state(det, saved_);
}
inline std::string get_master_file_name_prefix(const FileState &s) {
return s.file_path + "/" + s.file_prefix + "_master_" +
std::to_string(s.file_acq_index);
}
private:
Detector& det;
FileState saved_;
};
inline std::string get_virtual_file_name(const FileState &s) {
return s.file_path + "/" + s.file_prefix + "_virtual_" +
std::to_string(s.file_acq_index) + ".h5";
}
inline void print_file_state(const FileState &s) {
LOG(logINFO) << "File State:"
<< "\n Path: " << s.file_path
<< "\n Prefix: " << s.file_prefix
<< "\n Acq Index: " << s.file_acq_index
<< "\n Write: " << s.file_write
<< "\n Overwrite: " << s.file_overwrite
<< "\n Format: " << ToString(s.file_format)
<< "\n Master File: " << get_master_file_name_prefix(s)
<< "\n Virtual File: " << get_virtual_file_name(s);
class FileStateGuard {
public:
explicit FileStateGuard(Detector &det, const FileState &new_state)
: det(det), saved_(get_file_state(det)) {
set_file_state(det, new_state);
}
~FileStateGuard() { set_file_state(det, saved_); }
private:
Detector &det;
FileState saved_;
};
} // namespace sls::test::acquire