• 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 
16 #include "hiview_sa_test.h"
17 
18 #include <string>
19 #include <unistd.h>
20 
21 #include "hiview_service_ability_proxy.h"
22 #include "if_system_ability_manager.h"
23 #include "ipc_skeleton.h"
24 #include "iservice_registry.h"
25 #include "system_ability_definition.h"
26 
27 namespace OHOS {
28 namespace HiviewDFX {
SetUpTestCase()29 void HiviewSATest::SetUpTestCase() {}
30 
TearDownTestCase()31 void HiviewSATest::TearDownTestCase() {}
32 
SetUp()33 void HiviewSATest::SetUp() {}
34 
TearDown()35 void HiviewSATest::TearDown() {}
36 
37 /**
38  * @tc.name: CommonTest001
39  * @tc.desc: Check whether the SA is successfully obtained.
40  * @tc.type: FUNC
41  * @tc.require: AR000FJLO2
42  */
43 HWTEST_F(HiviewSATest, CommonTest001, testing::ext::TestSize.Level3)
44 {
45     sptr<ISystemAbilityManager> serviceManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
46     if (serviceManager == nullptr) {
47         printf("serviceManager == nullptr");
48         ASSERT_NE(serviceManager, nullptr);
49     }
50 
51     printf("ISystemAbilityManager ok \r\n");
52 
53     sptr<IRemoteObject> abilityObjext = serviceManager->CheckSystemAbility(DFX_SYS_HIVIEW_ABILITY_ID);
54     if (abilityObjext == nullptr) {
55         printf("abilityObjext == nullptr");
56         ASSERT_NE(abilityObjext, nullptr);
57     }
58 
59     printf("CheckSystemAbility ok \r\n");
60 
61     auto hiviewSAProxy = new HiviewServiceAbilityProxy(abilityObjext);
62     if (hiviewSAProxy == nullptr) {
63         printf("hiviewSAProxy == nullptr");
64         ASSERT_NE(hiviewSAProxy, nullptr);
65     }
66 
67     printf("end \r\n");
68 }
69 
70 /**
71  * @tc.name: CommonTest001
72  * @tc.desc: Check hidumper -s 1201.
73  * @tc.type: FUNC
74  * @tc.require: AR000FJLO2
75  */
76 HWTEST_F(HiviewSATest, CommonTest002, testing::ext::TestSize.Level3)
77 {
78     printf("system(\"hidumper -s 1201\") \r\n");
79     char buffer[256];
80     FILE* fp = popen("hidumper -s 1201", "r");
81     if (fp != nullptr) {
82         fgets(buffer, sizeof(buffer), fp);
83         printf("%s", buffer);
84         pclose(fp);
85         std::string str(buffer);
86         if (str.find("Error") != std::string::npos) {
87             printf("hidumper -s 1201 fail!\r\n");
88             FAIL();
89         }
90     } else {
91         printf("popen fail!\r\n");
92         FAIL();
93     }
94 }
95 }
96 }