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 crashes caused by ASLR

This commit is contained in:
Steffen Vogel 2018-10-21 13:00:50 +01:00
parent 93612d8773
commit 39e29964ab
8 changed files with 84 additions and 38 deletions

View file

@ -41,7 +41,7 @@ extern void init_memory();
#define NUM_VALUES 10
struct param {
const char *fmt;
char *fmt;
int cnt;
int bits;
};
@ -189,6 +189,15 @@ void cr_assert_eq_sample_raw(struct sample *a, struct sample *b, int flags, int
ParameterizedTestParameters(io, lowlevel)
{
for (int i = 0; i < ARRAY_LEN(params); i++) {
struct param *p = &params[i];
char *fmt = cr_malloc(strlen(p->fmt) + 1);
strcpy(fmt, p->fmt);
p->fmt = fmt;
}
return cr_make_param_array(struct param, params, ARRAY_LEN(params));
}
@ -255,6 +264,16 @@ ParameterizedTest(struct param *p, io, lowlevel, .init = init_memory)
ParameterizedTestParameters(io, highlevel)
{
for (int i = 0; i < ARRAY_LEN(params); i++) {
struct param *p = &params[i];
char *fmt = cr_malloc(strlen(p->fmt) + 1);
strcpy(fmt, p->fmt);
p->fmt = fmt;
}
return cr_make_param_array(struct param, params, ARRAY_LEN(params));
}

View file

@ -72,6 +72,20 @@ ParameterizedTestParameters(json, json_load_cli)
}
};
for (int i = 0; i < ARRAY_LEN(params); i++) {
struct param *p = &params[i];
char *json = cr_malloc(strlen(p->json) + 1);
strcpy(json, p->json);
p->json = json;
for (char **a = p->argv; *a; a++) {
char *argv = cr_malloc(strlen(*a) + 1);
strcpy(argv , *a);
*a = argv;
}
}
return cr_make_param_array(struct param, params, ARRAY_LEN(params));
}

View file

@ -56,6 +56,14 @@ ParameterizedTestParameters(log, facility_expression)
{ "", 0 }
};
for (int i = 0; i < ARRAY_LEN(params); i++) {
struct param *p = &params[i];
char *expression = cr_malloc(strlen(p->expression) + 1);
strcpy(expression, p->expression);
p->expression = expression;
}
return cr_make_param_array(struct param, params, ARRAY_LEN(params));
}

View file

