Add OEM command to request flash size
The BMC flash is `/dev/mtd0` and the size can found in
`/sys/class/mtd/mtd0/size`. This OEM command will request that
information with MTDINFO.
Tested:
Successfully requested the flash size information with ipmitool.
```
cat /sys/class/mtd/mtd0/size
67108864
```
67108864 / 1024 / 1024 = 64MB flash
```
ipmitool raw 0x2e 0x32 0x79 0x2b 0x00 0x09
79 2b 00 09 00 00 00 04
```
Output in little endian.
0x04000000 -> 67108864
Change-Id: Iec1b33503d1166a42ceef4b8491e5c19c3a077fe
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/test/flash_unittest.cpp b/test/flash_unittest.cpp
new file mode 100644
index 0000000..36f5d4a
--- /dev/null
+++ b/test/flash_unittest.cpp
@@ -0,0 +1,52 @@
+#include "commands.hpp"
+#include "flash_size.hpp"
+#include "handler_mock.hpp"
+
+#include <cstdint>
+#include <cstring>
+#include <string>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#define MAX_IPMI_BUFFER 64
+
+using ::testing::Return;
+
+namespace google
+{
+namespace ipmi
+{
+
+TEST(FlashSizeCommandTest, InvalidCommandLength)
+{
+ // GetFlashSizeRequest is one byte, let's send 0.
+ std::vector<std::uint8_t> request = {};
+ size_t dataLen = request.size();
+ std::uint8_t reply[MAX_IPMI_BUFFER];
+
+ HandlerMock hMock;
+ EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID,
+ getFlashSize(request.data(), reply, &dataLen, &hMock));
+}
+
+TEST(FlashSizeCommandTest, ValidRequest)
+{
+ std::vector<std::uint8_t> request = {SysOEMCommands::SysGetFlashSize};
+ size_t dataLen = request.size();
+ std::uint8_t reply[MAX_IPMI_BUFFER];
+ uint32_t flashSize = 5422312; // 0x52BCE8
+
+ HandlerMock hMock;
+ EXPECT_CALL(hMock, getFlashSize()).WillOnce(Return(flashSize));
+ EXPECT_EQ(IPMI_CC_OK,
+ getFlashSize(request.data(), reply, &dataLen, &hMock));
+ EXPECT_EQ(dataLen, 5);
+ EXPECT_EQ(reply[4], 0);
+ EXPECT_EQ(reply[3], 0x52);
+ EXPECT_EQ(reply[2], 0xBC);
+ EXPECT_EQ(reply[1], 0xE8);
+}
+
+} // namespace ipmi
+} // namespace google