Blender
V5.0
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
"
/* IWYU pragma: keep. 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
MultiresSubdivideModeType::Simple
@ Simple
Definition
BKE_multires.hh:164
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::ImplicitSharingPtr::get
const T * get() const
Definition
BLI_implicit_sharing_ptr.hh:94
blender::memory_counter::MemoryCount
Definition
BLI_memory_counter.hh:18
blender::memory_counter::MemoryCount::total_bytes
int64_t total_bytes
Definition
BLI_memory_counter.hh:27
blender::memory_counter::MemoryCounter
Definition
BLI_memory_counter.hh:39
blender::memory_counter::MemoryCounter::add
void add(const int64_t bytes)
Definition
memory_counter.cc:15
blender::memory_counter::MemoryCounter::add_shared
void add_shared(const ImplicitSharingInfo *sharing_info, const FunctionRef< void(MemoryCounter &shared_memory)> count_fn)
MEM_mallocN
void * MEM_mallocN(size_t len, const char *str)
Definition
mallocn.cc:128
blender::implicit_sharing::info_for_mem_free
const ImplicitSharingInfo * info_for_mem_free(void *data)
Definition
implicit_sharing.cc:35
blender::memory_counter
Definition
BLI_memory_counter.hh:16
blender::tests
Definition
BLF_tests.cc:9
blender::tests::TEST
TEST(blf_load, load)
Definition
BLF_tests.cc:34
Generated on
for Blender by
doxygen
1.16.1