The host-side tests run on the mock instead of the HLS simulation: JFJochReceiverIntegrationTest, JFJochReceiverProcessingTest (the GPU-stills cases too, in raw mode the card writes the generator's frame), JFJochStateMachineTest, StreamWriterTest. tests/MockCardOutput.h gives the mock what the card would write for a test's image - its conversion by the host's floating-point reference, pixel statistics, ROI counts and the strong pixels of the CPU spot finder - so the checks of the receiver's images and plots stay as they were. Two cases are new: a receiver on two cards at once (not possible with the HLS simulation) and a cancelled pedestal run. FPGAIntegrationTest.cpp (60 cases) tested the HLS device itself - conversion, summation, spot finder, integration, ROI, ADU histogram, pixel counts, in every mode - and is removed, not ported. Its host-side checks (FPGAAcquisitionDevice and AcquisitionCounters: the internal generator, data streams, missing modules, delays, lost frames, the last frame, bunch ID, the generator's memory limit) are FPGAAcquisitionDeviceTest.cpp on the mock, plus a check that the generator's frames are what the mock writes. Fromce8918062and710edd61e(rc186), resolved against rc188: JFJochReceiverTest() without quick_integrate, the FPGA receiver that indexes and does not integrate, StillsGPUAnalysisFPGA. JFJochReceiverFPGA_RugnuxOnStaysPerImage is not taken (rc188 keeps live stills on the FPGA receiver). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UqXYdHHZ4cogS1mrGUtfN7
217 lines
8.6 KiB
C++
217 lines
8.6 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
// The host side of the card - FPGAAcquisitionDevice and its AcquisitionCounters - on the mock of the card: what
|
|
// arrived, where it went, delays, the end of the data collection. The card itself is compared with the mock in
|
|
// MockAcquisitionDeviceTest.cpp.
|
|
|
|
#include <catch2/catch_all.hpp>
|
|
|
|
#include "../acquisition_device/MockAcquisitionDevice.h"
|
|
|
|
TEST_CASE("FPGAAcquisitionDevice_InternalPacketGenerator", "[FPGAAcquisitionDevice]") {
|
|
const uint16_t nmodules = 4;
|
|
DiffractionExperiment x(DetJF(nmodules));
|
|
x.Raw();
|
|
x.UseInternalPacketGenerator(true).ImagesPerTrigger(4).PedestalG0Frames(0);
|
|
|
|
MockAcquisitionDevice test(0, 64);
|
|
REQUIRE_NOTHROW(test.StartAction(x));
|
|
REQUIRE_NOTHROW(test.WaitForActionComplete());
|
|
|
|
REQUIRE(test.GetBytesReceived() == 128 * nmodules * 4 * JUNGFRAU_PACKET_SIZE_BYTES);
|
|
for (int image = 0; image < 4; image++) {
|
|
for (int m = 0; m < nmodules; m++) {
|
|
const auto &stats = test.GetDeviceOutput(image, m)->module_statistics;
|
|
CHECK(stats.frame_number == image);
|
|
CHECK(stats.module_number == m);
|
|
CHECK(stats.timestamp == INT_PKT_GEN_EXPTTIME * image);
|
|
CHECK(stats.pulse_id == INT_PKT_GEN_BUNCHID + image);
|
|
CHECK(stats.exptime == INT_PKT_GEN_EXPTTIME);
|
|
CHECK(stats.detector_type == SLS_DETECTOR_TYPE_JUNGFRAU);
|
|
}
|
|
}
|
|
REQUIRE(test.GetExpectedDescriptorsPerModule() == DMA_DESCRIPTORS_PER_MODULE);
|
|
}
|
|
|
|
// Of four data streams, the card of the last one generates only its own module
|
|
TEST_CASE("FPGAAcquisitionDevice_InternalPacketGenerator_DataStream", "[FPGAAcquisitionDevice]") {
|
|
const uint16_t nmodules = 4;
|
|
DiffractionExperiment x(DetJF(nmodules));
|
|
x.DataStreams(4);
|
|
x.Raw();
|
|
x.UseInternalPacketGenerator(true).ImagesPerTrigger(4).PedestalG0Frames(0);
|
|
|
|
MockAcquisitionDevice test(3, 64);
|
|
REQUIRE_NOTHROW(test.StartAction(x));
|
|
REQUIRE_NOTHROW(test.WaitForActionComplete());
|
|
|
|
REQUIRE(test.GetBytesReceived() == 128 * 4 * JUNGFRAU_PACKET_SIZE_BYTES);
|
|
for (int image = 0; image < 4; image++)
|
|
REQUIRE(test.Counters().IsFullModuleCollected(image, 0));
|
|
}
|
|
|
|
// Module 0 runs on, module 1 stops after 3 frames, modules 2 and 3 never come: the slowest frame moves on once the
|
|
// fastest module is far enough ahead
|
|
TEST_CASE("FPGAAcquisitionDevice_MissingModules", "[FPGAAcquisitionDevice]") {
|
|
const uint16_t nmodules = 4;
|
|
const uint64_t nframes = AcquisitionCounters::ThresholdFramesLost + 5;
|
|
|
|
DiffractionExperiment x(DetJF(nmodules));
|
|
x.Raw();
|
|
x.PedestalG0Frames(0).ImagesPerTrigger(nframes).NumTriggers(1);
|
|
|
|
MockAcquisitionDevice test(0, nframes + 2);
|
|
test.CreateJFPackets(x, 1, nframes, 0, nullptr);
|
|
test.CreateJFPackets(x, 1, 3, 1, nullptr);
|
|
test.CreateFinalPacket(x);
|
|
REQUIRE_NOTHROW(test.StartAction(x));
|
|
REQUIRE_NOTHROW(test.WaitForActionComplete());
|
|
|
|
REQUIRE(test.Counters().GetSlowestFrameNumber() == 5 - 1);
|
|
REQUIRE(test.Counters().GetBufferHandle(0, 0) != AcquisitionCounters::HandleNotFound);
|
|
REQUIRE(test.Counters().GetBufferHandle(0, 1) == AcquisitionCounters::HandleNotFound);
|
|
REQUIRE(test.Counters().GetBufferHandle(0, 2) == AcquisitionCounters::HandleNotFound);
|
|
REQUIRE(test.GetBytesReceived() == nframes * 128 * JUNGFRAU_PACKET_SIZE_BYTES);
|
|
}
|
|
|
|
TEST_CASE("FPGAAcquisitionDevice_Delay", "[FPGAAcquisitionDevice]") {
|
|
const uint16_t nmodules = 4;
|
|
DiffractionExperiment x(DetJF(nmodules));
|
|
x.Raw();
|
|
x.PedestalG0Frames(0).ImagesPerTrigger(3).NumTriggers(1);
|
|
|
|
MockAcquisitionDevice test(0, 64);
|
|
for (int f = 1; f <= 3; f++)
|
|
for (int m = 0; m < nmodules; m++)
|
|
test.CreateJFPacket(x, f, 0, m, nullptr);
|
|
test.CreateFinalPacket(x);
|
|
|
|
REQUIRE_NOTHROW(test.StartAction(x));
|
|
REQUIRE_NOTHROW(test.WaitForActionComplete());
|
|
|
|
REQUIRE(test.Counters().CalculateDelay(0) == 2);
|
|
REQUIRE(test.Counters().CalculateDelay(0, 0) == 2);
|
|
REQUIRE(test.Counters().CalculateDelay(1) == 1);
|
|
REQUIRE(test.Counters().CalculateDelay(1, 0) == 1);
|
|
REQUIRE(test.Counters().CalculateDelay(2) == 0);
|
|
REQUIRE(test.Counters().CalculateDelay(2, 0) == 0);
|
|
}
|
|
|
|
// A single packet of one module: that module of that frame is there, nothing else is
|
|
TEST_CASE("FPGAAcquisitionDevice_LostFrame", "[FPGAAcquisitionDevice]") {
|
|
const uint16_t nmodules = 4;
|
|
DiffractionExperiment x(DetJF(nmodules));
|
|
x.Raw();
|
|
x.PedestalG0Frames(0).ImagesPerTrigger(3).NumTriggers(1);
|
|
|
|
MockAcquisitionDevice test(0, 64);
|
|
test.CreateJFPacket(x, 1, 0, 0, nullptr);
|
|
test.CreateFinalPacket(x);
|
|
|
|
REQUIRE_NOTHROW(test.StartAction(x));
|
|
REQUIRE_NOTHROW(test.WaitForActionComplete());
|
|
|
|
REQUIRE(test.GetBytesReceived() == JUNGFRAU_PACKET_SIZE_BYTES);
|
|
REQUIRE_NOTHROW(test.GetDeviceOutput(0, 0));
|
|
REQUIRE(!test.Counters().IsFullModuleCollected(0, 0));
|
|
REQUIRE_THROWS(test.GetDeviceOutput(0, 1));
|
|
REQUIRE_THROWS(test.GetDeviceOutput(1, 0));
|
|
REQUIRE_THROWS(test.GetDeviceOutput(2, 1));
|
|
}
|
|
|
|
TEST_CASE("FPGAAcquisitionDevice_OneFrame", "[FPGAAcquisitionDevice]") {
|
|
const uint16_t nmodules = 4;
|
|
DiffractionExperiment x(DetJF(nmodules));
|
|
x.PedestalG0Frames(0).NumTriggers(1).ImagesPerTrigger(1);
|
|
|
|
MockAcquisitionDevice test(0, 64);
|
|
test.CreateJFPackets(x, 1, 1, 0, nullptr);
|
|
test.CreateFinalPacket(x);
|
|
|
|
REQUIRE_NOTHROW(test.StartAction(x));
|
|
test.WaitForActionComplete();
|
|
REQUIRE(test.Counters().IsAcquisitionFinished());
|
|
|
|
// address properly aligned
|
|
REQUIRE((uint64_t) test.GetDeviceOutput(0, 0)->pixels % 128 == 0);
|
|
|
|
REQUIRE(test.Counters().GetSlowestFrameNumber() == 0);
|
|
REQUIRE(test.Counters().GetCurrFrameNumber(0) == 0);
|
|
REQUIRE(test.GetBytesReceived() == 128 * JUNGFRAU_PACKET_SIZE_BYTES);
|
|
}
|
|
|
|
// A frame far past the last one ends the data collection
|
|
TEST_CASE("FPGAAcquisitionDevice_DetectLastFrame", "[FPGAAcquisitionDevice]") {
|
|
const uint16_t nmodules = 4;
|
|
DiffractionExperiment x(DetJF(nmodules));
|
|
x.PedestalG0Frames(0).NumTriggers(2).ImagesPerTrigger(5);
|
|
|
|
MockAcquisitionDevice test(0, 64);
|
|
REQUIRE_NOTHROW(test.StartAction(x));
|
|
REQUIRE(!test.Counters().IsAcquisitionFinished());
|
|
|
|
test.CreateJFPacket(x, 15, 0, 0, nullptr);
|
|
test.WaitForActionComplete();
|
|
REQUIRE(test.Counters().IsAcquisitionFinished());
|
|
}
|
|
|
|
TEST_CASE("FPGAAcquisitionDevice_BunchID", "[FPGAAcquisitionDevice]") {
|
|
const uint64_t bunchid = 0xAAAAAAAA87345600;
|
|
DiffractionExperiment x(DetJF(4));
|
|
x.Raw();
|
|
x.PedestalG0Frames(0).ImagesPerTrigger(3).NumTriggers(1);
|
|
|
|
MockAcquisitionDevice test(0, 64);
|
|
test.CreateXfelBunchIDPacket(bunchid, 0);
|
|
test.CreateFinalPacket(x);
|
|
|
|
REQUIRE_NOTHROW(test.StartAction(x));
|
|
REQUIRE_NOTHROW(test.WaitForActionComplete());
|
|
|
|
REQUIRE(test.GetBytesReceived() == 0);
|
|
REQUIRE(test.GetDataCollectionStatus().current_pulseid == bunchid);
|
|
}
|
|
|
|
TEST_CASE("FPGAAcquisitionDevice_InternalGeneratorMemory", "[FPGAAcquisitionDevice]") {
|
|
// 64 module frames in the card memory; the generator takes 63 at most
|
|
DiffractionExperiment x(DetJF(2));
|
|
x.UseInternalPacketGenerator(true).ImagesPerTrigger(1).NumTriggers(1);
|
|
MockAcquisitionDevice test(0, 64);
|
|
|
|
x.InternalPacketGeneratorImages(31);
|
|
REQUIRE_NOTHROW(test.PrepareAction(x));
|
|
|
|
x.InternalPacketGeneratorImages(32);
|
|
REQUIRE_THROWS(test.PrepareAction(x));
|
|
|
|
std::vector<uint16_t> frame(RAW_MODULE_SIZE);
|
|
REQUIRE_NOTHROW(test.SetInternalGeneratorFrame(frame.data(), 62));
|
|
REQUIRE_THROWS(test.SetInternalGeneratorFrame(frame.data(), 63));
|
|
}
|
|
|
|
// The generator's frames are what the card writes when no output was set for a module
|
|
TEST_CASE("FPGAAcquisitionDevice_InternalGeneratorFrames", "[FPGAAcquisitionDevice]") {
|
|
const uint16_t nmodules = 2;
|
|
DiffractionExperiment x(DetJF(nmodules));
|
|
x.Raw();
|
|
x.UseInternalPacketGenerator(true).InternalPacketGeneratorImages(2).ImagesPerTrigger(5).PedestalG0Frames(0);
|
|
|
|
MockAcquisitionDevice test(0, 64);
|
|
std::vector<uint16_t> frame(RAW_MODULE_SIZE);
|
|
for (int slot = 0; slot < 4; slot++) {
|
|
std::fill(frame.begin(), frame.end(), 100 + slot);
|
|
test.SetInternalGeneratorFrame(frame.data(), slot);
|
|
}
|
|
REQUIRE_NOTHROW(test.StartAction(x));
|
|
REQUIRE_NOTHROW(test.WaitForActionComplete());
|
|
|
|
for (int image = 0; image < 5; image++) {
|
|
for (int m = 0; m < nmodules; m++) {
|
|
const auto pixels = reinterpret_cast<const uint16_t *>(test.GetDeviceOutput(image, m)->pixels);
|
|
CHECK(pixels[0] == 100 + (image % 2) * nmodules + m);
|
|
CHECK(pixels[RAW_MODULE_SIZE - 1] == 100 + (image % 2) * nmodules + m);
|
|
}
|
|
}
|
|
}
|