MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / test_mp_stress_alloc_free

Function test_mp_stress_alloc_free

src/utest/mempool_tc.c:140–166  ·  view source on GitHub ↗

Stress test: allocate and free repeatedly */

Source from the content-addressed store, hash-verified

138
139/* Stress test: allocate and free repeatedly */
140static void test_mp_stress_alloc_free(void)
141{
142 void *blocks[MEMPOOL_BLOCK_COUNT];
143 int i, j;
144
145 for (j = 0; j < 100; j++) /* Repeat 100 times */
146 {
147 /* Allocate all blocks */
148 for (i = 0; i < MEMPOOL_BLOCK_COUNT; i++)
149 {
150 blocks[i] = rt_mp_alloc(&mp_static, 0);
151 uassert_not_null(blocks[i]);
152 }
153
154 /* Check free count */
155 uassert_true(mp_static.block_free_count == 0);
156
157 /* Free all blocks */
158 for (i = 0; i < MEMPOOL_BLOCK_COUNT; i++)
159 {
160 rt_mp_free(blocks[i]);
161 }
162
163 /* Check free count */
164 uassert_true(mp_static.block_free_count == MEMPOOL_BLOCK_COUNT);
165 }
166}
167
168static rt_err_t utest_tc_init(void)
169{

Callers

nothing calls this directly

Calls 2

rt_mp_allocFunction · 0.85
rt_mp_freeFunction · 0.85

Tested by

no test coverage detected