forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging_unittests.cc
71 lines (56 loc) · 1.93 KB
/
logging_unittests.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <signal.h>
#include "flutter/fml/build_config.h"
#include "flutter/fml/log_settings.h"
#include "flutter/fml/logging.h"
#include "gtest/gtest.h"
namespace fml {
namespace testing {
#ifndef OS_FUCHSIA
class MakeSureFmlLogDoesNotSegfaultWhenStaticallyCalled {
public:
MakeSureFmlLogDoesNotSegfaultWhenStaticallyCalled() {
SegfaultCatcher catcher;
// If this line causes a segfault, FML is using a method of logging that is
// not safe from static initialization on your platform.
FML_LOG(INFO)
<< "This log exists to verify that static logging from FML works.";
}
private:
struct SegfaultCatcher {
typedef void (*sighandler_t)(int);
SegfaultCatcher() {
handler = ::signal(SIGSEGV, SegfaultHandler);
FML_CHECK(handler != SIG_ERR);
}
~SegfaultCatcher() { FML_CHECK(::signal(SIGSEGV, handler) != SIG_ERR); }
static void SegfaultHandler(int signal) {
fprintf(stderr,
"FML failed to handle logging from static initialization.\n");
exit(signal);
}
sighandler_t handler;
};
};
static MakeSureFmlLogDoesNotSegfaultWhenStaticallyCalled fml_log_static_check_;
#endif // !defined(OS_FUCHSIA)
int UnreachableScopeWithoutReturnDoesNotMakeCompilerMad() {
KillProcess();
// return 0; <--- Missing but compiler is fine.
}
int UnreachableScopeWithMacroWithoutReturnDoesNotMakeCompilerMad() {
FML_UNREACHABLE();
// return 0; <--- Missing but compiler is fine.
}
TEST(LoggingTest, UnreachableKillProcess) {
::testing::FLAGS_gtest_death_test_style = "threadsafe";
ASSERT_DEATH(KillProcess(), "");
}
TEST(LoggingTest, UnreachableKillProcessWithMacro) {
::testing::FLAGS_gtest_death_test_style = "threadsafe";
ASSERT_DEATH({ FML_UNREACHABLE(); }, "");
}
} // namespace testing
} // namespace fml