buffer: Update the definition of QueueSize

There were confusion whether the QueueSize field represented just the
queue for the normal log or if it represented the whole circular buffer.
Settled on it being the whole circular buffer.

Tested: Unit tested and verified this works on a downstream machine

Signed-off-by: Brandon Kim <brandonkim@google.com>
Change-Id: I867e997b72500c7bcd03047d8eb3e4db146a8add
diff --git a/test/buffer_test.cpp b/test/buffer_test.cpp
index 0fff5ee..a78897a 100644
--- a/test/buffer_test.cpp
+++ b/test/buffer_test.cpp
@@ -44,7 +44,7 @@
     // CircularBufferHeader size is 0x30, ensure the test region is bigger
     static constexpr size_t testRegionSize = 0x200;
     static constexpr uint32_t testBmcInterfaceVersion = 123;
-    static constexpr uint32_t testQueueSize = 0x100;
+    static constexpr uint32_t testQueueSize = 0x200;
     static constexpr uint16_t testUeRegionSize = 0x50;
     static constexpr std::array<uint32_t, 4> testMagicNumber = {
         0x12345678, 0x22345678, 0x32345678, 0x42345678};
@@ -67,15 +67,14 @@
     EXPECT_THROW(
         try {
             // Test too big of a proposed buffer compared to the memori size
-            uint16_t bigQueueSize = 0x181;
+            uint16_t bigQueueSize = 0x201;
             uint16_t bigUeRegionSize = 0x50;
             bufferImpl->initialize(testBmcInterfaceVersion, bigQueueSize,
                                    bigUeRegionSize, testMagicNumber);
         } catch (const std::runtime_error& e) {
             EXPECT_STREQ(
                 e.what(),
-                "[initialize] Proposed region size '513' "
-                "is bigger than the BMC's allocated MMIO region of '512'");
+                "[initialize] Proposed queue size '513' is bigger than the BMC's allocated MMIO region of '512'");
             throw;
         },
         std::runtime_error);
@@ -83,18 +82,16 @@
 
     EXPECT_CALL(*dataInterfaceMockPtr, getMemoryRegionSize())
         .WillOnce(Return(testRegionSize));
-    size_t testProposedBufferSize =
-        sizeof(struct CircularBufferHeader) + testUeRegionSize + testQueueSize;
-    const std::vector<uint8_t> emptyArray(testProposedBufferSize, 0);
+    const std::vector<uint8_t> emptyArray(testQueueSize, 0);
     // Return a smaller write than the intended testRegionSize to test the error
     EXPECT_CALL(*dataInterfaceMockPtr, write(0, ElementsAreArray(emptyArray)))
-        .WillOnce(Return(testProposedBufferSize - 1));
+        .WillOnce(Return(testQueueSize - 1));
     EXPECT_THROW(
         try {
             bufferImpl->initialize(testBmcInterfaceVersion, testQueueSize,
                                    testUeRegionSize, testMagicNumber);
         } catch (const std::runtime_error& e) {
-            EXPECT_STREQ(e.what(), "[initialize] Only erased '383'");
+            EXPECT_STREQ(e.what(), "[initialize] Only erased '511'");
             throw;
         },
         std::runtime_error);
@@ -103,7 +100,7 @@
     EXPECT_CALL(*dataInterfaceMockPtr, getMemoryRegionSize())
         .WillOnce(Return(testRegionSize));
     EXPECT_CALL(*dataInterfaceMockPtr, write(0, ElementsAreArray(emptyArray)))
-        .WillOnce(Return(testProposedBufferSize));
+        .WillOnce(Return(testQueueSize));
     // Return a smaller write than the intended initializationHeader to test the
     // error
     EXPECT_CALL(*dataInterfaceMockPtr, write(0, _)).WillOnce(Return(0));
@@ -125,11 +122,9 @@
     InSequence s;
     EXPECT_CALL(*dataInterfaceMockPtr, getMemoryRegionSize())
         .WillOnce(Return(testRegionSize));
-    size_t testProposedBufferSize =
-        sizeof(struct CircularBufferHeader) + testUeRegionSize + testQueueSize;
-    const std::vector<uint8_t> emptyArray(testProposedBufferSize, 0);
+    const std::vector<uint8_t> emptyArray(testQueueSize, 0);
     EXPECT_CALL(*dataInterfaceMockPtr, write(0, ElementsAreArray(emptyArray)))
