From adf0124ea34cd297b874f906fb72d1c7b4674313 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 29 Apr 2025 17:35:55 +0200 Subject: [PATCH 01/17] rough draft of test acquire of all detectors for frames caught and file size. ctb not included yet --- .../tests/Caller/test-Caller.cpp | 169 ++++++++++++++++++ 1 file changed, 169 insertions(+) diff --git a/slsDetectorSoftware/tests/Caller/test-Caller.cpp b/slsDetectorSoftware/tests/Caller/test-Caller.cpp index ae21ed945..469b042ab 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller.cpp @@ -12,6 +12,7 @@ #include #include "tests/globals.h" +#include namespace sls { @@ -3608,4 +3609,172 @@ TEST_CASE("sleep", "[.cmdcall]") { REQUIRE_THROWS(caller.call("sleep", {}, -1, GET)); } +TEST_CASE("acquire_check_file_size", "[.cmdcall]") { + Detector det; + Caller caller(&det); + auto det_type = + det.getDetectorType().tsquash("Inconsistent detector types to test"); + + // save previous file state + auto file_write = + det.getFileWrite().tsquash("Inconsistent file write state"); + auto file_overwrite = + det.getFileOverWrite().tsquash("Inconsistent file overwrite state"); + auto file_format = det.getFileFormat().tsquash("Inconsistent file format"); + auto file_path = det.getFilePath().tsquash("Inconsistent file path"); + auto file_prefix = + det.getFileNamePrefix().tsquash("Inconsistent file prefix"); + auto file_acq_index = det.getAcquisitionIndex().tsquash( + "Inconsistent file acquisition index"); + // save previous det config state + auto timing_mode = det.getTimingMode().tsquash("Inconsistent timing mode"); + auto num_frames = + det.getNumberOfFrames().tsquash("Inconsistent number of frames"); + auto num_triggers = + det.getNumberOfTriggers().tsquash("Inconsistent number of triggers"); + auto period = det.getPeriod().tsquash("Inconsistent period"); + std::array exptime{}; + if (det_type != defs::MYTHEN3) { + exptime[0] = det.getExptime().tsquash("inconsistent exptime to test"); + } else { + exptime = + det.getExptimeForAllGates().tsquash("inconsistent exptime to test"); + } + // save previous specific det type config + auto num_udp_interfaces = det.getNumberofUDPInterfaces().tsquash( + "inconsistent number of udp interfaces"); + auto n_rows = 0; + if (det_type == defs::EIGER || det_type == defs::JUNGFRAU || + det_type == defs::MOENCH) { + n_rows = + det.getReadNRows().tsquash("inconsistent number of rows to test"); + } + auto dynamic_range = + det.getDynamicRange().tsquash("inconsistent dynamic range to test"); + + uint32_t counter_mask = 0; + if (det_type == defs::MYTHEN3) { + counter_mask = + det.getCounterMask().tsquash("inconsistent counter mask to test"); + } + int num_counters = __builtin_popcount(counter_mask); + + // defaults + int num_frames_to_acquire = 2; + int bytes_per_pixel = 2; + + // set default file state + det.setFileWrite(true); + det.setFileOverWrite(true); + det.setFileFormat(defs::BINARY); + det.setFilePath("/tmp"); + det.setFileNamePrefix("sls_test"); + det.setAcquisitionIndex(0); + // set default det config state + det.setTimingMode(defs::AUTO_TIMING); + det.setNumberOfFrames(num_frames_to_acquire); + det.setNumberOfTriggers(1); + det.setPeriod(std::chrono::milliseconds{2}); + det.setExptime(-1, std::chrono::microseconds{200}); + // set default specific det type config + if (det_type == defs::EIGER) { + det.setReadNRows(256); + } else if (det_type == defs::JUNGFRAU) { + det.setReadNRows(512); + } else if (det_type == defs::MOENCH) { + det.setReadNRows(400); + } + if (det_type == defs::EIGER || det_type == defs::MYTHEN3) { + det.setDynamicRange(bytes_per_pixel * 8); + } + if (det_type == defs::MYTHEN3) { + det.setCounterMask(0x1); + } + + // acquire + REQUIRE_NOTHROW(caller.call("rx_start", {}, -1, PUT)); + REQUIRE_NOTHROW(caller.call("start", {}, -1, PUT)); + std::this_thread::sleep_for(std::chrono::seconds{1}); + REQUIRE_NOTHROW(caller.call("rx_stop", {}, -1, PUT)); + + // check frames caught + auto frames_caught = det.getFramesCaught().tsquash( + "Inconsistent number of frames caught")[0]; + REQUIRE(frames_caught == num_frames_to_acquire); + + // check file size (assuming local pc) + size_t expected_image_size = 0; + switch (det_type) { + case defs::EIGER: + // pixels_row_per_chip * pixels_col_per_chip * num_chips * + // bytes_per_pixel + expected_image_size = 256 * 256 * 2 * bytes_per_pixel; + break; + case defs::JUNGFRAU: + // pixels_row_per_chip * pixels_col_per_chip * num_chips * + // bytes_per_pixel + if (num_udp_interfaces == 1) { + expected_image_size = 256 * 256 * 8 * bytes_per_pixel; + } else { + expected_image_size = 256 * 256 * 4 * bytes_per_pixel; + } + break; + case defs::MOENCH: + // pixels_row * pixels_col * bytes_per_pixel + if (num_udp_interfaces == 1) { + expected_image_size = 400 * 400 * bytes_per_pixel; + } else { + expected_image_size = 200 * 400 * bytes_per_pixel; + } + break; + case defs::GOTTHARD2: + // num_channels * num_chips + expected_image_size = 128 * 10 * bytes_per_pixel; + break; + case defs::MYTHEN3: + // num_channels * num_chips * num_counters + expected_image_size = 128 * 10 * num_counters * bytes_per_pixel; + break; + // to include ctb and xilinx_ctb + default: + break; + } + size_t expected_file_size = + num_frames_to_acquire * + (expected_image_size + sizeof(defs::sls_receiver_header)); + std::string fname = file_path + "/" + file_prefix + "f0_" + + std::to_string(file_acq_index) + ".raw"; + auto actual_file_size = std::filesystem::file_size(fname); + REQUIRE(actual_file_size == expected_file_size); + + // restore to previous file state + det.setFileWrite(file_write); + det.setFileOverWrite(file_overwrite); + det.setFileFormat(file_format); + det.setFilePath(file_path); + det.setFileNamePrefix(file_prefix); + det.setAcquisitionIndex(file_acq_index); + // restore to previous det config state + det.setTimingMode(timing_mode); + det.setNumberOfFrames(num_frames); + det.setNumberOfTriggers(num_triggers); + det.setPeriod(period); + if (det_type != defs::MYTHEN3) { + det.setExptime(exptime[0]); + } else { + for (int iGate = 0; iGate < 3; ++iGate) { + det.setExptime(iGate, exptime[iGate]); + } + } + // restore previous specific det type config + if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) { + det.setNumberofUDPInterfaces(num_udp_interfaces); + } + if (det_type == defs::EIGER || det_type == defs::MYTHEN3) { + det.setDynamicRange(dynamic_range); + } + if (det_type == defs::MYTHEN3) { + det.setCounterMask(counter_mask); + } + } // namespace sls \ No newline at end of file From f09879a46c06435f637c3b9d2013bd42fec1f826 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Wed, 30 Apr 2025 15:00:00 +0200 Subject: [PATCH 02/17] added tests to check file size and frames caught with an acquire (virtual) for every detector --- .../Caller/test-Caller-chiptestboard.cpp | 251 ++++++++++++++++++ .../tests/Caller/test-Caller-eiger.cpp | 56 ++++ .../tests/Caller/test-Caller-global.cpp | 87 ++++++ .../tests/Caller/test-Caller-global.h | 40 +++ .../tests/Caller/test-Caller-gotthard2.cpp | 57 ++++ .../tests/Caller/test-Caller-jungfrau.cpp | 57 ++++ .../tests/Caller/test-Caller-moench.cpp | 56 ++++ .../tests/Caller/test-Caller-mythen3.cpp | 55 ++++ .../tests/Caller/test-Caller.cpp | 168 ------------ slsReceiverSoftware/src/DataProcessor.cpp | 13 +- 10 files changed, 667 insertions(+), 173 deletions(-) diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp index fe30c9d2d..2bba9b474 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp @@ -17,6 +17,257 @@ namespace sls { using test::GET; using test::PUT; +struct testCtbAcquireInfo { + defs::readoutMode readout_mode{defs::ANALOG_AND_DIGITAL}; + bool teng_giga{false}; + int num_adc_samples{5000}; + int num_dbit_samples{6000}; + int num_trans_samples{288}; + uint32_t adc_enable_1g{0xFFFFFFFF}; + uint32_t adc_enable_10g{0xFFFFFFFF}; + int dbit_offset{0}; + std::vector dbit_list{0, 12, 2, 43}; + bool dbit_reorder{false}; + uint32_t transceiver_mask{0x3}; +}; + +testCtbAcquireInfo get_ctb_config_state(const Detector &det) { + return testCtbAcquireInfo{ + det.getReadoutMode().tsquash("inconsistent readout mode to test"), + det.getTenGiga().tsquash("inconsistent ten giga enable to test"), + 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"), + det.getADCEnableMask().tsquash("inconsistent adc enable mask to test"), + 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")}; +} + +void set_ctb_config_state(Detector &det, + const testCtbAcquireInfo &ctb_config_info) { + det.setReadoutMode(ctb_config_info.readout_mode); + det.setTenGiga(ctb_config_info.teng_giga); + 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.setADCEnableMask(ctb_config_info.adc_enable_1g); + 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); +} + +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 + test_acquire_with_receiver(caller, std::chrono::seconds{2}); + + // check frames caught + test_frames_caught(det, num_frames_to_acquire); + + // calculate image size + 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.teng_giga ? test_info.adc_enable_1g + : test_info.adc_enable_10g); + 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; + std::cout << "[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); + } + std::cout << "[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; + std::cout << "[Transceiver Databytes: " << num_transceiver_bytes << ']'; + } + std::cout << std::endl; + // check file size (assuming local pc) + uint64_t expected_image_size = + num_analog_bytes + num_digital_bytes + num_transceiver_bytes; + std::cout << "Expected image size: " << expected_image_size << std::endl; + 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); +} + +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; + set_ctb_config_state(det, test_ctb_config); + 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; + set_ctb_config_state(det, test_ctb_config); + 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; + set_ctb_config_state(det, test_ctb_config); + 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; + set_ctb_config_state(det, test_ctb_config); + 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(); + set_ctb_config_state(det, test_ctb_config); + 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; + set_ctb_config_state(det, test_ctb_config); + 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; + set_ctb_config_state(det, test_ctb_config); + 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; + set_ctb_config_state(det, test_ctb_config); + 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(); + set_ctb_config_state(det, test_ctb_config); + 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(); + set_ctb_config_state(det, test_ctb_config); + 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; + set_ctb_config_state(det, test_ctb_config); + test_ctb_acquire_with_receiver(test_ctb_config, + num_frames_to_acquire, det, caller); + } + } +} + /* dacs */ TEST_CASE("dacname", "[.cmdcall]") { diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-eiger.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-eiger.cpp index ae6a6c824..b59083add 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-eiger.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-eiger.cpp @@ -17,6 +17,62 @@ 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 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.setReadNRows(256); + det.setDynamicRange(16); + + // acquire + test_acquire_with_receiver(caller, std::chrono::seconds{2}); + + // check frames caught + test_frames_caught(det, num_frames_to_acquire); + + // check file size (assuming local pc) + // pixels_row_per_chip * pixels_col_per_chip * num_chips * + // bytes_per_pixel + size_t expected_image_size = 256 * 256 * 2 * 2; + 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.setReadNRows(n_rows); + det.setDynamicRange(dynamic_range); + } +} + /** temperature */ TEST_CASE("temp_fpgaext", "[.cmdcall]") { diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-global.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-global.cpp index 7900f3340..84e65656e 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-global.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-global.cpp @@ -88,4 +88,91 @@ 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)); + std::cout << "exepected file size: " << expected_file_size + << " receiver header size :" << sizeof(defs::sls_receiver_header) + << " num frames:" << num_frames_to_acquire << std::endl; + 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, std::chrono::seconds timeout) { + REQUIRE_NOTHROW(caller.call("rx_start", {}, -1, PUT)); + REQUIRE_NOTHROW(caller.call("start", {}, -1, PUT)); + std::this_thread::sleep_for(timeout); + REQUIRE_NOTHROW(caller.call("rx_stop", {}, -1, PUT)); +} + +testCommonDetAcquireInfo get_common_acquire_config_state(const Detector &det) { + testCommonDetAcquireInfo det_config_info{ + 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"), + {}}; + auto det_type = + det.getDetectorType().tsquash("Inconsistent detector types to test"); + if (det_type != defs::MYTHEN3) { + det_config_info.exptime[0] = + det.getExptime().tsquash("inconsistent exptime to test"); + } else { + det_config_info.exptime = + det.getExptimeForAllGates().tsquash("inconsistent exptime to test"); + } + return det_config_info; +} + +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); + auto det_type = + det.getDetectorType().tsquash("Inconsistent detector types to test"); + if (det_type != defs::MYTHEN3) { + det.setExptime(det_config_info.exptime[0]); + } else { + for (int iGate = 0; iGate < 3; ++iGate) { + det.setExptime(iGate, det_config_info.exptime[iGate]); + } + } +} + } // namespace sls diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-global.h b/slsDetectorSoftware/tests/Caller/test-Caller-global.h index 98fa46860..d7f777deb 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-global.h +++ b/slsDetectorSoftware/tests/Caller/test-Caller-global.h @@ -1,9 +1,35 @@ // 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 +#include +#include + 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}}; + std::array exptime{ + std::chrono::microseconds{200}, std::chrono::nanoseconds{0}, + std::chrono::nanoseconds{0}}; +}; + void test_valid_port_caller(const std::string &command, const std::vector &arguments, int detector_id, int action); @@ -13,4 +39,18 @@ 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, std::chrono::seconds timeout); + +testCommonDetAcquireInfo get_common_acquire_config_state(const Detector &det); +void set_common_acquire_config_state( + Detector &det, const testCommonDetAcquireInfo &det_config_info); + } // namespace sls diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-gotthard2.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-gotthard2.cpp index 54bba5ce2..a747c46dd 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-gotthard2.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-gotthard2.cpp @@ -17,6 +17,63 @@ 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 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.setBurstMode(defs::CONTINUOUS_EXTERNAL); + det.setNumberOfBursts(1); + det.setBurstPeriod(std::chrono::milliseconds{0}); + + // acquire + test_acquire_with_receiver(caller, std::chrono::seconds{2}); + + // check frames caught + test_frames_caught(det, num_frames_to_acquire); + + // check file size (assuming local pc) + // num_channels * num_chips * bytes_per_pixel * num_frames + size_t expected_image_size = 128 * 10 * 2; + 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.setBurstMode(burst_mode); + det.setNumberOfBursts(number_of_bursts); + det.setBurstPeriod(burst_period); + } +} + // time specific measurements for gotthard2 TEST_CASE("timegotthard2", "[.cmdcall]") { Detector det; diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-jungfrau.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-jungfrau.cpp index 4563cd32f..413937632 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-jungfrau.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-jungfrau.cpp @@ -15,6 +15,63 @@ 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 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.setReadNRows(512); + + // acquire + test_acquire_with_receiver(caller, std::chrono::seconds{2}); + + // check frames caught + test_frames_caught(det, num_frames_to_acquire); + + // check file size (assuming local pc) + size_t expected_image_size = 0; + // pixels_row_per_chip * pixels_col_per_chip * num_chips * + // bytes_per_pixel + if (num_udp_interfaces == 1) { + expected_image_size = 256 * 256 * 8 * 2; + } else { + expected_image_size = 256 * 256 * 4 * 2; + } + 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.setReadNRows(n_rows); + } +} + /* dacs */ TEST_CASE("Setting and reading back Jungfrau dacs", "[.cmdcall][.dacs]") { diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-moench.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-moench.cpp index 56353f44b..577a2f3b2 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-moench.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-moench.cpp @@ -15,6 +15,62 @@ 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 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.setReadNRows(400); + + // acquire + test_acquire_with_receiver(caller, std::chrono::seconds{2}); + + // check frames caught + test_frames_caught(det, num_frames_to_acquire); + + // check file size (assuming local pc) + size_t expected_image_size = 0; + // pixels_row * pixels_col * bytes_per_pixel + if (num_udp_interfaces == 1) { + expected_image_size = 400 * 400 * 2; + } else { + expected_image_size = 400 * 200 * 2; + } + 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.setReadNRows(n_rows); + } +} + /* dacs */ TEST_CASE("Setting and reading back moench dacs", "[.cmdcall][.dacs]") { diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-mythen3.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-mythen3.cpp index 16295a3e1..598439407 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-mythen3.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-mythen3.cpp @@ -17,6 +17,61 @@ 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 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.setDynamicRange(16); + int test_counter_mask = 0x1; + int num_counters = __builtin_popcount(counter_mask); + det.setCounterMask(test_counter_mask); + + // acquire + test_acquire_with_receiver(caller, std::chrono::seconds{2}); + + // check frames caught + test_frames_caught(det, num_frames_to_acquire); + + // check file size (assuming local pc) + // num_channels * num_chips * num_counters + size_t expected_image_size = 128 * 10 * num_counters * 2; + 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.setDynamicRange(dynamic_range); + det.setCounterMask(counter_mask); + } +} + /* dacs */ TEST_CASE("Setting and reading back MYTHEN3 dacs", "[.cmdcall][.dacs]") { diff --git a/slsDetectorSoftware/tests/Caller/test-Caller.cpp b/slsDetectorSoftware/tests/Caller/test-Caller.cpp index 469b042ab..1ce35b41a 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller.cpp @@ -3609,172 +3609,4 @@ TEST_CASE("sleep", "[.cmdcall]") { REQUIRE_THROWS(caller.call("sleep", {}, -1, GET)); } -TEST_CASE("acquire_check_file_size", "[.cmdcall]") { - Detector det; - Caller caller(&det); - auto det_type = - det.getDetectorType().tsquash("Inconsistent detector types to test"); - - // save previous file state - auto file_write = - det.getFileWrite().tsquash("Inconsistent file write state"); - auto file_overwrite = - det.getFileOverWrite().tsquash("Inconsistent file overwrite state"); - auto file_format = det.getFileFormat().tsquash("Inconsistent file format"); - auto file_path = det.getFilePath().tsquash("Inconsistent file path"); - auto file_prefix = - det.getFileNamePrefix().tsquash("Inconsistent file prefix"); - auto file_acq_index = det.getAcquisitionIndex().tsquash( - "Inconsistent file acquisition index"); - // save previous det config state - auto timing_mode = det.getTimingMode().tsquash("Inconsistent timing mode"); - auto num_frames = - det.getNumberOfFrames().tsquash("Inconsistent number of frames"); - auto num_triggers = - det.getNumberOfTriggers().tsquash("Inconsistent number of triggers"); - auto period = det.getPeriod().tsquash("Inconsistent period"); - std::array exptime{}; - if (det_type != defs::MYTHEN3) { - exptime[0] = det.getExptime().tsquash("inconsistent exptime to test"); - } else { - exptime = - det.getExptimeForAllGates().tsquash("inconsistent exptime to test"); - } - // save previous specific det type config - auto num_udp_interfaces = det.getNumberofUDPInterfaces().tsquash( - "inconsistent number of udp interfaces"); - auto n_rows = 0; - if (det_type == defs::EIGER || det_type == defs::JUNGFRAU || - det_type == defs::MOENCH) { - n_rows = - det.getReadNRows().tsquash("inconsistent number of rows to test"); - } - auto dynamic_range = - det.getDynamicRange().tsquash("inconsistent dynamic range to test"); - - uint32_t counter_mask = 0; - if (det_type == defs::MYTHEN3) { - counter_mask = - det.getCounterMask().tsquash("inconsistent counter mask to test"); - } - int num_counters = __builtin_popcount(counter_mask); - - // defaults - int num_frames_to_acquire = 2; - int bytes_per_pixel = 2; - - // set default file state - det.setFileWrite(true); - det.setFileOverWrite(true); - det.setFileFormat(defs::BINARY); - det.setFilePath("/tmp"); - det.setFileNamePrefix("sls_test"); - det.setAcquisitionIndex(0); - // set default det config state - det.setTimingMode(defs::AUTO_TIMING); - det.setNumberOfFrames(num_frames_to_acquire); - det.setNumberOfTriggers(1); - det.setPeriod(std::chrono::milliseconds{2}); - det.setExptime(-1, std::chrono::microseconds{200}); - // set default specific det type config - if (det_type == defs::EIGER) { - det.setReadNRows(256); - } else if (det_type == defs::JUNGFRAU) { - det.setReadNRows(512); - } else if (det_type == defs::MOENCH) { - det.setReadNRows(400); - } - if (det_type == defs::EIGER || det_type == defs::MYTHEN3) { - det.setDynamicRange(bytes_per_pixel * 8); - } - if (det_type == defs::MYTHEN3) { - det.setCounterMask(0x1); - } - - // acquire - REQUIRE_NOTHROW(caller.call("rx_start", {}, -1, PUT)); - REQUIRE_NOTHROW(caller.call("start", {}, -1, PUT)); - std::this_thread::sleep_for(std::chrono::seconds{1}); - REQUIRE_NOTHROW(caller.call("rx_stop", {}, -1, PUT)); - - // check frames caught - auto frames_caught = det.getFramesCaught().tsquash( - "Inconsistent number of frames caught")[0]; - REQUIRE(frames_caught == num_frames_to_acquire); - - // check file size (assuming local pc) - size_t expected_image_size = 0; - switch (det_type) { - case defs::EIGER: - // pixels_row_per_chip * pixels_col_per_chip * num_chips * - // bytes_per_pixel - expected_image_size = 256 * 256 * 2 * bytes_per_pixel; - break; - case defs::JUNGFRAU: - // pixels_row_per_chip * pixels_col_per_chip * num_chips * - // bytes_per_pixel - if (num_udp_interfaces == 1) { - expected_image_size = 256 * 256 * 8 * bytes_per_pixel; - } else { - expected_image_size = 256 * 256 * 4 * bytes_per_pixel; - } - break; - case defs::MOENCH: - // pixels_row * pixels_col * bytes_per_pixel - if (num_udp_interfaces == 1) { - expected_image_size = 400 * 400 * bytes_per_pixel; - } else { - expected_image_size = 200 * 400 * bytes_per_pixel; - } - break; - case defs::GOTTHARD2: - // num_channels * num_chips - expected_image_size = 128 * 10 * bytes_per_pixel; - break; - case defs::MYTHEN3: - // num_channels * num_chips * num_counters - expected_image_size = 128 * 10 * num_counters * bytes_per_pixel; - break; - // to include ctb and xilinx_ctb - default: - break; - } - size_t expected_file_size = - num_frames_to_acquire * - (expected_image_size + sizeof(defs::sls_receiver_header)); - std::string fname = file_path + "/" + file_prefix + "f0_" + - std::to_string(file_acq_index) + ".raw"; - auto actual_file_size = std::filesystem::file_size(fname); - REQUIRE(actual_file_size == expected_file_size); - - // restore to previous file state - det.setFileWrite(file_write); - det.setFileOverWrite(file_overwrite); - det.setFileFormat(file_format); - det.setFilePath(file_path); - det.setFileNamePrefix(file_prefix); - det.setAcquisitionIndex(file_acq_index); - // restore to previous det config state - det.setTimingMode(timing_mode); - det.setNumberOfFrames(num_frames); - det.setNumberOfTriggers(num_triggers); - det.setPeriod(period); - if (det_type != defs::MYTHEN3) { - det.setExptime(exptime[0]); - } else { - for (int iGate = 0; iGate < 3; ++iGate) { - det.setExptime(iGate, exptime[iGate]); - } - } - // restore previous specific det type config - if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) { - det.setNumberofUDPInterfaces(num_udp_interfaces); - } - if (det_type == defs::EIGER || det_type == defs::MYTHEN3) { - det.setDynamicRange(dynamic_range); - } - if (det_type == defs::MYTHEN3) { - det.setCounterMask(counter_mask); - } - } // namespace sls \ No newline at end of file diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index 1956d3578..71ad69d6c 100644 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -591,6 +591,7 @@ void DataProcessor::ArrangeDbitData(size_t &size, char *data) { // store each selected bit from all samples consecutively if (ctbDbitReorder) { + LOG(logINFORED) << "Reordering digital data"; size_t numBitsPerDbit = numDigitalSamples; // num bits per selected digital // Bit for all samples @@ -605,6 +606,8 @@ void DataProcessor::ArrangeDbitData(size_t &size, char *data) { if ((numBitsPerSample % 8) != 0) numBitsPerSample += (8 - (numBitsPerSample % 8)); totalNumBytes = (numBitsPerSample / 8) * numDigitalSamples; + LOG(logINFORED) << "total numDigital bytes without reorder:" + << totalNumBytes; } std::vector result(totalNumBytes, 0); @@ -677,11 +680,11 @@ void DataProcessor::ArrangeDbitData(size_t &size, char *data) { memcpy(data + nAnalogDataBytes, result.data(), totalNumBytes * sizeof(uint8_t)); - LOG(logDEBUG1) << "totalNumBytes: " << totalNumBytes - << " nAnalogDataBytes:" << nAnalogDataBytes - << " ctbDbitOffset:" << ctbDbitOffset - << " nTransceiverDataBytes:" << nTransceiverDataBytes - << " size:" << size; + LOG(logINFORED) << "totalNumBytes: " << totalNumBytes + << " nAnalogDataBytes:" << nAnalogDataBytes + << " ctbDbitOffset:" << ctbDbitOffset + << " nTransceiverDataBytes:" << nTransceiverDataBytes + << " size:" << size; } void DataProcessor::CropImage(size_t &size, char *data) { From 91f9c4fa836260a979be844ee56b5a04f345589a Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 1 May 2025 11:25:34 +0200 Subject: [PATCH 03/17] minor printout removed --- slsDetectorSoftware/tests/Caller/test-Caller-global.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-global.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-global.cpp index 84e65656e..713e9d5f9 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-global.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-global.cpp @@ -119,9 +119,6 @@ void test_acquire_binary_file_size(const testFileInfo &file_info, uint64_t expected_file_size = num_frames_to_acquire * (expected_image_size + sizeof(defs::sls_receiver_header)); - std::cout << "exepected file size: " << expected_file_size - << " receiver header size :" << sizeof(defs::sls_receiver_header) - << " num frames:" << num_frames_to_acquire << std::endl; auto actual_file_size = std::filesystem::file_size(fname); REQUIRE(actual_file_size == expected_file_size); } From 5a24a79bf758ff8abc164d1bb0e8756b5b73b32e Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 1 May 2025 11:26:38 +0200 Subject: [PATCH 04/17] typo fixed --- .../tests/Caller/test-Caller-chiptestboard.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp index 2bba9b474..f4bc2a1cb 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp @@ -19,7 +19,7 @@ using test::PUT; struct testCtbAcquireInfo { defs::readoutMode readout_mode{defs::ANALOG_AND_DIGITAL}; - bool teng_giga{false}; + bool ten_giga{false}; int num_adc_samples{5000}; int num_dbit_samples{6000}; int num_trans_samples{288}; @@ -54,7 +54,7 @@ testCtbAcquireInfo get_ctb_config_state(const Detector &det) { void set_ctb_config_state(Detector &det, const testCtbAcquireInfo &ctb_config_info) { det.setReadoutMode(ctb_config_info.readout_mode); - det.setTenGiga(ctb_config_info.teng_giga); + det.setTenGiga(ctb_config_info.ten_giga); det.setNumberOfAnalogSamples(ctb_config_info.num_adc_samples); det.setNumberOfDigitalSamples(ctb_config_info.num_dbit_samples); det.setNumberOfTransceiverSamples(ctb_config_info.num_trans_samples); @@ -99,8 +99,8 @@ void test_ctb_acquire_with_receiver(const testCtbAcquireInfo &test_info, if (test_info.readout_mode == defs::ANALOG_ONLY || test_info.readout_mode == defs::ANALOG_AND_DIGITAL) { uint32_t adc_enable_mask = - (test_info.teng_giga ? test_info.adc_enable_1g - : test_info.adc_enable_10g); + (test_info.ten_giga ? test_info.adc_enable_1g + : test_info.adc_enable_10g); int num_analog_chans = __builtin_popcount(adc_enable_mask); const int num_bytes_per_sample = 2; num_analog_bytes = From dca0edcfcc7c1ba1e98e2e4f375312ca7d1de7f4 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 1 May 2025 11:28:19 +0200 Subject: [PATCH 05/17] removed minor printout --- .../tests/Caller/test-Caller-chiptestboard.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp index f4bc2a1cb..c309f3859 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp @@ -105,7 +105,6 @@ void test_ctb_acquire_with_receiver(const testCtbAcquireInfo &test_info, const int num_bytes_per_sample = 2; num_analog_bytes = num_analog_chans * num_bytes_per_sample * test_info.num_adc_samples; - std::cout << "[Analog Databytes: " << num_analog_bytes << ']'; } // digital channels @@ -136,7 +135,6 @@ void test_ctb_acquire_with_receiver(const testCtbAcquireInfo &test_info, } num_digital_bytes = num_digital_chans * (num_bits_per_bit / 8); } - std::cout << "[Digital Databytes: " << num_digital_bytes << ']'; } // transceiver channels if (test_info.readout_mode == defs::TRANSCEIVER_ONLY || @@ -146,13 +144,10 @@ void test_ctb_acquire_with_receiver(const testCtbAcquireInfo &test_info, const int num_bytes_per_channel = 8; num_transceiver_bytes = num_transceiver_chans * num_bytes_per_channel * test_info.num_trans_samples; - std::cout << "[Transceiver Databytes: " << num_transceiver_bytes << ']'; } - std::cout << std::endl; // check file size (assuming local pc) uint64_t expected_image_size = num_analog_bytes + num_digital_bytes + num_transceiver_bytes; - std::cout << "Expected image size: " << expected_image_size << std::endl; test_acquire_binary_file_size(test_file_info, num_frames_to_acquire, expected_image_size); From d4a1044fce8bb8b0748971e3fe8dd92abed4fbbf Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 1 May 2025 12:08:29 +0200 Subject: [PATCH 06/17] incorrect counter mask tested --- slsDetectorSoftware/tests/Caller/test-Caller-mythen3.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-mythen3.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-mythen3.cpp index 598439407..ec1a68ef5 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-mythen3.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-mythen3.cpp @@ -47,7 +47,7 @@ TEST_CASE("mythen3_acquire_check_file_size", "[.cmdcall]") { // set default specific det type config det.setDynamicRange(16); int test_counter_mask = 0x1; - int num_counters = __builtin_popcount(counter_mask); + int num_counters = __builtin_popcount(test_counter_mask); det.setCounterMask(test_counter_mask); // acquire From aabec193ff483e9435d22b9e6d395868f3527b7b Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 1 May 2025 12:10:33 +0200 Subject: [PATCH 07/17] fix 10g adc enable mask, switched with 1g --- .../tests/Caller/test-Caller-chiptestboard.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp index c309f3859..27e5e89c2 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp @@ -23,8 +23,8 @@ struct testCtbAcquireInfo { int num_adc_samples{5000}; int num_dbit_samples{6000}; int num_trans_samples{288}; - uint32_t adc_enable_1g{0xFFFFFFFF}; - uint32_t adc_enable_10g{0xFFFFFFFF}; + uint32_t adc_enable_1g{0xFFFFFF00}; + uint32_t adc_enable_10g{0xFF00FFFF}; int dbit_offset{0}; std::vector dbit_list{0, 12, 2, 43}; bool dbit_reorder{false}; @@ -99,8 +99,8 @@ void test_ctb_acquire_with_receiver(const testCtbAcquireInfo &test_info, 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_1g - : test_info.adc_enable_10g); + (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 = From 50737694037f2fcdd59ef85a796689070a21defa Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 1 May 2025 12:41:05 +0200 Subject: [PATCH 08/17] fixed hardcoded values of nchip nchan etc from detPArameters --- .../Caller/test-Caller-chiptestboard.cpp | 20 +++++++++++++++++++ .../tests/Caller/test-Caller-eiger.cpp | 15 +++++++++----- .../tests/Caller/test-Caller-gotthard2.cpp | 13 +++++++----- .../tests/Caller/test-Caller-jungfrau.cpp | 19 +++++++++--------- .../tests/Caller/test-Caller-moench.cpp | 17 ++++++++-------- .../tests/Caller/test-Caller-mythen3.cpp | 19 ++++++++++++------ 6 files changed, 69 insertions(+), 34 deletions(-) diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp index 27e5e89c2..42c811bef 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp @@ -260,6 +260,26 @@ TEST_CASE("ctb_acquire_check_file_size", "[.cmdcall]") { 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; + set_ctb_config_state(det, test_ctb_config); + 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; + set_ctb_config_state(det, test_ctb_config); + test_ctb_acquire_with_receiver(test_ctb_config, + num_frames_to_acquire, det, caller); + } } } diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-eiger.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-eiger.cpp index b59083add..bd9c4a04e 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-eiger.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-eiger.cpp @@ -57,11 +57,16 @@ TEST_CASE("eiger_acquire_check_file_size", "[.cmdcall]") { test_frames_caught(det, num_frames_to_acquire); // check file size (assuming local pc) - // pixels_row_per_chip * pixels_col_per_chip * num_chips * - // bytes_per_pixel - size_t expected_image_size = 256 * 256 * 2 * 2; - test_acquire_binary_file_size(test_file_info, num_frames_to_acquire, - expected_image_size); + { + 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); diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-gotthard2.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-gotthard2.cpp index a747c46dd..70b781640 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-gotthard2.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-gotthard2.cpp @@ -58,11 +58,14 @@ TEST_CASE("gotthard2_acquire_check_file_size", "[.cmdcall]") { test_frames_caught(det, num_frames_to_acquire); // check file size (assuming local pc) - // num_channels * num_chips * bytes_per_pixel * num_frames - size_t expected_image_size = 128 * 10 * 2; - test_acquire_binary_file_size(test_file_info, num_frames_to_acquire, - expected_image_size); - + { + 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); diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-jungfrau.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-jungfrau.cpp index 413937632..253fa0c49 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-jungfrau.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-jungfrau.cpp @@ -52,17 +52,16 @@ TEST_CASE("jungfrau_acquire_check_file_size", "[.cmdcall]") { test_frames_caught(det, num_frames_to_acquire); // check file size (assuming local pc) - size_t expected_image_size = 0; - // pixels_row_per_chip * pixels_col_per_chip * num_chips * - // bytes_per_pixel - if (num_udp_interfaces == 1) { - expected_image_size = 256 * 256 * 8 * 2; - } else { - expected_image_size = 256 * 256 * 4 * 2; + { + 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); } - 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); diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-moench.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-moench.cpp index 577a2f3b2..f3bb026a9 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-moench.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-moench.cpp @@ -52,15 +52,16 @@ TEST_CASE("moench_acquire_check_file_size", "[.cmdcall]") { test_frames_caught(det, num_frames_to_acquire); // check file size (assuming local pc) - size_t expected_image_size = 0; - // pixels_row * pixels_col * bytes_per_pixel - if (num_udp_interfaces == 1) { - expected_image_size = 400 * 400 * 2; - } else { - expected_image_size = 400 * 200 * 2; + { + 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); } - 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); diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-mythen3.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-mythen3.cpp index ec1a68ef5..7e7b5ca2b 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-mythen3.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-mythen3.cpp @@ -45,8 +45,9 @@ TEST_CASE("mythen3_acquire_check_file_size", "[.cmdcall]") { set_common_acquire_config_state(det, det_config); // set default specific det type config - det.setDynamicRange(16); - int test_counter_mask = 0x1; + 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); @@ -57,10 +58,16 @@ TEST_CASE("mythen3_acquire_check_file_size", "[.cmdcall]") { test_frames_caught(det, num_frames_to_acquire); // check file size (assuming local pc) - // num_channels * num_chips * num_counters - size_t expected_image_size = 128 * 10 * num_counters * 2; - test_acquire_binary_file_size(test_file_info, num_frames_to_acquire, - expected_image_size); + { + 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); From 62a5fda33f3893016c8d65d80e3bc3d59545ff39 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 1 May 2025 15:45:14 +0200 Subject: [PATCH 09/17] fixed ctb tests, need to fix in develoepr (if digital modfe not enabled, should not take into accoutn dbitlist or dbitoffset or dbitreorder --- .../Caller/test-Caller-chiptestboard.cpp | 317 +++++++++--------- .../tests/Caller/test-Caller-eiger.cpp | 3 + .../tests/Caller/test-Caller-global.cpp | 24 +- .../tests/Caller/test-Caller-global.h | 3 - .../tests/Caller/test-Caller-gotthard2.cpp | 3 + .../tests/Caller/test-Caller-jungfrau.cpp | 3 + .../tests/Caller/test-Caller-moench.cpp | 3 + .../tests/Caller/test-Caller-mythen3.cpp | 6 + slsReceiverSoftware/src/DataProcessor.cpp | 13 +- tests/scripts/test_simulators.py | 4 +- 10 files changed, 188 insertions(+), 191 deletions(-) diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp index 42c811bef..d9fc6972b 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp @@ -8,6 +8,7 @@ #include "sls/Result.h" #include "sls/ToString.h" +#include "sls/logger.h" #include "sls/versionAPI.h" #include "test-Caller-global.h" #include "tests/globals.h" @@ -30,6 +31,126 @@ struct testCtbAcquireInfo { bool dbit_reorder{false}; uint32_t transceiver_mask{0x3}; }; +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); + +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_aclogDEBUGquire_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)); + }*/ + } +} testCtbAcquireInfo get_ctb_config_state(const Detector &det) { return testCtbAcquireInfo{ @@ -66,34 +187,7 @@ void set_ctb_config_state(Detector &det, det.setTransceiverEnableMask(ctb_config_info.transceiver_mask); } -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 - test_acquire_with_receiver(caller, std::chrono::seconds{2}); - - // check frames caught - test_frames_caught(det, num_frames_to_acquire); - - // calculate image size +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 || @@ -105,6 +199,7 @@ void test_ctb_acquire_with_receiver(const testCtbAcquireInfo &test_info, 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 @@ -135,6 +230,7 @@ void test_ctb_acquire_with_receiver(const testCtbAcquireInfo &test_info, } 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 || @@ -144,10 +240,45 @@ void test_ctb_acquire_with_receiver(const testCtbAcquireInfo &test_info, 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 + << ']'; } - // check file size (assuming local pc) - uint64_t expected_image_size = + + 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 + test_acquire_with_receiver(caller, std::chrono::seconds{2}); + + // check frames caught + 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); test_acquire_binary_file_size(test_file_info, num_frames_to_acquire, expected_image_size); @@ -157,132 +288,6 @@ void test_ctb_acquire_with_receiver(const testCtbAcquireInfo &test_info, set_ctb_config_state(det, prev_ctb_config_info); } -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; - set_ctb_config_state(det, test_ctb_config); - 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; - set_ctb_config_state(det, test_ctb_config); - 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; - set_ctb_config_state(det, test_ctb_config); - 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; - set_ctb_config_state(det, test_ctb_config); - 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(); - set_ctb_config_state(det, test_ctb_config); - 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; - set_ctb_config_state(det, test_ctb_config); - 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; - set_ctb_config_state(det, test_ctb_config); - 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; - set_ctb_config_state(det, test_ctb_config); - 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(); - set_ctb_config_state(det, test_ctb_config); - 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(); - set_ctb_config_state(det, test_ctb_config); - 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; - set_ctb_config_state(det, test_ctb_config); - 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; - set_ctb_config_state(det, test_ctb_config); - 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; - set_ctb_config_state(det, test_ctb_config); - test_ctb_acquire_with_receiver(test_ctb_config, - num_frames_to_acquire, det, caller); - } - } -} - /* dacs */ TEST_CASE("dacname", "[.cmdcall]") { diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-eiger.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-eiger.cpp index bd9c4a04e..3053ca9e4 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-eiger.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-eiger.cpp @@ -31,6 +31,7 @@ TEST_CASE("eiger_acquire_check_file_size", "[.cmdcall]") { 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 = @@ -47,6 +48,7 @@ TEST_CASE("eiger_acquire_check_file_size", "[.cmdcall]") { 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); @@ -73,6 +75,7 @@ TEST_CASE("eiger_acquire_check_file_size", "[.cmdcall]") { 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); } diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-global.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-global.cpp index 713e9d5f9..0604666d4 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-global.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-global.cpp @@ -137,22 +137,11 @@ void test_acquire_with_receiver(Caller &caller, std::chrono::seconds timeout) { } testCommonDetAcquireInfo get_common_acquire_config_state(const Detector &det) { - testCommonDetAcquireInfo det_config_info{ + 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"), - {}}; - auto det_type = - det.getDetectorType().tsquash("Inconsistent detector types to test"); - if (det_type != defs::MYTHEN3) { - det_config_info.exptime[0] = - det.getExptime().tsquash("inconsistent exptime to test"); - } else { - det_config_info.exptime = - det.getExptimeForAllGates().tsquash("inconsistent exptime to test"); - } - return det_config_info; + det.getPeriod().tsquash("Inconsistent period")}; } void set_common_acquire_config_state( @@ -161,15 +150,6 @@ void set_common_acquire_config_state( det.setNumberOfFrames(det_config_info.num_frames_to_acquire); det.setNumberOfTriggers(det_config_info.num_triggers); det.setPeriod(det_config_info.period); - auto det_type = - det.getDetectorType().tsquash("Inconsistent detector types to test"); - if (det_type != defs::MYTHEN3) { - det.setExptime(det_config_info.exptime[0]); - } else { - for (int iGate = 0; iGate < 3; ++iGate) { - det.setExptime(iGate, det_config_info.exptime[iGate]); - } - } } } // namespace sls diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-global.h b/slsDetectorSoftware/tests/Caller/test-Caller-global.h index d7f777deb..aa08c4332 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-global.h +++ b/slsDetectorSoftware/tests/Caller/test-Caller-global.h @@ -25,9 +25,6 @@ struct testCommonDetAcquireInfo { int64_t num_frames_to_acquire{2}; int64_t num_triggers{1}; std::chrono::nanoseconds period{std::chrono::milliseconds{2}}; - std::array exptime{ - std::chrono::microseconds{200}, std::chrono::nanoseconds{0}, - std::chrono::nanoseconds{0}}; }; void test_valid_port_caller(const std::string &command, diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-gotthard2.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-gotthard2.cpp index 70b781640..103167f07 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-gotthard2.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-gotthard2.cpp @@ -31,6 +31,7 @@ TEST_CASE("gotthard2_acquire_check_file_size", "[.cmdcall]") { 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( @@ -47,6 +48,7 @@ TEST_CASE("gotthard2_acquire_check_file_size", "[.cmdcall]") { 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}); @@ -71,6 +73,7 @@ TEST_CASE("gotthard2_acquire_check_file_size", "[.cmdcall]") { 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); diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-jungfrau.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-jungfrau.cpp index 253fa0c49..7d56a0a00 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-jungfrau.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-jungfrau.cpp @@ -29,6 +29,7 @@ TEST_CASE("jungfrau_acquire_check_file_size", "[.cmdcall]") { 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 = @@ -43,6 +44,7 @@ TEST_CASE("jungfrau_acquire_check_file_size", "[.cmdcall]") { set_common_acquire_config_state(det, det_config); // set default specific det type config + det.setExptime(std::chrono::microseconds{200}); det.setReadNRows(512); // acquire @@ -67,6 +69,7 @@ TEST_CASE("jungfrau_acquire_check_file_size", "[.cmdcall]") { set_common_acquire_config_state(det, prev_det_config_info); // restore previous specific det type config + det.setExptime(exptime); det.setReadNRows(n_rows); } } diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-moench.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-moench.cpp index f3bb026a9..52e3c27e3 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-moench.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-moench.cpp @@ -29,6 +29,7 @@ TEST_CASE("moench_acquire_check_file_size", "[.cmdcall]") { 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 = @@ -43,6 +44,7 @@ TEST_CASE("moench_acquire_check_file_size", "[.cmdcall]") { set_common_acquire_config_state(det, det_config); // set default specific det type config + det.setExptime(std::chrono::microseconds{200}); det.setReadNRows(400); // acquire @@ -68,6 +70,7 @@ TEST_CASE("moench_acquire_check_file_size", "[.cmdcall]") { set_common_acquire_config_state(det, prev_det_config_info); // restore previous specific det type config + det.setExptime(exptime); det.setReadNRows(n_rows); } } diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-mythen3.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-mythen3.cpp index 7e7b5ca2b..13270aefe 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-mythen3.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-mythen3.cpp @@ -31,6 +31,8 @@ TEST_CASE("mythen3_acquire_check_file_size", "[.cmdcall]") { 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 = @@ -45,6 +47,7 @@ TEST_CASE("mythen3_acquire_check_file_size", "[.cmdcall]") { 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; @@ -74,6 +77,9 @@ TEST_CASE("mythen3_acquire_check_file_size", "[.cmdcall]") { 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); } diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index c9b2201b3..f9307ebe5 100644 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -589,7 +589,6 @@ void DataProcessor::ArrangeDbitData(size_t &size, char *data) { // store each selected bit from all samples consecutively if (ctbDbitReorder) { - LOG(logINFORED) << "Reordering digital data"; size_t numBitsPerDbit = numDigitalSamples; // num bits per selected digital // Bit for all samples @@ -604,8 +603,6 @@ void DataProcessor::ArrangeDbitData(size_t &size, char *data) { if ((numBitsPerSample % 8) != 0) numBitsPerSample += (8 - (numBitsPerSample % 8)); totalNumBytes = (numBitsPerSample / 8) * numDigitalSamples; - LOG(logINFORED) << "total numDigital bytes without reorder:" - << totalNumBytes; } std::vector result(totalNumBytes, 0); @@ -678,11 +675,11 @@ void DataProcessor::ArrangeDbitData(size_t &size, char *data) { memcpy(data + nAnalogDataBytes, result.data(), totalNumBytes * sizeof(uint8_t)); - LOG(logINFORED) << "totalNumBytes: " << totalNumBytes - << " nAnalogDataBytes:" << nAnalogDataBytes - << " ctbDbitOffset:" << ctbDbitOffset - << " nTransceiverDataBytes:" << nTransceiverDataBytes - << " size:" << size; + LOG(logDEBUG1) << "nDigitalDataBytes: " << totalNumBytes + << " nAnalogDataBytes:" << nAnalogDataBytes + << " ctbDbitOffset:" << ctbDbitOffset + << " nTransceiverDataBytes:" << nTransceiverDataBytes + << " toal size:" << size; } void DataProcessor::CropImage(size_t &size, char *data) { diff --git a/tests/scripts/test_simulators.py b/tests/scripts/test_simulators.py index ea580c5e6..e392274ee 100644 --- a/tests/scripts/test_simulators.py +++ b/tests/scripts/test_simulators.py @@ -32,8 +32,8 @@ 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) + #if p.returncode != 0: + # raise RuntimeException('killall failed for ' + name) else: print('process not running : ' + name) From 22f2662e3ba2db17d20b8a0dfec6c8e436f1f120 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 1 May 2025 16:19:25 +0200 Subject: [PATCH 10/17] trying to fix acquire for xilinx --- .../Caller/test-Caller-chiptestboard.cpp | 158 ------------------ .../tests/Caller/test-Caller-global.cpp | 150 +++++++++++++++++ .../tests/Caller/test-Caller-global.h | 22 +++ 3 files changed, 172 insertions(+), 158 deletions(-) diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp index d9fc6972b..22354af78 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp @@ -8,7 +8,6 @@ #include "sls/Result.h" #include "sls/ToString.h" -#include "sls/logger.h" #include "sls/versionAPI.h" #include "test-Caller-global.h" #include "tests/globals.h" @@ -18,27 +17,6 @@ namespace sls { using test::GET; using test::PUT; -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 dbit_list{0, 12, 2, 43}; - bool dbit_reorder{false}; - uint32_t transceiver_mask{0x3}; -}; -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); - TEST_CASE("ctb_acquire_check_file_size", "[.cmdcall]") { Detector det; Caller caller(&det); @@ -152,142 +130,6 @@ TEST_CASE("ctb_acquire_check_file_size", "[.cmdcall]") { } } -testCtbAcquireInfo get_ctb_config_state(const Detector &det) { - return testCtbAcquireInfo{ - det.getReadoutMode().tsquash("inconsistent readout mode to test"), - det.getTenGiga().tsquash("inconsistent ten giga enable to test"), - 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"), - det.getADCEnableMask().tsquash("inconsistent adc enable mask to test"), - 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")}; -} - -void set_ctb_config_state(Detector &det, - const testCtbAcquireInfo &ctb_config_info) { - det.setReadoutMode(ctb_config_info.readout_mode); - det.setTenGiga(ctb_config_info.ten_giga); - 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.setADCEnableMask(ctb_config_info.adc_enable_1g); - 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 - test_acquire_with_receiver(caller, std::chrono::seconds{2}); - - // check frames caught - 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); - 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); -} - /* dacs */ TEST_CASE("dacname", "[.cmdcall]") { diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-global.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-global.cpp index 0604666d4..c04ccfb8b 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-global.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-global.cpp @@ -4,6 +4,7 @@ #include "Caller.h" #include "catch.hpp" #include "sls/Detector.h" +#include "sls/logger.h" #include "tests/globals.h" namespace sls { @@ -152,4 +153,153 @@ void set_common_acquire_config_state( 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, std::chrono::seconds{2})); + + // 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 diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-global.h b/slsDetectorSoftware/tests/Caller/test-Caller-global.h index aa08c4332..2d9345623 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-global.h +++ b/slsDetectorSoftware/tests/Caller/test-Caller-global.h @@ -27,6 +27,20 @@ struct testCommonDetAcquireInfo { 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 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 &arguments, int detector_id, int action); @@ -50,4 +64,12 @@ 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 From 451b50dfed304480b87ac68ddc3fe2cdccda8134 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 1 May 2025 16:42:11 +0200 Subject: [PATCH 11/17] fix for xilinx ctb virtual --- .../slsDetectorFunctionList.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c index 77670525a..3fe36be67 100644 --- a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c @@ -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); } From fb6ef8b8186816ff4cb575b6854521548aa979be Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 1 May 2025 16:43:00 +0200 Subject: [PATCH 12/17] alloweing all tests --- .../Caller/test-Caller-chiptestboard.cpp | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp index 22354af78..fe03a3ebe 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp @@ -108,25 +108,25 @@ TEST_CASE("ctb_acquire_check_file_size", "[.cmdcall]") { 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_aclogDEBUGquire_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)); - }*/ + } + { + 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_aclogDEBUGquire_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)); + } } } From 53b90d92d784179f528483e776395ec317eb3c85 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 1 May 2025 16:46:23 +0200 Subject: [PATCH 13/17] typo --- slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp index fe03a3ebe..955a30169 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp @@ -115,7 +115,7 @@ TEST_CASE("ctb_acquire_check_file_size", "[.cmdcall]") { test_ctb_config.dbit_offset = 16; test_ctb_config.dbit_list.clear(); test_ctb_config.dbit_reorder = true; - REQUIRE_NOTHROW(test_ctb_aclogDEBUGquire_with_receiver( + REQUIRE_NOTHROW(test_ctb_acquire_with_receiver( test_ctb_config, num_frames_to_acquire, det, caller)); } { From 7bc48e3111bfe803d5d1ea3f974e3b57aa4338bc Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 1 May 2025 16:55:09 +0200 Subject: [PATCH 14/17] fix for slsreceiver killed but complaining for virtual tests with script --- tests/scripts/test_simulators.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/scripts/test_simulators.py b/tests/scripts/test_simulators.py index e392274ee..c1bc4a199 100644 --- a/tests/scripts/test_simulators.py +++ b/tests/scripts/test_simulators.py @@ -32,8 +32,8 @@ 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) + if p.returncode != 0 and checkIfProcessRunning(name): + raise RuntimeException('killall failed for ' + name) else: print('process not running : ' + name) From fb79ba768ca6e19a3fb4366a0967c390583f4728 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 2 May 2025 11:30:08 +0200 Subject: [PATCH 15/17] fixed bug found by @AliceMazzoleni99 that for ctb server is still shown in pgrep -f if xilinx server running, so now the pid is killed and looking for any DetectorServer_virtual instead. also reset color coding after Log --- .../tests/Caller/test-Caller-eiger.cpp | 2 +- .../tests/Caller/test-Caller-global.cpp | 18 ++++-- .../tests/Caller/test-Caller-global.h | 2 +- .../tests/Caller/test-Caller-gotthard2.cpp | 2 +- .../tests/Caller/test-Caller-jungfrau.cpp | 2 +- .../tests/Caller/test-Caller-moench.cpp | 2 +- .../tests/Caller/test-Caller-mythen3.cpp | 2 +- tests/scripts/test_simulators.py | 58 +++++++++---------- 8 files changed, 46 insertions(+), 42 deletions(-) diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-eiger.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-eiger.cpp index 3053ca9e4..265c39510 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-eiger.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-eiger.cpp @@ -53,7 +53,7 @@ TEST_CASE("eiger_acquire_check_file_size", "[.cmdcall]") { det.setDynamicRange(16); // acquire - test_acquire_with_receiver(caller, std::chrono::seconds{2}); + test_acquire_with_receiver(caller, det); // check frames caught test_frames_caught(det, num_frames_to_acquire); diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-global.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-global.cpp index c04ccfb8b..0c56ac15d 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-global.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-global.cpp @@ -130,10 +130,21 @@ void test_frames_caught(const Detector &det, int num_frames_to_acquire) { REQUIRE(frames_caught == num_frames_to_acquire); } -void test_acquire_with_receiver(Caller &caller, std::chrono::seconds timeout) { +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)); - std::this_thread::sleep_for(timeout); + 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)); } @@ -285,8 +296,7 @@ void test_ctb_acquire_with_receiver(const testCtbAcquireInfo &test_info, set_ctb_config_state(det, test_info); // acquire - REQUIRE_NOTHROW( - test_acquire_with_receiver(caller, std::chrono::seconds{2})); + REQUIRE_NOTHROW(test_acquire_with_receiver(caller, det)); // check frames caught REQUIRE_NOTHROW(test_frames_caught(det, num_frames_to_acquire)); diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-global.h b/slsDetectorSoftware/tests/Caller/test-Caller-global.h index 2d9345623..be944ecd2 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-global.h +++ b/slsDetectorSoftware/tests/Caller/test-Caller-global.h @@ -58,7 +58,7 @@ void test_acquire_binary_file_size(const testFileInfo &file_info, void test_frames_caught(const Detector &det, int num_frames_to_acquire); -void test_acquire_with_receiver(Caller &caller, std::chrono::seconds timeout); +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( diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-gotthard2.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-gotthard2.cpp index 103167f07..c56e79634 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-gotthard2.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-gotthard2.cpp @@ -54,7 +54,7 @@ TEST_CASE("gotthard2_acquire_check_file_size", "[.cmdcall]") { det.setBurstPeriod(std::chrono::milliseconds{0}); // acquire - test_acquire_with_receiver(caller, std::chrono::seconds{2}); + test_acquire_with_receiver(caller, det); // check frames caught test_frames_caught(det, num_frames_to_acquire); diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-jungfrau.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-jungfrau.cpp index 7d56a0a00..07cabaa04 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-jungfrau.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-jungfrau.cpp @@ -48,7 +48,7 @@ TEST_CASE("jungfrau_acquire_check_file_size", "[.cmdcall]") { det.setReadNRows(512); // acquire - test_acquire_with_receiver(caller, std::chrono::seconds{2}); + test_acquire_with_receiver(caller, det); // check frames caught test_frames_caught(det, num_frames_to_acquire); diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-moench.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-moench.cpp index 52e3c27e3..9c79a51ab 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-moench.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-moench.cpp @@ -48,7 +48,7 @@ TEST_CASE("moench_acquire_check_file_size", "[.cmdcall]") { det.setReadNRows(400); // acquire - test_acquire_with_receiver(caller, std::chrono::seconds{2}); + test_acquire_with_receiver(caller, det); // check frames caught test_frames_caught(det, num_frames_to_acquire); diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-mythen3.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-mythen3.cpp index 13270aefe..c5d644b3d 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-mythen3.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-mythen3.cpp @@ -55,7 +55,7 @@ TEST_CASE("mythen3_acquire_check_file_size", "[.cmdcall]") { det.setCounterMask(test_counter_mask); // acquire - test_acquire_with_receiver(caller, std::chrono::seconds{2}); + test_acquire_with_receiver(caller, det); // check frames caught test_frames_caught(det, num_frames_to_acquire); diff --git a/tests/scripts/test_simulators.py b/tests/scripts/test_simulators.py index c1bc4a199..46510fc6a 100644 --- a/tests/scripts/test_simulators.py +++ b/tests/scripts/test_simulators.py @@ -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,42 @@ 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 and checkIfProcessRunning(name): - 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: + cmd = f"kill -9 {pid}" + p = subprocess.run(['kill', '-9', pid]) + if p.returncode != 0: + raise RuntimeException("'kill -9' failed for " + name) + 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 +178,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 +201,7 @@ with open(fname, 'w') as fp: try: startGeneralTests(fp, file_results) - killAllStaleProcesses(fp) + cleanup(fp) testError = False for server in servers: @@ -222,12 +216,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 From 9f4298ac15127454597360225ee0f3db1b8489b1 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 2 May 2025 13:55:44 +0200 Subject: [PATCH 16/17] check if process running for kill -9 slsReceiver fail --- tests/scripts/test_simulators.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/scripts/test_simulators.py b/tests/scripts/test_simulators.py index 46510fc6a..370ecc1b9 100644 --- a/tests/scripts/test_simulators.py +++ b/tests/scripts/test_simulators.py @@ -35,8 +35,8 @@ def killProcess(name): try: cmd = f"kill -9 {pid}" p = subprocess.run(['kill', '-9', pid]) - if p.returncode != 0: - raise RuntimeException("'kill -9' failed for " + name) + if p.returncode != 0 and bool(checkIfProcessRunning(name)): + raise RuntimeException(f"'kill -9' failed for {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 From eb3d51d20c0948d05bd57e22511035fd9abcce8e Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 2 May 2025 15:40:10 +0200 Subject: [PATCH 17/17] removed -9 to kill with cleanup --- tests/scripts/test_simulators.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/scripts/test_simulators.py b/tests/scripts/test_simulators.py index 370ecc1b9..c3cac14c4 100644 --- a/tests/scripts/test_simulators.py +++ b/tests/scripts/test_simulators.py @@ -33,10 +33,9 @@ def killProcess(name): Log(Fore.GREEN, f"Killing '{name}' processes with PIDs: {', '.join(pids)}") for pid in pids: try: - cmd = f"kill -9 {pid}" - p = subprocess.run(['kill', '-9', pid]) + p = subprocess.run(['kill', pid]) if p.returncode != 0 and bool(checkIfProcessRunning(name)): - raise RuntimeException(f"'kill -9' failed for {name} with pid {pid}") + 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