ZeroCopyReturnValue: Reset status properly
This commit is contained in:
@@ -243,3 +243,93 @@ TEST_CASE("ImageBuffer_BuffersNotReturned") {
|
||||
REQUIRE(buf_ctrl.GetAvailSlots() == 3);
|
||||
REQUIRE(!buf_ctrl.CheckIfBufferReturned(std::chrono::microseconds(1)));
|
||||
}
|
||||
|
||||
TEST_CASE("ImageBuffer_SlotReuse") {
|
||||
DiffractionExperiment experiment(DetJF(18,3,8,36));
|
||||
|
||||
// Only 1 slot so reuse is guaranteed
|
||||
ImageBuffer buf_ctrl(experiment.GetImageBufferLocationSize());
|
||||
buf_ctrl.StartMeasurement(experiment);
|
||||
|
||||
REQUIRE(buf_ctrl.GetStatus().total_slots == 1);
|
||||
REQUIRE(buf_ctrl.GetAvailSlots() == 1);
|
||||
|
||||
// First cycle: acquire -> ReadyToSend -> release
|
||||
ZeroCopyReturnValue *ret = buf_ctrl.GetImageSlot();
|
||||
REQUIRE(ret != nullptr);
|
||||
REQUIRE(buf_ctrl.GetAvailSlots() == 0);
|
||||
|
||||
ret->SetImageNumber(0);
|
||||
ret->SetImageSize(100);
|
||||
ret->SetIndexed(false);
|
||||
ret->ReadyToSend();
|
||||
|
||||
REQUIRE(buf_ctrl.GetStatus().sending_slots == 1);
|
||||
REQUIRE(buf_ctrl.GetStatus().preparation_slots == 0);
|
||||
|
||||
ret->release();
|
||||
|
||||
REQUIRE(buf_ctrl.GetAvailSlots() == 1);
|
||||
REQUIRE(buf_ctrl.GetStatus().sending_slots == 0);
|
||||
|
||||
// Second cycle: reuse the same slot — this is where the bug manifested
|
||||
ZeroCopyReturnValue *ret2 = buf_ctrl.GetImageSlot();
|
||||
REQUIRE(ret2 != nullptr);
|
||||
REQUIRE(buf_ctrl.GetAvailSlots() == 0);
|
||||
REQUIRE(buf_ctrl.GetStatus().preparation_slots == 1);
|
||||
|
||||
ret2->SetImageNumber(1);
|
||||
ret2->SetImageSize(200);
|
||||
ret2->SetIndexed(true);
|
||||
REQUIRE_NOTHROW(ret2->ReadyToSend());
|
||||
|
||||
REQUIRE(buf_ctrl.GetStatus().sending_slots == 1);
|
||||
REQUIRE(buf_ctrl.GetStatus().preparation_slots == 0);
|
||||
|
||||
REQUIRE_NOTHROW(ret2->release());
|
||||
|
||||
REQUIRE(buf_ctrl.GetAvailSlots() == 1);
|
||||
REQUIRE(buf_ctrl.GetStatus().sending_slots == 0);
|
||||
|
||||
// Third cycle: verify it keeps working
|
||||
ZeroCopyReturnValue *ret3 = buf_ctrl.GetImageSlot();
|
||||
REQUIRE(ret3 != nullptr);
|
||||
|
||||
ret3->SetImageNumber(2);
|
||||
ret3->SetImageSize(300);
|
||||
ret3->SetIndexed(false);
|
||||
REQUIRE_NOTHROW(ret3->ReadyToSend());
|
||||
REQUIRE_NOTHROW(ret3->release());
|
||||
|
||||
REQUIRE(buf_ctrl.GetAvailSlots() == 1);
|
||||
REQUIRE(buf_ctrl.Finalize(std::chrono::microseconds(1)));
|
||||
}
|
||||
|
||||
TEST_CASE("ImageBuffer_SlotReuse_ReleaseFromInPreparation") {
|
||||
DiffractionExperiment experiment(DetJF(18,3,8,36));
|
||||
|
||||
ImageBuffer buf_ctrl(experiment.GetImageBufferLocationSize());
|
||||
buf_ctrl.StartMeasurement(experiment);
|
||||
|
||||
// First cycle: acquire -> release directly (skipping explicit ReadyToSend)
|
||||
ZeroCopyReturnValue *ret = buf_ctrl.GetImageSlot();
|
||||
REQUIRE(ret != nullptr);
|
||||
|
||||
ret->SetImageNumber(0);
|
||||
ret->SetImageSize(100);
|
||||
ret->release();
|
||||
|
||||
REQUIRE(buf_ctrl.GetAvailSlots() == 1);
|
||||
|
||||
// Second cycle: reuse after release-from-InPreparation path
|
||||
ZeroCopyReturnValue *ret2 = buf_ctrl.GetImageSlot();
|
||||
REQUIRE(ret2 != nullptr);
|
||||
|
||||
ret2->SetImageNumber(1);
|
||||
ret2->SetImageSize(200);
|
||||
REQUIRE_NOTHROW(ret2->ReadyToSend());
|
||||
REQUIRE_NOTHROW(ret2->release());
|
||||
|
||||
REQUIRE(buf_ctrl.GetAvailSlots() == 1);
|
||||
REQUIRE(buf_ctrl.Finalize(std::chrono::microseconds(1)));
|
||||
}
|
||||
Reference in New Issue
Block a user