git: e40785bcb232 - main - libthr: Enable the thread name test
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 22 Nov 2026 19:23:23 UTC
The branch main has been updated by ngie:
URL: https://cgit.FreeBSD.org/src/commit/?id=e40785bcb23241d1de7759df781b260b0385e640
commit e40785bcb23241d1de7759df781b260b0385e640
Author: Pavel Grakhov <altogetherx@gmail.com>
AuthorDate: 2026-11-22 19:22:57 +0000
Commit: Enji Cooper <ngie@FreeBSD.org>
CommitDate: 2026-11-22 19:23:07 +0000
libthr: Enable the thread name test
Adapt NetBSD's thread naming tests to run it on FreeBSD.
Account for differences in `pthread_setname_np()` and the absence
of thread naming attributes on FreeBSD.
MFC after: 1 week
Reviewed by: ngie, kib
Differential Revision: https://reviews.freebsd.org/D61609
---
contrib/netbsd-tests/lib/libpthread/t_name.c | 31 ++++++++++++++++++++++++++++
lib/libthr/tests/Makefile | 2 +-
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/contrib/netbsd-tests/lib/libpthread/t_name.c b/contrib/netbsd-tests/lib/libpthread/t_name.c
index d17895efe70e..cfbf35a12051 100644
--- a/contrib/netbsd-tests/lib/libpthread/t_name.c
+++ b/contrib/netbsd-tests/lib/libpthread/t_name.c
@@ -54,10 +54,29 @@ threadfunc(void *arg)
pthread_t self = pthread_self();
char retname[32];
+#ifdef __FreeBSD__
+ /* Check initial name is empty on the created thread */
+ (void)strcpy(retname, "foo");
PTHREAD_REQUIRE(pthread_getname_np(self, retname, sizeof(retname)));
+ ATF_REQUIRE_EQ(retname[0], '\0');
+
+ /*
+ * FreeBSD sets the name explicitly after the thread is created,
+ * whereas NetBSD supplies the initial name through the thread
+ * attributes.
+ */
+ PTHREAD_REQUIRE(pthread_setname_np(self, NAME_JUST_RIGHT));
+ PTHREAD_REQUIRE(pthread_getname_np(self, retname, sizeof(retname)));
+#else
+ PTHREAD_REQUIRE(pthread_getname_np(self, retname, sizeof(retname)));
+#endif
ATF_REQUIRE_STREQ(retname, NAME_JUST_RIGHT);
+#ifdef __FreeBSD__
+ PTHREAD_REQUIRE(pthread_setname_np(self, non_const_name));
+#else
PTHREAD_REQUIRE(pthread_setname_np(self, non_const_name, NULL));
+#endif
(void) memset(non_const_name, 0, sizeof(non_const_name));
PTHREAD_REQUIRE(pthread_getname_np(self, retname, sizeof(retname)));
ATF_REQUIRE_STREQ(retname, CONST_NAME);
@@ -68,8 +87,13 @@ threadfunc(void *arg)
ATF_TC(name);
ATF_TC_HEAD(name, tc)
{
+#ifdef __FreeBSD__
+ atf_tc_set_md_var(tc, "descr",
+ "Checks pthread_{get,set}name_np() API");
+#else
atf_tc_set_md_var(tc, "descr",
"Checks pthread_{,attr}_{get,set}name_np() API");
+#endif
}
ATF_TC_BODY(name, tc)
{
@@ -78,12 +102,19 @@ ATF_TC_BODY(name, tc)
char retname[32];
PTHREAD_REQUIRE(pthread_attr_init(&attr));
+#ifdef __NetBSD__
PTHREAD_REQUIRE(pthread_attr_getname_np(&attr, retname,
sizeof(retname), NULL));
ATF_REQUIRE_EQ(retname[0], '\0');
+ /*
+ * NetBSD rejects 32-character names in thread attributes.
+ * FreeBSD's pthread_setname_np() does not impose a fixed name length
+ * limit, so this length boundary check is specific to NetBSD.
+ */
ATF_REQUIRE_EQ(pthread_attr_setname_np(&attr, NAME_TOO_LONG, NULL), EINVAL);
PTHREAD_REQUIRE(pthread_attr_setname_np(&attr, "%s",
__UNCONST(NAME_JUST_RIGHT)));
+#endif
(void) strcpy(retname, "foo");
PTHREAD_REQUIRE(pthread_getname_np(self, retname, sizeof(retname)));
diff --git a/lib/libthr/tests/Makefile b/lib/libthr/tests/Makefile
index 286d46feac45..ba8cbb8f2ab1 100644
--- a/lib/libthr/tests/Makefile
+++ b/lib/libthr/tests/Makefile
@@ -4,7 +4,6 @@ WARNS?= 3
TESTSRC= ${SRCTOP}/contrib/netbsd-tests/lib/libpthread
-# TODO: t_name (missing pthread_getname_np support in FreeBSD)
NETBSD_ATF_TESTS_C= barrier_test
NETBSD_ATF_TESTS_C+= cond_test
NETBSD_ATF_TESTS_C+= condwait_test
@@ -15,6 +14,7 @@ NETBSD_ATF_TESTS_C+= fpu_test
NETBSD_ATF_TESTS_C+= join_test
NETBSD_ATF_TESTS_C+= kill_test
NETBSD_ATF_TESTS_C+= mutex_test
+NETBSD_ATF_TESTS_C+= name_test
NETBSD_ATF_TESTS_C+= once_test
NETBSD_ATF_TESTS_C+= preempt_test
NETBSD_ATF_TESTS_C+= rwlock_test