From e6918187568dbd01842d8d1d2c808ce16a894239 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 21 Apr 2024 13:54:28 +0200 Subject: Adding upstream version 18.2.2. Signed-off-by: Daniel Baumann --- src/test/signals.cc | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 src/test/signals.cc (limited to 'src/test/signals.cc') diff --git a/src/test/signals.cc b/src/test/signals.cc new file mode 100644 index 000000000..dc24900a8 --- /dev/null +++ b/src/test/signals.cc @@ -0,0 +1,158 @@ +#include "common/config.h" +#include "common/signal.h" +#include "global/signal_handler.h" +#include "common/debug.h" +#include "include/coredumpctl.h" + +#include "gtest/gtest.h" + +#include +#include +#include +#include + +#include "include/ceph_assert.h" + +#define dout_context g_ceph_context +static volatile sig_atomic_t got_sigusr1 = 0; + +static void handle_sigusr1(int signo) +{ + got_sigusr1 = 1; +} + +TEST(SignalApi, SimpleInstall) +{ + install_sighandler(SIGPIPE, handle_sigusr1, 0); +} + +TEST(SignalApi, SimpleInstallAndTest) +{ + install_sighandler(SIGPIPE, handle_sigusr1, 0); + + // SIGPIPE starts out blocked + int ret = kill(getpid(), SIGPIPE); + ASSERT_EQ(ret, 0); + ASSERT_EQ(got_sigusr1, 0); + + // handle SIGPIPE + sigset_t mask; + sigemptyset(&mask); + ret = sigsuspend(&mask); + if (ret == -1) + ret = errno; + + // we should have gotten it + ASSERT_EQ(ret, EINTR); + ASSERT_EQ(got_sigusr1, 1); +} + +TEST(SignalEffects, ErrnoTest1) +{ +} + +bool usr1 = false; +bool usr2 = false; + +void reset() +{ + usr1 = false; + usr2 = false; +} + +void testhandler(int signal) +{ + switch (signal) { + case SIGUSR1: + usr1 = true; + break; + case SIGUSR2: + usr2 = true; + break; + default: + ceph_abort_msg("unexpected signal"); + } +} + +TEST(SignalHandler, Single) +{ + reset(); + init_async_signal_handler(); + register_async_signal_handler(SIGUSR1, testhandler); + ASSERT_TRUE(usr1 == false); + + int ret = kill(getpid(), SIGUSR1); + ASSERT_EQ(ret, 0); + + sleep(1); + ASSERT_TRUE(usr1 == true); + + unregister_async_signal_handler(SIGUSR1, testhandler); + shutdown_async_signal_handler(); +} + +TEST(SignalHandler, Multiple) +{ + int ret; + + reset(); + init_async_signal_handler(); + register_async_signal_handler(SIGUSR1, testhandler); + register_async_signal_handler(SIGUSR2, testhandler); + ASSERT_TRUE(usr1 == false); + ASSERT_TRUE(usr2 == false); + + ret = kill(getpid(), SIGUSR1); + ASSERT_EQ(ret, 0); + ret = kill(getpid(), SIGUSR2); + ASSERT_EQ(ret, 0); + + sleep(1); + ASSERT_TRUE(usr1 == true); + ASSERT_TRUE(usr2 == true); + + unregister_async_signal_handler(SIGUSR1, testhandler); + unregister_async_signal_handler(SIGUSR2, testhandler); + shutdown_async_signal_handler(); +} + +TEST(SignalHandler, LogInternal) +{ + g_ceph_context->_log->inject_segv(); + { + PrCtl unset_dumpable; + ASSERT_DEATH(derr << "foo" << dendl, ".*"); + } + g_ceph_context->_log->reset_segv(); +} + + +/* +TEST(SignalHandler, MultipleBigFd) +{ + int ret; + + for (int i = 0; i < 1500; i++) + ::open(".", O_RDONLY); + + reset(); + init_async_signal_handler(); + register_async_signal_handler(SIGUSR1, testhandler); + register_async_signal_handler(SIGUSR2, testhandler); + ASSERT_TRUE(usr1 == false); + ASSERT_TRUE(usr2 == false); + + ret = kill(getpid(), SIGUSR1); + ASSERT_EQ(ret, 0); + ret = kill(getpid(), SIGUSR2); + ASSERT_EQ(ret, 0); + + sleep(1); + ASSERT_TRUE(usr1 == true); + ASSERT_TRUE(usr2 == true); + + unregister_async_signal_handler(SIGUSR1, testhandler); + unregister_async_signal_handler(SIGUSR2, testhandler); + shutdown_async_signal_handler(); +} +*/ -- cgit v1.2.3