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