Patrick Venture | 59a6b1f | 2018-08-29 11:41:01 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | 59a6b1f | 2018-08-29 11:41:01 -0700 | [diff] [blame] | 3 | namespace phosphor |
| 4 | { |
| 5 | namespace logging |
| 6 | { |
| 7 | |
| 8 | /** |
| 9 | * Implementation that calls into real sd_journal methods. |
| 10 | */ |
| 11 | class 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 III | d8255c9 | 2021-05-19 17:08:10 -0700 | [diff] [blame] | 29 | virtual int journal_send_call(const char* fmt); |
Patrick Venture | 59a6b1f | 2018-08-29 11:41:01 -0700 | [diff] [blame] | 30 | |
| 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 III | d8255c9 | 2021-05-19 17:08:10 -0700 | [diff] [blame] | 41 | __attribute__((format(printf, 2, 0))) __attribute__((sentinel)); |
Patrick Venture | 59a6b1f | 2018-08-29 11:41:01 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | extern 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 Venture | 7bb7a77 | 2018-12-04 14:43:21 -0800 | [diff] [blame] | 53 | SdJournalHandler* SwapJouralHandler(SdJournalHandler* with); |
Patrick Venture | 59a6b1f | 2018-08-29 11:41:01 -0700 | [diff] [blame] | 54 | |
| 55 | } // namespace logging |
| 56 | } // namespace phosphor |