summaryrefslogtreecommitdiff
path: root/tests/unit/mempool_safeguards_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/mempool_safeguards_test.c')
-rw-r--r--tests/unit/mempool_safeguards_test.c38
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;
+}