y2038: testsuite/smokey/2038: move mutex test to another thread
PATCH 2/2 y2038: testsuite/smokey/2038: move mutex test to another thread
If a process is able to acquire a mutex immediately, we should lock the mutex in the main thread and validate timeout in the other thread.
--- testsuite/smokey/y2038/syscall-tests.c | 74 +++++++++++++++++----------------- 1 file changed, 36 insertions(+), 38 deletions(-)
testsuite/smokey/y2038/syscall-tests.c +36 -38
@@ -207,7 +207,34 @@ static void *__mutex_timedlock64_thread(void *arg)struct xn_timespec64 ts64, ts_wu;struct timespec ts_nat; - ret =clock_gettime (CLOCK_MONOTONIC , &ts_nat); +/* +* The mutex is already exhausted, so calling again will validate +* the provided timeout now. Providing NULL has to deliver EFAULT +*/ + ret =XENOMAI_SYSCALL2 (sr_nc, lock,NULL ); +if (!smokey_assert (ret == -EFAULT )) +return ret ? ret : -EINVAL ; + +/* +* The mutex is already exhausted, so calling again will validate +* the provided timeout now. Providing an invalid address has to deliver +* EFAULT +*/ + ret =XENOMAI_SYSCALL2 (sr_nc, lock, (void *)0xdeadbeefUL ); +if (!smokey_assert (ret == -EFAULT )) +return ret ? ret : -EINVAL ; + +/* +* The mutex is still exhausted, calling again will validate the +* timeout, providing an invalid timeout has to deliver EINVAL +*/ + ts64.tv_sec =-1 ; + ret =XENOMAI_SYSCALL2 (sr_nc, lock, &ts64); +if (!smokey_assert (ret == -EINVAL )) +return ret ? ret : -EINVAL ; + + + ret =clock_gettime (CLOCK_REALTIME , &ts_nat);if (ret)return NULL ;
@@ -219,7 +246,7 @@ static void *__mutex_timedlock64_thread(void *arg)if (!smokey_assert (ret == -ETIMEDOUT ))return NULL ; - ret =clock_gettime (CLOCK_MONOTONIC , &ts_nat); + ret =clock_gettime (CLOCK_REALTIME , &ts_nat);if (ret)return NULL ;
@@ -240,10 +267,12 @@ static int __mutex_timedlock64(pthread_mutex_t *lock) {int ret;pthread_t tid; +int sr_nc = sc_cobalt_mutex_timedlock64; - ret =pthread_mutex_lock (lock); -if (ret) -return -errno; +/* Timeout is never read by the kernel, so NULL should be OK */ + ret =XENOMAI_SYSCALL2 (sr_nc, lock,NULL ); +if (!smokey_assert (!ret)) +return ret ? ret : -EINVAL ; ret =pthread_create (&tid,NULL , __mutex_timedlock64_thread, lock);if (ret)
@@ -289,40 +318,9 @@ static int test_sc_cobalt_mutex_timedlock64(void)if (!smokey_assert (ret == -EINVAL ))return ret ? ret : -EINVAL ; -/* Timeout is never read by the kernel, so NULL should be OK */ - ret =XENOMAI_SYSCALL2 (sr_nc, &lock,NULL ); -if (!smokey_assert (!ret)) -smokey_warning ("POSIX mutex_timedlock64 violation detected" ); - -/* -* The mutex is already exhausted, so calling again will validate -* the provided timeout now. Providing NULL has to deliver EFAULT -*/ - ret =XENOMAI_SYSCALL2 (sr_nc, &lock,NULL ); -if (!smokey_assert (ret == -EFAULT )) -return ret ? ret : -EINVAL ; - -/* -* The mutex is already exhausted, so calling again will validate -* the provided timeout now. Providing an invalid address has to deliver -* EFAULT -*/ - ret =XENOMAI_SYSCALL2 (sr_nc, &lock, (void *)0xdeadbeefUL ); -if (!smokey_assert (ret == -EFAULT )) -return ret ? ret : -EINVAL ; - -/* -* The mutex is still exhausted, calling again will validate the -* timeout, providing an invalid timeout has to deliver EINVAL -*/ - ts64.tv_sec =-1 ; - ret =XENOMAI_SYSCALL2 (sr_nc, &lock, &ts64); -if (!smokey_assert (ret == -EINVAL )) -return ret ? ret : -EINVAL ; -/* -* Providing a valid timeout, waiting for it to time out and check -* that we didn't come back to early. +* mutex will be acquired in current thread, timeout will be +* validated in the other thread */ ret =__mutex_timedlock64 (&lock);if (ret)
Signature · 1 line
2.7.4
Quoted 2 lines · Song Chen
If a process is able to acquire a mutex immediately, we should lock the mutex in the main thread and validate timeout in the other thread.
a) I hope there is a posix/mutex test somewhere. I guess it should be updated.
b) The changes to the y2038 tests are unexpected / to big at first glance, will recheck later. If the mutex can be taken immediately the timeout is not validated, so the "other thread" does not need to validate anything.
c) The y2038 related mutex stuff is not in master / next now. So we should
- make patch one of this series patch one of the y2038 series
- squash patch 2 of this series into the patch that added the y2038 mutex tests
Quoted 135 lines
Signed-off-by Song Chen <[email protected]>---
testsuite/smokey/y2038/syscall-tests.c | 74 +++++++++++++++++-----------------1 file changed, 36 insertions(+), 38 deletions(-)testsuite/smokey/y2038/syscall-tests.c +0
-0@@ -207,7 +207,34 @@ static void *__mutex_timedlock64_thread(void *arg) struct xn_timespec64 ts64, ts_wu; struct timespec ts_nat;testsuite/smokey/y2038/syscall-tests.c +28
-1- ret =clock_gettime (CLOCK_MONOTONIC , &ts_nat); +/* +* The mutex is already exhausted, so calling again will validate +* the provided timeout now. Providing NULL has to deliver EFAULT +*/ + ret =XENOMAI_SYSCALL2 (sr_nc, lock,NULL ); +if (!smokey_assert (ret == -EFAULT )) +return ret ? ret : -EINVAL ; + +/* +* The mutex is already exhausted, so calling again will validate +* the provided timeout now. Providing an invalid address has to deliver +* EFAULT +*/ + ret =XENOMAI_SYSCALL2 (sr_nc, lock, (void *)0xdeadbeefUL ); +if (!smokey_assert (ret == -EFAULT )) +return ret ? ret : -EINVAL ; + +/* +* The mutex is still exhausted, calling again will validate the +* timeout, providing an invalid timeout has to deliver EINVAL +*/ + ts64.tv_sec =-1 ; + ret =XENOMAI_SYSCALL2 (sr_nc, lock, &ts64); +if (!smokey_assert (ret == -EINVAL )) +return ret ? ret : -EINVAL ; + + + ret =clock_gettime (CLOCK_REALTIME , &ts_nat);if (ret)
return NULL;testsuite/smokey/y2038/syscall-tests.c +0
-0@@ -219,7 +246,7 @@ static void *__mutex_timedlock64_thread(void *arg) if (!smokey_assert(ret == -ETIMEDOUT)) return NULL;testsuite/smokey/y2038/syscall-tests.c +1
-1- ret =clock_gettime (CLOCK_MONOTONIC , &ts_nat); + ret =clock_gettime (CLOCK_REALTIME , &ts_nat);if (ret)
return NULL;testsuite/smokey/y2038/syscall-tests.c +1
-0@@ -240,10 +267,12 @@ static int __mutex_timedlock64(pthread_mutex_t *lock) { int ret; pthread_t tid; +int sr_nc = sc_cobalt_mutex_timedlock64;testsuite/smokey/y2038/syscall-tests.c +4
-3- ret =pthread_mutex_lock (lock); -if (ret) -return -errno; +/* Timeout is never read by the kernel, so NULL should be OK */ + ret =XENOMAI_SYSCALL2 (sr_nc, lock,NULL ); +if (!smokey_assert (!ret)) +return ret ? ret : -EINVAL ;ret =
pthread_create(&tid, NULL, __mutex_timedlock64_thread, lock); if (ret)testsuite/smokey/y2038/syscall-tests.c +0
-0@@ -289,40 +318,9 @@ static int test_sc_cobalt_mutex_timedlock64(void) if (!smokey_assert(ret == -EINVAL)) return ret ? ret : -EINVAL;testsuite/smokey/y2038/syscall-tests.c +0
-31-/* Timeout is never read by the kernel, so NULL should be OK */ - ret =XENOMAI_SYSCALL2 (sr_nc, &lock,NULL ); -if (!smokey_assert (!ret)) -smokey_warning ("POSIX mutex_timedlock64 violation detected" ); - -/* -* The mutex is already exhausted, so calling again will validate -* the provided timeout now. Providing NULL has to deliver EFAULT -*/ - ret =XENOMAI_SYSCALL2 (sr_nc, &lock,NULL ); -if (!smokey_assert (ret == -EFAULT )) -return ret ? ret : -EINVAL ; - -/* -* The mutex is already exhausted, so calling again will validate -* the provided timeout now. Providing an invalid address has to deliver -* EFAULT -*/ - ret =XENOMAI_SYSCALL2 (sr_nc, &lock, (void *)0xdeadbeefUL ); -if (!smokey_assert (ret == -EFAULT )) -return ret ? ret : -EINVAL ; - -/* -* The mutex is still exhausted, calling again will validate the -* timeout, providing an invalid timeout has to deliver EINVAL -*/ - ts64.tv_sec =-1 ; - ret =XENOMAI_SYSCALL2 (sr_nc, &lock, &ts64); -if (!smokey_assert (ret == -EINVAL )) -return ret ? ret : -EINVAL ; -/*
testsuite/smokey/y2038/syscall-tests.c +2
-2-* Providing a valid timeout, waiting for it to time out and check -* that we didn't come back to early. +* mutex will be acquired in current thread, timeout will be +* validated in the other thread */
ret =__mutex_timedlock64(&lock);
if (ret)