ipmi: start implementing flashStartTransfer

Change-Id: I1f8b1498d517c0661e98b1ba895e7152f7a9ed8e
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/test/ipmi_starttransfer_unittest.cpp b/test/ipmi_starttransfer_unittest.cpp
new file mode 100644
index 0000000..448287b
--- /dev/null
+++ b/test/ipmi_starttransfer_unittest.cpp
@@ -0,0 +1,61 @@
+#include "flash-ipmi.hpp"
+#include "ipmi.hpp"
+
+#include "updater_mock.hpp"
+
+#include <cstring>
+#include <gtest/gtest.h>
+
+using ::testing::NotNull;
+using ::testing::Return;
+using ::testing::StrictMock;
+
+// ipmid.hpp isn't installed where we can grab it and this value is per BMC
+// SoC.
+#define MAX_IPMI_BUFFER 64
+#define THIRTYTWO_MIB 33554432
+
+TEST(IpmiStartTransferTest, InvalidRequestLengthReturnsFailure)
+{
+    // Verify that the request is sanity checked w.r.t length.
+
+    StrictMock<UpdaterMock> updater;
+
+    size_t dataLen;
+    uint8_t request[MAX_IPMI_BUFFER] = {0};
+    uint8_t reply[MAX_IPMI_BUFFER] = {0};
+
+    struct StartTx tx;
+    tx.cmd = FlashSubCmds::flashStartTransfer;
+    tx.length = THIRTYTWO_MIB;
+    std::memcpy(request, &tx, sizeof(tx));
+
+    dataLen = sizeof(tx) - 1; // It's too small to be a valid packet.
+
+    EXPECT_EQ(IPMI_CC_INVALID,
+              startTransfer(&updater, request, reply, &dataLen));
+}
+
+TEST(IpmiStartTransferTest, ValidRequestBoringCase)
+{
+    // Verify that if the request is valid it calls into the flash updater.
+
+    StrictMock<UpdaterMock> updater;
+
+    size_t dataLen;
+    uint8_t request[MAX_IPMI_BUFFER] = {0};
+    uint8_t reply[MAX_IPMI_BUFFER] = {0};
+
+    struct StartTx tx;
+    tx.cmd = FlashSubCmds::flashStartTransfer;
+    tx.length = THIRTYTWO_MIB;
+    std::memcpy(request, &tx, sizeof(tx));
+
+    dataLen = sizeof(tx);
+
+    EXPECT_CALL(updater, start(THIRTYTWO_MIB)).WillOnce(Return(true));
+
+    EXPECT_EQ(IPMI_CC_OK, startTransfer(&updater, request, reply, &dataLen));
+    EXPECT_EQ(sizeof(uint8_t), dataLen);
+    EXPECT_EQ(0, reply[0]);
+}