[LTP] [PATCH] open_posix: Update pthread_rwlock_rdlock 2nd assertion
Ricardo B. Marlière
rbm@suse.com
Tue May 20 20:10:54 CEST 2025
From: Ricardo B. Marlière <rbm@suse.com>
The pthread_rwlock_rdlock/2-*.c tests are broken because they rely on an
old version of the POSIX standard which says:
If the Thread Execution Scheduling option is supported, and the threads
involved in the lock are executing with the scheduling policies
SCHED_FIFO or SCHED_RR, the calling thread shall not acquire the lock if
a writer holds the lock or if writers of higher or equal priority are
blocked on the lock; otherwise, the calling thread shall acquire the
lock.
Whereas the new version says:
If the Thread Execution Scheduling option is supported, and the threads
that hold or are blocked on the lock are executing with the scheduling
policies SCHED_FIFO or SCHED_RR, the calling thread shall not acquire the
lock if a writer holds the lock or if the calling thread does not already
hold a read lock and writers of higher or equal priority are blocked on
the lock; otherwise, the calling thread shall acquire the lock.
This behaviour is not supported by default on GNU/Linux, so add a call to
Glibc pthread_rwlockattr_setkind_np() to set the correct lock kind as a
prerequisite to the 2-1.c and 2-2.c tests.
Link: https://austingroupbugs.net/view.php?id=1111
Link: https://sourceware.org/bugzilla/show_bug.cgi?id=13701
Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
.../interfaces/pthread_rwlock_rdlock/2-1.c | 21 ++++++++++++++-------
.../interfaces/pthread_rwlock_rdlock/2-2.c | 21 ++++++++++++++-------
.../interfaces/pthread_rwlock_rdlock/2-3.c | 13 +++++++------
.../interfaces/pthread_rwlock_rdlock/assertions.xml | 15 ++++++++-------
4 files changed, 43 insertions(+), 27 deletions(-)
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-1.c
index 288eb3e3566abf26100f999d02081b5ef02a6694..3b27a0bbbbdfaadf37fa94e129a937cdd9e986db 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-1.c
@@ -6,12 +6,13 @@
* Test that pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
*
- * If the Thread Execution Scheduling option is supported,
- * and the threads involved in the lock are executing with the
- * scheduling policies SCHED_FIFO or SCHED_RR, the calling thread shall not
- * acquire the lock if a writer holds the lock or if writers of
- * higher or equal priority are blocked on the lock;
- * otherwise, the calling thread shall acquire the lock.
+ * If the Thread Execution Scheduling option is supported,
+ * and the threads that hold or are blocked on the lock are
+ * executing with the scheduling policies SCHED_FIFO or SCHED_RR,
+ * the calling thread shall not acquire the lock if a writer
+ * holds the lock or if the calling thread does not already hold
+ * a read lock and writers of higher or equal priority are blocked
+ * on the lock; otherwise, the calling thread shall acquire the lock.
*
* In this case, we test "higher priority writer block"
*
@@ -143,13 +144,19 @@ int main(void)
int cnt = 0;
pthread_t rd_thread, wr_thread;
int priority;
+ pthread_rwlockattr_t attr;
+
+ pthread_rwlockattr_init(&attr);
+#ifdef __GNUC__
+ pthread_rwlockattr_setkind_np(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
+#endif
/* main thread needs to have the highest priority */
priority = sched_get_priority_min(TRD_POLICY) + 2;
set_priority(pthread_self(), TRD_POLICY, priority);
printf("main: has priority: %d\n", priority);
- if (pthread_rwlock_init(&rwlock, NULL) != 0) {
+ if (pthread_rwlock_init(&rwlock, &attr) != 0) {
printf("main: Error at pthread_rwlock_init()\n");
return PTS_UNRESOLVED;
}
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-2.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-2.c
index 3593e4c7966bef183bc5979e296beff512196d47..4799b1e885caab509fd31173c34ae89beace68e6 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-2.c
@@ -6,12 +6,13 @@
* Test that pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
*
- * If the Thread Execution Scheduling option is supported,
- * and the threads involved in the lock are executing with the
- * scheduling policies SCHED_FIFO or SCHED_RR, the calling thread shall not
- * acquire the lock if a writer holds the lock or if writers of
- * higher or equal priority are blocked on the lock;
- * otherwise, the calling thread shall acquire the lock.
+ * If the Thread Execution Scheduling option is supported,
+ * and the threads that hold or are blocked on the lock are
+ * executing with the scheduling policies SCHED_FIFO or SCHED_RR,
+ * the calling thread shall not acquire the lock if a writer
+ * holds the lock or if the calling thread does not already hold
+ * a read lock and writers of higher or equal priority are blocked
+ * on the lock; otherwise, the calling thread shall acquire the lock.
*
* In this case, we test "equal priority writer block"
*
@@ -143,12 +144,18 @@ int main(void)
int cnt = 0;
pthread_t rd_thread, wr_thread;
int priority;
+ pthread_rwlockattr_t attr;
+
+ pthread_rwlockattr_init(&attr);
+#ifdef __GNUC__
+ pthread_rwlockattr_setkind_np(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
+#endif
/* main thread needs to have the highest priority */
priority = sched_get_priority_min(TRD_POLICY) + 2;
set_priority(pthread_self(), TRD_POLICY, priority);
- if (pthread_rwlock_init(&rwlock, NULL) != 0) {
+ if (pthread_rwlock_init(&rwlock, &attr) != 0) {
printf("main: Error at pthread_rwlock_init()\n");
return PTS_UNRESOLVED;
}
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-3.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-3.c
index 40170dbb2d025ffda3693644c7d9aa4246f16bcf..aa1511bae3703efc92bc8569d7f4dc81f6219aa3 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-3.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-3.c
@@ -6,12 +6,13 @@
* Test that pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
*
- * If the Thread Execution Scheduling option is supported,
- * and the threads involved in the lock are executing with the
- * scheduling policies SCHED_FIFO or SCHED_RR, the calling thread shall not
- * acquire the lock if a writer holds the lock or if writers of
- * higher or equal priority are blocked on the lock;
- * otherwise, the calling thread shall acquire the lock.
+ * If the Thread Execution Scheduling option is supported,
+ * and the threads that hold or are blocked on the lock are
+ * executing with the scheduling policies SCHED_FIFO or SCHED_RR,
+ * the calling thread shall not acquire the lock if a writer
+ * holds the lock or if the calling thread does not already hold
+ * a read lock and writers of higher or equal priority are blocked
+ * on the lock; otherwise, the calling thread shall acquire the lock.
*
* In this case, reader has higher priority than the writer
*
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/assertions.xml b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/assertions.xml
index 07263b3dedde488196037e7140fcaa367cc49f5c..deb318cb786a5299c20b846eabfbad1111cb24ed 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/assertions.xml
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/assertions.xml
@@ -6,13 +6,14 @@
no writers blocked on the lock.
</assertion>
- <assertion id="2" tag="ref:XSH6:34768:34771">
- If the Thread Execution Scheduling option is supported,
- and the threads involved in the lock are executing with the
- scheduling policies SCHED_FIFO or SCHED_RR, the calling thread shall not
- acquire the lock if a writer holds the lock or if writers of
- higher or equal priority are blocked on the lock;
- otherwise, the calling thread shall acquire the lock.
+ <assertion id="2" tag="ref:XSH8:{System Interfaces:pthread_rwlock_rdlock:DESCRIPTION}">
+ If the Thread Execution Scheduling option is supported,
+ and the threads that hold or are blocked on the lock are
+ executing with the scheduling policies SCHED_FIFO or SCHED_RR,
+ the calling thread shall not acquire the lock if a writer
+ holds the lock or if the calling thread does not already hold
+ a read lock and writers of higher or equal priority are blocked
+ on the lock; otherwise, the calling thread shall acquire the lock.
</assertion>
<assertion id="3" tag="ref:XSH6:34772:34775">
---
base-commit: c9e5b1e50889adec8c2bb38ea5fd69cd48edb8b7
change-id: 20250520-fixes-pthread_rwlock_rdlock-b2b8e427160a
Best regards,
--
Ricardo B. Marlière <rbm@suse.com>
More information about the ltp
mailing list