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.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "../src/config.h"
  2. #include "../src/mem_pool.h"
  3. #include "tests.h"
  4. #define TEST_BUF "test bufffer"
  5. #define TEST2_BUF "test bufffertest bufffer"
  6. void
  7. rspamd_mem_pool_test_func ()
  8. {
  9. memory_pool_t *pool;
  10. memory_pool_stat_t st;
  11. char *tmp, *tmp2, *tmp3;
  12. pid_t pid;
  13. int ret;
  14. pool = memory_pool_new (sizeof (TEST_BUF));
  15. tmp = memory_pool_alloc (pool, sizeof (TEST_BUF));
  16. tmp2 = memory_pool_alloc (pool, sizeof (TEST_BUF) * 2);
  17. tmp3 = memory_pool_alloc_shared (pool, sizeof (TEST_BUF));
  18. snprintf (tmp, sizeof (TEST_BUF), "%s", TEST_BUF);
  19. snprintf (tmp2, sizeof (TEST_BUF) * 2, "%s", TEST2_BUF);
  20. snprintf (tmp3, sizeof (TEST_BUF), "%s", TEST_BUF);
  21. g_assert (strncmp (tmp, TEST_BUF, sizeof (TEST_BUF)) == 0);
  22. g_assert (strncmp (tmp2, TEST2_BUF, sizeof (TEST2_BUF)) == 0);
  23. g_assert (strncmp (tmp3, TEST_BUF, sizeof (TEST_BUF)) == 0);
  24. memory_pool_lock_shared (pool, tmp3);
  25. if ((pid = fork ()) == 0) {
  26. memory_pool_lock_shared (pool, tmp3);
  27. g_assert (*tmp3 == 's');
  28. *tmp3 = 't';
  29. memory_pool_unlock_shared (pool, tmp3);
  30. exit (EXIT_SUCCESS);
  31. }
  32. else {
  33. *tmp3 = 's';
  34. memory_pool_unlock_shared (pool, tmp3);
  35. }
  36. wait (&ret);
  37. g_assert (*tmp3 == 't');
  38. memory_pool_delete (pool);
  39. memory_pool_stat (&st);
  40. }