blob: 706514109f93e8b8b87aa8a82384b00c832aa4db [file] [log] [blame]
John Park33858a32018-09-28 23:05:48 -07001#ifndef AOS_UTIL_DEATH_TEST_LOG_IMPLEMENTATION_H_
2#define AOS_UTIL_DEATH_TEST_LOG_IMPLEMENTATION_H_
Brian Silverman01be0002014-05-10 15:44:38 -07003
Tyler Chatowbf0609c2021-07-31 16:13:27 -07004#include <cstdlib>
Brian Silverman01be0002014-05-10 15:44:38 -07005
John Park33858a32018-09-28 23:05:48 -07006#include "aos/logging/implementations.h"
Brian Silverman01be0002014-05-10 15:44:38 -07007
8namespace aos {
9namespace 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 Chatowbf0609c2021-07-31 16:13:27 -070014class DeathTestLogImplementation
15 : public logging::HandleMessageLogImplementation {
Brian Silverman01be0002014-05-10 15:44:38 -070016 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 Park33858a32018-09-28 23:05:48 -070028#endif // AOS_UTIL_DEATH_TEST_LOG_IMPLEMENTATION_H_