2011-01-16 09:55:41 -08:00
|
|
|
/* EINA - EFL data type library
|
|
|
|
* Copyright (C) 2008 Cedric Bail
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library;
|
|
|
|
* if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2016-02-04 05:44:58 -08:00
|
|
|
#include <Eina.h>
|
|
|
|
|
2011-01-16 09:55:41 -08:00
|
|
|
#include "eina_suite.h"
|
|
|
|
|
|
|
|
static void
|
2017-08-15 13:46:38 -07:00
|
|
|
_eina_mempool_test(Eina_Mempool *mp,
|
|
|
|
Eina_Bool with_realloc, Eina_Bool with_gc, Eina_Bool accurate_from)
|
2011-01-16 09:55:41 -08:00
|
|
|
{
|
2019-09-14 10:54:05 -07:00
|
|
|
Eina_Iterator *it;
|
2011-01-16 09:55:41 -08:00
|
|
|
int *tbl[512];
|
2019-09-14 10:54:05 -07:00
|
|
|
int *ptr;
|
2011-01-16 09:55:41 -08:00
|
|
|
int i;
|
|
|
|
|
2019-09-14 10:54:05 -07:00
|
|
|
fail_if(!mp);
|
2011-01-16 09:55:41 -08:00
|
|
|
|
|
|
|
for (i = 0; i < 512; ++i)
|
|
|
|
{
|
|
|
|
tbl[i] = eina_mempool_malloc(mp, sizeof (int));
|
|
|
|
fail_if(!tbl[i]);
|
2017-08-15 13:46:38 -07:00
|
|
|
if (accurate_from)
|
|
|
|
fail_if(eina_mempool_from(mp, tbl[i]) != EINA_TRUE);
|
2011-01-16 09:55:41 -08:00
|
|
|
*tbl[i] = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 512; ++i)
|
|
|
|
fail_if(*tbl[i] != i);
|
|
|
|
|
|
|
|
for (i = 0; i < 256; ++i)
|
2017-08-15 13:46:38 -07:00
|
|
|
{
|
2011-01-16 09:55:41 -08:00
|
|
|
eina_mempool_free(mp, tbl[i]);
|
2017-08-15 13:46:38 -07:00
|
|
|
if (accurate_from)
|
|
|
|
fail_if(eina_mempool_from(mp, tbl[i]) != EINA_FALSE);
|
|
|
|
}
|
2011-01-16 09:55:41 -08:00
|
|
|
|
2019-09-14 10:54:05 -07:00
|
|
|
it = eina_mempool_iterator_new(mp);
|
|
|
|
EINA_ITERATOR_FOREACH(it, ptr)
|
|
|
|
{
|
|
|
|
ck_assert_int_gt(*ptr, 255);
|
|
|
|
*ptr = 0;
|
|
|
|
}
|
|
|
|
eina_iterator_free(it);
|
|
|
|
|
|
|
|
if (it) // Only check if the mempool support iterator
|
|
|
|
{
|
|
|
|
for (; i < 512; ++i)
|
|
|
|
ck_assert_int_eq(*tbl[i], 0);
|
|
|
|
}
|
|
|
|
|
2011-01-16 09:55:41 -08:00
|
|
|
if (with_realloc)
|
|
|
|
fail_if(eina_mempool_realloc(mp, tbl[500], 25) == NULL);
|
|
|
|
else
|
|
|
|
fail_if(eina_mempool_realloc(mp, tbl[500], 25) != NULL);
|
|
|
|
|
|
|
|
if (with_gc)
|
|
|
|
{
|
|
|
|
eina_mempool_gc(mp);
|
|
|
|
eina_mempool_statistics(mp);
|
|
|
|
}
|
|
|
|
|
|
|
|
eina_mempool_del(mp);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef EINA_BUILD_CHAINED_POOL
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_mempool_chained_mempool)
|
2011-01-16 09:55:41 -08:00
|
|
|
{
|
|
|
|
Eina_Mempool *mp;
|
|
|
|
|
|
|
|
mp = eina_mempool_add("chained_mempool", "test", NULL, sizeof (int), 256);
|
2017-08-15 13:46:38 -07:00
|
|
|
_eina_mempool_test(mp, EINA_FALSE, EINA_FALSE, EINA_TRUE);
|
2011-01-16 09:55:41 -08:00
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2011-01-16 09:55:41 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef EINA_BUILD_PASS_THROUGH
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_mempool_pass_through)
|
2011-01-16 09:55:41 -08:00
|
|
|
{
|
|
|
|
Eina_Mempool *mp;
|
|
|
|
|
|
|
|
mp = eina_mempool_add("pass_through", "test", NULL, sizeof (int), 8, 0);
|
2017-08-15 13:46:38 -07:00
|
|
|
_eina_mempool_test(mp, EINA_TRUE, EINA_FALSE, EINA_FALSE);
|
2011-01-16 09:55:41 -08:00
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2011-01-16 09:55:41 -08:00
|
|
|
#endif
|
|
|
|
|
2019-09-14 10:52:37 -07:00
|
|
|
#ifdef EINA_BUILD_ONE_BIG
|
|
|
|
EFL_START_TEST(eina_mempool_one_big)
|
|
|
|
{
|
|
|
|
Eina_Mempool *mp;
|
|
|
|
|
|
|
|
mp = eina_mempool_add("one_big", "test", NULL, sizeof (int), 384);
|
|
|
|
_eina_mempool_test(mp, EINA_FALSE, EINA_FALSE, EINA_TRUE);
|
|
|
|
}
|
|
|
|
EFL_END_TEST
|
|
|
|
#endif
|
|
|
|
|
2011-01-16 09:55:41 -08:00
|
|
|
void
|
|
|
|
eina_test_mempool(TCase *tc)
|
|
|
|
{
|
|
|
|
#ifdef EINA_BUILD_CHAINED_POOL
|
|
|
|
tcase_add_test(tc, eina_mempool_chained_mempool);
|
|
|
|
#endif
|
|
|
|
#ifdef EINA_BUILD_PASS_THROUGH
|
|
|
|
tcase_add_test(tc, eina_mempool_pass_through);
|
|
|
|
#endif
|
2019-09-14 10:52:37 -07:00
|
|
|
#ifdef EINA_BUILD_ONE_BIG
|
|
|
|
tcase_add_test(tc, eina_mempool_one_big);
|
|
|
|
#endif
|
2011-01-16 09:55:41 -08:00
|
|
|
}
|