Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "elog_serialize.hpp" |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 4 | #include "log_manager.hpp" |
| 5 | #include "xyz/openbmc_project/Common/error.hpp" |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 6 | |
Patrick Williams | 331c485 | 2021-04-16 15:38:59 -0500 | [diff] [blame] | 7 | #include <filesystem> |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 8 | #include <phosphor-logging/elog-errors.hpp> |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 9 | #include <phosphor-logging/elog.hpp> |
| 10 | #include <phosphor-logging/log.hpp> |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 11 | #include <sdbusplus/bus.hpp> |
| 12 | |
| 13 | #include <gmock/gmock.h> |
| 14 | #include <gtest/gtest.h> |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 15 | |
| 16 | namespace phosphor |
| 17 | { |
| 18 | namespace logging |
| 19 | { |
| 20 | namespace internal |
| 21 | { |
| 22 | |
Patrick Williams | 331c485 | 2021-04-16 15:38:59 -0500 | [diff] [blame] | 23 | namespace fs = std::filesystem; |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 24 | |
| 25 | class journalInterface |
| 26 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 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; |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | class journalImpl : public journalInterface |
| 36 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 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); |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 43 | }; |
| 44 | |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 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, |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 57 | const void** data, size_t length) |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 58 | { |
| 59 | return 1; |
| 60 | } |
| 61 | |
| 62 | void journalImpl::sd_journal_close(sd_journal* j) |
| 63 | { |
| 64 | return; |
| 65 | } |
| 66 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 67 | class MockJournal : public Manager |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 68 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 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*)); |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 77 | }; |
| 78 | |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 79 | class TestLogManager : public testing::Test |
| 80 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 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 | } |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 90 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 91 | ~TestLogManager() |
| 92 | { |
Matt Spinler | 7ec2ab7 | 2020-04-03 11:54:29 -0500 | [diff] [blame] | 93 | // Leave the directory as other testcases use it and they |
| 94 | // may be running in parallel from other jobs. |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 95 | } |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 96 | }; |
| 97 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 98 | } // namespace internal |
| 99 | } // namespace logging |
| 100 | } // namespace phosphor |