• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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("hidumper --mem 1");
75     system("cat /proc/1/smaps_rollup");
76     ASSERT_EQ(size > 0, true);
77 }
78 
79 HWTEST_F(MemInfoTest, GetPssByPid_Test_002, TestSize.Level1)
80 {
81     int pid = -1;
82     uint64_t size = 0;
83     size = GetPssByPid(pid);
84     ASSERT_EQ(size == 0, true);
85 }
86 }
87 }
88