aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/pthread
diff options
context:
space:
mode:
authorJoseph Myers <josmyers@redhat.com>2024-10-23 16:45:15 +0000
committerJoseph Myers <josmyers@redhat.com>2024-10-23 16:45:15 +0000
commitc5dd659f22058bf9b371ab1cba07631f1206c674 (patch)
tree654287e9df1f314289e2a66b9d1975d321c73e4e /sysdeps/pthread
parent9f0d2c0ee6c728643fcf9a4879e9f20f5e45ce5f (diff)
downloadglibc-c5dd659f22058bf9b371ab1cba07631f1206c674.zip
glibc-c5dd659f22058bf9b371ab1cba07631f1206c674.tar.gz
glibc-c5dd659f22058bf9b371ab1cba07631f1206c674.tar.bz2
Add more tests of pthread_mutexattr_gettype and pthread_mutexattr_settype
Add basic tests of pthread_mutexattr_gettype and pthread_mutexattr_settype with each valid mutex kind, plus test for EINVAL with an invalid mutex kind. Tested for x86_64.
Diffstat (limited to 'sysdeps/pthread')
-rw-r--r--sysdeps/pthread/Makefile1
-rw-r--r--sysdeps/pthread/tst-pthread-mutexattr-2.c60
2 files changed, 61 insertions, 0 deletions
diff --git a/sysdeps/pthread/Makefile b/sysdeps/pthread/Makefile
index 939438f..4c1dc04 100644
--- a/sysdeps/pthread/Makefile
+++ b/sysdeps/pthread/Makefile
@@ -216,6 +216,7 @@ tests += \
tst-pt-vfork2 \
tst-pthread-exit-signal \
tst-pthread-mutexattr \
+ tst-pthread-mutexattr-2 \
tst-pthread-raise-blocked-self \
tst-pthread-setuid-loop \
tst-pthread_cancel-exited \
diff --git a/sysdeps/pthread/tst-pthread-mutexattr-2.c b/sysdeps/pthread/tst-pthread-mutexattr-2.c
new file mode 100644
index 0000000..ec92e55
--- /dev/null
+++ b/sysdeps/pthread/tst-pthread-mutexattr-2.c
@@ -0,0 +1,60 @@
+/* Test pthread_mutexattr_gettype and pthread_mutexattr_settype with
+ valid and invalid kinds.
+
+ Copyright (C) 2024 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stdio.h>
+#include <pthread.h>
+
+#include <support/check.h>
+#include <support/xthread.h>
+
+
+static void
+do_test_kind (int test_kind, const char *name)
+{
+ printf ("testing %s\n", name);
+ pthread_mutexattr_t attr;
+ xpthread_mutexattr_init (&attr);
+ int ret = pthread_mutexattr_settype (&attr, test_kind);
+ TEST_COMPARE (ret, 0);
+ int kind = 123456789;
+ ret = pthread_mutexattr_gettype (&attr, &kind);
+ TEST_COMPARE (ret, 0);
+ TEST_COMPARE (kind, test_kind);
+}
+
+int
+do_test (void)
+{
+ do_test_kind (PTHREAD_MUTEX_NORMAL, "PTHREAD_MUTEX_NORMAL");
+ do_test_kind (PTHREAD_MUTEX_ERRORCHECK, "PTHREAD_MUTEX_ERRORCHECK");
+ do_test_kind (PTHREAD_MUTEX_RECURSIVE, "PTHREAD_MUTEX_RECURSIVE");
+ do_test_kind (PTHREAD_MUTEX_DEFAULT, "PTHREAD_MUTEX_DEFAULT");
+
+ /* Also test an invalid kind. */
+ pthread_mutexattr_t attr;
+ xpthread_mutexattr_init (&attr);
+ int ret = pthread_mutexattr_settype (&attr, 123456789);
+ TEST_COMPARE (ret, EINVAL);
+
+ return 0;
+}
+
+#include <support/test-driver.c>