buffer: Update cachedBufferHeader during "initialize"
We know what the bufferheader is after we call "initialize" (as we
clear the buffer before updating the known header). Update
cachedBufferHeader after successful initialization.
Signed-off-by: Brandon Kim <brandonkim@google.com>
Change-Id: Ia4c6f5258b5ccd0294bba267717b8e77c0bf5449
diff --git a/src/buffer.cpp b/src/buffer.cpp
index a2b8ee4..524984a 100644
--- a/src/buffer.cpp
+++ b/src/buffer.cpp
@@ -60,6 +60,7 @@
"Buffer initialization buffer header write only wrote '{}'",
byteWritten));
}
+ cachedBufferHeader = initializationHeader;
}
void BufferImpl::readBufferHeader()
@@ -76,7 +77,7 @@
}
cachedBufferHeader =
- *reinterpret_cast<CircularBufferHeader*>(bytesRead.data());
+ *reinterpret_cast<struct CircularBufferHeader*>(bytesRead.data());
};
struct CircularBufferHeader BufferImpl::getCachedBufferHeader() const
diff --git a/test/buffer_test.cpp b/test/buffer_test.cpp
index e3d5621..e8943a9 100644
--- a/test/buffer_test.cpp
+++ b/test/buffer_test.cpp
@@ -78,6 +78,7 @@
throw;
},
std::runtime_error);
+ EXPECT_NE(bufferImpl->getCachedBufferHeader(), testInitializationHeader);
EXPECT_CALL(*dataInterfaceMockPtr, getMemoryRegionSize())
.WillOnce(Return(testRegionSize));
@@ -97,6 +98,7 @@
throw;
},
std::runtime_error);
+ EXPECT_NE(bufferImpl->getCachedBufferHeader(), testInitializationHeader);
}
TEST_F(BufferTest, BufferInitializePass)
@@ -117,6 +119,7 @@
EXPECT_NO_THROW(bufferImpl->initialize(testBmcInterfaceVersion,
testQueueSize, testUeRegionSize,
testMagicNumber));
+ EXPECT_EQ(bufferImpl->getCachedBufferHeader(), testInitializationHeader);
}
TEST_F(BufferTest, BufferHeaderReadFail)