From d45f069002f211398fd7790509fbd25ec6d1c713 Mon Sep 17 00:00:00 2001 From: Xiaoqiang Zhao Date: Sat, 10 Oct 2026 10:39:44 -0700 Subject: [PATCH] tests/libc: use an allowlist for sbrk in NetBSD-derived tests sbrk is obsolete and libc only provides it on amd64, arm, i386 and powerpc. Replace the growing exclusion lists in t_dir.c and t_mlock.c with a single positive HAVE_SBRK definition per file, so architectures without sbrk need not be enumerated as they are added. Signed-off-by: Xiaoqiang Zhao Reviewed by: ngie Differential Revision: https://reviews.freebsd.org/D60358 --- contrib/netbsd-tests/lib/libc/gen/t_dir.c | 14 ++++++++++---- contrib/netbsd-tests/lib/libc/sys/t_mlock.c | 14 +++++++++++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/contrib/netbsd-tests/lib/libc/gen/t_dir.c b/contrib/netbsd-tests/lib/libc/gen/t_dir.c index 53d1fce26e2d..49800bfb3f34 100644 --- a/contrib/netbsd-tests/lib/libc/gen/t_dir.c +++ b/contrib/netbsd-tests/lib/libc/gen/t_dir.c @@ -38,7 +38,14 @@ #include #include - +/* + * sbrk is obsolete, and libc only provides it on a subset of + * architectures. + */ +#if defined(__amd64__) || defined(__arm__) || defined(__i386__) || \ + defined(__powerpc__) +#define HAVE_SBRK +#endif ATF_TC(seekdir_basic); ATF_TC_HEAD(seekdir_basic, tc) @@ -134,8 +141,7 @@ ATF_TC_BODY(seekdir_basic, tc) free(wasname); } -/* There is no sbrk on AArch64 and RISC-V */ -#if !defined(__aarch64__) && !defined(__riscv) +#ifdef HAVE_SBRK ATF_TC(telldir_leak); ATF_TC_HEAD(telldir_leak, tc) { @@ -185,7 +191,7 @@ ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, seekdir_basic); -#if !defined(__aarch64__) && !defined(__riscv) +#ifdef HAVE_SBRK ATF_TP_ADD_TC(tp, telldir_leak); #endif diff --git a/contrib/netbsd-tests/lib/libc/sys/t_mlock.c b/contrib/netbsd-tests/lib/libc/sys/t_mlock.c index d9ffbe366a04..b081c60bbecc 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_mlock.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_mlock.c @@ -46,6 +46,15 @@ __RCSID("$NetBSD: t_mlock.c,v 1.6 2016/08/09 12:02:44 kre Exp $"); #include #include +/* + * sbrk is obsolete, and libc only provides it on a subset of + * architectures. + */ +#if defined(__amd64__) || defined(__arm__) || defined(__i386__) || \ + defined(__powerpc__) +#define HAVE_SBRK +#endif + #ifdef __FreeBSD__ #include #define _KMEMUSER @@ -103,7 +112,7 @@ ATF_TC_BODY(mlock_err, tc) unsigned long vmin = 0; size_t len = sizeof(vmin); #endif -#if !defined(__aarch64__) && !defined(__riscv) +#ifdef HAVE_SBRK void *invalid_ptr; #endif void *buf; @@ -159,8 +168,7 @@ ATF_TC_BODY(mlock_err, tc) #endif (void)free(buf); -/* There is no sbrk on AArch64 and RISC-V */ -#if !defined(__aarch64__) && !defined(__riscv) +#ifdef HAVE_SBRK /* * Try to create a pointer to an unmapped page - first after current * brk will likely do.