mirror of
https://github.com/rspamd/rspamd.git
synced 2024-09-09 22:25:58 +02:00
![Vsevolod Stakhov](/assets/img/avatar_default.png)
* Adopt build system for new structure --HG-- rename : cfg_file.h => src/cfg_file.h rename : cfg_file.l => src/cfg_file.l rename : cfg_file.y => src/cfg_file.y rename : cfg_utils.c => src/cfg_utils.c rename : controller.c => src/controller.c rename : filter.c => src/filter.c rename : filter.h => src/filter.h rename : fstring.c => src/fstring.c rename : fstring.h => src/fstring.h rename : main.c => src/main.c rename : main.h => src/main.h rename : mem_pool.c => src/mem_pool.c rename : mem_pool.h => src/mem_pool.h rename : memcached-test.c => src/memcached-test.c rename : memcached.c => src/memcached.c rename : memcached.h => src/memcached.h rename : perl.c => src/perl.c rename : perl.h => src/perl.h rename : plugins/regexp.c => src/plugins/regexp.c rename : plugins/surbl.c => src/plugins/surbl.c rename : protocol.c => src/protocol.c rename : protocol.h => src/protocol.h rename : upstream.c => src/upstream.c rename : upstream.h => src/upstream.h rename : url.c => src/url.c rename : url.h => src/url.h rename : util.c => src/util.c rename : util.h => src/util.h rename : worker.c => src/worker.c
58 lines
1.5 KiB
C
58 lines
1.5 KiB
C
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <glib.h>
|
|
|
|
#include "../src/mem_pool.h"
|
|
#include "tests.h"
|
|
|
|
#define TEST_BUF "test bufffer"
|
|
#define TEST2_BUF "test bufffertest bufffer"
|
|
|
|
void
|
|
rspamd_mem_pool_test_func ()
|
|
{
|
|
memory_pool_t *pool;
|
|
memory_pool_stat_t st;
|
|
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) * 4);
|
|
g_assert (st.chunks_allocated == 2);
|
|
g_assert (st.shared_chunks_allocated == 1);
|
|
g_assert (st.chunks_freed == 3);
|
|
}
|