diff options
author | Siddhesh Poyarekar <siddhesh@sourceware.org> | 2024-11-21 17:13:33 -0500 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@sourceware.org> | 2024-11-22 14:01:39 -0500 |
commit | 03b8d764109be48a53b18abd4b5050e8cdc2c6da (patch) | |
tree | a62650988d2c00e62943bfc537d292a53fd85b0e | |
parent | 99671e72bb27a3cb98860bdc4c0e25961ce96b3e (diff) | |
download | glibc-03b8d764109be48a53b18abd4b5050e8cdc2c6da.zip glibc-03b8d764109be48a53b18abd4b5050e8cdc2c6da.tar.gz glibc-03b8d764109be48a53b18abd4b5050e8cdc2c6da.tar.bz2 |
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>
-rw-r--r-- | nptl/Makefile | 1 | ||||
-rw-r--r-- | nptl/tst-pthread-getcpuclockid-invalid.c | 50 |
2 files changed, 51 insertions, 0 deletions
diff --git a/nptl/Makefile b/nptl/Makefile index ceb91af..88077e2 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -319,6 +319,7 @@ tests = \ tst-pthread-defaultattr-free \ tst-pthread-gdb-attach \ tst-pthread-gdb-attach-static \ + tst-pthread-getcpuclockid-invalid \ tst-pthread-key1-static \ tst-pthread-timedlock-lockloop \ 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 0000000..e88a563 --- /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> |