From 67b9e08a5c5362cd5b7892ada32f52f05cf85ea4 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Thu, 19 Oct 2023 19:48:40 +0200 Subject: [PATCH] FPGAIntegrationTest: Add test for spot finder based on count limit --- tests/FPGAIntegrationTest.cpp | 42 +++++++++++++++++++++++++++++++ tests/FPGASpotFindingUnitTest.cpp | 3 ++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/tests/FPGAIntegrationTest.cpp b/tests/FPGAIntegrationTest.cpp index 5faf3000..1b1a16d5 100644 --- a/tests/FPGAIntegrationTest.cpp +++ b/tests/FPGAIntegrationTest.cpp @@ -1140,3 +1140,45 @@ TEST_CASE("HLS_C_Simulation_internal_packet_generator_integration", "[FPGA][Full CHECK(integration_result[54].sum == 32754 * (RAW_MODULE_SIZE - 2)); CHECK(integration_result[54].count == RAW_MODULE_SIZE - 2); } + +TEST_CASE("HLS_C_Simulation_internal_packet_generator_spot_finder_count_threshold", "[FPGA][Full]") { + const uint16_t nmodules = 4; + + DiffractionExperiment x((DetectorGeometry(nmodules))); + + x.Mode(DetectorMode::Raw); + x.UseInternalPacketGenerator(true).ImagesPerTrigger(1).PedestalG0Frames(0); + + HLSSimulatedDevice test(0, 64); + + std::vector frame(RAW_MODULE_SIZE, 0); + frame [ 0] = 11; + frame [123*1024 + 578] = 10; + frame [121*1024 + 800] = 12; + frame [ 89*1024 + 300] = 8; + frame [300*1024 + 0] = 9; + + test.SetInternalGeneratorFrame(frame); + + test.SetSpotFinderParameters(9, 0.0); + + REQUIRE_NOTHROW(test.StartAction(x)); + REQUIRE_NOTHROW(test.WaitForActionComplete()); + + REQUIRE(test.OutputStream().size() == 1); + + JFJochProtoBuf::AcquisitionDeviceStatistics device_statistics; + REQUIRE_NOTHROW(test.SaveStatistics(x, device_statistics)); + REQUIRE(device_statistics.bytes_received() == 128 * nmodules * JUNGFRAU_PACKET_SIZE_BYTES); + + auto imageBuf = test.GetDeviceOutput(0, 0)->pixels; + REQUIRE(memcmp(imageBuf, frame.data(), RAW_MODULE_SIZE * sizeof(uint16_t)) == 0); + + auto spot_finder_result = test.GetDeviceOutput(0, 0)->spot_finding_result; + REQUIRE (spot_finder_result.strong_pixel_count == 3); + REQUIRE (spot_finder_result.snr_threshold == 0); + REQUIRE (spot_finder_result.count_threshold == 9); + REQUIRE (spot_finder_result.strong_pixel[0] == (1<<0)); + REQUIRE (spot_finder_result.strong_pixel[(123*1024 + 578) / 8] == (1<<2)); // 578 % 8 == 2 + REQUIRE (spot_finder_result.strong_pixel[(121*1024 + 800) / 8] == (1<<0)); // 800 % 8 == 0 +} \ No newline at end of file diff --git a/tests/FPGASpotFindingUnitTest.cpp b/tests/FPGASpotFindingUnitTest.cpp index abd53b2e..df885298 100644 --- a/tests/FPGASpotFindingUnitTest.cpp +++ b/tests/FPGASpotFindingUnitTest.cpp @@ -22,7 +22,6 @@ TEST_CASE("FPGA_spot_finder_core","[FPGA][SpotFinder]") { input_frame[i] = i % RAW_MODULE_COLS; } auto input_frame_512 = (ap_uint<512> *) input_frame.data(); - auto output_frame_512 = (ap_uint<512> *) output_frame.data(); input << packet_512_t{.user = 0}; for (int i = 0; i < RAW_MODULE_SIZE * sizeof(uint16_t) / 64; i++) @@ -39,4 +38,6 @@ TEST_CASE("FPGA_spot_finder_core","[FPGA][SpotFinder]") { REQUIRE(input.size() == 0); REQUIRE(output.size() == RAW_MODULE_SIZE * sizeof(uint16_t) / 64 + 2); REQUIRE(strong_pixel.size() == RAW_MODULE_SIZE * sizeof(uint16_t) / 64 + 16 + 1); + + } \ No newline at end of file