@ -37,21 +37,25 @@ extern void init_memory();
TheoryDataPoints(memory, aligned) = {
DataPoints(size_t, 1, 32, 55, 1 << 10, PAGESIZE, HUGEPAGESIZE),
DataPoints(size_t, 1, 8, PAGESIZE, PAGESIZE),
DataPoints(struct memory_type *, &memory_heap, &memory_hugepage, &memory_hugepage)
DataPoints(enum memory_type_flags, MEMORY_HEAP, MEMORY_HUGEPAGE, MEMORY_HUGEPAGE)
};
Theory((size_t len, size_t align, struct memory_type *m), memory, aligned, .init = init_memory) {
Theory((size_t len, size_t align, enum memory_type_flags memory_type), memory, aligned, .init = init_memory) {
int ret;
void *ptr;
ptr = memory_alloc_aligned(m, len, align);
struct memory_type *mt = memory_type_lookup(memory_type);
ptr = memory_alloc_aligned(mt, len, align);
cr_assert_not_null(ptr, "Failed to allocate memory");
cr_assert(IS_ALIGNED(ptr, align), "Memory at %p is not alligned to %#zx byte bounary", ptr, align);
if (m == &memory_hugepage) {
#ifndef __APPLE__
if (mt == &memory_hugepage) {
cr_assert(IS_ALIGNED(ptr, HUGEPAGESIZE), "Memory at %p is not alligned to %#x byte bounary", ptr, HUGEPAGESIZE);
}
#endif
ret = memory_free(ptr);
cr_assert_eq(ret, 0, "Failed to release memory: ret=%d, ptr=%p, len=%zu: %s", ret, ptr, len, strerror(errno));

View file

@ -34,16 +34,16 @@ struct param {
int thread_count;
int pool_size;
size_t block_size;
struct memory_type *memory_type;
enum memory_type_flags memory_type;
};
ParameterizedTestParameters(pool, basic)
{
static struct param params[] = {
{ 1, 4096, 150, &memory_heap },
{ 1, 128, 8, &memory_hugepage },
{ 1, 4, 8192, &memory_hugepage },
{ 1, 1 << 13, 4, &memory_heap }
{ 1, 4096, 150, MEMORY_HEAP },
{ 1, 128, 8, MEMORY_HUGEPAGE },
{ 1, 4, 8192, MEMORY_HUGEPAGE },
{ 1, 1 << 13, 4, MEMORY_HUGEPAGE }
};
return cr_make_param_array(struct param, params, ARRAY_LEN(params));
@ -56,7 +56,9 @@ ParameterizedTest(struct param *p, pool, basic, .init = init_memory)
void *ptr, *ptrs[p->pool_size];
ret = pool_init(&pool, p->pool_size, p->block_size, p->memory_type);
struct memory_type *mt = memory_type_lookup(p->memory_type);
ret = pool_init(&pool, p->pool_size, p->block_size, mt);
cr_assert_eq(ret, 0, "Failed to create pool");
ptr = pool_get(&pool);

View file

@ -52,9 +52,9 @@ struct param {
int queue_size;
int iter_count;
int batch_size;
void * (*thread_func)(void *);
bool many;
struct queue queue;
const struct memory_type *memory_type;
enum memory_type_flags memory_type;
};
/** Get thread id as integer
@ -266,37 +266,37 @@ ParameterizedTestParameters(queue, multi_threaded)
.iter_count = 1 << 12,
.queue_size = 1 << 9,
.thread_count = 32,
.thread_func = producer_consumer_many,
.many = true,
.batch_size = 10,
.memory_type = &memory_heap
.memory_type = MEMORY_HEAP
}, {
.iter_count = 1 << 8,
.queue_size = 1 << 9,
.thread_count = 4,
.thread_func = producer_consumer_many,
.many = true,
.batch_size = 100,
.memory_type = &memory_heap
.memory_type = MEMORY_HEAP
}, {
.iter_count = 1 << 16,
.queue_size = 1 << 14,
.thread_count = 16,
.thread_func = producer_consumer_many,
.many = true,
.batch_size = 100,
.memory_type = &memory_heap
.memory_type = MEMORY_HEAP
}, {
.iter_count = 1 << 8,
.queue_size = 1 << 9,
.thread_count = 4,
.thread_func = producer_consumer_many,
.many = true,
.batch_size = 10,
.memory_type = &memory_heap
.memory_type = MEMORY_HEAP
}, {
.iter_count = 1 << 16,
.queue_size = 1 << 9,
.thread_count = 16,
.thread_func = producer_consumer,
.many = false,
.batch_size = 10,
.memory_type = &memory_hugepage
.memory_type = MEMORY_HUGEPAGE
}
};
@ -312,7 +312,9 @@ ParameterizedTest(struct param *p, queue, multi_threaded, .timeout = 20, .init =
p->start = 0;
ret = queue_init(&p->queue, p->queue_size, &memory_heap);
struct memory_type *mt = memory_type_lookup(p->memory_type);
ret = queue_init(&p->queue, p->queue_size, mt);
cr_assert_eq(ret, 0, "Failed to create queue");
uint64_t start_tsc_time, end_tsc_time;
@ -320,7 +322,7 @@ ParameterizedTest(struct param *p, queue, multi_threaded, .timeout = 20, .init =
pthread_barrier_init(&barrier, NULL, p->thread_count);
for (int i = 0; i < p->thread_count; ++i)
pthread_create(&threads[i], NULL, p->thread_func, p);
pthread_create(&threads[i], NULL, p->many ? producer_consumer_many : producer_consumer, p);
sleep(0.2);

View file

@ -36,7 +36,7 @@ extern void init_memory();
struct param {
int flags;
void * (*consumer_func)(void *);
bool polled;
};
static void * producer(void * ctx)
@ -112,14 +112,14 @@ again: ret = poll(&pfd, 1, -1);
ParameterizedTestParameters(queue_signalled, simple)
{
static struct param params[] = {
{ 0, consumer },
{ QUEUE_SIGNALLED_PTHREAD, consumer },
{ QUEUE_SIGNALLED_PTHREAD, consumer },
{ QUEUE_SIGNALLED_PTHREAD | QUEUE_SIGNALLED_PROCESS_SHARED, consumer },
{ QUEUE_SIGNALLED_POLLING, consumer },
{ 0, false },
{ QUEUE_SIGNALLED_PTHREAD, false },
{ QUEUE_SIGNALLED_PTHREAD, false },
{ QUEUE_SIGNALLED_PTHREAD | QUEUE_SIGNALLED_PROCESS_SHARED, false },
{ QUEUE_SIGNALLED_POLLING, false },
#if defined(__linux__) && defined(HAS_EVENTFD)
{ QUEUE_SIGNALLED_EVENTFD, consumer },
{ QUEUE_SIGNALLED_EVENTFD, polled_consumer }
{ QUEUE_SIGNALLED_EVENTFD, false },
{ QUEUE_SIGNALLED_EVENTFD, true }
#endif
};
@ -140,7 +140,7 @@ ParameterizedTest(struct param *param, queue_signalled, simple, .timeout = 5, .i
ret = pthread_create(&t1, NULL, producer, &q);
cr_assert_eq(ret, 0);
ret = pthread_create(&t2, NULL, param->consumer_func, &q);
ret = pthread_create(&t2, NULL, param->polled ? polled_consumer : consumer, &q);
cr_assert_eq(ret, 0);
ret = pthread_join(t1, &r1);

View file

@ -31,10 +31,7 @@ Test(timing, time_now)
struct timespec now1 = time_now();
struct timespec now2 = time_now();
double delta = time_delta(&now1, &now2);
cr_assert_float_eq(delta, 0, 1e-5, "time_now() shows large variance!");
cr_assert_gt(delta, 0, "time_now() was reordered!");
cr_assert(time_cmp(&now1, &now2) <= 0, "time_now() was reordered!");
}
Test(timing, time_diff)