aboutsummaryrefslogtreecommitdiff
path: root/mem/test/mem_test.c
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2024-03-09 08:36:02 -0800
committer3gg <3gg@shellblade.net>2024-03-09 08:36:02 -0800
commitafe1e1d12e42a0881aff63c766c14e48319b560c (patch)
treea17d08200e0046eb8929812fd2d9116a364ca04f /mem/test/mem_test.c
parent3b3c2c14a1eda5894d5db27bbaf4dd5f9a8c67db (diff)
Define functions to get the number of used blocks.
Diffstat (limited to 'mem/test/mem_test.c')
-rw-r--r--mem/test/mem_test.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/mem/test/mem_test.c b/mem/test/mem_test.c
index d3c43b9..97db079 100644
--- a/mem/test/mem_test.c
+++ b/mem/test/mem_test.c
@@ -41,6 +41,8 @@ TEST_CASE(mem_fully_allocate) {
41 const int* block = mem_alloc(&mem, 1); 41 const int* block = mem_alloc(&mem, 1);
42 TEST_TRUE(block != 0); 42 TEST_TRUE(block != 0);
43 } 43 }
44
45 TEST_TRUE(mem_size(&mem) == NUM_BLOCKS);
44} 46}
45 47
46// Allocate N chunks of 1 block each, then free them. 48// Allocate N chunks of 1 block each, then free them.
@@ -60,6 +62,7 @@ TEST_CASE(mem_fill_then_free) {
60 } 62 }
61 63
62 TEST_EQUAL(count(&mem), 0); 64 TEST_EQUAL(count(&mem), 0);
65 TEST_TRUE(mem_size(&mem) == 0);
63} 66}
64 67
65// Attempt to allocate blocks past the maximum allocator size. 68// Attempt to allocate blocks past the maximum allocator size.
@@ -78,6 +81,8 @@ TEST_CASE(mem_allocate_beyond_max_size) {
78 for (int i = 0; i < NUM_BLOCKS; ++i) { 81 for (int i = 0; i < NUM_BLOCKS; ++i) {
79 TEST_EQUAL(mem_alloc(&mem, 1), 0); 82 TEST_EQUAL(mem_alloc(&mem, 1), 0);
80 } 83 }
84
85 TEST_TRUE(mem_size(&mem) == NUM_BLOCKS);
81} 86}
82 87
83// Free blocks should always remain zeroed out. 88// Free blocks should always remain zeroed out.
@@ -114,6 +119,7 @@ TEST_CASE(mem_traverse_empty) {
114 mem_make(&mem); 119 mem_make(&mem);
115 120
116 TEST_EQUAL(count(&mem), 0); 121 TEST_EQUAL(count(&mem), 0);
122 TEST_TRUE(mem_size(&mem) == 0);
117} 123}
118 124
119// Traverse a partially full allocator. 125// Traverse a partially full allocator.
@@ -130,6 +136,7 @@ TEST_CASE(mem_traverse_partially_full) {
130 } 136 }
131 137
132 TEST_EQUAL(sum(&mem), (N) * (N + 1) / 2); 138 TEST_EQUAL(sum(&mem), (N) * (N + 1) / 2);
139 TEST_TRUE(mem_size(&mem) == N);
133} 140}
134 141
135// Traverse a full allocator. 142// Traverse a full allocator.
@@ -144,6 +151,7 @@ TEST_CASE(mem_traverse_full) {
144 } 151 }
145 152
146 TEST_EQUAL(sum(&mem), (NUM_BLOCKS) * (NUM_BLOCKS + 1) / 2); 153 TEST_EQUAL(sum(&mem), (NUM_BLOCKS) * (NUM_BLOCKS + 1) / 2);
154 TEST_TRUE(mem_size(&mem) == NUM_BLOCKS);
147} 155}
148 156
149// Get the ith (allocated) chunk. 157// Get the ith (allocated) chunk.