1 /*
2  * Copyright (c) 2024 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 <gtest/gtest.h>
16 #include <message_parcel.h>
17 #include "dump_broker_cpu_stub.h"
18 #include "dump_cpu_data.h"
19 #include "hidumper_cpu_service_ipc_interface_code.h"
20 using namespace std;
21 using namespace testing::ext;
22 using namespace OHOS;
23 using namespace OHOS::HiviewDFX;
24 namespace OHOS {
25 namespace HiviewDFX {
26 class HidumperCpuZidlTest : public testing::Test {
27 public:
28     static void SetUpTestCase(void);
29     static void TearDownTestCase(void);
30     void SetUp();
31     void TearDown();
32 };
33 
34 class TestDumpBrokerCpuStub : public DumpBrokerCpuStub {
35 public:
TestDumpBrokerCpuStub()36     TestDumpBrokerCpuStub() {};
~TestDumpBrokerCpuStub()37     virtual ~TestDumpBrokerCpuStub() {};
Request(DumpCpuData & dumpCpuData)38     int32_t Request(DumpCpuData &dumpCpuData)
39     {
40         return 0;
41     }
GetCpuUsageByPid(int32_t pid,double & cpuUsage)42     int32_t GetCpuUsageByPid(int32_t pid, double &cpuUsage)
43     {
44         return 0;
45     }
46 };
47 
SetUpTestCase(void)48 void HidumperCpuZidlTest::SetUpTestCase(void)
49 {
50 }
51 
TearDownTestCase(void)52 void HidumperCpuZidlTest::TearDownTestCase(void)
53 {
54 }
55 
SetUp(void)56 void HidumperCpuZidlTest::SetUp(void)
57 {
58 }
59 
TearDown(void)60 void HidumperCpuZidlTest::TearDown(void)
61 {
62 }
63 
64 /**
65  * @tc.name: HidumperCpuZidlTest001
66  * @tc.desc: Test cpu service stub.
67  * @tc.type: FUNC
68  */
69 HWTEST_F(HidumperCpuZidlTest, HidumperCpuZidlTest001, TestSize.Level3)
70 {
71     DumpBrokerCpuStub* stub = new(std::nothrow) TestDumpBrokerCpuStub();
72     MessageParcel data, reply;
73     MessageOption option;
74     int ret = stub->OnRemoteRequest(static_cast<uint32_t>(HidumperCpuServiceInterfaceCode::DUMP_REQUEST_CPUINFO),
75         data, reply, option);
76     ASSERT_TRUE(ret != 0);
77     stub->OnRemoteRequest(static_cast<uint32_t>(HidumperCpuServiceInterfaceCode::DUMP_USAGE_ONLY),
78         data, reply, option);
79     ret = stub->DumpCpuUsageOnly(data, reply);
80     ASSERT_TRUE(ret != 0);
81 }
82 } // namespace HiviewDFX
83 } // namespace OHOS