John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 1 | #ifndef AOS_UTIL_DEATH_TEST_LOG_IMPLEMENTATION_H_ |
| 2 | #define AOS_UTIL_DEATH_TEST_LOG_IMPLEMENTATION_H_ |
Brian Silverman | 01be000 | 2014-05-10 15:44:38 -0700 | [diff] [blame] | 3 | |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame^] | 4 | #include <cstdlib> |
Brian Silverman | 01be000 | 2014-05-10 15:44:38 -0700 | [diff] [blame] | 5 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 6 | #include "aos/logging/implementations.h" |
Brian Silverman | 01be000 | 2014-05-10 15:44:38 -0700 | [diff] [blame] | 7 | |
| 8 | namespace aos { |
| 9 | namespace util { |
| 10 | |
| 11 | // Prints all FATAL messages to stderr and then abort(3)s before the regular |
| 12 | // stuff can print out anything else. Ignores all other messages. |
| 13 | // This is useful in death tests that expect a LOG(FATAL) to cause the death. |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame^] | 14 | class DeathTestLogImplementation |
| 15 | : public logging::HandleMessageLogImplementation { |
Brian Silverman | 01be000 | 2014-05-10 15:44:38 -0700 | [diff] [blame] | 16 | public: |
| 17 | virtual void HandleMessage(const logging::LogMessage &message) override { |
| 18 | if (message.level == FATAL) { |
| 19 | logging::internal::PrintMessage(stderr, message); |
| 20 | abort(); |
| 21 | } |
| 22 | } |
| 23 | }; |
| 24 | |
| 25 | } // namespace util |
| 26 | } // namespace aos |
| 27 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 28 | #endif // AOS_UTIL_DEATH_TEST_LOG_IMPLEMENTATION_H_ |