summaryrefslogtreecommitdiffstats
path: root/test/crc_unittest.cpp
diff options
context:
space:
mode:
authorPatrick Venture <venture@google.com>2018-09-12 08:53:29 -0700
committerPatrick Venture <venture@google.com>2018-09-15 13:11:30 -0700
commitef3aeadc9be37c47d0627e576e81a74a5bb9e94f (patch)
tree95c183977468b107bdd3faaaa988b5d853be2f00 /test/crc_unittest.cpp
parentbaa73da1abaaf05ea1133319405fb2b891825618 (diff)
downloadphosphor-ipmi-blobs-ef3aeadc9be37c47d0627e576e81a74a5bb9e94f.tar.gz
phosphor-ipmi-blobs-ef3aeadc9be37c47d0627e576e81a74a5bb9e94f.zip
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>
Diffstat (limited to 'test/crc_unittest.cpp')
-rw-r--r--test/crc_unittest.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/crc_unittest.cpp b/test/crc_unittest.cpp
new file mode 100644
index 0000000..fb69cb4
--- /dev/null
+++ b/test/crc_unittest.cpp
@@ -0,0 +1,44 @@
+#include "crc.hpp"
+
+#include <string>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+namespace blobs
+{
+
+TEST(Crc16Test, VerifyCrcValue)
+{
+ // Verify the crc16 is producing the value we expect.
+
+ // Origin: security/crypta/ipmi/portable/ipmi_utils_test.cc
+ struct CrcTestVector
+ {
+ std::string input;
+ uint16_t output;
+ };
+
+ std::string longString =
+ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
+ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
+ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
+ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
+ "AAAAAAAAAAAAAAAA";
+
+ std::vector<CrcTestVector> vectors({{"", 0x1D0F},
+ {"A", 0x9479},
+ {"123456789", 0xE5CC},
+ {longString, 0xE938}});
+
+ Crc16 crc;
+
+ for (const CrcTestVector& testVector : vectors)
+ {
+ crc.clear();
+ auto data = reinterpret_cast<const uint8_t*>(testVector.input.data());
+ crc.compute(data, testVector.input.size());
+ EXPECT_EQ(crc.get(), testVector.output);
+ }
+}
+} // namespace blobs
OpenPOWER on IntegriCloud