7#include "flutter/fml/build_config.h"
8#include "flutter/fml/log_settings.h"
9#include "flutter/fml/logging.h"
11#include "gtest/gtest.h"
24 SegfaultCatcher catcher;
28 <<
"This log exists to verify that static logging from FML works.";
32 struct SegfaultCatcher {
33 typedef void (*sighandler_t)(
int);
36 handler = ::signal(SIGSEGV, SegfaultHandler);
40 ~SegfaultCatcher() {
FML_CHECK(::signal(SIGSEGV, handler) != SIG_ERR); }
42 static void SegfaultHandler(
int signal) {
44 "FML failed to handle logging from static initialization.\n");
65TEST(LoggingTest, UnreachableKillProcess) {
66 ::testing::FLAGS_gtest_death_test_style =
"threadsafe";
70TEST(LoggingTest, UnreachableKillProcessWithMacro) {
71 ::testing::FLAGS_gtest_death_test_style =
"threadsafe";
76TEST(LoggingTest, SanityTests) {
77 ::testing::FLAGS_gtest_death_test_style =
"threadsafe";
78 std::vector<std::string> severities = {
"INFO",
"WARNING",
"ERROR",
81 for (
size_t i = 0;
i < severities.size();
i++) {
85 log.stream() <<
"Hello!";
87 EXPECT_EQ(capture.
str(), std::string(
"[" + severities[
i] +
88 ":path/to/file.cc(4)] Hello!\n"));
94 log.stream() <<
"Goodbye";
96 R
"(\[FATAL:path/to/file.cc\(5\)\] Goodbye)");
MakeSureFmlLogDoesNotSegfaultWhenStaticallyCalled()
#define FML_LOG(severity)
#define FML_CHECK(condition)
#define FML_UNREACHABLE()
int UnreachableScopeWithoutReturnDoesNotMakeCompilerMad()
static MakeSureFmlLogDoesNotSegfaultWhenStaticallyCalled fml_log_static_check_
int UnreachableScopeWithMacroWithoutReturnDoesNotMakeCompilerMad()
TEST(BacktraceTest, CanGatherBacktrace)
constexpr LogSeverity kLogFatal
constexpr LogSeverity kLogNumSeverities
constexpr LogSeverity kLogImportant
constexpr LogSeverity kLogError