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: |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame^] | 28 | virtual ~journalInterface() = default; |
| 29 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 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; |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | class journalImpl : public journalInterface |
| 38 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 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); |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 45 | }; |
| 46 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame^] | 47 | int journalImpl::sd_journal_open(sd_journal**, int) |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 48 | { |
| 49 | return 1; |
| 50 | } |
| 51 | |
| 52 | void journalImpl::journalSync() |
| 53 | { |
| 54 | return; |
| 55 | } |
| 56 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame^] | 57 | int journalImpl::sd_journal_get_data(sd_journal*, const char*, const void**, |
| 58 | size_t) |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 59 | { |
| 60 | return 1; |
| 61 | } |
| 62 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame^] | 63 | void journalImpl::sd_journal_close(sd_journal*) |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 64 | { |
| 65 | return; |
| 66 | } |
| 67 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 68 | class MockJournal : public Manager |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 69 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 70 | public: |
| 71 | MockJournal(sdbusplus::bus::bus& 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*)); |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 78 | }; |
| 79 | |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 80 | class TestLogManager : public testing::Test |
| 81 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 82 | public: |
| 83 | sdbusplus::bus::bus 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 | } |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 91 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 92 | ~TestLogManager() |
| 93 | { |
Matt Spinler | 7ec2ab7 | 2020-04-03 11:54:29 -0500 | [diff] [blame] | 94 | // Leave the directory as other testcases use it and they |
| 95 | // may be running in parallel from other jobs. |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 96 | } |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 97 | }; |
| 98 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 99 | } // namespace internal |
| 100 | } // namespace logging |
| 101 | } // namespace phosphor |