mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-05-05 20:30:03 +02:00
Merge pull request #1199 from slsdetectorgroup/dev/test_all_acquire_file
Dev/test all acquire file
This commit is contained in:
commit
0d5d851585
@ -1537,8 +1537,12 @@ void *start_timer(void *arg) {
|
||||
packetSize, packetsPerFrame));
|
||||
|
||||
// Generate Data
|
||||
char imageData[imageSize];
|
||||
char *imageData = (char *)malloc(imageSize);
|
||||
memset(imageData, 0, imageSize);
|
||||
if (imageData == NULL) {
|
||||
LOG(logERROR, ("Can not allocate image.\n"));
|
||||
return NULL;
|
||||
}
|
||||
for (int i = 0; i < imageSize; i += sizeof(uint16_t)) {
|
||||
*((uint16_t *)(imageData + i)) = i;
|
||||
}
|
||||
@ -1561,6 +1565,7 @@ void *start_timer(void *arg) {
|
||||
usleep(expUs);
|
||||
|
||||
int srcOffset = 0;
|
||||
int dataSent = 0;
|
||||
// loop packet
|
||||
for (int i = 0; i != packetsPerFrame; ++i) {
|
||||
|
||||
@ -1577,10 +1582,12 @@ void *start_timer(void *arg) {
|
||||
header->column = detPos[X];
|
||||
|
||||
// fill data
|
||||
int remaining = imageSize - dataSent;
|
||||
int dataSize = remaining < maxDataSize ? remaining : maxDataSize;
|
||||
memcpy(packetData + sizeof(sls_detector_header),
|
||||
imageData + srcOffset,
|
||||
(imageSize < maxDataSize ? imageSize : maxDataSize));
|
||||
srcOffset += maxDataSize;
|
||||
imageData + srcOffset, dataSize);
|
||||
srcOffset += dataSize;
|
||||
dataSent += dataSize;
|
||||
|
||||
sendUDPPacket(0, 0, packetData, packetSize);
|
||||
}
|
||||
|
@ -17,6 +17,119 @@ namespace sls {
|
||||
using test::GET;
|
||||
using test::PUT;
|
||||
|
||||
TEST_CASE("ctb_acquire_check_file_size", "[.cmdcall]") {
|
||||
Detector det;
|
||||
Caller caller(&det);
|
||||
auto det_type =
|
||||
det.getDetectorType().tsquash("Inconsistent detector types to test");
|
||||
|
||||
if (det_type == defs::CHIPTESTBOARD ||
|
||||
det_type == defs::XILINX_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_acquire_with_receiver(
|
||||
test_ctb_config, num_frames_to_acquire, det, caller));
|
||||
}
|
||||
{
|
||||
testCtbAcquireInfo test_ctb_config;
|
||||
test_ctb_config.readout_mode = defs::ANALOG_AND_DIGITAL;
|
||||
test_ctb_config.dbit_offset = 16;
|
||||
REQUIRE_NOTHROW(test_ctb_acquire_with_receiver(
|
||||
test_ctb_config, num_frames_to_acquire, det, caller));
|
||||
}
|
||||
{
|
||||
testCtbAcquireInfo test_ctb_config;
|
||||
test_ctb_config.readout_mode = defs::ANALOG_AND_DIGITAL;
|
||||
test_ctb_config.dbit_reorder = true;
|
||||
REQUIRE_NOTHROW(test_ctb_acquire_with_receiver(
|
||||
test_ctb_config, num_frames_to_acquire, det, caller));
|
||||
}
|
||||
{
|
||||
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_acquire_with_receiver(
|
||||
test_ctb_config, num_frames_to_acquire, det, caller));
|
||||
}
|
||||
{
|
||||
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_acquire_with_receiver(
|
||||
test_ctb_config, num_frames_to_acquire, det, caller));
|
||||
}
|
||||
{
|
||||
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_acquire_with_receiver(
|
||||
test_ctb_config, num_frames_to_acquire, det, caller));
|
||||
}
|
||||
{
|
||||
testCtbAcquireInfo test_ctb_config;
|
||||
test_ctb_config.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
|
||||
REQUIRE_NOTHROW(test_ctb_acquire_with_receiver(
|
||||
test_ctb_config, num_frames_to_acquire, det, caller));
|
||||
}
|
||||
{
|
||||
testCtbAcquireInfo test_ctb_config;
|
||||
test_ctb_config.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
|
||||
test_ctb_config.dbit_offset = 16;
|
||||
REQUIRE_NOTHROW(test_ctb_acquire_with_receiver(
|
||||
test_ctb_config, num_frames_to_acquire, det, caller));
|
||||
}
|
||||
{
|
||||
testCtbAcquireInfo test_ctb_config;
|
||||
test_ctb_config.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
|
||||
test_ctb_config.dbit_list.clear();
|
||||
REQUIRE_NOTHROW(test_ctb_acquire_with_receiver(
|
||||
test_ctb_config, num_frames_to_acquire, det, caller));
|
||||
}
|
||||
{
|
||||
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_acquire_with_receiver(
|
||||
test_ctb_config, num_frames_to_acquire, det, caller));
|
||||
}
|
||||
{
|
||||
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_acquire_with_receiver(
|
||||
test_ctb_config, num_frames_to_acquire, det, caller));
|
||||
}
|
||||
{
|
||||
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_acquire_with_receiver(
|
||||
test_ctb_config, num_frames_to_acquire, det, caller));
|
||||
}
|
||||
{
|
||||
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_acquire_with_receiver(
|
||||
test_ctb_config, num_frames_to_acquire, det, caller));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* dacs */
|
||||
|
||||
TEST_CASE("dacname", "[.cmdcall]") {
|
||||
|
@ -17,6 +17,70 @@ namespace sls {
|
||||
using test::GET;
|
||||
using test::PUT;
|
||||
|
||||
TEST_CASE("eiger_acquire_check_file_size", "[.cmdcall]") {
|
||||
Detector det;
|
||||
Caller caller(&det);
|
||||
auto det_type =
|
||||
det.getDetectorType().tsquash("Inconsistent detector types to test");
|
||||
|
||||
if (det_type == defs::EIGER) {
|
||||
|
||||
// save previous state
|
||||
testFileInfo prev_file_info = get_file_state(det);
|
||||
testCommonDetAcquireInfo prev_det_config_info =
|
||||
get_common_acquire_config_state(det);
|
||||
|
||||
// save previous specific det type config
|
||||
auto exptime = det.getExptime().tsquash("inconsistent exptime to test");
|
||||
auto n_rows =
|
||||
det.getReadNRows().tsquash("inconsistent number of rows to test");
|
||||
auto dynamic_range =
|
||||
det.getDynamicRange().tsquash("inconsistent dynamic range to test");
|
||||
REQUIRE(false ==
|
||||
det.getTenGiga().tsquash("inconsistent 10Giga to test"));
|
||||
|
||||
// defaults
|
||||
int num_frames_to_acquire = 2;
|
||||
testFileInfo test_file_info;
|
||||
set_file_state(det, test_file_info);
|
||||
testCommonDetAcquireInfo det_config;
|
||||
det_config.num_frames_to_acquire = num_frames_to_acquire;
|
||||
set_common_acquire_config_state(det, det_config);
|
||||
|
||||
// set default specific det type config
|
||||
det.setExptime(std::chrono::microseconds{200});
|
||||
det.setReadNRows(256);
|
||||
det.setDynamicRange(16);
|
||||
|
||||
// acquire
|
||||
test_acquire_with_receiver(caller, det);
|
||||
|
||||
// check frames caught
|
||||
test_frames_caught(det, num_frames_to_acquire);
|
||||
|
||||
// check file size (assuming local pc)
|
||||
{
|
||||
detParameters par(det_type);
|
||||
// data split into half due to 2 udp interfaces per half module
|
||||
int num_chips = (par.nChipX / 2);
|
||||
int bytes_per_pixel = (dynamic_range / 8);
|
||||
size_t expected_image_size =
|
||||
par.nChanX * par.nChanY * num_chips * bytes_per_pixel;
|
||||
test_acquire_binary_file_size(test_file_info, num_frames_to_acquire,
|
||||
expected_image_size);
|
||||
}
|
||||
|
||||
// restore previous state
|
||||
set_file_state(det, prev_file_info);
|
||||
set_common_acquire_config_state(det, prev_det_config_info);
|
||||
|
||||
// restore previous specific det type config
|
||||
det.setExptime(exptime);
|
||||
det.setReadNRows(n_rows);
|
||||
det.setDynamicRange(dynamic_range);
|
||||
}
|
||||
}
|
||||
|
||||
/** temperature */
|
||||
|
||||
TEST_CASE("temp_fpgaext", "[.cmdcall]") {
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "Caller.h"
|
||||
#include "catch.hpp"
|
||||
#include "sls/Detector.h"
|
||||
#include "sls/logger.h"
|
||||
#include "tests/globals.h"
|
||||
|
||||
namespace sls {
|
||||
@ -88,4 +89,227 @@ 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,
|
||||
uint64_t num_frames_to_acquire,
|
||||
uint64_t expected_image_size) {
|
||||
assert(file_info.file_format == defs::BINARY);
|
||||
std::string fname = file_info.file_path + "/" + file_info.file_prefix +
|
||||
"_d0_f0_" + std::to_string(file_info.file_acq_index) +
|
||||
".raw";
|
||||
uint64_t expected_file_size =
|
||||
num_frames_to_acquire *
|
||||
(expected_image_size + sizeof(defs::sls_receiver_header));
|
||||
auto actual_file_size = std::filesystem::file_size(fname);
|
||||
REQUIRE(actual_file_size == expected_file_size);
|
||||
}
|
||||
|
||||
void test_frames_caught(const Detector &det, int num_frames_to_acquire) {
|
||||
auto frames_caught = det.getFramesCaught().tsquash(
|
||||
"Inconsistent number of frames caught")[0];
|
||||
REQUIRE(frames_caught == num_frames_to_acquire);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
testCommonDetAcquireInfo get_common_acquire_config_state(const Detector &det) {
|
||||
return testCommonDetAcquireInfo{
|
||||
det.getTimingMode().tsquash("Inconsistent timing mode"),
|
||||
det.getNumberOfFrames().tsquash("Inconsistent number of frames"),
|
||||
det.getNumberOfTriggers().tsquash("Inconsistent number of triggers"),
|
||||
det.getPeriod().tsquash("Inconsistent period")};
|
||||
}
|
||||
|
||||
void set_common_acquire_config_state(
|
||||
Detector &det, const testCommonDetAcquireInfo &det_config_info) {
|
||||
det.setTimingMode(det_config_info.timing_mode);
|
||||
det.setNumberOfFrames(det_config_info.num_frames_to_acquire);
|
||||
det.setNumberOfTriggers(det_config_info.num_triggers);
|
||||
det.setPeriod(det_config_info.period);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
uint64_t calculate_ctb_image_size(const testCtbAcquireInfo &test_info) {
|
||||
uint64_t num_analog_bytes = 0, num_digital_bytes = 0,
|
||||
num_transceiver_bytes = 0;
|
||||
if (test_info.readout_mode == defs::ANALOG_ONLY ||
|
||||
test_info.readout_mode == defs::ANALOG_AND_DIGITAL) {
|
||||
uint32_t adc_enable_mask =
|
||||
(test_info.ten_giga ? test_info.adc_enable_10g
|
||||
: test_info.adc_enable_1g);
|
||||
int num_analog_chans = __builtin_popcount(adc_enable_mask);
|
||||
const int num_bytes_per_sample = 2;
|
||||
num_analog_bytes =
|
||||
num_analog_chans * num_bytes_per_sample * test_info.num_adc_samples;
|
||||
LOG(logDEBUG1) << "[Analog Databytes: " << num_analog_bytes << ']';
|
||||
}
|
||||
|
||||
// digital channels
|
||||
if (test_info.readout_mode == defs::DIGITAL_ONLY ||
|
||||
test_info.readout_mode == defs::ANALOG_AND_DIGITAL ||
|
||||
test_info.readout_mode == defs::DIGITAL_AND_TRANSCEIVER) {
|
||||
int num_digital_samples = test_info.num_dbit_samples;
|
||||
if (test_info.dbit_offset > 0) {
|
||||
uint64_t num_digital_bytes_reserved =
|
||||
num_digital_samples * sizeof(uint64_t);
|
||||
num_digital_bytes_reserved -= test_info.dbit_offset;
|
||||
num_digital_samples = num_digital_bytes_reserved / sizeof(uint64_t);
|
||||
}
|
||||
int num_digital_chans = test_info.dbit_list.size();
|
||||
if (num_digital_chans == 0) {
|
||||
num_digital_chans = 64;
|
||||
}
|
||||
if (!test_info.dbit_reorder) {
|
||||
uint32_t num_bits_per_sample = num_digital_chans;
|
||||
if (num_bits_per_sample % 8 != 0) {
|
||||
num_bits_per_sample += (8 - (num_bits_per_sample % 8));
|
||||
}
|
||||
num_digital_bytes = (num_bits_per_sample / 8) * num_digital_samples;
|
||||
} else {
|
||||
uint32_t num_bits_per_bit = num_digital_samples;
|
||||
if (num_bits_per_bit % 8 != 0) {
|
||||
num_bits_per_bit += (8 - (num_bits_per_bit % 8));
|
||||
}
|
||||
num_digital_bytes = num_digital_chans * (num_bits_per_bit / 8);
|
||||
}
|
||||
LOG(logDEBUG1) << "[Digital Databytes: " << num_digital_bytes << ']';
|
||||
}
|
||||
// transceiver channels
|
||||
if (test_info.readout_mode == defs::TRANSCEIVER_ONLY ||
|
||||
test_info.readout_mode == defs::DIGITAL_AND_TRANSCEIVER) {
|
||||
int num_transceiver_chans =
|
||||
__builtin_popcount(test_info.transceiver_mask);
|
||||
const int num_bytes_per_channel = 8;
|
||||
num_transceiver_bytes = num_transceiver_chans * num_bytes_per_channel *
|
||||
test_info.num_trans_samples;
|
||||
LOG(logDEBUG1) << "[Transceiver Databytes: " << num_transceiver_bytes
|
||||
<< ']';
|
||||
}
|
||||
|
||||
uint64_t image_size =
|
||||
num_analog_bytes + num_digital_bytes + num_transceiver_bytes;
|
||||
LOG(logDEBUG1) << "Expected image size: " << image_size;
|
||||
return image_size;
|
||||
}
|
||||
|
||||
void test_ctb_acquire_with_receiver(const testCtbAcquireInfo &test_info,
|
||||
int64_t num_frames_to_acquire,
|
||||
Detector &det, Caller &caller) {
|
||||
|
||||
// save previous state
|
||||
testFileInfo prev_file_info = get_file_state(det);
|
||||
testCommonDetAcquireInfo prev_det_config_info =
|
||||
// overwrite exptime if not using virtual ctb server
|
||||
get_common_acquire_config_state(det);
|
||||
testCtbAcquireInfo prev_ctb_config_info = get_ctb_config_state(det);
|
||||
|
||||
// defaults
|
||||
testFileInfo test_file_info;
|
||||
set_file_state(det, test_file_info);
|
||||
testCommonDetAcquireInfo det_config;
|
||||
det_config.num_frames_to_acquire = num_frames_to_acquire;
|
||||
set_common_acquire_config_state(det, det_config);
|
||||
|
||||
// set ctb config
|
||||
set_ctb_config_state(det, test_info);
|
||||
|
||||
// acquire
|
||||
REQUIRE_NOTHROW(test_acquire_with_receiver(caller, det));
|
||||
|
||||
// check frames caught
|
||||
REQUIRE_NOTHROW(test_frames_caught(det, num_frames_to_acquire));
|
||||
|
||||
// check file size (assuming local pc)
|
||||
uint64_t expected_image_size = calculate_ctb_image_size(test_info);
|
||||
REQUIRE_NOTHROW(test_acquire_binary_file_size(
|
||||
test_file_info, num_frames_to_acquire, expected_image_size));
|
||||
|
||||
// restore previous state
|
||||
set_file_state(det, prev_file_info);
|
||||
set_common_acquire_config_state(det, prev_det_config_info);
|
||||
set_ctb_config_state(det, prev_ctb_config_info);
|
||||
}
|
||||
|
||||
} // namespace sls
|
||||
|
@ -1,9 +1,46 @@
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-other
|
||||
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||
#pragma once
|
||||
|
||||
class Caller;
|
||||
#include "sls/Detector.h"
|
||||
#include "sls/sls_detector_defs.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#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};
|
||||
};
|
||||
|
||||
struct testCommonDetAcquireInfo {
|
||||
slsDetectorDefs::timingMode timing_mode{slsDetectorDefs::AUTO_TIMING};
|
||||
int64_t num_frames_to_acquire{2};
|
||||
int64_t num_triggers{1};
|
||||
std::chrono::nanoseconds period{std::chrono::milliseconds{2}};
|
||||
};
|
||||
|
||||
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};
|
||||
};
|
||||
|
||||
void test_valid_port_caller(const std::string &command,
|
||||
const std::vector<std::string> &arguments,
|
||||
int detector_id, int action);
|
||||
@ -13,4 +50,26 @@ 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,
|
||||
uint64_t num_frames_to_acquire,
|
||||
uint64_t expected_image_size);
|
||||
|
||||
void test_frames_caught(const Detector &det, int num_frames_to_acquire);
|
||||
|
||||
void test_acquire_with_receiver(Caller &caller, const Detector &det);
|
||||
|
||||
testCommonDetAcquireInfo get_common_acquire_config_state(const Detector &det);
|
||||
void set_common_acquire_config_state(
|
||||
Detector &det, const testCommonDetAcquireInfo &det_config_info);
|
||||
|
||||
testCtbAcquireInfo get_ctb_config_state(const Detector &det);
|
||||
void set_ctb_config_state(Detector &det,
|
||||
const testCtbAcquireInfo &ctb_config_info);
|
||||
uint64_t calculate_ctb_image_size(const testCtbAcquireInfo &test_info);
|
||||
void test_ctb_acquire_with_receiver(const testCtbAcquireInfo &test_info,
|
||||
int64_t num_frames_to_acquire,
|
||||
Detector &det, Caller &caller);
|
||||
|
||||
} // namespace sls
|
||||
|
@ -17,6 +17,69 @@ namespace sls {
|
||||
using test::GET;
|
||||
using test::PUT;
|
||||
|
||||
TEST_CASE("gotthard2_acquire_check_file_size", "[.cmdcall]") {
|
||||
Detector det;
|
||||
Caller caller(&det);
|
||||
auto det_type =
|
||||
det.getDetectorType().tsquash("Inconsistent detector types to test");
|
||||
|
||||
if (det_type == defs::GOTTHARD2) {
|
||||
|
||||
// save previous state
|
||||
testFileInfo prev_file_info = get_file_state(det);
|
||||
testCommonDetAcquireInfo prev_det_config_info =
|
||||
get_common_acquire_config_state(det);
|
||||
|
||||
// save previous specific det type config
|
||||
auto exptime = det.getExptime().tsquash("inconsistent exptime to test");
|
||||
auto burst_mode =
|
||||
det.getBurstMode().tsquash("inconsistent burst mode to test");
|
||||
auto number_of_bursts = det.getNumberOfBursts().tsquash(
|
||||
"inconsistent number of bursts to test");
|
||||
auto burst_period =
|
||||
det.getBurstPeriod().tsquash("inconsistent burst period to test");
|
||||
|
||||
// defaults
|
||||
int num_frames_to_acquire = 2;
|
||||
testFileInfo test_file_info;
|
||||
set_file_state(det, test_file_info);
|
||||
testCommonDetAcquireInfo det_config;
|
||||
det_config.num_frames_to_acquire = num_frames_to_acquire;
|
||||
set_common_acquire_config_state(det, det_config);
|
||||
|
||||
// set default specific det type config
|
||||
det.setExptime(std::chrono::microseconds{200});
|
||||
det.setBurstMode(defs::CONTINUOUS_EXTERNAL);
|
||||
det.setNumberOfBursts(1);
|
||||
det.setBurstPeriod(std::chrono::milliseconds{0});
|
||||
|
||||
// acquire
|
||||
test_acquire_with_receiver(caller, det);
|
||||
|
||||
// check frames caught
|
||||
test_frames_caught(det, num_frames_to_acquire);
|
||||
|
||||
// check file size (assuming local pc)
|
||||
{
|
||||
detParameters par(det_type);
|
||||
int bytes_per_pixel = det.getDynamicRange().squash() / 8;
|
||||
size_t expected_image_size =
|
||||
par.nChanX * par.nChipX * bytes_per_pixel;
|
||||
test_acquire_binary_file_size(test_file_info, num_frames_to_acquire,
|
||||
expected_image_size);
|
||||
}
|
||||
// restore previous state
|
||||
set_file_state(det, prev_file_info);
|
||||
set_common_acquire_config_state(det, prev_det_config_info);
|
||||
|
||||
// restore previous specific det type config
|
||||
det.setExptime(exptime);
|
||||
det.setBurstMode(burst_mode);
|
||||
det.setNumberOfBursts(number_of_bursts);
|
||||
det.setBurstPeriod(burst_period);
|
||||
}
|
||||
}
|
||||
|
||||
// time specific measurements for gotthard2
|
||||
TEST_CASE("timegotthard2", "[.cmdcall]") {
|
||||
Detector det;
|
||||
|
@ -15,6 +15,65 @@ namespace sls {
|
||||
using test::GET;
|
||||
using test::PUT;
|
||||
|
||||
TEST_CASE("jungfrau_acquire_check_file_size", "[.cmdcall]") {
|
||||
Detector det;
|
||||
Caller caller(&det);
|
||||
auto det_type =
|
||||
det.getDetectorType().tsquash("Inconsistent detector types to test");
|
||||
|
||||
if (det_type == defs::JUNGFRAU) {
|
||||
|
||||
// save previous state
|
||||
testFileInfo prev_file_info = get_file_state(det);
|
||||
testCommonDetAcquireInfo prev_det_config_info =
|
||||
get_common_acquire_config_state(det);
|
||||
|
||||
// save previous specific det type config
|
||||
auto exptime = det.getExptime().tsquash("inconsistent exptime to test");
|
||||
auto num_udp_interfaces = det.getNumberofUDPInterfaces().tsquash(
|
||||
"inconsistent number of udp interfaces");
|
||||
auto n_rows =
|
||||
det.getReadNRows().tsquash("inconsistent number of rows to test");
|
||||
|
||||
// defaults
|
||||
int num_frames_to_acquire = 2;
|
||||
testFileInfo test_file_info;
|
||||
set_file_state(det, test_file_info);
|
||||
testCommonDetAcquireInfo det_config;
|
||||
det_config.num_frames_to_acquire = num_frames_to_acquire;
|
||||
set_common_acquire_config_state(det, det_config);
|
||||
|
||||
// set default specific det type config
|
||||
det.setExptime(std::chrono::microseconds{200});
|
||||
det.setReadNRows(512);
|
||||
|
||||
// acquire
|
||||
test_acquire_with_receiver(caller, det);
|
||||
|
||||
// check frames caught
|
||||
test_frames_caught(det, num_frames_to_acquire);
|
||||
|
||||
// check file size (assuming local pc)
|
||||
{
|
||||
detParameters par(det_type);
|
||||
int bytes_per_pixel = det.getDynamicRange().squash() / 8;
|
||||
// if 2 udp interfaces, data split into half
|
||||
size_t expected_image_size = (par.nChanX * par.nChanY * par.nChipX *
|
||||
par.nChipY * bytes_per_pixel) /
|
||||
num_udp_interfaces;
|
||||
test_acquire_binary_file_size(test_file_info, num_frames_to_acquire,
|
||||
expected_image_size);
|
||||
}
|
||||
// restore previous state
|
||||
set_file_state(det, prev_file_info);
|
||||
set_common_acquire_config_state(det, prev_det_config_info);
|
||||
|
||||
// restore previous specific det type config
|
||||
det.setExptime(exptime);
|
||||
det.setReadNRows(n_rows);
|
||||
}
|
||||
}
|
||||
|
||||
/* dacs */
|
||||
|
||||
TEST_CASE("Setting and reading back Jungfrau dacs", "[.cmdcall][.dacs]") {
|
||||
|
@ -15,6 +15,66 @@ namespace sls {
|
||||
using test::GET;
|
||||
using test::PUT;
|
||||
|
||||
TEST_CASE("moench_acquire_check_file_size", "[.cmdcall]") {
|
||||
Detector det;
|
||||
Caller caller(&det);
|
||||
auto det_type =
|
||||
det.getDetectorType().tsquash("Inconsistent detector types to test");
|
||||
|
||||
if (det_type == defs::MOENCH) {
|
||||
|
||||
// save previous state
|
||||
testFileInfo prev_file_info = get_file_state(det);
|
||||
testCommonDetAcquireInfo prev_det_config_info =
|
||||
get_common_acquire_config_state(det);
|
||||
|
||||
// save previous specific det type config
|
||||
auto exptime = det.getExptime().tsquash("inconsistent exptime to test");
|
||||
auto num_udp_interfaces = det.getNumberofUDPInterfaces().tsquash(
|
||||
"inconsistent number of udp interfaces");
|
||||
auto n_rows =
|
||||
det.getReadNRows().tsquash("inconsistent number of rows to test");
|
||||
|
||||
// defaults
|
||||
int num_frames_to_acquire = 2;
|
||||
testFileInfo test_file_info;
|
||||
set_file_state(det, test_file_info);
|
||||
testCommonDetAcquireInfo det_config;
|
||||
det_config.num_frames_to_acquire = num_frames_to_acquire;
|
||||
set_common_acquire_config_state(det, det_config);
|
||||
|
||||
// set default specific det type config
|
||||
det.setExptime(std::chrono::microseconds{200});
|
||||
det.setReadNRows(400);
|
||||
|
||||
// acquire
|
||||
test_acquire_with_receiver(caller, det);
|
||||
|
||||
// check frames caught
|
||||
test_frames_caught(det, num_frames_to_acquire);
|
||||
|
||||
// check file size (assuming local pc)
|
||||
{
|
||||
detParameters par(det_type);
|
||||
int bytes_per_pixel = det.getDynamicRange().squash() / 8;
|
||||
// if 2 udp interfaces, data split into half
|
||||
size_t expected_image_size = (par.nChanX * par.nChanY * par.nChipX *
|
||||
par.nChipY * bytes_per_pixel) /
|
||||
num_udp_interfaces;
|
||||
test_acquire_binary_file_size(test_file_info, num_frames_to_acquire,
|
||||
expected_image_size);
|
||||
}
|
||||
|
||||
// restore previous state
|
||||
set_file_state(det, prev_file_info);
|
||||
set_common_acquire_config_state(det, prev_det_config_info);
|
||||
|
||||
// restore previous specific det type config
|
||||
det.setExptime(exptime);
|
||||
det.setReadNRows(n_rows);
|
||||
}
|
||||
}
|
||||
|
||||
/* dacs */
|
||||
|
||||
TEST_CASE("Setting and reading back moench dacs", "[.cmdcall][.dacs]") {
|
||||
|
@ -17,6 +17,74 @@ namespace sls {
|
||||
using test::GET;
|
||||
using test::PUT;
|
||||
|
||||
TEST_CASE("mythen3_acquire_check_file_size", "[.cmdcall]") {
|
||||
Detector det;
|
||||
Caller caller(&det);
|
||||
auto det_type =
|
||||
det.getDetectorType().tsquash("Inconsistent detector types to test");
|
||||
|
||||
if (det_type == defs::MYTHEN3) {
|
||||
|
||||
// save previous state
|
||||
testFileInfo prev_file_info = get_file_state(det);
|
||||
testCommonDetAcquireInfo prev_det_config_info =
|
||||
get_common_acquire_config_state(det);
|
||||
|
||||
// save previous specific det type config
|
||||
auto exptime =
|
||||
det.getExptimeForAllGates().tsquash("inconsistent exptime to test");
|
||||
auto dynamic_range =
|
||||
det.getDynamicRange().tsquash("inconsistent dynamic range to test");
|
||||
uint32_t counter_mask =
|
||||
det.getCounterMask().tsquash("inconsistent counter mask to test");
|
||||
|
||||
// defaults
|
||||
int num_frames_to_acquire = 2;
|
||||
testFileInfo test_file_info;
|
||||
set_file_state(det, test_file_info);
|
||||
testCommonDetAcquireInfo det_config;
|
||||
det_config.num_frames_to_acquire = num_frames_to_acquire;
|
||||
set_common_acquire_config_state(det, det_config);
|
||||
|
||||
// set default specific det type config
|
||||
det.setExptime(-1, std::chrono::microseconds{200});
|
||||
int test_dynamic_range = 16;
|
||||
det.setDynamicRange(test_dynamic_range);
|
||||
int test_counter_mask = 0x3;
|
||||
int num_counters = __builtin_popcount(test_counter_mask);
|
||||
det.setCounterMask(test_counter_mask);
|
||||
|
||||
// acquire
|
||||
test_acquire_with_receiver(caller, det);
|
||||
|
||||
// check frames caught
|
||||
test_frames_caught(det, num_frames_to_acquire);
|
||||
|
||||
// check file size (assuming local pc)
|
||||
{
|
||||
detParameters par(det_type);
|
||||
int bytes_per_pixel = test_dynamic_range / 8;
|
||||
int num_channels_per_counter = par.nChanX / 3;
|
||||
size_t expected_image_size = num_channels_per_counter *
|
||||
num_counters * par.nChipX *
|
||||
bytes_per_pixel;
|
||||
test_acquire_binary_file_size(test_file_info, num_frames_to_acquire,
|
||||
expected_image_size);
|
||||
}
|
||||
|
||||
// restore previous state
|
||||
set_file_state(det, prev_file_info);
|
||||
set_common_acquire_config_state(det, prev_det_config_info);
|
||||
|
||||
// restore previous specific det type config
|
||||
for (int iGate = 0; iGate < 3; ++iGate) {
|
||||
det.setExptime(iGate, exptime[iGate]);
|
||||
}
|
||||
det.setDynamicRange(dynamic_range);
|
||||
det.setCounterMask(counter_mask);
|
||||
}
|
||||
}
|
||||
|
||||
/* dacs */
|
||||
|
||||
TEST_CASE("Setting and reading back MYTHEN3 dacs", "[.cmdcall][.dacs]") {
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <thread>
|
||||
|
||||
#include "tests/globals.h"
|
||||
#include <filesystem>
|
||||
|
||||
namespace sls {
|
||||
|
||||
|
@ -679,11 +679,11 @@ void DataProcessor::ArrangeDbitData(size_t &size, char *data) {
|
||||
memcpy(data + nAnalogDataBytes, result.data(),
|
||||
totalNumBytes * sizeof(uint8_t));
|
||||
|
||||
LOG(logDEBUG1) << "totalNumBytes: " << totalNumBytes
|
||||
LOG(logDEBUG1) << "nDigitalDataBytes: " << totalNumBytes
|
||||
<< " nAnalogDataBytes:" << nAnalogDataBytes
|
||||
<< " ctbDbitOffset:" << ctbDbitOffset
|
||||
<< " nTransceiverDataBytes:" << nTransceiverDataBytes
|
||||
<< " size:" << size;
|
||||
<< " toal size:" << size;
|
||||
}
|
||||
|
||||
void DataProcessor::CropImage(size_t &size, char *data) {
|
||||
|
@ -6,7 +6,7 @@ This file is used to start up simulators, receivers and run all the tests on the
|
||||
import argparse
|
||||
import os, sys, subprocess, time, colorama
|
||||
|
||||
from colorama import Fore
|
||||
from colorama import Fore, Style
|
||||
from slsdet import Detector, detectorType, detectorSettings
|
||||
from slsdet.defines import DEFAULT_TCP_CNTRL_PORTNO, DEFAULT_TCP_RX_PORTNO, DEFAULT_UDP_DST_PORTNO
|
||||
HALFMOD2_TCP_CNTRL_PORTNO=1955
|
||||
@ -14,48 +14,41 @@ HALFMOD2_TCP_RX_PORTNO=1957
|
||||
|
||||
colorama.init(autoreset=True)
|
||||
|
||||
def Log(color, message):
|
||||
print(f"{color}{message}{Style.RESET_ALL}", flush=True)
|
||||
|
||||
class RuntimeException (Exception):
|
||||
def __init__ (self, message):
|
||||
super().__init__(Fore.RED + message)
|
||||
super().__init__(Log(Fore.RED, message))
|
||||
|
||||
def Log(color, message):
|
||||
print('\n' + color + message, flush=True)
|
||||
|
||||
|
||||
def checkIfProcessRunning(processName):
|
||||
cmd = f"pgrep -f {processName}"
|
||||
res = subprocess.getoutput(cmd)
|
||||
return bool(res.strip())
|
||||
return res.strip().splitlines()
|
||||
|
||||
|
||||
def killProcess(name):
|
||||
if checkIfProcessRunning(name):
|
||||
Log(Fore.GREEN, 'killing ' + name)
|
||||
p = subprocess.run(['killall', name])
|
||||
if p.returncode != 0:
|
||||
raise RuntimeException('killall failed for ' + name)
|
||||
else:
|
||||
print('process not running : ' + name)
|
||||
pids = checkIfProcessRunning(name)
|
||||
if pids:
|
||||
Log(Fore.GREEN, f"Killing '{name}' processes with PIDs: {', '.join(pids)}")
|
||||
for pid in pids:
|
||||
try:
|
||||
p = subprocess.run(['kill', pid])
|
||||
if p.returncode != 0 and bool(checkIfProcessRunning(name)):
|
||||
raise RuntimeException(f"Could not kill {name} with pid {pid}")
|
||||
except Exception as e:
|
||||
Log(Fore.RED, f"Failed to kill process {name} pid:{pid}. Exception occured: [code:{e}, msg:{e.stderr}]")
|
||||
raise
|
||||
#else:
|
||||
# Log(Fore.WHITE, 'process not running : ' + name)
|
||||
|
||||
|
||||
def killAllStaleProcesses(fp):
|
||||
killProcess('eigerDetectorServer_virtual')
|
||||
killProcess('jungfrauDetectorServer_virtual')
|
||||
killProcess('mythen3DetectorServer_virtual')
|
||||
killProcess('gotthard2DetectorServer_virtual')
|
||||
killProcess('ctbDetectorServer_virtual')
|
||||
killProcess('moenchDetectorServer_virtual')
|
||||
killProcess('xilinx_ctbDetectorServer_virtual')
|
||||
killProcess('slsReceiver')
|
||||
killProcess('slsMultiReceiver')
|
||||
cleanSharedmemory(fp)
|
||||
|
||||
def cleanup(name, fp):
|
||||
def cleanup(fp):
|
||||
'''
|
||||
kill both servers, receivers and clean shared memory
|
||||
'''
|
||||
Log(Fore.GREEN, 'Cleaning up...')
|
||||
killProcess(name + 'DetectorServer_virtual')
|
||||
killProcess('DetectorServer_virtual')
|
||||
killProcess('slsReceiver')
|
||||
killProcess('slsMultiReceiver')
|
||||
cleanSharedmemory(fp)
|
||||
@ -184,7 +177,7 @@ else:
|
||||
servers = args.servers
|
||||
|
||||
|
||||
Log(Fore.WHITE, 'Arguments:\nrx_hostname: ' + args.rx_hostname + '\nsettingspath: \'' + args.settingspath + '\'')
|
||||
Log(Fore.WHITE, 'Arguments:\nrx_hostname: ' + args.rx_hostname + '\nsettingspath: \'' + args.settingspath + '\nservers: \'' + ' '.join(servers) + '\'')
|
||||
|
||||
|
||||
# redirect to file
|
||||
@ -207,7 +200,7 @@ with open(fname, 'w') as fp:
|
||||
|
||||
try:
|
||||
startGeneralTests(fp, file_results)
|
||||
killAllStaleProcesses(fp)
|
||||
cleanup(fp)
|
||||
|
||||
testError = False
|
||||
for server in servers:
|
||||
@ -222,12 +215,12 @@ with open(fname, 'w') as fp:
|
||||
Log(Fore.BLUE, 'Cmd tests for ' + server + ' (results: ' + file_results + ')')
|
||||
|
||||
# cmd tests for det
|
||||
cleanup(server, fp)
|
||||
cleanup(fp)
|
||||
startServer(server)
|
||||
startReceiver(server)
|
||||
loadConfig(server, args.rx_hostname, args.settingspath)
|
||||
startCmdTests(server, fp, file_results)
|
||||
cleanup(server, fp)
|
||||
cleanup(fp)
|
||||
|
||||
except Exception as e:
|
||||
# redirect to terminal
|
||||
|
Loading…
x
Reference in New Issue
Block a user