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

added unit tests for memory functions

This commit is contained in:
Steffen Vogel 2016-10-30 18:39:22 -04:00
parent d50f5ea694
commit f13c6c14e4
2 changed files with 43 additions and 0 deletions

View file

@ -8,6 +8,7 @@
*/
#include <stddef.h>
#include <stdint.h>
#ifndef _MEMORY_H_
#define _MEMORY_H_

42
tests/memory.c Normal file
View file

@ -0,0 +1,42 @@
/** Unit tests for memory management
*
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @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 <criterion/criterion.h>
#include <criterion/theories.h>
#include <errno.h>
#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));
}