72 lines
2.2 KiB
C++
72 lines
2.2 KiB
C++
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include <catch2/catch_all.hpp>
|
|
|
|
#include "../common/SendBufferControl.h"
|
|
|
|
TEST_CASE("SendBuffer") {
|
|
SendBuffer buf(2*1024*1024);
|
|
REQUIRE_THROWS(buf.SetBufferLocationSize(4 * 1024 * 1024));
|
|
REQUIRE_NOTHROW(buf.SetBufferLocationSize(1024 * 1024));
|
|
|
|
REQUIRE(buf.GetNumOfLocations() == 2);
|
|
|
|
REQUIRE(buf.GetBufferLocationSize() == 1024*1024);
|
|
|
|
REQUIRE(buf.GetBufferLocationID(buf.GetBufferLocation(0)) == 0);
|
|
REQUIRE(buf.GetBufferLocationID(buf.GetBufferLocation(1)) == 1);
|
|
REQUIRE_THROWS(buf.GetBufferLocation(2));
|
|
REQUIRE_THROWS(buf.GetBufferLocationID(nullptr));
|
|
}
|
|
|
|
TEST_CASE("SendBufferControl") {
|
|
DiffractionExperiment experiment(DetectorGeometry(18,3,8,36));
|
|
|
|
SendBuffer buf(4*experiment.GetSendBufferLocationSize());
|
|
SendBufferControl buf_ctrl(experiment, buf);
|
|
|
|
REQUIRE(buf_ctrl.GetAvailBufLocations() == 4);
|
|
|
|
ZeroCopyReturnValue *ret0 = buf_ctrl.GetBufLocation();
|
|
REQUIRE(ret0 != nullptr);
|
|
REQUIRE(buf_ctrl.GetAvailBufLocations() == 3);
|
|
|
|
ZeroCopyReturnValue *ret1 = buf_ctrl.GetBufLocation();
|
|
REQUIRE(ret1 != nullptr);
|
|
|
|
ZeroCopyReturnValue *ret2 = buf_ctrl.GetBufLocation();
|
|
REQUIRE(ret2 != nullptr);
|
|
|
|
ZeroCopyReturnValue *ret3 = buf_ctrl.GetBufLocation();
|
|
REQUIRE(ret3 != nullptr);
|
|
|
|
REQUIRE(buf_ctrl.GetAvailBufLocations() == 0);
|
|
|
|
ZeroCopyReturnValue *ret4 = buf_ctrl.GetBufLocation();
|
|
REQUIRE(ret4 == nullptr);
|
|
|
|
ret0->release();
|
|
ret1->release();
|
|
ret2->release();
|
|
ret3->release();
|
|
|
|
REQUIRE(buf_ctrl.GetAvailBufLocations() == 4);
|
|
|
|
REQUIRE(buf_ctrl.CheckIfBufferReturned(std::chrono::microseconds(1)));
|
|
}
|
|
|
|
TEST_CASE("SendBufferControl_BuffersNotReturned") {
|
|
DiffractionExperiment experiment(DetectorGeometry(18,3,8,36));
|
|
|
|
SendBuffer buf(4*experiment.GetSendBufferLocationSize());
|
|
SendBufferControl buf_ctrl(experiment, buf);
|
|
|
|
REQUIRE(buf_ctrl.GetAvailBufLocations() == 4);
|
|
|
|
ZeroCopyReturnValue *ret0 = buf_ctrl.GetBufLocation();
|
|
REQUIRE(ret0 != nullptr);
|
|
REQUIRE(buf_ctrl.GetAvailBufLocations() == 3);
|
|
REQUIRE(!buf_ctrl.CheckIfBufferReturned(std::chrono::microseconds(1)));
|
|
}
|