• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <gtest/gtest.h>
2 #include <sigchain.h>
3 using namespace testing::ext;
4 
5 class SigchainAddSpecialSignalHandlerTest : public testing::Test {
SetUp()6     void SetUp() override {}
TearDown()7     void TearDown() override {}
8 };
9 constexpr int NUM = 2;
10 static int g_count = 0;
11 
SigchainSigint1(int signo,siginfo_t * siginfo,void * contextRaw)12 static bool SigchainSigint1(int signo, siginfo_t* siginfo, void* contextRaw)
13 {
14     g_count++;
15     EXPECT_EQ(signo, SIGINT);
16     return false;
17 }
SigchainSigint2(int signo,siginfo_t * siginfo,void * contextRaw)18 static bool SigchainSigint2(int signo, siginfo_t* siginfo, void* contextRaw)
19 {
20     g_count++;
21     EXPECT_EQ(signo, SIGINT);
22     return true;
23 }
24 
25 /**
26  * @tc.name: add_special_signal_handler_001
27  * @tc.desc: Verify that the add_special_signal_handler function successfully registers and invokes the specified
28  *           special signal handlers when a SIGINT signal is raised.
29  * @tc.type: FUNC
30  **/
31 HWTEST_F(SigchainAddSpecialSignalHandlerTest, add_special_signal_handler_001, TestSize.Level1)
32 {
33     struct signal_chain_action sigint1 = {
34         .sca_sigaction = SigchainSigint1,
35         .sca_mask = {},
36         .sca_flags = 0,
37     };
38     add_special_signal_handler(SIGINT, &sigint1);
39 
40     struct signal_chain_action sigint2 = {
41         .sca_sigaction = SigchainSigint2,
42         .sca_mask = {},
43         .sca_flags = SIGCHAIN_ALLOW_NORETURN,
44     };
45     add_special_signal_handler(SIGINT, &sigint2);
46 
47     raise(SIGINT);
48     EXPECT_EQ(g_count, NUM);
49 }