blob: d5a4b33fb5a6a541316a81eb56121d21837d8197 [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"
5#include "xyz/openbmc_project/Common/error.hpp"
Patrick Venturef18bf832018-10-26 18:14:00 -07006
Patrick Williams331c4852021-04-16 15:38:59 -05007#include <filesystem>
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
13#include <gmock/gmock.h>
14#include <gtest/gtest.h>
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050015
16namespace phosphor
17{
18namespace logging
19{
20namespace internal
21{
22
Patrick Williams331c4852021-04-16 15:38:59 -050023namespace fs = std::filesystem;
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050024
25class journalInterface
26{
Patrick Venturef18bf832018-10-26 18:14:00 -070027 public:
Patrick Williamsce0bdf12021-04-16 20:09:22 -050028 virtual ~journalInterface() = default;
29
Patrick Venturef18bf832018-10-26 18:14:00 -070030 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 Goruganti477b7312018-06-25 23:28:58 -050035};
36
37class journalImpl : public journalInterface
38{
Patrick Venturef18bf832018-10-26 18:14:00 -070039 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 Goruganti477b7312018-06-25 23:28:58 -050045};
46
Patrick Williamsce0bdf12021-04-16 20:09:22 -050047int journalImpl::sd_journal_open(sd_journal**, int)
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050048{
49 return 1;
50}
51
52void journalImpl::journalSync()
53{
54 return;
55}
56
Patrick Williamsce0bdf12021-04-16 20:09:22 -050057int journalImpl::sd_journal_get_data(sd_journal*, const char*, const void**,
58 size_t)
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050059{
60 return 1;
61}
62
Patrick Williamsce0bdf12021-04-16 20:09:22 -050063void journalImpl::sd_journal_close(sd_journal*)
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050064{
65 return;
66}
67
Patrick Venturef18bf832018-10-26 18:14:00 -070068class MockJournal : public Manager
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050069{
Patrick Venturef18bf832018-10-26 18:14:00 -070070 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 Goruganti477b7312018-06-25 23:28:58 -050078};
79
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050080class TestLogManager : public testing::Test
81{
Patrick Venturef18bf832018-10-26 18:14:00 -070082 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 Goruganti477b7312018-06-25 23:28:58 -050091
Patrick Venturef18bf832018-10-26 18:14:00 -070092 ~TestLogManager()
93 {
Matt Spinler7ec2ab72020-04-03 11:54:29 -050094 // Leave the directory as other testcases use it and they
95 // may be running in parallel from other jobs.
Patrick Venturef18bf832018-10-26 18:14:00 -070096 }
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050097};
98
Patrick Venturef18bf832018-10-26 18:14:00 -070099} // namespace internal
100} // namespace logging
101} // namespace phosphor