1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <cerrno>
17 #include <cstdio>
18 #include "init_unittest.h"
19 #include "init.h"
20 #include "loop_event.h"
21 #include "le_epoll.h"
22 #include "le_signal.h"
23 #include "init_hashmap.h"
24
25 using namespace testing::ext;
26 using namespace std;
27
28 static SignalHandle g_sigHandler = nullptr;
29
ProcessSignal(const struct signalfd_siginfo * siginfo)30 static void ProcessSignal(const struct signalfd_siginfo *siginfo)
31 {
32 return;
33 }
34
35 namespace init_ut {
36 class SignalInitUnitTest : public testing::Test {
37 public:
SetUpTestCase(void)38 static void SetUpTestCase(void) {};
TearDownTestCase(void)39 static void TearDownTestCase(void) {};
SetUp()40 void SetUp() {};
TearDown()41 void TearDown() {};
42 };
43
44 HWTEST_F(SignalInitUnitTest, SignalInitTestRmSig, TestSize.Level1)
45 {
46 LE_CreateSignalTask(LE_GetDefaultLoop(), &g_sigHandler, ProcessSignal);
47 ASSERT_NE(g_sigHandler, nullptr);
48 int ret = LE_AddSignal(LE_GetDefaultLoop(), g_sigHandler, SIGUSR1);
49 ASSERT_EQ(ret, 0);
50 LE_AddSignal(LE_GetDefaultLoop(), g_sigHandler, SIGUSR1);
51 LE_AddSignal(LE_GetDefaultLoop(), g_sigHandler, SIGUSR2);
52 ret = LE_RemoveSignal(LE_GetDefaultLoop(), g_sigHandler, SIGUSR1);
53 ASSERT_EQ(ret, 0);
54 LE_RemoveSignal(LE_GetDefaultLoop(), g_sigHandler, SIGUSR1);
55 LE_RemoveSignal(LE_GetDefaultLoop(), g_sigHandler, SIGUSR2);
56 ((BaseTask *)g_sigHandler)->handleEvent(LE_GetDefaultLoop(), (TaskHandle)&g_sigHandler, Event_Write);
57 LE_CloseSignalTask(LE_GetDefaultLoop(), g_sigHandler);
58 ASSERT_EQ(ret, 0);
59 }
60 }
61