glibc/glibc-RHEL-70395-1.patch
Frédéric Bérat 13a2c1bb05 Backport pthread_getcpuclockid tests
Resolves: RHEL-70395
2025-01-09 13:33:09 +01:00

86 lines
2.5 KiB
Diff

commit 03b8d764109be48a53b18abd4b5050e8cdc2c6da
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
Date: Thu Nov 21 17:13:33 2024 -0500
nptl: Add smoke test for pthread_getcpuclockid failure
Exercise the case where an exited thread will cause
pthread_getcpuclockid to fail.
Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
Conflicts:
nptl/Makefile (new test added)
diff --git a/nptl/Makefile b/nptl/Makefile
index 9a56d34313d06444..f89bb07747cf5522 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -306,7 +306,8 @@ tests = tst-attr2 tst-attr3 tst-default-attr \
tst-pthread-gdb-attach tst-pthread-gdb-attach-static \
tst-pthread_exit-nothreads \
tst-pthread_exit-nothreads-static \
- tst-thread-setspecific
+ tst-thread-setspecific \
+ tst-pthread-getcpuclockid-invalid \
tests-nolibpthread = \
tst-pthread_exit-nothreads \
diff --git a/nptl/tst-pthread-getcpuclockid-invalid.c b/nptl/tst-pthread-getcpuclockid-invalid.c
new file mode 100644
index 0000000000000000..e88a56342767a83e
--- /dev/null
+++ b/nptl/tst-pthread-getcpuclockid-invalid.c
@@ -0,0 +1,50 @@
+/* Smoke test to verify that pthread_getcpuclockid fails with ESRCH when the
+ thread in question has exited.
+ Copyright the GNU Toolchain Authors.
+ 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 <pthread.h>
+#include <sched.h>
+#include <time.h>
+
+#include <support/check.h>
+#include <support/test-driver.h>
+#include <support/xthread.h>
+
+void *
+thr (void *in)
+{
+ return in;
+}
+
+int
+do_test (void)
+{
+ clockid_t c;
+ pthread_t t = xpthread_create (NULL, thr, NULL);
+
+ int ret = 0;
+ while ((ret = pthread_getcpuclockid (t, &c)) == 0)
+ sched_yield ();
+
+ TEST_COMPARE (ret, ESRCH);
+
+ return 0;
+}
+
+#include <support/test-driver.c>