]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/signals.cc
update ceph source to reef 18.2.0
[ceph.git] / ceph / src / test / signals.cc
CommitLineData
7c673cae
FG
1#include "common/config.h"
2#include "common/signal.h"
3#include "global/signal_handler.h"
4#include "common/debug.h"
5#include "include/coredumpctl.h"
6
7#include "gtest/gtest.h"
8
9#include <errno.h>
10#include <signal.h>
11#include <stdlib.h>
12#include <unistd.h>
13
11fdf7f2 14#include "include/ceph_assert.h"
7c673cae
FG
15
16#define dout_context g_ceph_context
17static volatile sig_atomic_t got_sigusr1 = 0;
18
19static void handle_sigusr1(int signo)
20{
21 got_sigusr1 = 1;
22}
23
24TEST(SignalApi, SimpleInstall)
25{
26 install_sighandler(SIGPIPE, handle_sigusr1, 0);
27}
28
29TEST(SignalApi, SimpleInstallAndTest)
30{
31 install_sighandler(SIGPIPE, handle_sigusr1, 0);
32
33 // SIGPIPE starts out blocked
34 int ret = kill(getpid(), SIGPIPE);
35 ASSERT_EQ(ret, 0);
36 ASSERT_EQ(got_sigusr1, 0);
37
38 // handle SIGPIPE
39 sigset_t mask;
40 sigemptyset(&mask);
41 ret = sigsuspend(&mask);
42 if (ret == -1)
43 ret = errno;
44
45 // we should have gotten it
46 ASSERT_EQ(ret, EINTR);
47 ASSERT_EQ(got_sigusr1, 1);
48}
49
50TEST(SignalEffects, ErrnoTest1)
51{
52}
53
54bool usr1 = false;
55bool usr2 = false;
56
57void reset()
58{
59 usr1 = false;
60 usr2 = false;
61}
62
63void testhandler(int signal)
64{
65 switch (signal) {
66 case SIGUSR1:
67 usr1 = true;
68 break;
69 case SIGUSR2:
70 usr2 = true;
71 break;
72 default:
11fdf7f2 73 ceph_abort_msg("unexpected signal");
7c673cae
FG
74 }
75}
76
77TEST(SignalHandler, Single)
78{
79 reset();
80 init_async_signal_handler();
81 register_async_signal_handler(SIGUSR1, testhandler);
82 ASSERT_TRUE(usr1 == false);
83
84 int ret = kill(getpid(), SIGUSR1);
85 ASSERT_EQ(ret, 0);
86
87 sleep(1);
88 ASSERT_TRUE(usr1 == true);
89
90 unregister_async_signal_handler(SIGUSR1, testhandler);
91 shutdown_async_signal_handler();
92}
93
94TEST(SignalHandler, Multiple)
95{
96 int ret;
97
98 reset();
99 init_async_signal_handler();
100 register_async_signal_handler(SIGUSR1, testhandler);
101 register_async_signal_handler(SIGUSR2, testhandler);
102 ASSERT_TRUE(usr1 == false);
103 ASSERT_TRUE(usr2 == false);
104
105 ret = kill(getpid(), SIGUSR1);
106 ASSERT_EQ(ret, 0);
107 ret = kill(getpid(), SIGUSR2);
108 ASSERT_EQ(ret, 0);
109
110 sleep(1);
111 ASSERT_TRUE(usr1 == true);
112 ASSERT_TRUE(usr2 == true);
113
114 unregister_async_signal_handler(SIGUSR1, testhandler);
115 unregister_async_signal_handler(SIGUSR2, testhandler);
116 shutdown_async_signal_handler();
117}
118
119TEST(SignalHandler, LogInternal)
120{
121 g_ceph_context->_log->inject_segv();
122 {
123 PrCtl unset_dumpable;
124 ASSERT_DEATH(derr << "foo" << dendl, ".*");
125 }
126 g_ceph_context->_log->reset_segv();
127}
128
129
130/*
131TEST(SignalHandler, MultipleBigFd)
132{
133 int ret;
134
135 for (int i = 0; i < 1500; i++)
136 ::open(".", O_RDONLY);
137
138 reset();
139 init_async_signal_handler();
140 register_async_signal_handler(SIGUSR1, testhandler);
141 register_async_signal_handler(SIGUSR2, testhandler);
142 ASSERT_TRUE(usr1 == false);
143 ASSERT_TRUE(usr2 == false);
144
145 ret = kill(getpid(), SIGUSR1);
146 ASSERT_EQ(ret, 0);
147 ret = kill(getpid(), SIGUSR2);
148 ASSERT_EQ(ret, 0);
149
150 sleep(1);
151 ASSERT_TRUE(usr1 == true);
152 ASSERT_TRUE(usr2 == true);
153
154 unregister_async_signal_handler(SIGUSR1, testhandler);
155 unregister_async_signal_handler(SIGUSR2, testhandler);
156 shutdown_async_signal_handler();
157}
158*/