MCPcopy Create free account
hub / github.com/defold/defold / TEST

Function TEST

engine/dlib/src/test/test_memprofile.cpp:37–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35#if !defined(DM_SANITIZE_ADDRESS) // until we can load the dylibs properly
36
37TEST(dmMemProfile, TestMalloc)
38{
39 // We assume that the memory (actual size) allocated is 1024 <= x <= 1024 + sizeof(size_t)
40 // This is by inspection...
41
42 dmMemProfile::Stats stats1, stats2, stats3;
43 dmMemProfile::GetStats(&stats1);
44 void* p = malloc(1024);
45 g_dont_optimize = p;
46 dmMemProfile::GetStats(&stats2);
47
48 if (g_MemprofileActive)
49 {
50 ASSERT_EQ(1, stats2.m_AllocationCount - stats1.m_AllocationCount);
51 ASSERT_GE(stats2.m_TotalActive - stats1.m_TotalActive, 1024);
52 ASSERT_LE(stats2.m_TotalActive - stats1.m_TotalActive, 1024 + sizeof(size_t));
53 ASSERT_GE(stats2.m_TotalAllocated - stats1.m_TotalAllocated, 1024);
54 ASSERT_LE(stats2.m_TotalAllocated - stats1.m_TotalAllocated, 1024 + sizeof(size_t));
55 }
56
57 free(p);
58 dmMemProfile::GetStats(&stats3);
59
60 if (g_MemprofileActive)
61 {
62 ASSERT_EQ(1, stats3.m_AllocationCount - stats1.m_AllocationCount);
63 ASSERT_EQ(0, stats3.m_TotalActive - stats1.m_TotalActive);
64 ASSERT_GE(stats3.m_TotalAllocated - stats1.m_TotalAllocated, 1024);
65 ASSERT_LE(stats3.m_TotalAllocated - stats1.m_TotalAllocated, 1024 + sizeof(size_t));
66 }
67}
68
69TEST(dmMemProfile, TestCalloc)
70{

Callers

nothing calls this directly

Calls 11

mallocFunction · 0.85
freeFunction · 0.85
callocFunction · 0.85
reallocFunction · 0.85
memalignFunction · 0.85
posix_memalignFunction · 0.85
func1aFunction · 0.85
func1bFunction · 0.85
GetStatsFunction · 0.50
reserveMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected