Blender
V4.3
source
blender
blenlib
tests
BLI_memory_counter_test.cc
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2024 Blender Authors
2
*
3
* SPDX-License-Identifier: Apache-2.0 */
4
5
#include "
BLI_implicit_sharing_ptr.hh
"
6
#include "
BLI_memory_counter.hh
"
7
8
#include "testing/testing.h"
9
10
#include "
BLI_strict_flags.h
"
/* Keep last. */
11
12
namespace
blender::tests
{
13
14
TEST
(memory_counter, Simple)
15
{
16
MemoryCount
memory_count;
17
MemoryCounter
memory{memory_count};
18
EXPECT_EQ
(memory_count.
total_bytes
, 0);
19
memory.add(10);
20
EXPECT_EQ
(memory_count.
total_bytes
, 10);
21
memory.add(10);
22
EXPECT_EQ
(memory_count.
total_bytes
, 20);
23
24
const
int
alloc_size = 100;
25
void
*data1 =
MEM_mallocN
(alloc_size, __func__);
26
void
*data2 =
MEM_mallocN
(alloc_size, __func__);
27
const
ImplicitSharingPtr
sharing_info1{
implicit_sharing::info_for_mem_free
(data1)};
28
const
ImplicitSharingPtr
sharing_info2{
implicit_sharing::info_for_mem_free
(data2)};
29
30
memory.add_shared(sharing_info1.get(), alloc_size);
31
EXPECT_EQ
(memory_count.
total_bytes
, 120);
32
33
memory.add_shared(sharing_info1.get(), [&](
MemoryCounter
&
/*shared_memory*/
) { FAIL(); });
34
EXPECT_EQ
(memory_count.
total_bytes
, 120);
35
36
memory.add_shared(sharing_info2.get(),
37
[&](
MemoryCounter
&shared_memory) { shared_memory.add(alloc_size); });
38
EXPECT_EQ
(memory_count.
total_bytes
, 220);
39
40
memory.add_shared(
nullptr
, 1000);
41
EXPECT_EQ
(memory_count.
total_bytes
, 1220);
42
43
memory.add_shared(
nullptr
, 1000);
44
EXPECT_EQ
(memory_count.
total_bytes
, 2220);
45
}
46
47
}
// namespace blender::tests
EXPECT_EQ
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
BLI_implicit_sharing_ptr.hh
BLI_memory_counter.hh
BLI_strict_flags.h
blender::ImplicitSharingPtr
Definition
BLI_implicit_sharing_ptr.hh:24
blender::memory_counter::MemoryCount
Definition
BLI_memory_counter.hh:20
blender::memory_counter::MemoryCount::total_bytes
int64_t total_bytes
Definition
BLI_memory_counter.hh:29
blender::memory_counter::MemoryCounter
Definition
BLI_memory_counter.hh:41
MEM_mallocN
void *(* MEM_mallocN)(size_t len, const char *str)
Definition
mallocn.cc:44
blender::implicit_sharing::info_for_mem_free
const ImplicitSharingInfo * info_for_mem_free(void *data)
Definition
implicit_sharing.cc:31
blender::tests
Definition
BLI_any_test.cc:10
blender::tests::TEST
TEST(any, DefaultConstructor)
Definition
BLI_any_test.cc:12
Generated on Thu Feb 6 2025 07:36:39 for Blender by
doxygen
1.11.0