diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2018-02-02 08:00:23 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2018-02-02 15:01:19 +0100 |
commit | d71d1da5083a211eca91c48b58359e9e8245bdbb (patch) | |
tree | e3a608740ff59e71896d51fc0c9634f8f4020a52 /testsuites/sptests/spsyslock01/init.c | |
parent | sp20: Fix print buffer size (diff) | |
download | rtems-d71d1da5083a211eca91c48b58359e9e8245bdbb.tar.bz2 |
spsyslock01: Fix object compare
Due to structure internal padding the use of memcmp() may lead to
sporadic test failures.
Update #3082.
Diffstat (limited to 'testsuites/sptests/spsyslock01/init.c')
-rw-r--r-- | testsuites/sptests/spsyslock01/init.c | 64 |
1 files changed, 59 insertions, 5 deletions
diff --git a/testsuites/sptests/spsyslock01/init.c b/testsuites/sptests/spsyslock01/init.c index 1e3d16a675..23546670a2 100644 --- a/testsuites/sptests/spsyslock01/init.c +++ b/testsuites/sptests/spsyslock01/init.c @@ -94,6 +94,60 @@ static void get_abs_timeout(struct timespec *to) } } +static bool eq_tq( + const struct _Thread_queue_Queue *a, + const struct _Thread_queue_Queue *b +) +{ + return a->_Lock._next_ticket == b->_Lock._next_ticket + && a->_Lock._now_serving == b->_Lock._now_serving + && a->_heads == b->_heads + && a->_owner == b->_owner + && a->_name == b->_name; +} + +static bool eq_mtx( + const struct _Mutex_Control *a, + const struct _Mutex_Control *b +) +{ + return eq_tq(&a->_Queue, &b->_Queue); +} + +static bool eq_rec_mtx( + const struct _Mutex_recursive_Control *a, + const struct _Mutex_recursive_Control *b +) +{ + return eq_mtx(&a->_Mutex, &b->_Mutex) + && a->_nest_level == b->_nest_level; +} + +static bool eq_cond( + const struct _Condition_Control *a, + const struct _Condition_Control *b +) +{ + return eq_tq(&a->_Queue, &b->_Queue); +} + +static bool eq_sem( + const struct _Semaphore_Control *a, + const struct _Semaphore_Control *b +) +{ + return eq_tq(&a->_Queue, &b->_Queue) + && a->_count == b->_count; +} + +static bool eq_futex( + const struct _Futex_Control *a, + const struct _Futex_Control *b +) +{ + return eq_tq(&a->_Queue, &b->_Queue); +} + static void test_initialization(test_context *ctx) { struct _Mutex_Control mtx = _MUTEX_INITIALIZER; @@ -108,11 +162,11 @@ static void test_initialization(test_context *ctx) _Semaphore_Initialize(&ctx->sem, 1); _Futex_Initialize(&ctx->futex); - rtems_test_assert(memcmp(&mtx, &ctx->mtx, sizeof(mtx)) == 0); - rtems_test_assert(memcmp(&rec_mtx, &ctx->rec_mtx, sizeof(rec_mtx)) == 0); - rtems_test_assert(memcmp(&cond, &ctx->cond, sizeof(cond)) == 0); - rtems_test_assert(memcmp(&sem, &ctx->sem, sizeof(sem)) == 0); - rtems_test_assert(memcmp(&futex, &ctx->futex, sizeof(futex)) == 0); + rtems_test_assert(eq_mtx(&mtx, &ctx->mtx)); + rtems_test_assert(eq_rec_mtx(&rec_mtx, &ctx->rec_mtx)); + rtems_test_assert(eq_cond(&cond, &ctx->cond)); + rtems_test_assert(eq_sem(&sem, &ctx->sem)); + rtems_test_assert(eq_futex(&futex, &ctx->futex)); _Mutex_Destroy(&mtx); _Mutex_recursive_Destroy(&rec_mtx); |