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 Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 7 | #include <phosphor-logging/elog-errors.hpp> |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 8 | #include <phosphor-logging/elog.hpp> |
| 9 | #include <phosphor-logging/log.hpp> |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 10 | #include <sdbusplus/bus.hpp> |
| 11 | |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 12 | #include <filesystem> |
| 13 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 14 | #include <gmock/gmock.h> |
| 15 | #include <gtest/gtest.h> |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 16 | |
| 17 | namespace phosphor |
| 18 | { |
| 19 | namespace logging |
| 20 | { |
| 21 | namespace internal |
| 22 | { |
| 23 | |
Patrick Williams | 331c485 | 2021-04-16 15:38:59 -0500 | [diff] [blame] | 24 | namespace fs = std::filesystem; |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 25 | |
| 26 | class journalInterface |
| 27 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 28 | public: |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 29 | virtual ~journalInterface() = default; |
| 30 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 31 | virtual void journalSync() = 0; |
| 32 | virtual int sd_journal_open(sd_journal** j, int k) = 0; |
| 33 | virtual int sd_journal_get_data(sd_journal* j, const char* transactionIdVar, |
| 34 | const void** data, size_t length) = 0; |
| 35 | virtual void sd_journal_close(sd_journal* j) = 0; |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | class journalImpl : public journalInterface |
| 39 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 40 | public: |
Matt Spinler | 4a37595 | 2022-07-01 11:15:33 -0500 | [diff] [blame] | 41 | void journalSync() override; |
| 42 | int sd_journal_open(sd_journal** j, int k) override; |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 43 | int sd_journal_get_data(sd_journal* j, const char* transactionIdVar, |
Matt Spinler | 4a37595 | 2022-07-01 11:15:33 -0500 | [diff] [blame] | 44 | const void** data, size_t length) override; |
| 45 | void sd_journal_close(sd_journal* j) override; |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 46 | }; |
| 47 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 48 | int journalImpl::sd_journal_open(sd_journal**, int) |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 49 | { |
| 50 | return 1; |
| 51 | } |
| 52 | |
| 53 | void journalImpl::journalSync() |
| 54 | { |
| 55 | return; |
| 56 | } |
| 57 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 58 | int journalImpl::sd_journal_get_data(sd_journal*, const char*, const void**, |
| 59 | size_t) |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 60 | { |
| 61 | return 1; |
| 62 | } |
| 63 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 64 | void journalImpl::sd_journal_close(sd_journal*) |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 65 | { |
| 66 | return; |
| 67 | } |
| 68 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 69 | class MockJournal : public Manager |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 70 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 71 | public: |
Patrick Williams | 45e8352 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 72 | MockJournal(sdbusplus::bus_t& bus, const char* objPath) : |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 73 | Manager(bus, objPath) {}; |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 74 | MOCK_METHOD0(journalSync, void()); |
| 75 | MOCK_METHOD2(sd_journal_open, int(sd_journal**, int)); |
| 76 | MOCK_METHOD4(sd_journal_get_data, |
| 77 | int(sd_journal*, const char*, const void**, size_t)); |
| 78 | MOCK_METHOD1(sd_journal_close, void(sd_journal*)); |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 79 | }; |
| 80 | |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 81 | class TestLogManager : public testing::Test |
| 82 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 83 | public: |
Patrick Williams | 45e8352 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 84 | sdbusplus::bus_t bus; |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 85 | MockJournal manager; |
| 86 | TestLogManager() : |
| 87 | bus(sdbusplus::bus::new_default()), |
| 88 | manager(bus, "/xyz/openbmc_test/abc") |
| 89 | { |
| 90 | fs::create_directories(ERRLOG_PERSIST_PATH); |
| 91 | } |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 92 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 93 | ~TestLogManager() |
| 94 | { |
Matt Spinler | 7ec2ab7 | 2020-04-03 11:54:29 -0500 | [diff] [blame] | 95 | // Leave the directory as other testcases use it and they |
| 96 | // may be running in parallel from other jobs. |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 97 | } |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 98 | }; |
| 99 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 100 | } // namespace internal |
| 101 | } // namespace logging |
| 102 | } // namespace phosphor |