ipmi: start implementing flashVerifyCheck

Change-Id: I811693d9e736d273d2df9e65f7c5de7efd1d884c
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/test/Makefile.am b/test/Makefile.am
index bed24e6..26f3439 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -20,6 +20,7 @@
 	ipmi_abort_unittest \
 	ipmi_validate_unittest \
 	ipmi_command_unittest \
+	ipmi_verifycheck_unittest \
 	flash_start_unittest \
 	flash_flashdata_unittest \
 	flash_flashfinish_unittest \
@@ -59,6 +60,9 @@
 ipmi_command_unittest_SOURCES = ipmi_command_unittest.cpp
 ipmi_command_unittest_LDADD = $(top_builddir)/ipmi.o
 
+ipmi_verifycheck_unittest_SOURCES = ipmi_verifycheck_unittest.cpp
+ipmi_verifycheck_unittest_LDADD = $(top_builddir)/ipmi.o
+
 flash_start_unittest_SOURCES = flash_start_unittest.cpp
 flash_start_unittest_LDADD = $(top_builddir)/flash-ipmi.o $(SDBUSPLUS_LIBS)
 
diff --git a/test/flash_flashdata_unittest.cpp b/test/flash_flashdata_unittest.cpp
index df561ec..112565a 100644
--- a/test/flash_flashdata_unittest.cpp
+++ b/test/flash_flashdata_unittest.cpp
@@ -30,7 +30,7 @@
     // Verify that there is sanity checking.
     std::vector<uint8_t> bytes = {0xaa, 0x55};
 
-    FlashUpdate updater(name);
+    FlashUpdate updater(name, "");
     EXPECT_FALSE(updater.flashData(0, bytes));
 
     // Verify the file doesn't exist.
@@ -43,7 +43,7 @@
     // Verify that under normal usage it writes the bytes.
     std::vector<uint8_t> bytes = {0xaa, 0x55};
 
-    FlashUpdate updater(name);
+    FlashUpdate updater(name, "");
     updater.start(THIRTYTWO_MIB);
     EXPECT_TRUE(updater.flashData(0, bytes));
 
@@ -65,7 +65,7 @@
 
     std::vector<uint8_t> bytes = {0xaa, 0x55};
 
-    FlashUpdate updater(name);
+    FlashUpdate updater(name, "");
     updater.start(THIRTYTWO_MIB);
     EXPECT_TRUE(updater.flashData(2, bytes));
 
diff --git a/test/flash_flashfinish_unittest.cpp b/test/flash_flashfinish_unittest.cpp
index bdddd5a..e160b29 100644
--- a/test/flash_flashfinish_unittest.cpp
+++ b/test/flash_flashfinish_unittest.cpp
@@ -30,7 +30,7 @@
     // Verify that there is sanity checking
     std::vector<uint8_t> bytes = {0xaa, 0x55};
 
-    FlashUpdate updater(name);
+    FlashUpdate updater(name, "");
     EXPECT_FALSE(updater.flashFinish());
 
     // Verify the file doesn't exist.
@@ -43,7 +43,7 @@
     // Verify that under normal usage it closes the file.
     std::vector<uint8_t> bytes = {0xaa, 0x55};
 
-    FlashUpdate updater(name);
+    FlashUpdate updater(name, "");
     updater.start(THIRTYTWO_MIB);
     EXPECT_TRUE(updater.flashFinish());
 
@@ -59,7 +59,7 @@
     // be closed twice.
     std::vector<uint8_t> bytes = {0xaa, 0x55};
 
-    FlashUpdate updater(name);
+    FlashUpdate updater(name, "");
     updater.start(THIRTYTWO_MIB);
     EXPECT_TRUE(updater.flashFinish());
 
diff --git a/test/flash_hashdata_unittest.cpp b/test/flash_hashdata_unittest.cpp
index f9a3ffa..8d7be77 100644
--- a/test/flash_hashdata_unittest.cpp
+++ b/test/flash_hashdata_unittest.cpp
@@ -35,7 +35,7 @@
 
     std::vector<uint8_t> bytes = {0xaa, 0x55};
 
-    FlashUpdate updater(name, name2);
+    FlashUpdate updater(name, "", name2);
     EXPECT_FALSE(updater.hashData(0, bytes));
 }
 
@@ -44,7 +44,7 @@
     // Verify the normal use case works.
     std::vector<uint8_t> bytes = {0xaa, 0x55};
 
-    FlashUpdate updater(name, name2);
+    FlashUpdate updater(name, "", name2);
     EXPECT_TRUE(updater.start(THIRTYTWO_MIB));
     EXPECT_TRUE(updater.startHash(THIRTYTWO_MIB));
     EXPECT_TRUE(updater.hashData(0, bytes));
@@ -67,7 +67,7 @@
 
     std::vector<uint8_t> bytes = {0xaa, 0x55};
 
