87 lines
2.5 KiB
C++
87 lines
2.5 KiB
C++
// Copyright (2019-2022) Paul Scherrer Institute
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
#include <catch2/catch.hpp>
|
|
|
|
#include "../receiver/host/ProcessJFPacket.h"
|
|
#include "../receiver/host/RawJFUDPPacket.h"
|
|
#include "../common/DiffractionExperiment.h"
|
|
|
|
TEST_CASE("ProcessRawPacketTest_Empty") {
|
|
ThreadSafeFIFO<Completion> c_fifo;
|
|
ThreadSafeFIFO<ProcessWorkRequest> wr_fifo;
|
|
{
|
|
ProcessJFPacket process(c_fifo, wr_fifo, 2);
|
|
}
|
|
REQUIRE(c_fifo.Size() == 0);
|
|
}
|
|
|
|
TEST_CASE("ProcessRawPacketTest") {
|
|
ThreadSafeFIFO<Completion> c_fifo;
|
|
ThreadSafeFIFO<ProcessWorkRequest> wr_fifo;
|
|
|
|
std::vector<uint16_t> array_0(RAW_MODULE_SIZE), array_1(RAW_MODULE_SIZE), array_2(RAW_MODULE_SIZE);
|
|
|
|
wr_fifo.Put(ProcessWorkRequest{.ptr = array_0.data(), .handle = 0});
|
|
wr_fifo.Put(ProcessWorkRequest{.ptr = array_1.data(), .handle = 1});
|
|
wr_fifo.Put(ProcessWorkRequest{.ptr = array_2.data(), .handle = 2});
|
|
|
|
DiffractionExperiment experiment(2, {4,4});
|
|
|
|
{
|
|
ProcessJFPacket process(c_fifo, wr_fifo, 4);
|
|
|
|
jf_payload datagram;
|
|
|
|
datagram.packetnum = 36;
|
|
datagram.framenum = 1;
|
|
datagram.bunchid = 84;
|
|
datagram.data[0] = 6789;
|
|
process.ProcessPacket(datagram, experiment.GetSrcIPv4Address(0, 4));
|
|
|
|
datagram.packetnum = 36;
|
|
datagram.framenum = 2;
|
|
datagram.bunchid = 84;
|
|
datagram.data[0] = 6345;
|
|
process.ProcessPacket(datagram, experiment.GetSrcIPv4Address(0, 5));
|
|
|
|
datagram.packetnum = 16;
|
|
datagram.framenum = 3;
|
|
datagram.bunchid = 84;
|
|
datagram.data[0] = 6346;
|
|
process.ProcessPacket(datagram, experiment.GetSrcIPv4Address(1,7));
|
|
|
|
}
|
|
|
|
REQUIRE(c_fifo.Size() == 3);
|
|
Completion c;
|
|
|
|
REQUIRE(c_fifo.Get(c));
|
|
CHECK(c.module == 2);
|
|
CHECK(c.bunchid == 84);
|
|
CHECK(c.frame_number == 0);
|
|
CHECK(c.packet_count == 1);
|
|
CHECK(c.packet_mask[0] == (1LU << 36));
|
|
CHECK(c.packet_mask[1] == 0);
|
|
|
|
REQUIRE(c_fifo.Get(c));
|
|
CHECK(c.module == 2);
|
|
CHECK(c.bunchid == 84);
|
|
CHECK(c.frame_number == 1);
|
|
CHECK(c.packet_count == 1);
|
|
CHECK(c.packet_mask[0] == 0);
|
|
CHECK(c.packet_mask[1] == (1LU << 36));
|
|
|
|
|
|
REQUIRE(c_fifo.Get(c));
|
|
CHECK(c.module == 3);
|
|
CHECK(c.bunchid == 84);
|
|
CHECK(c.frame_number == 2);
|
|
CHECK(c.packet_count == 1);
|
|
CHECK(c.packet_mask[0] == 0);
|
|
CHECK(c.packet_mask[1] == (1LU << 16));
|
|
|
|
CHECK(array_0[4096*36] == 6789);
|
|
CHECK(array_1[4096*(36+64)] == 6345);
|
|
CHECK(array_2[4096*(16+64)] == 6346);
|
|
} |