diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2008-10-16 19:41:45 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2008-10-16 19:41:45 +0400 |
commit | 802890f0f2619ff93f543d1fcf55831cb647b174 (patch) | |
tree | 7442f1afe9ba2752425d8af5dc1f7b4f628d51d2 /test | |
parent | cd9b528a22e190c11d47c452b6d83fd1fbd4550c (diff) | |
download | rspamd-802890f0f2619ff93f543d1fcf55831cb647b174.tar.gz rspamd-802890f0f2619ff93f543d1fcf55831cb647b174.zip |
* Add support of shared memory chunks to memory pool allocator. Also add locking support (spin mutexes)
* Add simple test case for shared memory allocation
Diffstat (limited to 'test')
-rw-r--r-- | test/rspamd_mem_pool_test.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/test/rspamd_mem_pool_test.c b/test/rspamd_mem_pool_test.c index 50e539cf7..97ee03604 100644 --- a/test/rspamd_mem_pool_test.c +++ b/test/rspamd_mem_pool_test.c @@ -2,6 +2,8 @@ #include "tests.h" #include <stdio.h> +#include <stdlib.h> +#include <unistd.h> #include <glib.h> #define TEST_BUF "test bufffer" @@ -12,23 +14,43 @@ rspamd_mem_pool_test_func () { memory_pool_t *pool; memory_pool_stat_t st; - char *tmp, *tmp2; + char *tmp, *tmp2, *tmp3; + pid_t pid; + int ret; pool = memory_pool_new (sizeof (TEST_BUF)); tmp = memory_pool_alloc (pool, sizeof (TEST_BUF)); tmp2 = memory_pool_alloc (pool, sizeof (TEST_BUF) * 2); + tmp3 = memory_pool_alloc_shared (pool, sizeof (TEST_BUF)); snprintf (tmp, sizeof (TEST_BUF), "%s", TEST_BUF); snprintf (tmp2, sizeof (TEST_BUF) * 2, "%s", TEST2_BUF); + snprintf (tmp3, sizeof (TEST_BUF), "%s", TEST_BUF); g_assert (strncmp (tmp, TEST_BUF, sizeof (TEST_BUF)) == 0); g_assert (strncmp (tmp2, TEST2_BUF, sizeof (TEST2_BUF)) == 0); + g_assert (strncmp (tmp3, TEST_BUF, sizeof (TEST_BUF)) == 0); + memory_pool_lock_shared (pool, tmp3); + if ((pid = fork ()) == 0) { + memory_pool_lock_shared (pool, tmp3); + g_assert (*tmp3 == 's'); + *tmp3 = 't'; + memory_pool_unlock_shared (pool, tmp3); + exit (EXIT_SUCCESS); + } + else { + *tmp3 = 's'; + memory_pool_unlock_shared (pool, tmp3); + } + wait (&ret); + g_assert (*tmp3 == 't'); memory_pool_delete (pool); memory_pool_stat (&st); /* Check allocator stat */ - g_assert (st.bytes_allocated == sizeof (TEST_BUF) * 3); + g_assert (st.bytes_allocated == sizeof (TEST_BUF) * 4); g_assert (st.chunks_allocated == 2); - g_assert (st.chunks_freed == 2); + g_assert (st.shared_chunks_allocated == 1); + g_assert (st.chunks_freed == 3); } |