1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00
VILLASnode/tests/unit/pool.c

83 lines
2.1 KiB
C
Raw Permalink Normal View History

2016-10-30 19:40:50 -04:00
/** Unit tests for memory pool
*
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
2017-04-27 12:56:43 +02:00
* @license GNU General Public License (version 3)
*
* VILLASnode
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
2017-04-27 12:56:43 +02:00
* This program 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 General Public License for more details.
*
2017-04-27 12:56:43 +02:00
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2016-10-30 19:40:50 -04:00
*********************************************************************************/
#include <criterion/criterion.h>
#include <criterion/parameterized.h>
#include <signal.h>
2018-03-26 12:50:15 +02:00
#include <villas/pool.h>
#include <villas/utils.h>
2016-10-30 19:40:50 -04:00
struct param {
int thread_count;
int pool_size;
size_t block_size;
2018-07-02 14:17:50 +02:00
struct memory_type *memory_type;
2016-10-30 19:40:50 -04:00
};
ParameterizedTestParameters(pool, basic)
{
static struct param params[] = {
2018-07-02 14:17:50 +02:00
{ 1, 4096, 150, &memory_type_heap },
{ 1, 128, 8, &memory_hugepage },
{ 1, 4, 8192, &memory_hugepage },
{ 1, 1 << 13, 4, &memory_type_heap }
2016-10-30 19:40:50 -04:00
};
2016-10-30 19:40:50 -04:00
return cr_make_param_array(struct param, params, ARRAY_LEN(params));
}
ParameterizedTest(struct param *p, pool, basic)
{
int ret;
2017-03-25 21:23:48 +01:00
struct pool pool = { .state = STATE_DESTROYED };
2016-10-30 19:40:50 -04:00
void *ptr, *ptrs[p->pool_size];
2018-07-02 14:17:50 +02:00
ret = pool_init(&pool, p->pool_size, p->block_size, p->memory_type);
2016-10-30 19:40:50 -04:00
cr_assert_eq(ret, 0, "Failed to create pool");
2016-10-30 19:40:50 -04:00
ptr = pool_get(&pool);
cr_assert_neq(ptr, NULL);
2016-10-30 19:40:50 -04:00
memset(ptr, 1, p->block_size); /* check that we dont get a seg fault */
int i;
for (i = 1; i < p->pool_size; i++) {
2016-10-30 19:40:50 -04:00
ptrs[i] = pool_get(&pool);
if (ptrs[i] == NULL)
break;
2016-10-30 19:40:50 -04:00
}
if (i < p->pool_size)
cr_assert_neq(ptrs[i], NULL);
2016-10-30 19:40:50 -04:00
ptr = pool_get(&pool);
cr_assert_eq(ptr, NULL);
2016-10-30 19:40:50 -04:00
ret = pool_destroy(&pool);
cr_assert_eq(ret, 0, "Failed to destroy pool");
2017-03-28 10:28:20 +02:00
}