Unit test framework for phosphor-debug-collector
Change:
-Serialize method does not use any of the watch functionalities,
so defining set in serialization header as using watch header
creates unnecessary dependency.
Test:
Added 3 test cases related to dump serialization.
Ran the UTs on docker environment.
Result:
1/1 debug_inif_test OK 1.48s
Ok: 1
Expected Fail: 0
Fail: 0
Unexpected Pass: 0
Skipped: 0
Timeout: 0
Signed-off-by: Chirag Sharma <chirshar@in.ibm.com>
Change-Id: I6a88559bf407fa70a96dda3b31aaa1acd038c958
diff --git a/test/debug_inif_test.cpp b/test/debug_inif_test.cpp
new file mode 100644
index 0000000..04fb6cf
--- /dev/null
+++ b/test/debug_inif_test.cpp
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: Apache-2.0
+#include <cstdlib>
+#include <dump_serialize.hpp>
+#include <exception>
+#include <filesystem>
+#include <set>
+#include <string>
+
+#include <gtest/gtest.h>
+
+namespace fs = std::filesystem;
+
+class TestDumpSerial : public ::testing::Test
+{
+ public:
+ TestDumpSerial()
+ {
+ }
+
+ void SetUp()
+ {
+ char tmpdir[] = "/tmp/dump.XXXXXX";
+ auto dirPtr = mkdtemp(tmpdir);
+ if (dirPtr == NULL)
+ {
+ throw std::bad_alloc();
+ }
+ dumpDir = std::string(dirPtr);
+ fs::create_directories(dumpDir);
+ dumpFile = dumpDir;
+ dumpFile /= "elogid";
+ }
+ void TearDown()
+ {
+ fs::remove_all(dumpDir);
+ }
+
+ std::string dumpDir;
+ fs::path dumpFile;
+};
+
+TEST_F(TestDumpSerial, Serialization)
+{
+ using ElogList = std::set<uint32_t>;
+ ElogList e;
+ e.insert(1);
+ e.insert(2);
+ e.insert(3);
+ phosphor::dump::elog::serialize(e, dumpFile.c_str());
+ bool value = phosphor::dump::elog::deserialize(dumpFile.c_str(), e);
+ EXPECT_EQ(value, true);
+}
+
+TEST_F(TestDumpSerial, DeserializationFalseCase)
+{
+ using ElogList = std::set<uint32_t>;
+ ElogList e;
+ e.insert(1);
+ bool value = phosphor::dump::elog::deserialize(dumpFile.c_str(), e);
+ EXPECT_EQ(value, false);
+}
+
+TEST(DumpDeSerialPath, DeserializationFalsePath)
+{
+ using ElogList = std::set<uint32_t>;
+ ElogList e;
+ e.insert(1);
+ // Providing dummy path
+ bool value = phosphor::dump::elog::deserialize("/tmp/Fake/serial", e);
+ EXPECT_EQ(value, false);
+}