1 /*
2 * Copyright (c) 2022 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 "gtest/gtest.h"
17
18 #define private public
19 #define protected public
20 #include <v1_0/imemory_tracker_interface.h>
21 #include "hdf_base.h"
22 #undef private
23 #undef protected
24
25 namespace OHOS {
26 namespace Memory {
27 using namespace testing;
28 using namespace testing::ext;
29 using namespace OHOS::HDI::Memorytracker::V1_0;
30
31 class HdfMemoryTrackerTest : public testing::Test {
32 public:
33 static void SetUpTestCase();
34 static void TearDownTestCase();
35 void SetUp();
36 void TearDown();
37 };
38
SetUpTestCase()39 void HdfMemoryTrackerTest::SetUpTestCase()
40 {
41 }
42
TearDownTestCase()43 void HdfMemoryTrackerTest::TearDownTestCase()
44 {
45 }
46
SetUp()47 void HdfMemoryTrackerTest::SetUp()
48 {
49 }
50
TearDown()51 void HdfMemoryTrackerTest::TearDown()
52 {
53 }
54
55 HWTEST_F(HdfMemoryTrackerTest, GetMemoryTest_01, TestSize.Level1)
56 {
57 printf("begin call memtrack by service \n");
58 sptr<IMemoryTrackerInterface> memtrack = IMemoryTrackerInterface::Get();
59 if (memtrack == nullptr) {
60 printf("memtrack service is null \n");
61 return;
62 }
63
64 std::vector<MemoryRecord> records;
65 int errCode = memtrack->GetDevMem(0, MEMORY_TRACKER_TYPE_GL, records);
66 if (errCode == HDF_SUCCESS) {
67 printf("memtrack calll GetMemory success, num_records=%zu \n", records.size());
68 int i = 0;
69 for (auto record : records) {
70 printf("memtrack: \trecords[%d], flag=%d, size=%lld \n", i++, record.flags, (long long)record.size);
71 }
72 }
73 }
74
75 HWTEST_F(HdfMemoryTrackerTest, GetMemoryTest_02, TestSize.Level1)
76 {
77 printf("begin call memtrack passthrough \n");
78 sptr<IMemoryTrackerInterface> memtrack = IMemoryTrackerInterface::Get(true);
79 if (memtrack == nullptr) {
80 printf("memtrack service is null \n");
81 return;
82 }
83
84 std::vector<MemoryRecord> records;
85 int errCode = memtrack->GetDevMem(0, MEMORY_TRACKER_TYPE_GL, records);
86 if (errCode == HDF_SUCCESS) {
87 printf("memtrack calll GetMemory success, num_records=%zu \n", records.size());
88 int i = 0;
89 for (auto record : records) {
90 printf("memtrack: \trecords[%d], flag=%d, size=%lld \n", i++, record.flags, (long long)record.size);
91 }
92 }
93 }
94 }
95 }
96