1 /*
2 * Copyright (c) 2022 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 "xcollie_inner_test.h"
17
18 #include <gtest/gtest.h>
19 #include <string>
20
21 #include "xcollie.h"
22 #include "xcollie_inner.h"
23 #include "xcollie_checker_test.h"
24
25 using namespace testing::ext;
26
27 namespace OHOS {
28 namespace HiviewDFX {
29
SetUpTestCase(void)30 void XCollieInnerTest::SetUpTestCase(void)
31 {
32 }
33
TearDownTestCase(void)34 void XCollieInnerTest::TearDownTestCase(void)
35 {
36 }
37
SetUp(void)38 void XCollieInnerTest::SetUp(void)
39 {
40 }
41
TearDown(void)42 void XCollieInnerTest::TearDown(void)
43 {
44 }
45
46 /**
47 * @tc.name: XCollieInnerTest
48 * @tc.desc: Verify xcollie register checker interface param
49 * @tc.type: FUNC
50 */
51 HWTEST_F(XCollieInnerTest, XCollieInnerTest_001, TestSize.Level3)
52 {
53 auto& xCollieInner = XCollieInner::GetInstance();
54 xCollieInner.RegisterXCollieChecker(nullptr, XCOLLIE_LOCK);
55 ASSERT_EQ(xCollieInner.GetBlockdServiceName(), "");
56 }
57
58 /**
59 * @tc.name: XCollieInnerTest
60 * @tc.desc: Verify xcollie register checker interface param
61 * @tc.type: FUNC
62 */
63 HWTEST_F(XCollieInnerTest, XCollieInnerTest_002, TestSize.Level3)
64 {
65 auto& xCollieInner = XCollieInner::GetInstance();
66 sptr<XCollieCheckerTest> checkerTest = new XCollieCheckerTest("CheckerTest_NoBlock");
67 xCollieInner.RegisterXCollieChecker(checkerTest, 0);
68 ASSERT_EQ(checkerTest->GetThreadBlockResult(), false);
69 }
70
71 /**
72 * @tc.name: XCollieInnerTest
73 * @tc.desc: Verify xcollie register checker interface param
74 * @tc.type: FUNC
75 */
76 HWTEST_F(XCollieInnerTest, XCollieInnerTest_003, TestSize.Level3)
77 {
78 auto& xCollieInner = XCollieInner::GetInstance();
79 sptr<XCollieCheckerTest> checkerTest = new XCollieCheckerTest("CheckerTest_003");
80 xCollieInner.RegisterXCollieChecker(checkerTest, XCOLLIE_LOCK);
81 for (int i = 0; xCollieInner.GetBlockdServiceName().empty() && (i < 10); ++i) {
82 std::this_thread::sleep_for(std::chrono::milliseconds(100));
83 }
84 xCollieInner.UnRegisterXCollieChecker(checkerTest);
85 ASSERT_EQ(xCollieInner.GetBlockdServiceName(), "");
86 }
87 } // namespace HiviewDFX
88 } // namespace OHOS
89