summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorNagaraju Goruganti <ngorugan@in.ibm.com>2018-06-25 23:28:58 -0500
committerNagaraju Goruganti <ngorugan@in.ibm.com>2018-08-08 04:53:31 -0500
commit477b731ad0fd8c116ffcaa8265a508c9fb112479 (patch)
tree6616e76e480d46a0a0f4e1f5d883f9882f16aae9 /test
parent80aa4762f78f1044d15c918d72316aa388ba0a02 (diff)
downloadphosphor-logging-477b731ad0fd8c116ffcaa8265a508c9fb112479.tar.gz
phosphor-logging-477b731ad0fd8c116ffcaa8265a508c9fb112479.zip
Add unit tests for the phosphor-logging server
-Add unit tests for error wrapping Change-Id: Ib15620d84de8ab5abdc85b8f88dd7c05f83fd6f3 Signed-off-by: Nagaraju Goruganti <ngorugan@in.ibm.com>
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am14
-rw-r--r--test/elog_errorwrap_test.cpp32
-rw-r--r--test/elog_errorwrap_test.hpp109
-rw-r--r--test/elog_unittest.cpp7
4 files changed, 150 insertions, 12 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index c9946d7..68ad467 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -3,7 +3,7 @@ AM_CPPFLAGS = -I${top_srcdir}
TESTS = $(check_PROGRAMS)
check_PROGRAMS = \
- elog_unittest \
+ elog_errorwrap_test \
serialization_test_path \
serialization_test_properties
@@ -19,6 +19,7 @@ test_cxxflags = \
test_ldflags = \
-lgtest_main -lgtest \
+ -lgmock_main -lgmock \
$(PTHREAD_LIBS) \
$(OESDK_TESTCASE_FLAGS) \
$(PHOSPHOR_DBUS_INTERFACES_LIBS) \
@@ -35,10 +36,13 @@ test_ldadd = \
$(top_builddir)/elog-process-metadata.o
-elog_unittest_CPPFLAGS = $(test_cppflags)
-elog_unittest_CXXFLAGS = $(test_cxxflags)
-elog_unittest_LDFLAGS = $(test_ldflags)
-elog_unittest_SOURCES = elog_unittest.cpp
+elog_errorwrap_test_CPPFLAGS = $(test_cppflags)
+elog_errorwrap_test_CXXFLAGS = $(test_cxxflags)
+elog_errorwrap_test_SOURCES = elog_errorwrap_test.cpp
+elog_errorwrap_test_LDADD = $(test_ldadd)
+elog_errorwrap_test_LDFLAGS = \
+ $(test_ldflags) \
+ -lstdc++fs
serialization_test_path_CPPFLAGS = $(test_cppflags)
serialization_test_path_CXXFLAGS = $(test_cxxflags)
diff --git a/test/elog_errorwrap_test.cpp b/test/elog_errorwrap_test.cpp
new file mode 100644
index 0000000..f341447
--- /dev/null
+++ b/test/elog_errorwrap_test.cpp
@@ -0,0 +1,32 @@
+#include "elog_errorwrap_test.hpp"
+
+namespace phosphor
+{
+namespace logging
+{
+namespace internal
+{
+
+TEST_F(TestLogManager, logCap)
+{
+ for (auto i = 0; i < ERROR_INFO_CAP + 20; i++)
+ {
+ manager.commitWithLvl(i, "FOO", 6);
+ }
+
+ // Max num of Info( and below Sev) errors can be created is qual to
+ // ERROR_INFO_CAP
+ EXPECT_EQ(ERROR_INFO_CAP , manager.getInfoErrSize());
+
+ for (auto i = 0; i < ERROR_CAP + 20; i++)
+ {
+ manager.commitWithLvl(i, "FOO", 0);
+ }
+ // Max num of high severity errors can be created is qual to ERROR_CAP
+ EXPECT_EQ(ERROR_CAP, manager.getRealErrSize());
+
+}
+
+}// namespace internal
+}// namespace logging
+}// namespace phosphor
diff --git a/test/elog_errorwrap_test.hpp b/test/elog_errorwrap_test.hpp
new file mode 100644
index 0000000..7c673b6
--- /dev/null
+++ b/test/elog_errorwrap_test.hpp
@@ -0,0 +1,109 @@
+#include "log_manager.hpp"
+#include "xyz/openbmc_project/Common/error.hpp"
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+#include <sdbusplus/bus.hpp>
+#include <experimental/filesystem>
+#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/elog-errors.hpp>
+#include "elog_serialize.hpp"
+#include "config.h"
+
+namespace phosphor
+{
+namespace logging
+{
+namespace internal
+{
+
+namespace fs = std::experimental::filesystem;
+
+class journalInterface
+{
+ public:
+ virtual void journalSync() = 0;
+ virtual int sd_journal_open(sd_journal** j, int k) = 0;
+ virtual int sd_journal_get_data(sd_journal* j,
+ const char* transactionIdVar,
+ const void** data,
+ size_t length) = 0;
+ virtual void sd_journal_close(sd_journal* j) = 0;
+};
+
+class journalImpl : public journalInterface
+{
+ public:
+ void journalSync();
+ int sd_journal_open(sd_journal** j, int k);
+ int sd_journal_get_data(sd_journal* j,
+ const char* transactionIdVar,
+ const void** data,
+ size_t length);
+ void sd_journal_close(sd_journal* j);
+};
+
+
+
+int journalImpl::sd_journal_open(sd_journal** j, int k)
+{
+ return 1;
+}
+
+void journalImpl::journalSync()
+{
+ return;
+}
+
+int journalImpl::sd_journal_get_data(sd_journal* j,
+ const char* transactionIdVar,
+ const void** data,
+ size_t length)
+{
+ return 1;
+}
+
+void journalImpl::sd_journal_close(sd_journal* j)
+{
+ return;
+}
+
+
+class MockJournal : public Manager
+{
+ public:
+ MockJournal(sdbusplus::bus::bus& bus,
+ const char* objPath): Manager(bus, objPath) {};
+ MOCK_METHOD0(journalSync, void());
+ MOCK_METHOD2(sd_journal_open, int(sd_journal**, int));
+ MOCK_METHOD4(sd_journal_get_data, int(sd_journal*,
+ const char*,
+ const void**, size_t));
+ MOCK_METHOD1(sd_journal_close, void(sd_journal*));
+};
+
+
+
+class TestLogManager : public testing::Test
+{
+ public:
+ sdbusplus::bus::bus bus;
+ MockJournal manager;
+ TestLogManager()
+ : bus(sdbusplus::bus::new_default()),
+ manager(bus, "/xyz/openbmc_test/abc")
+ {
+ fs::create_directories(ERRLOG_PERSIST_PATH);
+ }
+
+ ~TestLogManager()
+ {
+ fs::remove_all(ERRLOG_PERSIST_PATH);
+ }
+
+};
+
+
+}// nmaespace internal
+}// namespace logging
+}// namespace phosphor
diff --git a/test/elog_unittest.cpp b/test/elog_unittest.cpp
deleted file mode 100644
index febccf9..0000000
--- a/test/elog_unittest.cpp
+++ /dev/null
@@ -1,7 +0,0 @@
-#include <phosphor-logging/elog.hpp>
-#include <gtest/gtest.h>
-
-// TODO - need to get gtest working in the SDK
-TEST(BasicLog, Zero) {
- EXPECT_EQ(1, 1);
-}
OpenPOWER on IntegriCloud