-        .WillOnce(Return(testProposedBufferSize));
+        .WillOnce(Return(testQueueSize));
 
     uint8_t* testInitializationHeaderPtr =
         reinterpret_cast<uint8_t*>(&testInitializationHeader);
@@ -258,12 +253,10 @@
         InSequence s;
         EXPECT_CALL(*dataInterfaceMockPtr, getMemoryRegionSize())
             .WillOnce(Return(testRegionSize));
-        size_t testProposedBufferSize = sizeof(struct CircularBufferHeader) +
-                                        testUeRegionSize + testQueueSize;
-        const std::vector<uint8_t> emptyArray(testProposedBufferSize, 0);
+        const std::vector<uint8_t> emptyArray(testQueueSize, 0);
         EXPECT_CALL(*dataInterfaceMockPtr,
                     write(0, ElementsAreArray(emptyArray)))
-            .WillOnce(Return(testProposedBufferSize));
+            .WillOnce(Return(testQueueSize));
 
         EXPECT_CALL(*dataInterfaceMockPtr, write(0, _))
             .WillOnce(Return(bufferHeaderSize));
@@ -275,33 +268,39 @@
     static constexpr uint8_t expectedBmcReadPtrOffset = 0x21;
     static constexpr size_t expectedqueueOffset = 0x30 + testUeRegionSize;
 
+    static constexpr size_t testMaxOffset =
+        testQueueSize - testUeRegionSize - sizeof(struct CircularBufferHeader);
     uint8_t* testInitializationHeaderPtr =
         reinterpret_cast<uint8_t*>(&testInitializationHeader);
 };
 
+TEST_F(BufferWraparoundReadTest, GetMaxOffsetTest)
+{
+    EXPECT_EQ(bufferImpl->getMaxOffset(), testMaxOffset);
+}
+
 TEST_F(BufferWraparoundReadTest, ParamsTooBigFail)
 {
     InSequence s;
-
-    size_t tooBigOffset = testQueueSize + 1;
+    size_t tooBigOffset = testMaxOffset + 1;
     EXPECT_THROW(
         try {
             bufferImpl->wraparoundRead(tooBigOffset, /* length */ 1);
         } catch (const std::runtime_error& e) {
             EXPECT_STREQ(
                 e.what(),
-                "[wraparoundRead] relativeOffset '257' was bigger than queueSize '256'");
+                "[wraparoundRead] relativeOffset '385' was bigger than maxOffset '384'");
             throw;
         },
         std::runtime_error);
 
-    size_t tooBigLength = testQueueSize + 1;
+    size_t tooBigLength = testMaxOffset + 1;
     EXPECT_THROW(
         try {
             bufferImpl->wraparoundRead(/* relativeOffset */ 0, tooBigLength);
         } catch (const std::runtime_error& e) {
-            EXPECT_STREQ(e.what(), "[wraparoundRead] length '257' was bigger "
-                                   "than queueSize '256'");
+            EXPECT_STREQ(e.what(), "[wraparoundRead] length '385' was bigger "
+                                   "than maxOffset '384'");
             throw;
         },
         std::runtime_error);
@@ -364,7 +363,7 @@
     InSequence s;
     size_t testBytesLeft = 3;
     size_t testLength = 0x10;
-    size_t testOffset = testQueueSize - (testLength - testBytesLeft);
+    size_t testOffset = testMaxOffset - (testLength - testBytesLeft);
 
     // Read until the end of the queue
     std::vector<std::uint8_t> testBytesReadShort(testLength - testBytesLeft);
@@ -395,7 +394,7 @@
     InSequence s;
     size_t testBytesLeft = 3;
     size_t testLength = 0x10;
