From 231ef5b08b61c53e61ca34230ffdd115086840b7 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Thu, 27 Jul 2023 13:16:09 +0200 Subject: [PATCH] jfjoch_action_test_mock: Added, to be later merged with jfjoch_action_test --- receiver/CMakeLists.txt | 6 +- receiver/jfjoch_action_test_mock.cpp | 89 ++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 receiver/jfjoch_action_test_mock.cpp diff --git a/receiver/CMakeLists.txt b/receiver/CMakeLists.txt index 1a1712b6..b2670647 100644 --- a/receiver/CMakeLists.txt +++ b/receiver/CMakeLists.txt @@ -72,4 +72,8 @@ INSTALL(TARGETS jfjoch_receiver RUNTIME) ADD_EXECUTABLE(jfjoch_action_test jfjoch_action_test.cpp) TARGET_LINK_LIBRARIES(jfjoch_action_test JungfraujochHost JFJochReceiver) -INSTALL(TARGETS jfjoch_action_test RUNTIME) \ No newline at end of file +INSTALL(TARGETS jfjoch_action_test RUNTIME) + +ADD_EXECUTABLE(jfjoch_action_test_mock jfjoch_action_test_mock.cpp) +TARGET_LINK_LIBRARIES(jfjoch_action_test_mock JungfraujochHost JFJochReceiver) +INSTALL(TARGETS jfjoch_action_test_mock RUNTIME) \ No newline at end of file diff --git a/receiver/jfjoch_action_test_mock.cpp b/receiver/jfjoch_action_test_mock.cpp new file mode 100644 index 00000000..bb39b251 --- /dev/null +++ b/receiver/jfjoch_action_test_mock.cpp @@ -0,0 +1,89 @@ +// Copyright (2019-2022) Paul Scherrer Institute +// SPDX-License-Identifier: GPL-3.0-or-later + +#include + +#include "MockAcquisitionDevice.h" +#include "JFJochReceiverTest.h" +#include "../tests/FPGAUnitTest.h" + +int main(int argc, char **argv) { + uint16_t nstreams = 1; + const uint16_t nmodules = 1; + size_t nimages = 2; + uint64_t processing_period = 20; + + Logger logger("ActionTest"); + logger.Verbose(true); + + bool abort_test = false; + + if ((argc == 1) || (argc > 6)) { + logger.Error("Usage ./jfjoch_action_test {<# of images> {<# of modules> {<# of streams> {}}}}"); + exit(EXIT_FAILURE); + } + + if (argc >= 3) nimages = atol(argv[2]); + if (argc >= 4) nstreams = atoi(argv[3]); + if (argc >= 5) processing_period = atoi(argv[4]); + + DiffractionExperiment x(DetectorGeometry(nmodules*nstreams, 2, 8, 36, true)); + + x.Mode(DetectorMode::Conversion); + x.ImagesPerTrigger(nimages).PedestalG0Frames(0).UseInternalPacketGenerator(true).PhotonEnergy_keV(12.4).NumTriggers(1); + x.SpotFindingPeriod(std::chrono::milliseconds(processing_period)).MaskModuleEdges(false).MaskChipEdges(false); + x.Compression(JFJochProtoBuf::BSHUF_LZ4).DataStreams(nstreams); + + bool verbose = false; + bool print_status_updates = true; + uint16_t nthreads = 16; + + logger.Verbose(verbose); + + std::vector> pcie_devices; + std::vector aq_devices; + + std::string image_path = std::string(argv[1]) + "/tests/test_data/mod5_raw0.bin"; + std::vector input(RAW_MODULE_SIZE, 0); + LoadBinaryFile(image_path, input.data(), RAW_MODULE_SIZE); + + for (int i = 0; i < nstreams; i++) { + pcie_devices.push_back(std::make_unique(i, 1024)); + pcie_devices[i]->SetCustomInternalGeneratorFrame(input); + pcie_devices[i]->EnableLogging(&logger); + aq_devices.push_back(pcie_devices[i].get()); + } + + volatile bool done = false; + JFJochProtoBuf::ReceiverOutput output; + bool ret; + std::thread run_thread([&] { + try { + ret = JFJochReceiverTest(output, logger, aq_devices, x, nthreads,abort_test, verbose); + } catch (std::exception &e) { + logger.Error(e.what()); + ret = false; + } + done = true; + }); + + + run_thread.join(); + + double receiving_time = static_cast(output.end_time_ms() - output.start_time_ms())/1000.0; + + logger.Info("Efficiency: {:.2f}%", output.efficiency() * 100.f); + logger.Info("Max delay: {}",output.max_receive_delay()); + logger.Info("Compression factor: {}x", output.compressed_ratio()); + logger.Info("Receiving time: {} s", receiving_time); + logger.Info("Frame rate: {} Hz", static_cast(nimages)/receiving_time); + logger.Info("Total throughput: {:.2f} GB/s", + static_cast(nimages*nstreams*nmodules*RAW_MODULE_SIZE*sizeof(uint16_t)) / (receiving_time * 1e9)); + logger.Info(""); + + if (ret) { + logger.Info("Test properly executed! (check stall values manually)"); + exit(EXIT_SUCCESS); + } else + exit(EXIT_FAILURE); +}