initial drop of phosphor-ipmi-blobs

This implements a majority of the OEM IPMI BLOBS protocol.  The only
piece missing from this is the timed expiration of sessions.

Change-Id: I82c9d17b625c94fc3340edcfabbbf1ffeb5ad7ac
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/test/ipmi_write_unittest.cpp b/test/ipmi_write_unittest.cpp
new file mode 100644
index 0000000..55a1e3b
--- /dev/null
+++ b/test/ipmi_write_unittest.cpp
@@ -0,0 +1,73 @@
+#include "ipmi.hpp"
+#include "manager_mock.hpp"
+
+#include <cstring>
+
+#include <gtest/gtest.h>
+
+namespace blobs
+{
+
+using ::testing::ElementsAreArray;
+using ::testing::Return;
+
+// ipmid.hpp isn't installed where we can grab it and this value is per BMC
+// SoC.
+#define MAX_IPMI_BUFFER 64
+
+TEST(BlobWriteTest, ManagerReturnsFailureReturnsFailure)
+{
+    // This verifies a failure from the manager is passed back.
+
+    ManagerMock mgr;
+    size_t dataLen;
+    uint8_t request[MAX_IPMI_BUFFER] = {0};
+    uint8_t reply[MAX_IPMI_BUFFER] = {0};
+    auto req = reinterpret_cast<struct BmcBlobWriteTx*>(request);
+
+    req->cmd = BlobOEMCommands::bmcBlobWrite;
+    req->crc = 0;
+    req->sessionId = 0x54;
+    req->offset = 0x100;
+
+    uint8_t expectedBytes[2] = {0x66, 0x67};
+    std::memcpy(req->data, &expectedBytes[0], sizeof(expectedBytes));
+
+    dataLen = sizeof(struct BmcBlobWriteTx) + sizeof(expectedBytes);
+
+    EXPECT_CALL(mgr,
+                write(req->sessionId, req->offset,
+                      ElementsAreArray(expectedBytes, sizeof(expectedBytes))))
+        .WillOnce(Return(false));
+
+    EXPECT_EQ(IPMI_CC_INVALID, writeBlob(&mgr, request, reply, &dataLen));
+}
+
+TEST(BlobWriteTest, ManagerReturnsTrueWriteSucceeds)
+{
+    // The case where everything works.
+
+    ManagerMock mgr;
+    size_t dataLen;
+    uint8_t request[MAX_IPMI_BUFFER] = {0};
+    uint8_t reply[MAX_IPMI_BUFFER] = {0};
+    auto req = reinterpret_cast<struct BmcBlobWriteTx*>(request);
+
+    req->cmd = BlobOEMCommands::bmcBlobWrite;
+    req->crc = 0;
+    req->sessionId = 0x54;
+    req->offset = 0x100;
+
+    uint8_t expectedBytes[2] = {0x66, 0x67};
+    std::memcpy(req->data, &expectedBytes[0], sizeof(expectedBytes));
+
+    dataLen = sizeof(struct BmcBlobWriteTx) + sizeof(expectedBytes);
+
+    EXPECT_CALL(mgr,
+                write(req->sessionId, req->offset,
+                      ElementsAreArray(expectedBytes, sizeof(expectedBytes))))
+        .WillOnce(Return(true));
+
+    EXPECT_EQ(IPMI_CC_OK, writeBlob(&mgr, request, reply, &dataLen));
+}
+} // namespace blobs