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 | |
Austin Schuh | ad9e5eb | 2021-11-19 20:33:55 -0800 | [diff] [blame] | 6 | #include "aos/logging/context.h" |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 7 | #include "aos/logging/implementations.h" |
Brian Silverman | 01be000 | 2014-05-10 15:44:38 -0700 | [diff] [blame] | 8 | |
| 9 | namespace aos { |
| 10 | namespace util { |
| 11 | |
| 12 | // Prints all FATAL messages to stderr and then abort(3)s before the regular |
| 13 | // stuff can print out anything else. Ignores all other messages. |
| 14 | // 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] | 15 | class DeathTestLogImplementation |
| 16 | : public logging::HandleMessageLogImplementation { |
Brian Silverman | 01be000 | 2014-05-10 15:44:38 -0700 | [diff] [blame] | 17 | public: |
Austin Schuh | ad9e5eb | 2021-11-19 20:33:55 -0800 | [diff] [blame] | 18 | std::string_view MyName() override { |
| 19 | logging::internal::Context *context = logging::internal::Context::Get(); |
| 20 | return context->MyName(); |
| 21 | } |
Brian Silverman | 01be000 | 2014-05-10 15:44:38 -0700 | [diff] [blame] | 22 | virtual void HandleMessage(const logging::LogMessage &message) override { |
| 23 | if (message.level == FATAL) { |
| 24 | logging::internal::PrintMessage(stderr, message); |
| 25 | abort(); |
| 26 | } |
| 27 | } |
| 28 | }; |
| 29 | |
| 30 | } // namespace util |
| 31 | } // namespace aos |
| 32 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 33 | #endif // AOS_UTIL_DEATH_TEST_LOG_IMPLEMENTATION_H_ |