diff options
author | 3gg <3gg@shellblade.net> | 2024-03-09 08:36:02 -0800 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2024-03-09 08:36:02 -0800 |
commit | afe1e1d12e42a0881aff63c766c14e48319b560c (patch) | |
tree | a17d08200e0046eb8929812fd2d9116a364ca04f /mempool/test/mempool_test.c | |
parent | 3b3c2c14a1eda5894d5db27bbaf4dd5f9a8c67db (diff) |
Define functions to get the number of used blocks.
Diffstat (limited to 'mempool/test/mempool_test.c')
-rw-r--r-- | mempool/test/mempool_test.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/mempool/test/mempool_test.c b/mempool/test/mempool_test.c index 6c48a2a..5eaee51 100644 --- a/mempool/test/mempool_test.c +++ b/mempool/test/mempool_test.c | |||
@@ -41,6 +41,8 @@ TEST_CASE(mempool_allocate_until_full) { | |||
41 | const int* block = mempool_alloc(&pool); | 41 | const int* block = mempool_alloc(&pool); |
42 | TEST_TRUE(block != 0); | 42 | TEST_TRUE(block != 0); |
43 | } | 43 | } |
44 | |||
45 | TEST_TRUE(mempool_size(&pool) == NUM_BLOCKS); | ||
44 | } | 46 | } |
45 | 47 | ||
46 | // Allocate all N blocks, then free them. | 48 | // Allocate all N blocks, then free them. |
@@ -60,6 +62,7 @@ TEST_CASE(mempool_fill_then_free) { | |||
60 | } | 62 | } |
61 | 63 | ||
62 | TEST_EQUAL(count(&pool), 0); | 64 | TEST_EQUAL(count(&pool), 0); |
65 | TEST_TRUE(mempool_size(&pool) == 0); | ||
63 | } | 66 | } |
64 | 67 | ||
65 | // Attempt to allocate blocks past the maximum pool size. | 68 | // Attempt to allocate blocks past the maximum pool size. |
@@ -78,6 +81,8 @@ TEST_CASE(mempool_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(mempool_alloc(&pool), 0); | 82 | TEST_EQUAL(mempool_alloc(&pool), 0); |
80 | } | 83 | } |
84 | |||
85 | TEST_TRUE(mempool_size(&pool) == 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(mempool_traverse_empty) { | |||
114 | mempool_make(&pool); | 119 | mempool_make(&pool); |
115 | 120 | ||
116 | TEST_EQUAL(count(&pool), 0); | 121 | TEST_EQUAL(count(&pool), 0); |
122 | TEST_TRUE(mempool_size(&pool) == 0); | ||
117 | } | 123 | } |
118 | 124 | ||
119 | // Traverse a partially full pool. | 125 | // Traverse a partially full pool. |
@@ -130,6 +136,7 @@ TEST_CASE(mempool_traverse_partially_full) { | |||
130 | } | 136 | } |
131 | 137 | ||
132 | TEST_EQUAL(sum(&pool), N * (N + 1) / 2); | 138 | TEST_EQUAL(sum(&pool), N * (N + 1) / 2); |
139 | TEST_TRUE(mempool_size(&pool) == N); | ||
133 | } | 140 | } |
134 | 141 | ||
135 | // Traverse a full pool. | 142 | // Traverse a full pool. |
@@ -144,6 +151,7 @@ TEST_CASE(mempool_traverse_full) { | |||
144 | } | 151 | } |
145 | 152 | ||
146 | TEST_EQUAL(sum(&pool), NUM_BLOCKS * (NUM_BLOCKS + 1) / 2); | 153 | TEST_EQUAL(sum(&pool), NUM_BLOCKS * (NUM_BLOCKS + 1) / 2); |
154 | TEST_TRUE(mempool_size(&pool) == NUM_BLOCKS); | ||
147 | } | 155 | } |
148 | 156 | ||
149 | // Get the ith (allocated) block. | 157 | // Get the ith (allocated) block. |