blob: 154dee5b19da16891354737f1731ba0c42e9ac78 [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
Nagaraju Goruganti477b7312018-06-25 23:28:58 -05007#include <experimental/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
23namespace fs = std::experimental::filesystem;
24
25class journalInterface
26{
Patrick Venturef18bf832018-10-26 18:14:00 -070027 public:
28 virtual void journalSync() = 0;
29 virtual int sd_journal_open(sd_journal** j, int k) = 0;
30 virtual int sd_journal_get_data(sd_journal* j, const char* transactionIdVar,
31 const void** data, size_t length) = 0;
32 virtual void sd_journal_close(sd_journal* j) = 0;
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050033};
34
35class journalImpl : public journalInterface
36{
Patrick Venturef18bf832018-10-26 18:14:00 -070037 public:
38 void journalSync();
39 int sd_journal_open(sd_journal** j, int k);
40 int sd_journal_get_data(sd_journal* j, const char* transactionIdVar,
41 const void** data, size_t length);
42 void sd_journal_close(sd_journal* j);
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050043};
44
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050045int journalImpl::sd_journal_open(sd_journal** j, int k)
46{
47 return 1;
48}
49
50void journalImpl::journalSync()
51{
52 return;
53}
54
55int journalImpl::sd_journal_get_data(sd_journal* j,
56 const char* transactionIdVar,
Patrick Venturef18bf832018-10-26 18:14:00 -070057 const void** data, size_t length)
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050058{
59 return 1;
60}
61
62void journalImpl::sd_journal_close(sd_journal* j)
63{
64 return;
65}
66
Patrick Venturef18bf832018-10-26 18:14:00 -070067class MockJournal : public Manager
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050068{
Patrick Venturef18bf832018-10-26 18:14:00 -070069 public:
70 MockJournal(sdbusplus::bus::bus& bus, const char* objPath) :
71 Manager(bus, objPath){};
72 MOCK_METHOD0(journalSync, void());
73 MOCK_METHOD2(sd_journal_open, int(sd_journal**, int));
74 MOCK_METHOD4(sd_journal_get_data,
75 int(sd_journal*, const char*, const void**, size_t));
76 MOCK_METHOD1(sd_journal_close, void(sd_journal*));
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050077};
78
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050079class TestLogManager : public testing::Test
80{
Patrick Venturef18bf832018-10-26 18:14:00 -070081 public:
82 sdbusplus::bus::bus bus;
83 MockJournal manager;
84 TestLogManager() :
85 bus(sdbusplus::bus::new_default()),
86 manager(bus, "/xyz/openbmc_test/abc")
87 {
88 fs::create_directories(ERRLOG_PERSIST_PATH);
89 }
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050090
Patrick Venturef18bf832018-10-26 18:14:00 -070091 ~TestLogManager()
92 {
Matt Spinler7ec2ab72020-04-03 11:54:29 -050093 // Leave the directory as other testcases use it and they
94 // may be running in parallel from other jobs.
Patrick Venturef18bf832018-10-26 18:14:00 -070095 }
Nagaraju Goruganti477b7312018-06-25 23:28:58 -050096};
97
Patrick Venturef18bf832018-10-26 18:14:00 -070098} // namespace internal
99} // namespace logging
100} // namespace phosphor