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);
+}
diff --git a/test/meson.build b/test/meson.build
new file mode 100644
index 0000000..d375acc
--- /dev/null
+++ b/test/meson.build
@@ -0,0 +1,40 @@
+# SPDX-License-Identifier: Apache-2.0
+if get_option('oe-sdk').enabled()
+ # Setup OE SYSROOT
+ OECORE_TARGET_SYSROOT = run_command('sh', '-c', 'echo $OECORE_TARGET_SYSROOT').stdout().strip()
+ if OECORE_TARGET_SYSROOT == ''
+ error('Unable to get OECORE_TARGET_SYSROOT, check your environment.')
+ endif
+ message('OECORE_TARGET_SYSROOT: ' + OECORE_TARGET_SYSROOT)
+ rpath = ':'.join([OECORE_TARGET_SYSROOT + '/lib', OECORE_TARGET_SYSROOT + '/usr/lib'])
+ ld_so = run_command('sh', '-c', 'find ' + OECORE_TARGET_SYSROOT + '/lib/ld-*.so | sort -r -n | head -n1').stdout().strip()
+ dynamic_linker = ['-Wl,-dynamic-linker,' + ld_so]
+else
+ dynamic_linker = []
+endif
+
+gtest = dependency('gtest', main: true, disabler: true, required: true)
+gmock = dependency('gmock', disabler: true, required: true)
+
+dump = declare_dependency(
+ sources: [
+ '../dump_serialize.cpp'
+ ])
+
+tests = [
+ 'debug_inif_test',
+]
+
+foreach t : tests
+ test(t, executable(t.underscorify(), t + '.cpp',
+ include_directories: ['.', '../'],
+ implicit_include_directories: false,
+ link_args: dynamic_linker,
+ build_rpath: get_option('oe-sdk').enabled() ? rpath : '',
+ dependencies:[ gtest,
+ gmock,
+ dump,
+ phosphor_logging,
+ cppfs]),
+ workdir: meson.current_source_dir())
+endforeach