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 <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::filesystem; 24 25 class journalInterface 26 { 27 public: 28 virtual ~journalInterface() = default; 29 30 virtual void journalSync() = 0; 31 virtual int sd_journal_open(sd_journal** j, int k) = 0; 32 virtual int sd_journal_get_data(sd_journal* j, const char* transactionIdVar, 33 const void** data, size_t length) = 0; 34 virtual void sd_journal_close(sd_journal* j) = 0; 35 }; 36 37 class journalImpl : public journalInterface 38 { 39 public: 40 void journalSync(); 41 int sd_journal_open(sd_journal** j, int k); 42 int sd_journal_get_data(sd_journal* j, const char* transactionIdVar, 43 const void** data, size_t length); 44 void sd_journal_close(sd_journal* j); 45 }; 46 47 int journalImpl::sd_journal_open(sd_journal**, int) 48 { 49 return 1; 50 } 51 52 void journalImpl::journalSync() 53 { 54 return; 55 } 56 57 int journalImpl::sd_journal_get_data(sd_journal*, const char*, const void**, 58 size_t) 59 { 60 return 1; 61 } 62 63 void journalImpl::sd_journal_close(sd_journal*) 64 { 65 return; 66 } 67 68 class MockJournal : public Manager 69 { 70 public: 71 MockJournal(sdbusplus::bus_t& bus, const char* objPath) : 72 Manager(bus, objPath){}; 73 MOCK_METHOD0(journalSync, void()); 74 MOCK_METHOD2(sd_journal_open, int(sd_journal**, int)); 75 MOCK_METHOD4(sd_journal_get_data, 76 int(sd_journal*, const char*, const void**, size_t)); 77 MOCK_METHOD1(sd_journal_close, void(sd_journal*)); 78 }; 79 80 class TestLogManager : public testing::Test 81 { 82 public: 83 sdbusplus::bus_t bus; 84 MockJournal manager; 85 TestLogManager() : 86 bus(sdbusplus::bus::new_default()), 87 manager(bus, "/xyz/openbmc_test/abc") 88 { 89 fs::create_directories(ERRLOG_PERSIST_PATH); 90 } 91 92 ~TestLogManager() 93 { 94 // Leave the directory as other testcases use it and they 95 // may be running in parallel from other jobs. 96 } 97 }; 98 99 } // namespace internal 100 } // namespace logging 101 } // namespace phosphor 102