• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "hidumper_service_test.h"
16 #include <iservice_registry.h>
17 #include "dump_manager_client.h"
18 #include "dump_manager_service.h"
19 #include "inner/dump_service_id.h"
20 #include "dump_on_demand_load.h"
21 using namespace std;
22 using namespace testing::ext;
23 using namespace OHOS;
24 using namespace OHOS::HiviewDFX;
25 namespace OHOS {
26 namespace HiviewDFX {
27 const int32_t HidumperServiceTest::LIMIT_SIZE = 5000;
SetUpTestCase(void)28 void HidumperServiceTest::SetUpTestCase(void)
29 {
30 }
31 
TearDownTestCase(void)32 void HidumperServiceTest::TearDownTestCase(void)
33 {
34 }
35 
SetUp(void)36 void HidumperServiceTest::SetUp(void)
37 {
38 }
39 
TearDown(void)40 void HidumperServiceTest::TearDown(void)
41 {
42 }
43 
44 /**
45  * @tc.name: HidumperServiceTest001
46  * @tc.desc: Test DumpManagerService service ready.
47  * @tc.type: FUNC
48  */
49 HWTEST_F(HidumperServiceTest, HidumperServiceTest001, TestSize.Level3)
50 {
51     sptr<ISystemAbilityManager> sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
52     ASSERT_TRUE(sam != nullptr) << "HidumperServiceTest001 fail to get GetSystemAbilityManager";
53     sptr<OnDemandLoadCallback> loadCallback = new OnDemandLoadCallback();
54     int32_t result = sam->LoadSystemAbility(DFX_SYS_HIDUMPER_ABILITY_ID, loadCallback);
55     ASSERT_TRUE(result == ERR_OK) << "GetSystemAbility failed.";
56 }
57 
58 /**
59  * @tc.name: DumpManagerService002
60  * @tc.desc: Test DumpManagerService Request.
61  * @tc.type: FUNC
62  */
63 HWTEST_F(HidumperServiceTest, DumpManagerService002, TestSize.Level3)
64 {
65     auto dumpManagerService = std::make_shared<DumpManagerService>();
66     dumpManagerService->OnStart();
67     dumpManagerService->started_ = true;
68     std::vector<std::u16string> args;
69     int32_t ret = ERR_OK;
70     ret =  dumpManagerService->Dump(-1, args);
71     ASSERT_TRUE(ret == ERR_OK);
72     ret = dumpManagerService->Request(args, -1);
73     ASSERT_TRUE(ret == ERR_OK);
74 
75     dumpManagerService->OnStop();
76 }
77 
78 /**
79  * @tc.name: DumpManagerService003
80  * @tc.desc: Test DumpManagerService CountFdNums.
81  * @tc.type: FUNC
82  */
83 HWTEST_F(HidumperServiceTest, DumpManagerService003, TestSize.Level3)
84 {
85     auto dumpManagerService = std::make_shared<DumpManagerService>();
86     int32_t pid = 1;
87     uint32_t fdNums = 0;
88     std::string detailFdInfo;
89     std::string topLeakedType;
90     int32_t ret = dumpManagerService->CountFdNums(pid, fdNums, detailFdInfo, topLeakedType);
91     ASSERT_TRUE(ret == 0);
92     ASSERT_FALSE(detailFdInfo.empty());
93     ASSERT_FALSE(topLeakedType.empty());
94 }
95 
96 /**
97  * @tc.name: DumpManagerService004
98  * @tc.desc: Test DumpManagerService ScanPidOverLimit.
99  * @tc.type: FUNC
100  */
101 HWTEST_F(HidumperServiceTest, DumpManagerService004, TestSize.Level3)
102 {
103     auto dumpManagerService = std::make_shared<DumpManagerService>();
104     std::string requestType = "fd";
105     std::vector<int32_t> pidList;
106     int32_t ret = dumpManagerService->ScanPidOverLimit(requestType, LIMIT_SIZE, pidList);
107     ASSERT_TRUE(ret == 0);
108 }
109 } // namespace HiviewDFX
110 } // namespace OHOS