diff options
| author | Denys Fedoryshchenko <denys.f@collabora.com> | 2026-09-28 21:50:27 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-09-28 21:50:27 +0300 |
| commit | 50c54c477624d5a9b668225fde2b9844d362760a (patch) | |
| tree | d1fe53a3c637f8b963027aa483053ae7afb55b5e /tests/unit/mempool_safeguards_test.c | |
| parent | c9d938173838d6955c824d141f24672d7037eb4e (diff) | |
| parent | 06aa0ef737d6993fd18e7db1bc8fc35601079505 (diff) | |
| download | accel-ppp-master.tar.gz accel-ppp-master.zip | |
Additional safeguards
Diffstat (limited to 'tests/unit/mempool_safeguards_test.c')
| -rw-r--r-- | tests/unit/mempool_safeguards_test.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/unit/mempool_safeguards_test.c b/tests/unit/mempool_safeguards_test.c new file mode 100644 index 00000000..b0c6a3dc --- /dev/null +++ b/tests/unit/mempool_safeguards_test.c @@ -0,0 +1,38 @@ +/* Pool reuse must not expose the previous object's payload. */ +#include <assert.h> +#include <pthread.h> +#include "triton.h" +#undef __init +#define __init +#include "../../accel-pppd/triton/mempool.c" + +void triton_log_error(const char *fmt, ...) {} +void triton_stat_mempool_allocated_add(uint64_t v) {} +void triton_stat_mempool_allocated_sub(uint64_t v) {} +void triton_stat_mempool_available_add(uint64_t v) {} +void triton_stat_mempool_available_sub(uint64_t v) {} + +int main(void) +{ + mempool_t *pool; + unsigned char *p, *q; + int i; + + spinlock_init(&pools_lock); + pool = mempool_create(128); + p = mempool_alloc(pool); + assert(p); + memset(p, 0xa5, 128); + mempool_free(p); + q = mempool_alloc(pool); + assert(q == p); + for (i = 0; i < 128; i++) + assert(!q[i]); + memset(q, 0x5a, 128); + mempool_free(q); + mempool_clean(); + list_del(&((struct _mempool_t *)pool)->entry); + free(pool); + puts("Mempool safeguards: PASS"); + return 0; +} |
