• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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, Hardware
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 #include "image/trace_memory_dump.h"
19 
20 #ifdef RS_ENABLE_VK
21 #include "platform/ohos/backend/rs_vulkan_context.h"
22 #endif
23 
24 using namespace testing;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 namespace Rosen {
29 namespace Drawing {
30 class TraceMemoryDumpTest : public testing::Test {
31 public:
32     static void SetUpTestCase();
33     static void TearDownTestCase();
34     void SetUp() override;
35     void TearDown() override;
36 };
37 
SetUpTestCase()38 void TraceMemoryDumpTest::SetUpTestCase()
39 {
40 #ifdef RS_ENABLE_VK
41     RsVulkanContext::SetRecyclable(false);
42 #endif
43 }
TearDownTestCase()44 void TraceMemoryDumpTest::TearDownTestCase() {}
SetUp()45 void TraceMemoryDumpTest::SetUp() {}
TearDown()46 void TraceMemoryDumpTest::TearDown() {}
47 
48 /**
49  * @tc.name: DumpNumericValueTest001
50  * @tc.desc:
51  * @tc.type: FUNC
52  * @tc.require:AR000GGNV3
53  * @tc.author:
54  */
55 HWTEST_F(TraceMemoryDumpTest, DumpNumericValueTest001, TestSize.Level1)
56 {
57     std::unique_ptr<TraceMemoryDump> traceMemoryDump = std::make_unique<TraceMemoryDump>("category", true);
58     ASSERT_TRUE(traceMemoryDump != nullptr);
59     traceMemoryDump->DumpNumericValue("dumpName", "valueName", "units", 0);
60 }
61 
62 /**
63  * @tc.name: DumpStringValueTest001
64  * @tc.desc:
65  * @tc.type: FUNC
66  * @tc.require:AR000GGNV3
67  * @tc.author:
68  */
69 HWTEST_F(TraceMemoryDumpTest, DumpStringValueTest001, TestSize.Level1)
70 {
71     std::unique_ptr<TraceMemoryDump> traceMemoryDump = std::make_unique<TraceMemoryDump>("category", true);
72     ASSERT_TRUE(traceMemoryDump != nullptr);
73     traceMemoryDump->DumpStringValue("dumpName", "valueName", "value");
74 }
75 
76 /**
77  * @tc.name: LogOutputTest001
78  * @tc.desc:
79  * @tc.type: FUNC
80  * @tc.require:AR000GGNV3
81  * @tc.author:
82  */
83 HWTEST_F(TraceMemoryDumpTest, LogOutputTest001, TestSize.Level1)
84 {
85     std::unique_ptr<TraceMemoryDump> traceMemoryDump = std::make_unique<TraceMemoryDump>("category", true);
86     ASSERT_TRUE(traceMemoryDump != nullptr);
87     DfxString log;
88     traceMemoryDump->LogOutput(log);
89 }
90 
91 /**
92  * @tc.name: LogTotalsTest001
93  * @tc.desc:
94  * @tc.type: FUNC
95  * @tc.require:AR000GGNV3
96  * @tc.author:
97  */
98 HWTEST_F(TraceMemoryDumpTest, LogTotalsTest001, TestSize.Level1)
99 {
100     std::unique_ptr<TraceMemoryDump> traceMemoryDump = std::make_unique<TraceMemoryDump>("category", true);
101     ASSERT_TRUE(traceMemoryDump != nullptr);
102     DfxString log;
103     traceMemoryDump->LogTotals(log);
104 }
105 
106 /**
107  * @tc.name: GetGpuMemorySizeInMBTest001
108  * @tc.desc:
109  * @tc.type: FUNC
110  * @tc.require:AR000GGNV3
111  * @tc.author:
112  */
113 HWTEST_F(TraceMemoryDumpTest, GetGpuMemorySizeInMBTest001, TestSize.Level1)
114 {
115     std::unique_ptr<TraceMemoryDump> traceMemoryDump = std::make_unique<TraceMemoryDump>("category", true);
116     ASSERT_TRUE(traceMemoryDump != nullptr);
117     float mem = traceMemoryDump->GetGpuMemorySizeInMB();
118     EXPECT_GE(mem, 0.0);
119 }
120 
121 /**
122  * @tc.name: GetGLMemorySizeTest001
123  * @tc.desc:
124  * @tc.type: FUNC
125  * @tc.require:AR000GGNV3
126  * @tc.author:
127  */
128 HWTEST_F(TraceMemoryDumpTest, GetGLMemorySizeTest001, TestSize.Level1)
129 {
130     std::unique_ptr<TraceMemoryDump> traceMemoryDump = std::make_unique<TraceMemoryDump>("category", true);
131     ASSERT_TRUE(traceMemoryDump != nullptr);
132     float mem = traceMemoryDump->GetGLMemorySize();
133     EXPECT_GE(mem, 0.0);
134 }
135 } // namespace Drawing
136 } // namespace Rosen
137 } // namespace OHOS