public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* Add more tests of pthread attributes initial values
@ 2024-10-16 21:58 Joseph Myers
  2024-10-25 16:14 ` Ping " Joseph Myers
  2024-10-29 11:17 ` Florian Weimer
  0 siblings, 2 replies; 5+ messages in thread
From: Joseph Myers @ 2024-10-16 21:58 UTC (permalink / raw)
  To: libc-alpha

There are various existing tests that call pthread_attr_init and then
verify properties of the resulting initial values retrieved with
pthread_attr_get* functions.  However, those are missing coverage of
the initial values retrieved with pthread_attr_getschedparam and
pthread_attr_getstacksize.  Add testing for initial values from those
functions as well.

(tst-attr2 covers pthread_attr_getdetachstate,
pthread_attr_getguardsize, pthread_attr_getinheritsched,
pthread_attr_getschedpolicy, pthread_attr_getscope.  tst-attr3 covers
some of those together with pthread_attr_getaffinity_np.
tst-pthread-attr-sigmask covers pthread_attr_getsigmask_np.
pthread_attr_getstack has unspecified results if called before the
relevant attributes have been set, while pthread_attr_getstackaddr is
deprecated.)

Tested for x86_64.

diff --git a/nptl/Makefile b/nptl/Makefile
index bf4c29b6ed..ceb91afafc 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -276,6 +276,7 @@ LDLIBS-tst-minstack-throw = -lstdc++
 tests = \
   tst-attr2 \
   tst-attr3 \
+  tst-attr4 \
   tst-cancel4_1 \
   tst-cancel4_2 \
   tst-cancel7 \
