• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef HDF_MEMORYTRACKER_IS_IMPLEMENTED
56 HWTEST_F(HdfMemoryTrackerTest, GetMemoryTest_01, TestSize.Level1)
57 {
58     printf("begin call memtrack by service \n");
59     sptr<IMemoryTrackerInterface> memtrack = IMemoryTrackerInterface::Get();
60     EXPECT_EQ(memtrack, nullptr);
61     if (memtrack == nullptr) {
62         printf("memtrack service is null \n");
63         return;
64     }
65 
66     std::vector<MemoryRecord> records;
67     int errCode = memtrack->GetDevMem(0, MEMORY_TRACKER_TYPE_GL, records);
68     if (errCode == HDF_SUCCESS) {
69         printf("memtrack calll GetMemory success, num_records=%zu \n", records.size());
70         int i = 0;
71         for (auto record : records) {
72             printf("memtrack: \trecords[%d], flag=%d, size=%lld \n", i++, record.flags, (long long)record.size);
73         }
74     }
75 }
76 
77 HWTEST_F(HdfMemoryTrackerTest, GetMemoryTest_02, TestSize.Level1)
78 {
79     printf("begin call memtrack passthrough \n");
80     sptr<IMemoryTrackerInterface> memtrack = IMemoryTrackerInterface::Get(true);
81     EXPECT_NE(memtrack, nullptr);
82     if (memtrack == nullptr) {
83         printf("memtrack service is null \n");
84         return;
85     }
86 
87     std::vector<MemoryRecord> records;
88     int errCode = memtrack->GetDevMem(0, MEMORY_TRACKER_TYPE_GL, records);
89     EXPECT_EQ(errCode, HDF_SUCCESS);
90     if (errCode == HDF_SUCCESS) {
91         printf("memtrack calll GetMemory success, num_records=%zu \n", records.size());
92         int i = 0;
93         for (auto record : records) {
94             printf("memtrack: \trecords[%d], flag=%d, size=%lld \n", i++, record.flags, (long long)record.size);
95         }
96     }
97 }
98 #endif
99 }
100 }
101