Clock updates
This commit is contained in:
@@ -29,6 +29,13 @@ InputFrameMailboxConfig MakeConfig(std::size_t capacity = 2)
|
||||
return config;
|
||||
}
|
||||
|
||||
InputFrameMailboxConfig MakeBufferedConfig(std::size_t capacity = 4, std::size_t maxReadyFrames = 2)
|
||||
{
|
||||
InputFrameMailboxConfig config = MakeConfig(capacity);
|
||||
config.maxReadyFrames = maxReadyFrames;
|
||||
return config;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> MakeFrame(unsigned char value)
|
||||
{
|
||||
return std::vector<unsigned char>(16, value);
|
||||
@@ -90,6 +97,48 @@ void TestReadingFrameIsProtected()
|
||||
Expect(mailbox.Release(acquired), "protected frame releases");
|
||||
Expect(mailbox.SubmitFrame(frame2.data(), 8, 2), "producer can submit after release");
|
||||
}
|
||||
|
||||
void TestAcquireOldestConsumesFifoWithoutDroppingReadyFrames()
|
||||
{
|
||||
InputFrameMailbox mailbox(MakeConfig(3));
|
||||
const std::vector<unsigned char> frame1 = MakeFrame(1);
|
||||
const std::vector<unsigned char> frame2 = MakeFrame(2);
|
||||
|
||||
Expect(mailbox.SubmitFrame(frame1.data(), 8, 1), "fifo first frame submits");
|
||||
Expect(mailbox.SubmitFrame(frame2.data(), 8, 2), "fifo second frame submits");
|
||||
|
||||
InputFrame acquired;
|
||||
Expect(mailbox.TryAcquireOldest(acquired), "fifo oldest frame acquired");
|
||||
Expect(acquired.frameIndex == 1, "fifo acquire returns oldest frame");
|
||||
Expect(mailbox.Release(acquired), "fifo acquired frame releases");
|
||||
|
||||
const InputFrameMailboxMetrics metrics = mailbox.Metrics();
|
||||
Expect(metrics.readyCount == 1, "fifo acquire leaves newer frame ready");
|
||||
Expect(metrics.droppedReadyFrames == 0, "fifo acquire does not drop newer ready frame");
|
||||
}
|
||||
|
||||
void TestMaxReadyFramesKeepsConfiguredInputBuffer()
|
||||
{
|
||||
InputFrameMailbox mailbox(MakeBufferedConfig(4, 3));
|
||||
const std::vector<unsigned char> frame1 = MakeFrame(1);
|
||||
const std::vector<unsigned char> frame2 = MakeFrame(2);
|
||||
const std::vector<unsigned char> frame3 = MakeFrame(3);
|
||||
const std::vector<unsigned char> frame4 = MakeFrame(4);
|
||||
|
||||
Expect(mailbox.SubmitFrame(frame1.data(), 8, 1), "bounded first frame submits");
|
||||
Expect(mailbox.SubmitFrame(frame2.data(), 8, 2), "bounded second frame submits");
|
||||
Expect(mailbox.SubmitFrame(frame3.data(), 8, 3), "bounded third frame submits");
|
||||
Expect(mailbox.SubmitFrame(frame4.data(), 8, 4), "bounded fourth frame submits");
|
||||
|
||||
InputFrame acquired;
|
||||
Expect(mailbox.TryAcquireOldest(acquired), "bounded oldest available frame acquired");
|
||||
Expect(acquired.frameIndex == 2, "bounded buffer trims oldest beyond configured ready frame limit");
|
||||
Expect(mailbox.Release(acquired), "bounded acquired frame releases");
|
||||
|
||||
const InputFrameMailboxMetrics metrics = mailbox.Metrics();
|
||||
Expect(metrics.readyCount == 2, "bounded acquire leaves remaining configured ready frames");
|
||||
Expect(metrics.droppedReadyFrames == 1, "bounded buffer records trimmed frame");
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -97,6 +146,8 @@ int main()
|
||||
TestAcquireLatestDropsOlderReadyFrames();
|
||||
TestSubmitDropsOldestWhenFull();
|
||||
TestReadingFrameIsProtected();
|
||||
TestAcquireOldestConsumesFifoWithoutDroppingReadyFrames();
|
||||
TestMaxReadyFramesKeepsConfiguredInputBuffer();
|
||||
|
||||
if (gFailures != 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user