blob: 82269c47fae09850b067c9af759ddaaa31bfab9a [file] [log] [blame]
Patrick Venturef18bf832018-10-26 18:14:00 -07001#include "config.h"
2
3#include "elog_serialize.hpp"
Nagaraju Goruganti477b7312018-06-25 23:28:58 -05004#include "log_manager.hpp"
Patrick Williamsfa2d9622024-09-30 16:25:43 -04005#include "paths.hpp"
Nagaraju Goruganti477b7312018-06-25 23:28:58 -05006#include "xyz/openbmc_project/Common/error.hpp"
Patrick Venturef18bf832018-10-26 18:14:00 -07007
Patrick Venturef18bf832018-10-26 18:14:00 -07008#include <phosphor-logging/elog-errors.hpp>
Nagaraju Goruganti477b7312018-06-25 23:28:58 -05009#include <phosphor-logging/elog.hpp>
10#include <phosphor-logging/log.hpp>
Patrick Venturef18bf832018-10-26 18:14:00 -070011#include <sdbusplus/bus.hpp>
12
Patrick Williams2544b412022-10-04 08:41:06 -050013#include <filesystem>
14
Patrick Venturef18bf832018-10-26 18:14:00 -070015#include <gmock/gmock.h>
16#include <gtest/gtest.h>
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050017
18namespace phosphor
19{
20namespace logging
21{
22namespace internal
23{
24
Patrick Williams331c4852021-04-16 15:38:59 -050025namespace fs = std::filesystem;
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050026
27class journalInterface
28{
Patrick Venturef18bf832018-10-26 18:14:00 -070029 public:
Patrick Williamsce0bdf12021-04-16 20:09:22 -050030 virtual ~journalInterface() = default;
31
Patrick Venturef18bf832018-10-26 18:14:00 -070032 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 Goruganti477b7312018-06-25 23:28:58 -050037};
38
39class journalImpl : public journalInterface
40{
Patrick Venturef18bf832018-10-26 18:14:00 -070041 public:
Matt Spinler4a375952022-07-01 11:15:33 -050042 void journalSync() override;
43 int sd_journal_open(sd_journal** j, int k) override;
Patrick Venturef18bf832018-10-26 18:14:00 -070044 int sd_journal_get_data(sd_journal* j, const char* transactionIdVar,
Matt Spinler4a375952022-07-01 11:15:33 -050045 const void** data, size_t length) override;
46 void sd_journal_close(sd_journal* j) override;
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050047};
48
Patrick Williamsce0bdf12021-04-16 20:09:22 -050049int journalImpl::sd_journal_open(sd_journal**, int)
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050050{
51 return 1;
52}
53
54void journalImpl::journalSync()
55{
56 return;
57}
58
Patrick Williamsce0bdf12021-04-16 20:09:22 -050059int journalImpl::sd_journal_get_data(sd_journal*, const char*, const void**,
60 size_t)
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050061{
62 return 1;
63}
64
Patrick Williamsce0bdf12021-04-16 20:09:22 -050065void journalImpl::sd_journal_close(sd_journal*)
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050066{
67 return;
68}
69
Patrick Venturef18bf832018-10-26 18:14:00 -070070class MockJournal : public Manager
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050071{
Patrick Venturef18bf832018-10-26 18:14:00 -070072 public:
Patrick Williams45e83522022-07-22 19:26:52 -050073 MockJournal(sdbusplus::bus_t& bus, const char* objPath) :
Patrick Williams075c7922024-08-16 15:19:49 -040074 Manager(bus, objPath) {};
Patrick Venturef18bf832018-10-26 18:14:00 -070075 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 Goruganti477b7312018-06-25 23:28:58 -050080};
81
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050082class TestLogManager : public testing::Test
83{
Patrick Venturef18bf832018-10-26 18:14:00 -070084 public:
Patrick Williams45e83522022-07-22 19:26:52 -050085 sdbusplus::bus_t bus;
Patrick Venturef18bf832018-10-26 18:14:00 -070086 MockJournal manager;
87 TestLogManager() :
88 bus(sdbusplus::bus::new_default()),
89 manager(bus, "/xyz/openbmc_test/abc")
90 {
Patrick Williamsfa2d9622024-09-30 16:25:43 -040091 fs::create_directories(paths::error());
Patrick Venturef18bf832018-10-26 18:14:00 -070092 }
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050093
Patrick Venturef18bf832018-10-26 18:14:00 -070094 ~TestLogManager()
95 {
Matt Spinler7ec2ab72020-04-03 11:54:29 -050096 // Leave the directory as other testcases use it and they
97 // may be running in parallel from other jobs.
Patrick Venturef18bf832018-10-26 18:14:00 -070098 }
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050099};
100
Patrick Venturef18bf832018-10-26 18:14:00 -0700101} // namespace internal
102} // namespace logging
103} // namespace phosphor