Skip to content

Commit

Permalink
fix runtimestats heap test
Browse files Browse the repository at this point in the history
  • Loading branch information
dipinhora committed Dec 13, 2024
1 parent 3709c7d commit e5c1692
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions test/libponyrt/mem/heap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@

#include <gtest/gtest.h>

#define SMALL_CHUNK_T_SIZE 32
#define SMALL_CHUNK_T_ALLOC 32
#define CHUNK_T_SIZE 32
#define CHUNK_T_ALLOC 32
#define SMALL_CHUNK_BLOCK_SIZE 1024
#define LARGE_CHUNK_T_SIZE 24
#define LARGE_CHUNK_T_ALLOC 32

TEST(Heap, Init)
{
Expand All @@ -32,8 +30,8 @@ TEST(Heap, Init)
ASSERT_EQ((size_t)1, actor->actorstats.heap_alloc_counter);
ASSERT_EQ((size_t)1, actor->actorstats.heap_num_allocated);
ASSERT_EQ((size_t)0, actor->actorstats.heap_free_counter);
ASSERT_EQ((size_t)(128 + SMALL_CHUNK_T_SIZE), actor->actorstats.heap_mem_used);
ASSERT_EQ((size_t)(SMALL_CHUNK_T_ALLOC + SMALL_CHUNK_BLOCK_SIZE), actor->actorstats.heap_mem_allocated);
ASSERT_EQ((size_t)(128 + CHUNK_T_SIZE), actor->actorstats.heap_mem_used);
ASSERT_EQ((size_t)(CHUNK_T_ALLOC + SMALL_CHUNK_BLOCK_SIZE), actor->actorstats.heap_mem_allocated);
#endif

pony_actor_t* pagemap_actor = NULL;
Expand All @@ -51,8 +49,8 @@ TEST(Heap, Init)
ASSERT_EQ((size_t)2, actor->actorstats.heap_alloc_counter);
ASSERT_EQ((size_t)2, actor->actorstats.heap_num_allocated);
ASSERT_EQ((size_t)0, actor->actorstats.heap_free_counter);
ASSERT_EQ((size_t)(256 + SMALL_CHUNK_T_SIZE), actor->actorstats.heap_mem_used);
ASSERT_EQ((size_t)(SMALL_CHUNK_T_ALLOC + SMALL_CHUNK_BLOCK_SIZE), actor->actorstats.heap_mem_allocated);
ASSERT_EQ((size_t)(256 + CHUNK_T_SIZE), actor->actorstats.heap_mem_used);
ASSERT_EQ((size_t)(CHUNK_T_ALLOC + SMALL_CHUNK_BLOCK_SIZE), actor->actorstats.heap_mem_allocated);
#endif

heap.next_gc = 0;
Expand All @@ -78,8 +76,8 @@ TEST(Heap, Init)
ASSERT_EQ((size_t)2, actor->actorstats.heap_alloc_counter);
ASSERT_EQ((size_t)1, actor->actorstats.heap_num_allocated);
ASSERT_EQ((size_t)1, actor->actorstats.heap_free_counter);
ASSERT_EQ((size_t)(128 + SMALL_CHUNK_T_SIZE), actor->actorstats.heap_mem_used);
ASSERT_EQ((size_t)(SMALL_CHUNK_T_ALLOC + SMALL_CHUNK_BLOCK_SIZE), actor->actorstats.heap_mem_allocated);
ASSERT_EQ((size_t)(128 + CHUNK_T_SIZE), actor->actorstats.heap_mem_used);
ASSERT_EQ((size_t)(CHUNK_T_ALLOC + SMALL_CHUNK_BLOCK_SIZE), actor->actorstats.heap_mem_allocated);
#endif

void* p3 = ponyint_heap_alloc(actor, &heap, 107, TRACK_NO_FINALISERS);
Expand All @@ -89,8 +87,8 @@ TEST(Heap, Init)
ASSERT_EQ((size_t)3, actor->actorstats.heap_alloc_counter);
ASSERT_EQ((size_t)2, actor->actorstats.heap_num_allocated);
ASSERT_EQ((size_t)1, actor->actorstats.heap_free_counter);
ASSERT_EQ((size_t)(256 + SMALL_CHUNK_T_SIZE), actor->actorstats.heap_mem_used);
ASSERT_EQ((size_t)(SMALL_CHUNK_T_ALLOC + SMALL_CHUNK_BLOCK_SIZE), actor->actorstats.heap_mem_allocated);
ASSERT_EQ((size_t)(256 + CHUNK_T_SIZE), actor->actorstats.heap_mem_used);
ASSERT_EQ((size_t)(CHUNK_T_ALLOC + SMALL_CHUNK_BLOCK_SIZE), actor->actorstats.heap_mem_allocated);
#endif

ponyint_heap_used(&heap, 1024);
Expand All @@ -100,8 +98,8 @@ TEST(Heap, Init)
ASSERT_EQ((size_t)3, actor->actorstats.heap_alloc_counter);
ASSERT_EQ((size_t)2, actor->actorstats.heap_num_allocated);
ASSERT_EQ((size_t)1, actor->actorstats.heap_free_counter);
ASSERT_EQ((size_t)(256 + SMALL_CHUNK_T_SIZE), actor->actorstats.heap_mem_used);
ASSERT_EQ((size_t)(SMALL_CHUNK_T_ALLOC + SMALL_CHUNK_BLOCK_SIZE), actor->actorstats.heap_mem_allocated);
ASSERT_EQ((size_t)(256 + CHUNK_T_SIZE), actor->actorstats.heap_mem_used);
ASSERT_EQ((size_t)(CHUNK_T_ALLOC + SMALL_CHUNK_BLOCK_SIZE), actor->actorstats.heap_mem_allocated);
#endif

heap.next_gc = 0;
Expand All @@ -126,8 +124,8 @@ TEST(Heap, Init)
ASSERT_EQ((size_t)3, actor->actorstats.heap_alloc_counter);
ASSERT_EQ((size_t)1, actor->actorstats.heap_num_allocated);
ASSERT_EQ((size_t)2, actor->actorstats.heap_free_counter);
ASSERT_EQ((size_t)(128 + SMALL_CHUNK_T_SIZE), actor->actorstats.heap_mem_used);
ASSERT_EQ((size_t)(SMALL_CHUNK_T_ALLOC + SMALL_CHUNK_BLOCK_SIZE), actor->actorstats.heap_mem_allocated);
ASSERT_EQ((size_t)(128 + CHUNK_T_SIZE), actor->actorstats.heap_mem_used);
ASSERT_EQ((size_t)(CHUNK_T_ALLOC + SMALL_CHUNK_BLOCK_SIZE), actor->actorstats.heap_mem_allocated);
#endif

void* p4 = ponyint_heap_alloc(actor, &heap, 67, TRACK_NO_FINALISERS);
Expand All @@ -137,8 +135,8 @@ TEST(Heap, Init)
ASSERT_EQ((size_t)4, actor->actorstats.heap_alloc_counter);
ASSERT_EQ((size_t)2, actor->actorstats.heap_num_allocated);
ASSERT_EQ((size_t)2, actor->actorstats.heap_free_counter);
ASSERT_EQ((size_t)(256 + SMALL_CHUNK_T_SIZE), actor->actorstats.heap_mem_used);
ASSERT_EQ((size_t)(SMALL_CHUNK_T_ALLOC + SMALL_CHUNK_BLOCK_SIZE), actor->actorstats.heap_mem_allocated);
ASSERT_EQ((size_t)(256 + CHUNK_T_SIZE), actor->actorstats.heap_mem_used);
ASSERT_EQ((size_t)(CHUNK_T_ALLOC + SMALL_CHUNK_BLOCK_SIZE), actor->actorstats.heap_mem_allocated);
#endif

size_t large_size = (1 << 22) - 7;
Expand All @@ -150,8 +148,8 @@ TEST(Heap, Init)
ASSERT_EQ((size_t)5, actor->actorstats.heap_alloc_counter);
ASSERT_EQ((size_t)3, actor->actorstats.heap_num_allocated);
ASSERT_EQ((size_t)2, actor->actorstats.heap_free_counter);
ASSERT_EQ((size_t)(256 + SMALL_CHUNK_T_SIZE + 4194304 + LARGE_CHUNK_T_SIZE), actor->actorstats.heap_mem_used);
ASSERT_EQ((size_t)(SMALL_CHUNK_T_ALLOC + SMALL_CHUNK_BLOCK_SIZE + 4194304 + LARGE_CHUNK_T_ALLOC), actor->actorstats.heap_mem_allocated);
ASSERT_EQ((size_t)(256 + CHUNK_T_SIZE + 4194304 + CHUNK_T_SIZE), actor->actorstats.heap_mem_used);
ASSERT_EQ((size_t)(CHUNK_T_ALLOC + SMALL_CHUNK_BLOCK_SIZE + 4194304 + CHUNK_T_ALLOC), actor->actorstats.heap_mem_allocated);
#endif

size_t adjust_size = ponyint_pool_adjust_size(large_size);
Expand Down Expand Up @@ -198,8 +196,8 @@ TEST(Heap, Init)
ASSERT_EQ((size_t)5, actor->actorstats.heap_alloc_counter);
ASSERT_EQ((size_t)1, actor->actorstats.heap_num_allocated);
ASSERT_EQ((size_t)4, actor->actorstats.heap_free_counter);
ASSERT_EQ((size_t)(4194304 + LARGE_CHUNK_T_SIZE), actor->actorstats.heap_mem_used);
ASSERT_EQ((size_t)(4194304 + LARGE_CHUNK_T_ALLOC), actor->actorstats.heap_mem_allocated);
ASSERT_EQ((size_t)(4194304 + CHUNK_T_SIZE), actor->actorstats.heap_mem_used);
ASSERT_EQ((size_t)(4194304 + CHUNK_T_ALLOC), actor->actorstats.heap_mem_allocated);
#endif

ponyint_heap_destroy(&heap);
Expand Down

0 comments on commit e5c1692

Please sign in to comment.