1 #include "config.h" 2 3 #include "elog_serialize.hpp" 4 #include "log_manager.hpp" 5 #include "xyz/openbmc_project/Common/error.hpp" 6 7 #include <experimental/filesystem> 8 #include <phosphor-logging/elog-errors.hpp> 9 #include <phosphor-logging/elog.hpp> 10 #include <phosphor-logging/log.hpp> 11 #include <sdbusplus/bus.hpp> 12 13 #include <gmock/gmock.h> 14 #include <gtest/gtest.h> 15 16 namespace phosphor 17 { 18 namespace logging 19 { 20 namespace internal 21 { 22 23 namespace fs = std::experimental::filesystem; 24 25 class journalInterface 26 { 27 public: 28 virtual void journalSync() = 0; 29 virtual int sd_journal_open(sd_journal** j, int k) = 0; 30 virtual int sd_journal_get_data(sd_journal* j, const char* transactionIdVar, 31 const void** data, size_t length) = 0; 32 virtual void sd_journal_close(sd_journal* j) = 0; 33 }; 34 35 class journalImpl : public journalInterface 36 { 37 public: 38 void journalSync(); 39 int sd_journal_open(sd_journal** j, int k); 40 int sd_journal_get_data(sd_journal* j, const char* transactionIdVar, 41 const void** data, size_t length); 42 void sd_journal_close(sd_journal* j); 43 }; 44 45 int journalImpl::sd_journal_open(sd_journal** j, int k) 46 { 47 return 1; 48 } 49 50 void journalImpl::journalSync() 51 { 52 return; 53 } 54 55 int journalImpl::sd_journal_get_data(sd_journal* j, 56 const char* transactionIdVar, 57 const void** data, size_t length) 58 { 59 return 1; 60 } 61 62 void journalImpl::sd_journal_close(sd_journal* j) 63 { 64 return; 65 } 66 67 class MockJournal : public Manager 68 { 69 public: 70 MockJournal(sdbusplus::bus::bus& bus, const char* objPath) : 71 Manager(bus, objPath){}; 72 MOCK_METHOD0(journalSync, void()); 73 MOCK_METHOD2(sd_journal_open, int(sd_journal**, int)); 74 MOCK_METHOD4(sd_journal_get_data, 75 int(sd_journal*, const char*, const void**, size_t)); 76 MOCK_METHOD1(sd_journal_close, void(sd_journal*)); 77 }; 78 79 class TestLogManager : public testing::Test 80 { 81 public: 82 sdbusplus::bus::bus bus; 83 MockJournal manager; 84 TestLogManager() : 85 bus(sdbusplus::bus::new_default()), 86 manager(bus, "/xyz/openbmc_test/abc") 87 { 88 fs::create_directories(ERRLOG_PERSIST_PATH); 89 } 90 91 ~TestLogManager() 92 { 93 // Leave the directory as other testcases use it and they 94 // may be running in parallel from other jobs. 95 } 96 }; 97 98 } // namespace internal 99 } // namespace logging 100 } // namespace phosphor 101