From f13c6c14e413daf408a28e105edd521a2360db99 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sun, 30 Oct 2016 18:39:22 -0400 Subject: [PATCH] added unit tests for memory functions --- include/villas/memory.h | 1 + tests/memory.c | 42 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tests/memory.c diff --git a/include/villas/memory.h b/include/villas/memory.h index d66955727..b21d1b1a4 100644 --- a/include/villas/memory.h +++ b/include/villas/memory.h @@ -8,6 +8,7 @@ */ #include +#include #ifndef _MEMORY_H_ #define _MEMORY_H_ diff --git a/tests/memory.c b/tests/memory.c new file mode 100644 index 000000000..fc40bd610 --- /dev/null +++ b/tests/memory.c @@ -0,0 +1,42 @@ +/** Unit tests for memory management + * + * @author Steffen Vogel + * @copyright 2014-2016, Institute for Automation of Complex Power Systems, EONERC + * This file is part of VILLASnode. All Rights Reserved. Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + *********************************************************************************/ + +#include +#include + +#include + +#include "memory.h" +#include "utils.h" + +#define HUGEPAGESIZE (1 << 21) + +TheoryDataPoints(memory, aligned) = { +// DataPoints(size_t, 1, 32, 55, 1 << 10, 1 << 20), + DataPoints(size_t, 1<<12), + DataPoints(size_t, 1, 8, 1 << 12), + DataPoints(const struct memtype *, &memtype_heap, &memtype_hugepage) +}; + +Theory((size_t len, size_t align, const struct memtype *m), memory, aligned) { + int ret; + void *ptr; + + ptr = memory_alloc_aligned(m, len, align); + cr_assert_neq(ptr, NULL, "Failed to allocate memory"); + + //cr_assert(IS_ALIGNED(ptr, align)); + + if (m == &memtype_hugepage) { + cr_assert(IS_ALIGNED(ptr, HUGEPAGESIZE)); + len = ALIGN(len, HUGEPAGESIZE); /* ugly see: https://lkml.org/lkml/2015/3/27/171 */ + } + + ret = memory_free(m, ptr, len); + cr_assert_eq(ret, 0, "Failed to release memory: ret=%d, ptr=%p, len=%zu: %s", ret, ptr, len, strerror(errno)); +} \ No newline at end of file