blob: 73e3f41355d722148fff2087a464732a8f8d078b [file] [log] [blame]
Patrick Venture59a6b1f2018-08-29 11:41:01 -07001#pragma once
2
Patrick Venture59a6b1f2018-08-29 11:41:01 -07003namespace phosphor
4{
5namespace logging
6{
7
8/**
9 * Implementation that calls into real sd_journal methods.
10 */
11class SdJournalHandler
12{
13 public:
14 SdJournalHandler() = default;
15 virtual ~SdJournalHandler() = default;
16 SdJournalHandler(const SdJournalHandler&) = default;
17 SdJournalHandler& operator=(const SdJournalHandler&) = default;
18 SdJournalHandler(SdJournalHandler&&) = default;
19 SdJournalHandler& operator=(SdJournalHandler&&) = default;
20
21 /**
22 * Provide a fake method that's called by the real method so we can catch
23 * the journal_send call in testing.
24 *
25 * @param[in] fmt - the format string passed into journal_send.
26 * @return an int meant to be intepreted by the journal_send caller during
27 * testing.
28 */
William A. Kennington IIId8255c92021-05-19 17:08:10 -070029 virtual int journal_send_call(const char* fmt);
Patrick Venture59a6b1f2018-08-29 11:41:01 -070030
31 /**
32 * Send the information to sd_journal_send.
33 *
34 * @param[in] fmt - c string format.
35 * @param[in] ... - parameters.
36 * @return value from sd_journal_send
37 *
38 * sentinel default makes sure the last parameter is null.
39 */
40 virtual int journal_send(const char* fmt, ...)
William A. Kennington IIId8255c92021-05-19 17:08:10 -070041 __attribute__((format(printf, 2, 0))) __attribute__((sentinel));
Patrick Venture59a6b1f2018-08-29 11:41:01 -070042};
43
44extern SdJournalHandler* sdjournal_ptr;
45
46/**
47 * Swap out the sdjournal_ptr used by log<> such that a test
48 * won't need to hit the real sd_journal and fail.
49 *
50 * @param[in] with - pointer to your sdjournal_mock object.
51 * @return pointer to the previously stored sdjournal_ptr.
52 */
Patrick Venture7bb7a772018-12-04 14:43:21 -080053SdJournalHandler* SwapJouralHandler(SdJournalHandler* with);
Patrick Venture59a6b1f2018-08-29 11:41:01 -070054
55} // namespace logging
56} // namespace phosphor