ipmi: start implementing flashAbort
Change-Id: I1a05ba7e9323046a09b8582351be987cdaab5a15
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/flash-ipmi.cpp b/flash-ipmi.cpp
index 69002f7..4588b5b 100644
--- a/flash-ipmi.cpp
+++ b/flash-ipmi.cpp
@@ -73,3 +73,9 @@
/* TODO: implement. */
return false;
}
+
+bool FlashUpdate::abortUpdate()
+{
+ /* TODO: implement. */
+ return false;
+}
diff --git a/flash-ipmi.hpp b/flash-ipmi.hpp
index 561d6c8..5e5fb22 100644
--- a/flash-ipmi.hpp
+++ b/flash-ipmi.hpp
@@ -136,6 +136,13 @@
* @return true if it was started succesfully.
*/
virtual bool startDataVerification() = 0;
+
+ /**
+ * Attempt to abort everything.
+ *
+ * @return true if aborted, false if unable or failed.
+ */
+ virtual bool abortUpdate() = 0;
};
class FlashUpdate : public UpdateInterface
@@ -157,6 +164,7 @@
bool hashFinish() override;
bool startDataVerification() override;
+ bool abortUpdate() override;
private:
/**
diff --git a/ipmi.cpp b/ipmi.cpp
index fc6092c..10ac2fe 100644
--- a/ipmi.cpp
+++ b/ipmi.cpp
@@ -31,6 +31,7 @@
{FlashSubCmds::flashHashData, hashBlock},
{FlashSubCmds::flashHashFinish, hashFinish},
{FlashSubCmds::flashDataVerify, dataVerify},
+ {FlashSubCmds::flashAbort, abortUpdate},
};
auto results = subHandlers.find(command);
@@ -192,3 +193,20 @@
(*dataLen) = 1;
return IPMI_CC_OK;
}
+
+ipmi_ret_t abortUpdate(UpdateInterface* updater, const uint8_t* reqBuf,
+ uint8_t* replyBuf, size_t* dataLen)
+{
+ /* TODO: May make sense to work all the pass-through commands into one
+ * piece of code
+ */
+ if (!updater->abortUpdate())
+ {
+ return IPMI_CC_INVALID;
+ }
+
+ /* We were successful and set the response byte to 0. */
+ replyBuf[0] = 0x00;
+ (*dataLen) = 1;
+ return IPMI_CC_OK;
+}
diff --git a/ipmi.hpp b/ipmi.hpp
index a389e8e..7fc27b4 100644
--- a/ipmi.hpp
+++ b/ipmi.hpp
@@ -117,3 +117,16 @@
*/
ipmi_ret_t dataVerify(UpdateInterface* updater, const uint8_t* reqBuf,
uint8_t* replyBuf, size_t* dataLen);
+
+/**
+ * Abort the image update process.
+ *
+ * @param[in] updater - Pointer to Updater object.
+ * @param[in] reqBuf - the IPMI packet.
+ * @param[in] replyBuf - Pointer to buffer for any response.
+ * @param[in,out] dataLen - Initially reqBuf length, set to replyBuf
+ * length when done.
+ * @return corresponding IPMI return code.
+ */
+ipmi_ret_t abortUpdate(UpdateInterface* updater, const uint8_t* reqBuf,
+ uint8_t* replyBuf, size_t* dataLen);
diff --git a/test/Makefile.am b/test/Makefile.am
index 4d4c806..c02ebb0 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -17,6 +17,7 @@
ipmi_hashdata_unittest \
ipmi_hashfinish_unittest \
ipmi_startverify_unittest \
+ ipmi_abort_unittest \
ipmi_validate_unittest \
ipmi_command_unittest
@@ -43,6 +44,9 @@
ipmi_startverify_unittest_SOURCES = ipmi_startverify_unittest.cpp
ipmi_startverify_unittest_LDADD = $(top_builddir)/ipmi.o
+ipmi_abort_unittest_SOURCES = ipmi_abort_unittest.cpp
+ipmi_abort_unittest_LDADD = $(top_builddir)/ipmi.o
+
ipmi_validate_unittest_SOURCES = ipmi_validate_unittest.cpp
ipmi_validate_unittest_LDADD = $(top_builddir)/ipmi.o
diff --git a/test/ipmi_abort_unittest.cpp b/test/ipmi_abort_unittest.cpp
new file mode 100644
index 0000000..671a30c
--- /dev/null
+++ b/test/ipmi_abort_unittest.cpp
@@ -0,0 +1,32 @@
+#include "flash-ipmi.hpp"
+#include "ipmi.hpp"
+
+#include "updater_mock.hpp"
+
+#include <gtest/gtest.h>
+
+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
+
+TEST(IpmiAbortTest, CallPassedOn)
+{
+ // The abort call is another pass-through command.
+
+ StrictMock<UpdaterMock> updater;
+
+ size_t dataLen;
+ uint8_t request[MAX_IPMI_BUFFER] = {0};
+ uint8_t reply[MAX_IPMI_BUFFER] = {0};
+
+ dataLen = 1; // request is only the command.
+ request[0] = FlashSubCmds::flashAbort;
+
+ EXPECT_CALL(updater, abortUpdate()).WillOnce(Return(true));
+ EXPECT_EQ(IPMI_CC_OK, abortUpdate(&updater, request, reply, &dataLen));
+ EXPECT_EQ(sizeof(uint8_t), dataLen);
+ EXPECT_EQ(0, reply[0]);
+}
diff --git a/test/updater_mock.hpp b/test/updater_mock.hpp
index 2074eeb..589df39 100644
--- a/test/updater_mock.hpp
+++ b/test/updater_mock.hpp
@@ -17,4 +17,5 @@
MOCK_METHOD2(hashData, bool(uint32_t, const std::vector<uint8_t>&));
MOCK_METHOD0(hashFinish, bool());
MOCK_METHOD0(startDataVerification, bool());
+ MOCK_METHOD0(abortUpdate, bool());
};