test: fru-utils: Exercise the FRU checksum algorithm
Add some tests for basic cases and behaviour around the checksum
roll-over.
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Ia28fd62559846e653e066dc8c3063a9d254191cf
diff --git a/test/test_fru-utils.cpp b/test/test_fru-utils.cpp
index 094e3f9..11a1aba 100644
--- a/test/test_fru-utils.cpp
+++ b/test/test_fru-utils.cpp
@@ -100,3 +100,45 @@
EXPECT_TRUE(verifyOffset(fruData, fruAreas::fruAreaChassis, 1));
}
+
+TEST(VerifyChecksumTest, EmptyInput)
+{
+ std::vector<uint8_t> data = {};
+
+ EXPECT_EQ(calculateChecksum(data), 0);
+}
+
+TEST(VerifyChecksumTest, SingleOneInput)
+{
+ std::vector<uint8_t> data(1, 1);
+
+ EXPECT_EQ(calculateChecksum(data), 255);
+}
+
+TEST(VerifyChecksumTest, AllOneInput)
+{
+ std::vector<uint8_t> data(256, 1);
+
+ EXPECT_EQ(calculateChecksum(data), 0);
+}
+
+TEST(VerifyChecksumTest, WrapBoundaryLow)
+{
+ std::vector<uint8_t> data = { 255, 0 };
+
+ EXPECT_EQ(calculateChecksum(data), 1);
+}
+
+TEST(VerifyChecksumTest, WrapBoundaryExact)
+{
+ std::vector<uint8_t> data = { 255, 1 };
+
+ EXPECT_EQ(calculateChecksum(data), 0);
+}
+
+TEST(VerifyChecksumTest, WrapBoundaryHigh)
+{
+ std::vector<uint8_t> data = { 255, 2 };
+
+ EXPECT_EQ(calculateChecksum(data), 255);
+}