diff --git a/nptl/tst-attr4.c b/nptl/tst-attr4.c
new file mode 100644
index 0000000000..9ee8821d8c
--- /dev/null
+++ b/nptl/tst-attr4.c
@@ -0,0 +1,60 @@
+/* Test initial values of pthread attributes.
+   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 <sched.h>
+#include <stdio.h>
+#include <stdint.h>
+
+#include <support/check.h>
+#include <support/test-driver.h>
+#include <support/xthread.h>
+
+
+int
+do_test (void)
+{
+  pthread_attr_t a;
+  int ret;
+
+  xpthread_attr_init (&a);
+
+  size_t stacksize = 0;
+  verbose_printf ("testing default stack size\n");
+  ret = pthread_attr_getstacksize (&a, &stacksize);
+  TEST_VERIFY_EXIT (ret == 0);
+  TEST_VERIFY (stacksize >= PTHREAD_STACK_MIN);
+  TEST_VERIFY (stacksize <= SIZE_MAX / 2);
+
+  int policy;
+  verbose_printf ("testing default scheduler parameters\n");
+  ret = pthread_attr_getschedpolicy (&a, &policy);
+  TEST_VERIFY_EXIT (ret == 0);
+  struct sched_param param;
+  ret = pthread_attr_getschedparam (&a, &param);
+  TEST_VERIFY_EXIT (ret == 0);
+  int min = sched_get_priority_min (policy);
+  TEST_VERIFY (min != -1);
+  int max = sched_get_priority_max (policy);
+  TEST_VERIFY (max != -1);
+  TEST_VERIFY (param.sched_priority >= min);
+  TEST_VERIFY (param.sched_priority <= max);
+
+  return 0;
+}
+
+#include <support/test-driver.c>

-- 
Joseph S. Myers
josmyers@redhat.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Ping Re: Add more tests of pthread attributes initial values
  2024-10-16 21:58 Add more tests of pthread attributes initial values Joseph Myers
@ 2024-10-25 16:14 ` Joseph Myers
  2024-10-29 11:17 ` Florian Weimer
  1 sibling, 0 replies; 5+ messages in thread
From: Joseph Myers @ 2024-10-25 16:14 UTC (permalink / raw)
  To: libc-alpha

Ping.  This patch 
<https://sourceware.org/pipermail/libc-alpha/2024-October/160635.html> is 
pending review.

-- 
Joseph S. Myers
josmyers@redhat.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Add more tests of pthread attributes initial values
  2024-10-16 21:58 Add more tests of pthread attributes initial values Joseph Myers
  2024-10-25 16:14 ` Ping " Joseph Myers
@ 2024-10-29 11:17 ` Florian Weimer
  2024-10-29 17:08   ` [PATCH v2] " Joseph Myers
  1 sibling, 1 reply; 5+ messages in thread
From: Florian Weimer @ 2024-10-29 11:17 UTC (permalink / raw)
  To: Joseph Myers; +Cc: libc-alpha

* Joseph Myers:

> There are various existing tests that call pthread_attr_init and then
> verify properties of the resulting initial values retrieved with
> pthread_attr_get* functions.  However, those are missing coverage of
> the initial values retrieved with pthread_attr_getschedparam and
> pthread_attr_getstacksize.  Add testing for initial values from those
> functions as well.
>
> (tst-attr2 covers pthread_attr_getdetachstate,
> pthread_attr_getguardsize, pthread_attr_getinheritsched,
> pthread_attr_getschedpolicy, pthread_attr_getscope.  tst-attr3 covers
> some of those together with pthread_attr_getaffinity_np.
> tst-pthread-attr-sigmask covers pthread_attr_getsigmask_np.
> pthread_attr_getstack has unspecified results if called before the
> relevant attributes have been set, while pthread_attr_getstackaddr is
> deprecated.)
>
> Tested for x86_64.

Missing xpthread_attr_destroy.  Rest looks good.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] Add more tests of pthread attributes initial values
  2024-10-29 11:17 ` Florian Weimer
@ 2024-10-29 17:08   ` Joseph Myers
  2024-10-29 17:31     ` Florian Weimer
  0 siblings, 1 reply; 5+ messages in thread
From: Joseph Myers @ 2024-10-29 17:08 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha

On Tue, 29 Oct 2024, Florian Weimer wrote:

> * Joseph Myers:
> 
> > There are various existing tests that call pthread_attr_init and then
> > verify properties of the resulting initial values retrieved with
> > pthread_attr_get* functions.  However, those are missing coverage of
> > the initial values retrieved with pthread_attr_getschedparam and
> > pthread_attr_getstacksize.  Add testing for initial values from those
> > functions as well.
> >
> > (tst-attr2 covers pthread_attr_getdetachstate,
> > pthread_attr_getguardsize, pthread_attr_getinheritsched,
> > pthread_attr_getschedpolicy, pthread_attr_getscope.  tst-attr3 covers
> > some of those together with pthread_attr_getaffinity_np.
> > tst-pthread-attr-sigmask covers pthread_attr_getsigmask_np.
> > pthread_attr_getstack has unspecified results if called before the
> > relevant attributes have been set, while pthread_attr_getstackaddr is
> > deprecated.)
> >
> > Tested for x86_64.
> 
> Missing xpthread_attr_destroy.  Rest looks good.

Added in this version.


Add more tests of pthread attributes initial values

There are various existing tests that call pthread_attr_init and then
verify properties of the resulting initial values retrieved with
pthread_attr_get* functions.  However, those are missing coverage of
the initial values retrieved with pthread_attr_getschedparam and
pthread_attr_getstacksize.  Add testing for initial values from those
functions as well.

(tst-attr2 covers pthread_attr_getdetachstate,
pthread_attr_getguardsize, pthread_attr_getinheritsched,
pthread_attr_getschedpolicy, pthread_attr_getscope.  tst-attr3 covers
some of those together with pthread_attr_getaffinity_np.
tst-pthread-attr-sigmask covers pthread_attr_getsigmask_np.
pthread_attr_getstack has unspecified results if called before the
relevant attributes have been set, while pthread_attr_getstackaddr is
deprecated.)

Tested for x86_64.

---

Change in v2: call xpthread_attr_destroy at end.

diff --git a/nptl/Makefile b/nptl/Makefile
index bf4c29b6ed..ceb91afafc 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -276,6 +276,7 @@ LDLIBS-tst-minstack-throw = -lstdc++
 tests = \
   tst-attr2 \
   tst-attr3 \
+  tst-attr4 \
   tst-cancel4_1 \
   tst-cancel4_2 \
   tst-cancel7 \
diff --git a/nptl/tst-attr4.c b/nptl/tst-attr4.c
new file mode 100644
index 0000000000..c53781e7f3
--- /dev/null
+++ b/nptl/tst-attr4.c
@@ -0,0 +1,62 @@
+/* Test initial values of pthread attributes.
+   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 <sched.h>
+#include <stdio.h>
+#include <stdint.h>
+
+#include <support/check.h>
+#include <support/test-driver.h>
+#include <support/xthread.h>
+
+
+int
+do_test (void)
+{
+  pthread_attr_t a;
+  int ret;
+
+  xpthread_attr_init (&a);
+
+  size_t stacksize = 0;
+  verbose_printf ("testing default stack size\n");
+  ret = pthread_attr_getstacksize (&a, &stacksize);
+  TEST_VERIFY_EXIT (ret == 0);
+  TEST_VERIFY (stacksize >= PTHREAD_STACK_MIN);
+  TEST_VERIFY (stacksize <= SIZE_MAX / 2);
+
+  int policy;
+  verbose_printf ("testing default scheduler parameters\n");
+  ret = pthread_attr_getschedpolicy (&a, &policy);
+  TEST_VERIFY_EXIT (ret == 0);
+  struct sched_param param;
+  ret = pthread_attr_getschedparam (&a, &param);
+  TEST_VERIFY_EXIT (ret == 0);
+  int min = sched_get_priority_min (policy);
+  TEST_VERIFY (min != -1);
+  int max = sched_get_priority_max (policy);
+  TEST_VERIFY (max != -1);
+  TEST_VERIFY (param.sched_priority >= min);
+  TEST_VERIFY (param.sched_priority <= max);
+
+  xpthread_attr_destroy (&a);
+
+  return 0;
+}
+
+#include <support/test-driver.c>

-- 
Joseph S. Myers
josmyers@redhat.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] Add more tests of pthread attributes initial values
  2024-10-29 17:08   ` [PATCH v2] " Joseph Myers
@ 2024-10-29 17:31     ` Florian Weimer
  0 siblings, 0 replies; 5+ messages in thread
From: Florian Weimer @ 2024-10-29 17:31 UTC (permalink / raw)
  To: Joseph Myers; +Cc: libc-alpha

* Joseph Myers:

> Add more tests of pthread attributes initial values
>
> There are various existing tests that call pthread_attr_init and then
> verify properties of the resulting initial values retrieved with
> pthread_attr_get* functions.  However, those are missing coverage of
> the initial values retrieved with pthread_attr_getschedparam and
> pthread_attr_getstacksize.  Add testing for initial values from those
> functions as well.
>
> (tst-attr2 covers pthread_attr_getdetachstate,
> pthread_attr_getguardsize, pthread_attr_getinheritsched,
> pthread_attr_getschedpolicy, pthread_attr_getscope.  tst-attr3 covers
> some of those together with pthread_attr_getaffinity_np.
> tst-pthread-attr-sigmask covers pthread_attr_getsigmask_np.
> pthread_attr_getstack has unspecified results if called before the
> relevant attributes have been set, while pthread_attr_getstackaddr is
> deprecated.)
>
> Tested for x86_64.

This version looks okay to me.

Reviewed-by: Florian Weimer <fweimer@redhat.com>

Thanks,
Florian


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-10-29 17:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-16 21:58 Add more tests of pthread attributes initial values Joseph Myers
2024-10-25 16:14 ` Ping " Joseph Myers
2024-10-29 11:17 ` Florian Weimer
2024-10-29 17:08   ` [PATCH v2] " Joseph Myers
2024-10-29 17:31     ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).