-    FlashUpdate updater(name, name2);
+    FlashUpdate updater(name, "", name2);
     EXPECT_TRUE(updater.start(THIRTYTWO_MIB));
     EXPECT_TRUE(updater.startHash(THIRTYTWO_MIB));
     EXPECT_TRUE(updater.hashData(2, bytes));
diff --git a/test/flash_hashfinish_unittest.cpp b/test/flash_hashfinish_unittest.cpp
index de785ae..12ff7a8 100644
--- a/test/flash_hashfinish_unittest.cpp
+++ b/test/flash_hashfinish_unittest.cpp
@@ -33,7 +33,7 @@
     // Verify that there is sanity checking
     std::vector<uint8_t> bytes = {0xaa, 0x55};
 
-    FlashUpdate updater(name, name2);
+    FlashUpdate updater(name, "", name2);
     EXPECT_FALSE(updater.hashFinish());
 
     // Verify the file doesn't exist.
@@ -46,7 +46,7 @@
     // Verify that under normal usage it closes the file.
     std::vector<uint8_t> bytes = {0xaa, 0x55};
 
-    FlashUpdate updater(name, name2);
+    FlashUpdate updater(name, "", name2);
     EXPECT_TRUE(updater.start(THIRTYTWO_MIB));
     EXPECT_TRUE(updater.startHash(THIRTYTWO_MIB));
     EXPECT_TRUE(updater.hashFinish());
@@ -63,7 +63,7 @@
     // be closed twice.
     std::vector<uint8_t> bytes = {0xaa, 0x55};
 
-    FlashUpdate updater(name, name2);
+    FlashUpdate updater(name, "", name2);
     EXPECT_TRUE(updater.start(THIRTYTWO_MIB));
     EXPECT_TRUE(updater.startHash(THIRTYTWO_MIB));
     EXPECT_TRUE(updater.hashFinish());
diff --git a/test/flash_hashstart_unittest.cpp b/test/flash_hashstart_unittest.cpp
index a3a1d9f..60f8df1 100644
--- a/test/flash_hashstart_unittest.cpp
+++ b/test/flash_hashstart_unittest.cpp
@@ -13,7 +13,7 @@
     std::string name = std::tmpnam(nullptr);
     std::string name2 = std::tmpnam(nullptr);
 
-    FlashUpdate updater(name, name2);
+    FlashUpdate updater(name, "", name2);
     EXPECT_FALSE(updater.startHash(THIRTYTWO_MIB));
 
     (void)std::remove(name.c_str());
@@ -27,7 +27,7 @@
     std::string name = std::tmpnam(nullptr);
     std::string name2 = std::tmpnam(nullptr);
 
-    FlashUpdate updater(name, name2);
+    FlashUpdate updater(name, "", name2);
     EXPECT_TRUE(updater.start(THIRTYTWO_MIB));
     EXPECT_TRUE(updater.startHash(THIRTYTWO_MIB));
 
diff --git a/test/flash_start_unittest.cpp b/test/flash_start_unittest.cpp
index b287561..81c2d45 100644
--- a/test/flash_start_unittest.cpp
+++ b/test/flash_start_unittest.cpp
@@ -13,7 +13,7 @@
 
     std::string name = std::tmpnam(nullptr);
 
-    FlashUpdate updater(name);
+    FlashUpdate updater(name, "");
     updater.start(THIRTYTWO_MIB);
 
     auto file = std::fopen(name.c_str(), "r");
diff --git a/test/ipmi_verifycheck_unittest.cpp b/test/ipmi_verifycheck_unittest.cpp
new file mode 100644
index 0000000..f71155f
--- /dev/null
+++ b/test/ipmi_verifycheck_unittest.cpp
@@ -0,0 +1,32 @@
+#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(IpmiCheckVerifyTest, CallPassedOn)
+{
+    // This IPMI handler just bundles the response.
+
+    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::flashVerifyCheck;
+
+    EXPECT_CALL(updater, checkVerify())
+        .WillOnce(Return(VerifyCheckResponse::running));
+    EXPECT_EQ(IPMI_CC_OK, checkVerify(&updater, request, reply, &dataLen));
+    EXPECT_EQ(sizeof(uint8_t), dataLen);
+    EXPECT_EQ(VerifyCheckResponse::running, reply[0]);
+}
diff --git a/test/updater_mock.hpp b/test/updater_mock.hpp
index 589df39..0fd6683 100644
--- a/test/updater_mock.hpp
+++ b/test/updater_mock.hpp
@@ -18,4 +18,5 @@
     MOCK_METHOD0(hashFinish, bool());
     MOCK_METHOD0(startDataVerification, bool());
     MOCK_METHOD0(abortUpdate, bool());
+    MOCK_METHOD0(checkVerify, VerifyCheckResponse());
 };