mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
unit-tests: intialize global test params at runtime
Move the intialization of the paramters to runtime by converting the static array to a vector and filling it when critirion calls the test setup. Global variable initialization order across translation units is not defined. Referring to e.g. the memory::mmap global variable in the initialization of the static unit test parameter set may leave an incorrect address in the struct param. Signed-off-by: Philipp Jungkamp <Philipp.Jungkamp@opal-rt.com>
This commit is contained in:
parent
f77231f2a7
commit
0cb4ac79d5
2 changed files with 14 additions and 12 deletions
|
@ -17,17 +17,19 @@ using namespace villas;
|
|||
int villas::node::pool_init(struct Pool *p, size_t cnt, size_t blocksz, struct memory::Type *m)
|
||||
{
|
||||
int ret;
|
||||
auto logger = logging.get("pool");
|
||||
|
||||
/* Make sure that we use a block size that is aligned to the size of a cache line */
|
||||
p->alignment = kernel::getCachelineSize();
|
||||
p->blocksz = p->alignment * CEIL(blocksz, p->alignment);
|
||||
p->len = cnt * p->blocksz;
|
||||
|
||||
logger->debug("New memory pool: alignment={}, blocksz={}, len={}, memory={}", p->alignment, p->blocksz, p->len, m->name);
|
||||
|
||||
void *buffer = memory::alloc_aligned(p->len, p->alignment, m);
|
||||
if (!buffer)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
auto logger = logging.get("pool");
|
||||
logger->debug("Allocated {:#x} bytes for memory pool", p->len);
|
||||
|
||||
p->buffer_off = (char*) buffer - (char*) p;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <criterion/parameterized.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <vector>
|
||||
|
||||
#include <villas/pool.hpp>
|
||||
#include <villas/utils.hpp>
|
||||
|
@ -29,14 +30,15 @@ struct param {
|
|||
|
||||
ParameterizedTestParameters(pool, basic)
|
||||
{
|
||||
static struct param params[] = {
|
||||
{ 1, 4096, 150, &memory::heap },
|
||||
{ 1, 128, 8, &memory::mmap },
|
||||
{ 1, 4, 8192, &memory::mmap_hugetlb },
|
||||
{ 1, 1 << 13, 4, &memory::mmap_hugetlb }
|
||||
};
|
||||
static std::vector<struct param> params;
|
||||
|
||||
return cr_make_param_array(struct param, params, ARRAY_LEN(params));
|
||||
params.clear();
|
||||
params.push_back({ 1, 4096, 150, &memory::heap });
|
||||
params.push_back({ 1, 128, 8, &memory::mmap });
|
||||
params.push_back({ 1, 4, 8192, &memory::mmap_hugetlb });
|
||||
params.push_back({ 1, 1 << 13, 4, &memory::mmap_hugetlb });
|
||||
|
||||
return cr_make_param_array(struct param, params.data(), params.size());
|
||||
}
|
||||
|
||||
// cppcheck-suppress unknownMacro
|
||||
|
@ -44,12 +46,10 @@ ParameterizedTest(struct param *p, pool, basic, .init = init_memory)
|
|||
{
|
||||
int ret;
|
||||
struct Pool pool;
|
||||
|
||||
// some strange LTO stuff is going on here..
|
||||
auto *m __attribute__((unused)) = &memory::mmap;
|
||||
|
||||
void *ptr, *ptrs[p->pool_size];
|
||||
|
||||
logging.setLevel("trace");
|
||||
|
||||
if (!utils::isPrivileged() && p->mt == &memory::mmap_hugetlb)
|
||||
cr_skip_test("Skipping memory_mmap_hugetlb tests allocatpr because we are running in an unprivileged environment.");
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue