diff options
author | Patrick Venture <venture@google.com> | 2019-03-07 12:17:04 -0800 |
---|---|---|
committer | Patrick Venture <venture@google.com> | 2019-03-07 12:32:31 -0800 |
commit | 161b72119a289ace99752d4b5a203b7ac53f7ed8 (patch) | |
tree | 8d97517955995d1e2b6b7de8bf60d8f8fcae0758 | |
parent | 509ca629dcf67fb5fd8723ec07fd1e6205549085 (diff) | |
download | ipmi-blob-tool-161b72119a289ace99752d4b5a203b7ac53f7ed8.tar.gz ipmi-blob-tool-161b72119a289ace99752d4b5a203b7ac53f7ed8.zip |
test: add unit-tests for the crc module
Copied the unit-tests from phosphor-ipmi-blobs. The CRC module there
will be dropped in favor of this one.
Change-Id: I875ec67820218c7b9d1feec8aee84cdbbe84df54
Signed-off-by: Patrick Venture <venture@google.com>
-rw-r--r-- | test/Makefile.am | 6 | ||||
-rw-r--r-- | test/crc_unittest.cpp | 42 |
2 files changed, 48 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 05d9b1d..1fa4ced 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -23,3 +23,9 @@ check_PROGRAMS += tools_ipmi_error_unittest tools_ipmi_error_unittest_SOURCES = tools_ipmi_error_unittest.cpp tools_ipmi_error_unittest_CPPFLAGS = $(gtest_cppflags) tools_ipmi_error_unittest_LDADD = $(gtest_ldadd) + +check_PROGRAMS += crc_unittest +crc_unittest_SOURCES = crc_unittest.cpp +crc_unittest_CPPFLAGS = $(gtest_cppflags) +crc_unittest_LDADD = $(gtest_ldadd) +crc_unittest_LDADD += $(top_builddir)/src/ipmiblob/crc.o diff --git a/test/crc_unittest.cpp b/test/crc_unittest.cpp new file mode 100644 index 0000000..3816bba --- /dev/null +++ b/test/crc_unittest.cpp @@ -0,0 +1,42 @@ +#include <cstdint> +#include <ipmiblob/crc.hpp> +#include <string> +#include <vector> + +#include <gtest/gtest.h> + +namespace ipmiblob +{ + +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}}); + + for (const CrcTestVector& testVector : vectors) + { + std::vector<std::uint8_t> input; + input.insert(input.begin(), testVector.input.begin(), + testVector.input.end()); + EXPECT_EQ(generateCrc(input), testVector.output); + } +} +} // namespace ipmiblob |