-    size_t testOffset = testQueueSize - (testLength - testBytesLeft);
+    size_t testOffset = testMaxOffset - (testLength - testBytesLeft);
 
     // Read to the end of the queue
     std::vector<std::uint8_t> testBytesReadFirst{16, 15, 14, 13, 12, 11, 10,
@@ -431,7 +430,7 @@
     InSequence s;
     size_t testBytesLeft = 0;
     size_t testLength = 4;
-    size_t testOffset = testQueueSize - (testLength - testBytesLeft);
+    size_t testOffset = testMaxOffset - (testLength - testBytesLeft);
 
     // Read to the very end of the queue
     std::vector<std::uint8_t> testBytes{4, 3, 2, 1};
@@ -471,7 +470,7 @@
                             std::span<std::uint8_t> expetedBytesOutput)
     {
         InSequence s;
-        const uint32_t queueSizeToQueueEnd = testQueueSize - relativeOffset;
+        const uint32_t queueSizeToQueueEnd = testMaxOffset - relativeOffset;
 
         // This will wrap, split the read mocks in 2
         if (expetedBytesOutput.size() > queueSizeToQueueEnd)
@@ -555,7 +554,7 @@
         testEntryHeaderPtr, testEntryHeaderPtr + entryHeaderSize);
     // Set testOffset so that we can test the wraparound here at the header and
     // update the readPtr
-    testOffset = testQueueSize - 1;
+    testOffset = testMaxOffset - 1;
     EXPECT_CALL(*dataInterfaceMockPtr, write(expectedBmcReadPtrOffset, _))
         .WillOnce(Return(expectedWriteSize));
     EXPECT_NO_THROW(bufferImpl->updateReadPtr(testOffset));
@@ -575,7 +574,7 @@
 
     // Set testOffset so that we can test the wraparound here as well on our
     // second read for the entry (by 1 byte)
-    testOffset = testQueueSize - entryHeaderSize - 1;
+    testOffset = testMaxOffset - entryHeaderSize - 1;
     EXPECT_CALL(*dataInterfaceMockPtr, write(expectedBmcReadPtrOffset, _))
         .WillOnce(Return(expectedWriteSize));
     EXPECT_NO_THROW(bufferImpl->updateReadPtr(testOffset));
@@ -606,7 +605,7 @@
     InSequence s;
     // Set the biosWritePtr too big
     testInitializationHeader.biosWritePtr =
-        boost::endian::native_to_little((testQueueSize + 1));
+        boost::endian::native_to_little((testMaxOffset + 1));
     initializeFuncMock();
 
     EXPECT_CALL(*dataInterfaceMockPtr, read(0, bufferHeaderSize))
@@ -618,8 +617,8 @@
             bufferImpl->readErrorLogs();
         } catch (const std::runtime_error& e) {
             EXPECT_STREQ(e.what(),
-                         "[readErrorLogs] currentBiosWritePtr was '257' "
-                         "which was bigger than queueSize '256'");
+                         "[readErrorLogs] currentBiosWritePtr was '385' "
+                         "which was bigger than maxOffset '384'");
             throw;
         },
         std::runtime_error);
@@ -628,7 +627,7 @@
     testInitializationHeader.biosWritePtr = 0;
     initializeFuncMock();
     testInitializationHeader.bmcReadPtr =
-        boost::endian::native_to_little((testQueueSize + 1));
+        boost::endian::native_to_little((testMaxOffset + 1));
     initializeFuncMock();
 
     EXPECT_CALL(*dataInterfaceMockPtr, read(0, bufferHeaderSize))
@@ -639,8 +638,8 @@
         try {
             bufferImpl->readErrorLogs();
         } catch (const std::runtime_error& e) {
-            EXPECT_STREQ(e.what(), "[readErrorLogs] currentReadPtr was '257' "
-                                   "which was bigger than queueSize '256'");
+            EXPECT_STREQ(e.what(), "[readErrorLogs] currentReadPtr was '385' "
+                                   "which was bigger than maxOffset '384'");
             throw;
         },
         std::runtime_error);
@@ -685,7 +684,7 @@
 {
     InSequence s;
     // Set the bmcReadPtr to 1 entryHeader + entry size from the "end" exactly
-    uint32_t entryAndHeaderSizeAwayFromEnd = testQueueSize - entryAndHeaderSize;
+    uint32_t entryAndHeaderSizeAwayFromEnd = testMaxOffset - entryAndHeaderSize;
     testInitializationHeader.bmcReadPtr =
         boost::endian::native_to_little(entryAndHeaderSizeAwayFromEnd);
     // Set the biosWritePtr to 1 entryHeader + entry size from the "beginning"