From a1a4e0ea7ea1e49f9f5705f2f29bc40111d6ba44 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 31 Jan 2018 09:40:08 +0100 Subject: [PATCH] tests: fix portability issues for running the tests on OS X/BSD --- tests/unit/io.c | 2 +- tests/unit/kernel.c | 4 ++++ tests/unit/queue.c | 13 +++++++++++-- tests/unit/utils.c | 2 ++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/unit/io.c b/tests/unit/io.c index 034733844..270ecf43c 100644 --- a/tests/unit/io.c +++ b/tests/unit/io.c @@ -138,7 +138,7 @@ void cr_assert_eq_samples(struct io_format *f, struct sample *smps[], struct sam cr_assert_float_eq(smps[i]->data[j].f, smpt[i]->data[j].f, 1e-3, "Sample data mismatch at index %d: %f != %f", j, smps[i]->data[j].f, smpt[i]->data[j].f); break; case SAMPLE_DATA_FORMAT_INT: - cr_assert_eq(smps[i]->data[j].i, smpt[i]->data[j].i, "Sample data mismatch at index %d: %d != %d", j, smps[i]->data[j].i, smpt[i]->data[j].i); + cr_assert_eq(smps[i]->data[j].i, smpt[i]->data[j].i, "Sample data mismatch at index %d: %lld != %lld", j, smps[i]->data[j].i, smpt[i]->data[j].i); break; } } diff --git a/tests/unit/kernel.c b/tests/unit/kernel.c index 246356416..f14444588 100644 --- a/tests/unit/kernel.c +++ b/tests/unit/kernel.c @@ -25,6 +25,8 @@ #include "kernel/kernel.h" #include "utils.h" +#ifdef __linux__ + /* This test is not portable, but we currently support x86 only */ Test(kernel, sizes) { @@ -84,3 +86,5 @@ Test(kernel, module, .disabled = true) ret = kernel_module_loaded("does_not_exist"); cr_assert_neq(ret, 0); } + +#endif /* __linux__ */ diff --git a/tests/unit/queue.c b/tests/unit/queue.c index 37b90d4c8..7710f3c67 100644 --- a/tests/unit/queue.c +++ b/tests/unit/queue.c @@ -39,7 +39,9 @@ static struct queue q = { .state = STATE_DESTROYED }; +#if defined(_POSIX_BARRIERS) && _POSIX_BARRIERS > 0 static pthread_barrier_t barrier; +#endif struct param { int volatile start; @@ -87,6 +89,9 @@ static void * producer(void *ctx) /** @todo Criterion cr_log() is broken for multi-threaded programs */ //cr_log_info("producer: tid = %lu", thread_get_id()); +#ifdef __APPLE__ + #define pthread_yield pthread_yield_np +#endif /* Wait for global start signal */ while (p->start == 0) pthread_yield(); @@ -152,6 +157,7 @@ static void * consumer(void *ctx) return NULL; } +#if defined(_POSIX_BARRIERS) && _POSIX_BARRIERS > 0 void * producer_consumer(void *ctx) { struct param *p = ctx; @@ -226,6 +232,7 @@ void * producer_consumer_many(void *ctx) return 0; } +#endif /* _POSIX_BARRIERS */ Test(queue, single_threaded) { @@ -248,6 +255,7 @@ Test(queue, single_threaded) cr_assert_eq(ret, 0, "Failed to create queue"); } +#if defined(_POSIX_BARRIERS) && _POSIX_BARRIERS > 0 ParameterizedTestParameters(queue, multi_threaded) { static struct param params[] = { @@ -331,10 +339,11 @@ ParameterizedTest(struct param *p, queue, multi_threaded, .timeout = 20) ret = queue_destroy(&p->queue); cr_assert_eq(ret, 0, "Failed to destroy queue"); - + ret = pthread_barrier_destroy(&barrier); cr_assert_eq(ret, 0, "Failed to destroy barrier"); } +#endif /* _POSIX_BARRIERS */ Test(queue, init_destroy) { @@ -346,4 +355,4 @@ Test(queue, init_destroy) ret = queue_destroy(&q); cr_assert_eq(ret, 0); /* Should succeed */ -} \ No newline at end of file +} diff --git a/tests/unit/utils.c b/tests/unit/utils.c index 5684934a3..89015f9b0 100644 --- a/tests/unit/utils.c +++ b/tests/unit/utils.c @@ -55,6 +55,7 @@ Test(utils, box_muller) cr_assert_float_eq((double) sigma[0] / iter, 0.682829, 1e-2); } +#ifdef __linux__ Test(utils, cpuset) { int ret; @@ -78,6 +79,7 @@ Test(utils, cpuset) cr_assert_eq(int1, int2); } +#endif /* __linux__ */ Test(utils, memdup) {