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

tests: fix memory initialization in unit tests

This commit is contained in:
Steffen Vogel 2018-08-13 14:58:52 +02:00
parent 7c61f19fd2
commit fa9e239816
5 changed files with 19 additions and 18 deletions

View file

@ -27,6 +27,11 @@
#include <villas/memory.h>
#include <villas/config.h>
void init_memory()
{
memory_init(DEFAULT_NR_HUGEPAGES);
}
int main(int argc, char *argv[])
{
int ret;
@ -42,10 +47,6 @@ int main(int argc, char *argv[])
if (ret)
error("Failed to start logging sub-system");
ret = memory_init(DEFAULT_NR_HUGEPAGES);
if (ret)
error("Failed to initialize memory sub-system");
/* Run criterion tests */
tests = criterion_initialize();

View file

@ -36,13 +36,10 @@ TheoryDataPoints(memory, aligned) = {
DataPoints(struct memory_type *, &memory_type_heap, &memory_hugepage)
};
Theory((size_t len, size_t align, struct memory_type *m), memory, aligned) {
Theory((size_t len, size_t align, struct memory_type *m), memory, aligned, .init = init_memory) {
int ret;
void *ptr;
ret = memory_init(100);
cr_assert(!ret);
ptr = memory_alloc_aligned(m, len, align);
cr_assert_neq(ptr, NULL, "Failed to allocate memory");
@ -56,7 +53,7 @@ Theory((size_t len, size_t align, struct memory_type *m), memory, aligned) {
cr_assert_eq(ret, 0, "Failed to release memory: ret=%d, ptr=%p, len=%zu: %s", ret, ptr, len, strerror(errno));
}
Test(memory, manager) {
Test(memory, manager, .init = init_memory) {
size_t total_size;
size_t max_block;
@ -67,9 +64,6 @@ Test(memory, manager) {
total_size = 1 << 10;
max_block = total_size - sizeof(struct memory_type) - sizeof(struct memory_block);
ret = memory_init(0);
cr_assert(!ret);
p = memory_alloc(&memory_heap, total_size);
cr_assert_not_null(p);

View file

@ -28,6 +28,8 @@
#include <villas/pool.h>
#include <villas/utils.h>
extern void init_memory();
struct param {
int thread_count;
int pool_size;
@ -47,7 +49,7 @@ ParameterizedTestParameters(pool, basic)
return cr_make_param_array(struct param, params, ARRAY_LEN(params));
}
ParameterizedTest(struct param *p, pool, basic)
ParameterizedTest(struct param *p, pool, basic, .init = init_memory)
{
int ret;
struct pool pool = { .state = STATE_DESTROYED };

View file

@ -34,7 +34,9 @@
#include <villas/utils.h>
#include <villas/queue.h>
#include <villas/memory.h>
#include <villas/rdtsc.h>
#include <villas/tsc.h>
extern void init_memory();
#define SIZE (1 << 10)
@ -235,7 +237,7 @@ void * producer_consumer_many(void *ctx)
}
#endif /* _POSIX_BARRIERS */
Test(queue, single_threaded)
Test(queue, single_threaded, .init = init_memory)
{
int ret;
struct param p = {
@ -301,7 +303,7 @@ ParameterizedTestParameters(queue, multi_threaded)
return cr_make_param_array(struct param, params, ARRAY_LEN(params));
}
ParameterizedTest(struct param *p, queue, multi_threaded, .timeout = 20)
ParameterizedTest(struct param *p, queue, multi_threaded, .timeout = 20, .init = init_memory)
{
int ret, cycpop;
@ -346,7 +348,7 @@ ParameterizedTest(struct param *p, queue, multi_threaded, .timeout = 20)
}
#endif /* _POSIX_BARRIERS */
Test(queue, init_destroy)
Test(queue, init_destroy, .init = init_memory)
{
int ret;
struct queue q = { .state = STATE_DESTROYED };

View file

@ -30,6 +30,8 @@
#include <villas/memory.h>
#include <villas/queue_signalled.h>
extern void init_memory();
#define NUM_ELEM 1000
struct param {
@ -124,7 +126,7 @@ ParameterizedTestParameters(queue_signalled, simple)
return cr_make_param_array(struct param, params, ARRAY_LEN(params));
}
ParameterizedTest(struct param *param, queue_signalled, simple, .timeout = 5)
ParameterizedTest(struct param *param, queue_signalled, simple, .timeout = 5, .init = init_memory)
{
int ret;
void *r1, *r2;