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 <cstdio>
17
18 #include "gtest/gtest.h"
19 #include "meminfo.h"
20
21 namespace OHOS {
22 namespace MemInfo {
23 using namespace testing;
24 using namespace testing::ext;
25
26 class MemInfoTest : public testing::Test {
27 public:
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 void SetUp();
31 void TearDown();
32 };
33
SetUpTestCase()34 void MemInfoTest::SetUpTestCase()
35 {
36 }
37
TearDownTestCase()38 void MemInfoTest::TearDownTestCase()
39 {
40 }
41
SetUp()42 void MemInfoTest::SetUp()
43 {
44 }
45
TearDown()46 void MemInfoTest::TearDown()
47 {
48 }
49
HWTEST_F(MemInfoTest, GetRssByPid_Test_001, TestSize.Level1)50 HWTEST_F(MemInfoTest, GetRssByPid_Test_001, TestSize.Level1)
51 {
52 int pid = 1;
53 uint64_t size = 0;
54 size = GetRssByPid(pid);
55 std::cout << "size = " << size << std::endl;
56 ASSERT_EQ(size > 0, true);
57 }
58
HWTEST_F(MemInfoTest, GetRssByPid_Test_002, TestSize.Level1)59 HWTEST_F(MemInfoTest, GetRssByPid_Test_002, TestSize.Level1)
60 {
61 int pid = -1;
62 uint64_t size = 0;
63 size = GetRssByPid(pid);
64 ASSERT_EQ(size == 0, true);
65 }
66
HWTEST_F(MemInfoTest, GetPssByPid_Test_001, TestSize.Level1)67 HWTEST_F(MemInfoTest, GetPssByPid_Test_001, TestSize.Level1)
68 {
69 int pid = 1;
70 uint64_t size = 0;
71 size = GetPssByPid(pid);
72 std::cout << "size = " << size << std::endl;
73 system("hidumper --mem 1");
74 system("cat /proc/1/smaps_rollup");
75 ASSERT_EQ(size > 0, true);
76 }
77
HWTEST_F(MemInfoTest, GetPssByPid_Test_002, TestSize.Level1)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 }
87