From 21b8c7ca8b82b98a5176e12e8a27ca57e2536118 Mon Sep 17 00:00:00 2001 From: Tom Date: Mon, 16 Sep 2019 18:11:13 +0200 Subject: [PATCH] test: add case signal-handler-reuse --- test/test.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/test.cpp b/test/test.cpp index 665a161..d04c48e 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -9,6 +9,7 @@ #include #include +#include #include @@ -162,3 +163,30 @@ TEST_CASE("exit-condition-looping") } } +TEST_CASE("signal-handler-reuse") +{ + std::map signal_map({{SIGINT, 1 << 0}, + {SIGTERM, 1 << 1}, + {SIGUSR1, 1 << 2}, + {SIGUSR2, 1 << 3}}); + + sgnl::AtomicCondition condition(0); + sgnl::SignalHandler signal_handler(signal_map, condition); + + for( auto p : signal_map ) + { + std::promise signal_handler_thread_id; + std::future ft_sig_handler = + std::async(std::launch::async, [&]() { + signal_handler_thread_id.set_value(pthread_self()); + return signal_handler(); + }); + REQUIRE( + pthread_kill( + signal_handler_thread_id.get_future().get(), + p.first) == 0 ); + REQUIRE( ft_sig_handler.get() == p.first ); + REQUIRE( condition.get() == p.second ); + } +} +