You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rspamd_mem_pool_test.c 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "config.h"
  2. #include "mem_pool.h"
  3. #include "tests.h"
  4. #include "unix-std.h"
  5. #include <math.h>
  6. #ifdef HAVE_SYS_WAIT_H
  7. #include <sys/wait.h>
  8. #endif
  9. #define TEST_BUF "test bufffer"
  10. #define TEST2_BUF "test bufffertest bufffer"
  11. void
  12. rspamd_mem_pool_test_func ()
  13. {
  14. rspamd_mempool_t *pool;
  15. rspamd_mempool_stat_t st;
  16. char *tmp, *tmp2, *tmp3;
  17. pid_t pid;
  18. int ret;
  19. pool = rspamd_mempool_new (sizeof (TEST_BUF), NULL);
  20. tmp = rspamd_mempool_alloc (pool, sizeof (TEST_BUF));
  21. tmp2 = rspamd_mempool_alloc (pool, sizeof (TEST_BUF) * 2);
  22. tmp3 = rspamd_mempool_alloc_shared (pool, sizeof (TEST_BUF));
  23. snprintf (tmp, sizeof (TEST_BUF), "%s", TEST_BUF);
  24. snprintf (tmp2, sizeof (TEST_BUF) * 2, "%s", TEST2_BUF);
  25. snprintf (tmp3, sizeof (TEST_BUF), "%s", TEST_BUF);
  26. g_assert (strncmp (tmp, TEST_BUF, sizeof (TEST_BUF)) == 0);
  27. g_assert (strncmp (tmp2, TEST2_BUF, sizeof (TEST2_BUF)) == 0);
  28. g_assert (strncmp (tmp3, TEST_BUF, sizeof (TEST_BUF)) == 0);
  29. rspamd_mempool_lock_shared (pool, tmp3);
  30. if ((pid = fork ()) == 0) {
  31. rspamd_mempool_lock_shared (pool, tmp3);
  32. g_assert (*tmp3 == 's');
  33. *tmp3 = 't';
  34. rspamd_mempool_unlock_shared (pool, tmp3);
  35. exit (EXIT_SUCCESS);
  36. }
  37. else {
  38. *tmp3 = 's';
  39. rspamd_mempool_unlock_shared (pool, tmp3);
  40. }
  41. wait (&ret);
  42. g_assert (*tmp3 == 't');
  43. rspamd_mempool_delete (pool);
  44. rspamd_mempool_stat (&st);
  45. }