1 /*
2  * Copyright (c) 2023 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 "meminfo.h"
17 
18 #include <cstdio>
19 
20 #include "gtest/gtest.h"
21 
22 namespace OHOS {
23 namespace MemInfo {
24 using namespace testing;
25 using namespace testing::ext;
26 
27 class MemInfoTest : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31     void SetUp();
32     void TearDown();
33 };
34 
SetUpTestCase()35 void MemInfoTest::SetUpTestCase()
36 {
37 }
38 
TearDownTestCase()39 void MemInfoTest::TearDownTestCase()
40 {
41 }
42 
SetUp()43 void MemInfoTest::SetUp()
44 {
45 }
46 
TearDown()47 void MemInfoTest::TearDown()
48 {
49 }
50 
51 HWTEST_F(MemInfoTest, GetRssByPid_Test_001, TestSize.Level1)
52 {
53     int pid = 1;
54     uint64_t size = 0;
55     size = GetRssByPid(pid);
56     std::cout << "size = " << size << std::endl;
57     ASSERT_EQ(size > 0, true);
58 }
59 
60 HWTEST_F(MemInfoTest, GetRssByPid_Test_002, TestSize.Level1)
61 {
62     int pid = -1;
63     uint64_t size = 0;
64     size = GetRssByPid(pid);
65     ASSERT_EQ(size == 0, true);
66 }
67 
68 HWTEST_F(MemInfoTest, GetPssByPid_Test_001, TestSize.Level1)
69 {
70     int pid = 1;
71     uint64_t size = 0;
72     size = GetPssByPid(pid);
73     std::cout << "size = " << size << std::endl;
74     system("cat /proc/1/smaps_rollup");
75     ASSERT_EQ(size > 0, true);
76 }
77 
78 HWTEST_F(MemInfoTest, GetPssByPid_Test_002, TestSize.Level1)
79 {
80     int pid = -1;
81     uint64_t size = 0;
82     size = GetPssByPid(pid);
83     ASSERT_EQ(size == 0, true);
84 }
85 
86 HWTEST_F(MemInfoTest, GetSwapPssByPid_Test_001, TestSize.Level1)
87 {
88     int pid = 1;
89     uint64_t size = 0;
90     size = GetSwapPssByPid(pid);
91     std::cout << "size = " << size << std::endl;
92     system("cat /proc/1/smaps_rollup");
93     ASSERT_EQ(size >= 0, true);
94 }
95 
96 HWTEST_F(MemInfoTest, GetSwapPssByPid_Test_002, TestSize.Level1)
97 {
98     int pid = -1;
99     uint64_t size = 0;
100     size = GetSwapPssByPid(pid);
101     ASSERT_EQ(size == 0, true);
102 }
103 
104 HWTEST_F(MemInfoTest, GetGraphicsMemory_Test, TestSize.Level1)
105 {
106     int pid = 1;
107     uint64_t gl = 0;
108     uint64_t graph = 0;
109     GetGraphicsMemory(pid, gl, graph);
110     ASSERT_EQ(gl == 0, true);
111 }
112 }
113 }
114