Message ID | 20241122135453.1274876-1-siddhesh@sourceware.org |
---|---|
State | New |
Headers | show |
Series | [v3] nptl: Add smoke test for pthread_getcpuclockid failure | expand |
* Siddhesh Poyarekar: > Exercise the invalid thread descriptor case to ensure full test > coverage for the function. Commit message should say exited thread, not invalid thread descriptor, I think. > +int > +do_test (void) > +{ > + clockid_t c; > + pthread_t t = xpthread_create (NULL, thr, NULL); > + > + while (pthread_getcpuclockid (t, &c) != ESRCH); > + > + return 0; > +} Please loop until the return value is non zero and then check the error code against ESRCH with TEST_COMPARE. And join the thread afterwards using xpthread_join. Thanks, Florian
* Florian Weimer: > * Siddhesh Poyarekar: > >> Exercise the invalid thread descriptor case to ensure full test >> coverage for the function. > > Commit message should say exited thread, not invalid thread descriptor, > I think. > >> +int >> +do_test (void) >> +{ >> + clockid_t c; >> + pthread_t t = xpthread_create (NULL, thr, NULL); >> + >> + while (pthread_getcpuclockid (t, &c) != ESRCH); >> + >> + return 0; >> +} > > Please loop until the return value is non zero and then check the error > code against ESRCH with TEST_COMPARE. And join the thread afterwards > using xpthread_join. … and maybe use sched_yield in the loop. Florian
On 2024-11-22 10:14, Florian Weimer wrote: > * Florian Weimer: > >> * Siddhesh Poyarekar: >> >>> Exercise the invalid thread descriptor case to ensure full test >>> coverage for the function. >> >> Commit message should say exited thread, not invalid thread descriptor, >> I think. >> >>> +int >>> +do_test (void) >>> +{ >>> + clockid_t c; >>> + pthread_t t = xpthread_create (NULL, thr, NULL); >>> + >>> + while (pthread_getcpuclockid (t, &c) != ESRCH); >>> + >>> + return 0; >>> +} >> >> Please loop until the return value is non zero and then check the error >> code against ESRCH with TEST_COMPARE. And join the thread afterwards >> using xpthread_join. > > … and maybe use sched_yield in the loop. Thanks, done, sent v4 with all changes suggested. Sid
diff --git a/nptl/Makefile b/nptl/Makefile index ceb91afafc..88077e27bb 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 0000000000..deb6042696 --- /dev/null +++ b/nptl/tst-pthread-getcpuclockid-invalid.c @@ -0,0 +1,46 @@ +/* Smoke test to verify that pthread_getcpuclockid fails with invalid thread + IDs. + 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 <assert.h> +#include <errno.h> +#include <pthread.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); + + while (pthread_getcpuclockid (t, &c) != ESRCH); + + return 0; +} + +#include <support/test-driver.c>
Exercise the invalid thread descriptor case to ensure full test coverage for the function. Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org> --- Change from v2: - Drop pthread_join to avoid invalidating the thread descriptor itself. nptl/Makefile | 1 + nptl/tst-pthread-getcpuclockid-invalid.c | 46 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 nptl/tst-pthread-getcpuclockid-invalid.c