473 Commits
Author SHA1 Message Date
Xiaoqiang Zhao d45f069002 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 <[email protected]>
Reviewed by:	ngie
Differential Revision:	https://reviews.freebsd.org/D60358
2026-10-10 10:43:46 -07:00
Enji Cooper e8431fae65 Revert "tests/libc: use an allowlist for sbrk in NetBSD-derived tests"
Need to update the commit message.

This reverts commit 36b849b5c7.
2026-10-10 10:43:00 -07:00
Xiaoqiang Zhao 36b849b5c7 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 HAS_SBRK definition per file, so architectures
without sbrk need not be enumerated as they are added.

Signed-off-by: Xiaoqiang Zhao <[email protected]>
Reviewed by:	ngie
Differential Revision:	https://reviews.freebsd.org/D60358
2026-10-10 10:41:27 -07:00
Olivier Cochard 9af3990ba7 sem test: avoid ETIMEDOUT races in the EINTR test cases
timedwait and clockwait_absolute_intr_remaining arm a 50ms SIGALRM and then
wait until an absolute deadline only 100ms in the future.
On a loaded VM the signal can be delivered more than 50ms late, so the wait
times out first.

Approved by:	imp
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D60347
2026-10-07 02:03:27 +02:00
Enji Cooper 9d5a33d9c2 [tests] lib/libc/gen:assert_test: undefine NDEBUG
In the event `NDEBUG` was defined, `assert` would become a no-op,
breaking some of the expectations in `assert_test` around `assert(..)`
failing generating a coredump.

This is a better approach than the previous one committed in 6f3445006a
as it continues to test the `assert(..)` function instead of just
skipping it if `NDEBUG` was defined.

Suggested by:	kevans
MFC after:	4 days
MFC with:	6f3445006a
Fixes:		6f3445006a
Differential Revision: https://reviews.freebsd.org/D60253
2026-10-02 13:42:53 -07:00
Enji Cooper 6f3445006a [tests] lib/libc/gen:assert_test: skip tests when NDEBUG set
In the event that NDEBUG is specified in CFLAGS--which is most likely
triggered via `MK_ASSERT_DEBUG` == "no" -- all assert(3) statements are
optimized out by design. This breaks the assert(3) tests as they
specifically rely on assert(3) actually raising a `SIGABRT` instead of
quietly succeeding.

Skip both tests if `NDEBUG` is set. There's no sense running the
`assert(true)` test if the result could instead be a false positive.

MFC after:	2 weeks
2026-09-21 23:30:30 -07:00
Warner Losh a259b98fa2 tests: skip gracefully when the tested binary's own package isn't installed
pkgbase splits programs and their tests into separate packages (e.g.
unifdef/yacc/indent/file2c -> toolchain, jail -> jail, etc), while their
tests always land in the generic tests package.  Installing just the
tests package therefore leaves these suites unable to find the binary
they exercise, and they fail confusingly instead of skipping.

Rather than force all packages to be installed for the tests package,
make the tests cope with the missing packages.  Add require.progs (or,
for TAP/PLAIN-style suites with no atf_set hook: TEST_METADATA
required_programs) for the binary under test in: bectl, certctl,
ctfconvert, dhclient, file2c, indent, ipfw, jail, lastcomm, mixer,
newsyslog, nvmecontrol, pfctl, praudit, sa, syslogd, tunefs, unifdef,
yacc, ztest.

I skipped adding data for all the binaries in the base runtime
package for simplicity.

Assisted-by:		Claude Code (Sonnet 5)
Sponsored by:		Netflix
Reviewed by:		ngie
Differential Revision:	https://reviews.freebsd.org/D58262
2026-09-10 23:42:25 -06:00
Enji Cooper 8109a5c0fb contrib/netbsd-tests: lib/libc/c063: sync with NetBSD
This change syncs the lib/libc/c063 NetBSD tests with FreeBSD. This does
two things:
- Addresses bogus tautologically true assertions flagged by clang and gcc
  with ATF 0.22+ [1].
- Brings in some new test coverage.

Obtained from:	NetBSD (date tag: `20260818UTC`)
MFC after:	2 weeks
1. https://github.com/freebsd/atf/pull/72
2026-08-19 01:10:20 -07:00
Konstantin Belousov 10ea2300bf tests/libpthread: add pthread_cond_clockwait(3) tests
Reviewed by:	markj, ngie
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58458
2026-07-27 19:17:29 +03:00
Mark Johnston 150df709c2 iconv: Fix a stack buffer overflow in _ISO2022_sputwchar()
In the ISO2022-CN encoding, characters may require at least seven bytes,
and MB_LEN_MAX==6 is insufficient.  From code inspection,
_ISO2022_sputwchar() can emit 10 bytes in the worst case, so use that to
size buffers.

Add a regression test.

Approved by:	so
Security:	FreeBSD-SA-26:49.iconv
Security:	CVE-2026-58082
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D57950
2026-06-30 17:00:23 +00:00
Taylor R Campbell 2ee2274244 iconv(3): Draft some automatic tests.
Based on a report by Nick Wellnhofer.

Approved by:	so
Security:	FreeBSD-SA-26:49.iconv
Reviewed by:	markj, kevans
Differential Revision:	https://reviews.freebsd.org/D57948
2026-06-30 17:00:23 +00:00
Mark Johnston e3b8e55e71 netbsd-tests: Fix the mmap_truncate_signal test
Add a volatile qualifier in the loop which triggers SIGBUS, as otherwise
the compiler is smart enough to elide it, replacing it with a check for
page != 0.

MFC after:	1 week
2026-04-26 01:56:14 +00:00
Konstantin Belousov e56858f05f posix_spawn test: switch to POSIX spelling for addchdir and addfchdir
Reviewed by:	dim
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D56222
2026-04-03 11:22:53 +03:00
Enji Cooper 35237ff987 t_access.c: remove unnecessary local modification
FreeBSD 11.x is no longer supported; there's no reason why the
`FreeBSD_version__` check is still required (now).

MFC after:	1 week
2026-02-15 11:40:00 -08:00
Enji Cooper 411a566d56 t_create.sh: use ATF_TESTS_SH_SED & remove local mods
This particular change replaces all local modifications to the test
script like so:
- Use `ATF_TESTS_SH_SED_test` with a sed(1) statement in the Makefile,
  instead of the equivalent local modifications.
- Remove the need for expecting the output of newfs_msdos to be empty.
  There isn't much to gain from deviating from the upstream NetBSD test--it's
  just another local modification that would need to be carried forward. If
  it's worth testing this FreeBSD-specific behavior, it should be in a
  FreeBSD-specific test.

This makes moving new modifications to the script easier moving forward.

MFC after:	1 week
2026-02-15 10:36:29 -08:00
Enji Cooper fa3519d068 t_ptrace_wait.c: clean up trailing whitespace
This is being done to aid with future potential updates of this file.

MFC after:	1 week
2026-02-08 15:42:57 -08:00
Brooks Davis 18d47c1856 rpc: correct resultproc_t's type
It takes exactly three arguments of known type.

Tweak the types of various resultproc_t functions to match the type (mostly
added const to struct pointers) allowing us to drop casts.

Effort:		CHERI upstreaming
Reviewed by:	vangyzen, glebius
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D54941
2026-02-02 21:20:16 +00:00
Mark Johnston 938915a22c netbsd-tests: Fix regcomp_too_big flakiness
The test sometimes crashes with ASLR enabled.  This seems to happen when
regcomp() grows the process stack and happens to run into the virtual
memory limit set at the beginning of the test.  ASLR triggers the
problem since it introduces a bit of fragmentation and thus introduces
cases where stack allocation can be the trigger of virtual memory
exhaustion, rather than dynamic memory allocation in regcomp().

Make the test stable by priming the stack before doing anything else.
This effectively reserves 16MB of virtual memory for the stack, which in
practice is enough to make the test stable on amd64.

PR:		259971
Reviewed by:	ngie, emaste
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D54880
2026-01-27 21:08:35 +00:00
John Baldwin 2dea50a661 netbsd-tests t_regex_att: Use __nonstring for a non-string constant
Fixes the following warning from GCC 15:

contrib/netbsd-tests/lib/libc/regex/t_regex_att.c:54:30: error: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (4 chars into 3 available) [-Werror=unterminated-string-initialization]
   54 | static const char delim[3] = "\\\\\0";
      |                              ^~~~~~~~

Reviewed by:	ngie, imp, dim
Differential Revision:	https://reviews.freebsd.org/D54866
2026-01-27 13:38:31 -05:00
Viacheslav Chimishuk 0a5535d1c5 grep: add testcase to test color when matches is greater than MAX_MATCHES
Reviewed by: imp, kevans
Pull Request: https://github.com/freebsd/freebsd-src/pull/1442
2026-01-09 16:22:48 -07:00
Siva Mahadevan 6c18c40b29 lib/msun/tests: xfail fe_round on riscv64
Replace ATF_CHECK_* with ATF_REQUIRE_* to fail fast and
avoid unexpected aborts.

Signed-off-by: Siva Mahadevan <[email protected]>
PR:		290099
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1871
2025-12-17 18:43:19 +08:00
Siva Mahadevan ec640742e3 lib/msun/tests: Remove newlines in ATF msgs
This fixes broken test reports with the following message:

lib/msun/fe_round_test:fe_round  ->  broken: Test result contains
multiple lines: expected_failure:
/usr/src/contrib/netbsd-tests/lib/libm/t_fe_round.c:95: Didn't get the
same rounding mode out!<<NEWLINE>>(index 0) fed in 64 rounding mode, got
0 out<<NEWLINE>>  [0.079s]

Signed-off-by: Siva Mahadevan <[email protected]>
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1871
2025-12-17 18:43:06 +08:00
Jose Luis Duran 2f29d0f3e6 mtree: tests: Import NetBSD's mtree test suite
Manually import latest mtree test suite from NetBSD.

MFC after:	1 week
2025-12-13 14:37:20 +00:00
Ed Maste 08345e62a2 regex/exhaust_test: Update require.memory
PR:		259971
Obtained from:	NetBSD 7753bf0b705a
Sponsored by:	The FreeBSD Foundation
2025-10-17 10:45:11 -04:00
Siva Mahadevan 1ddff51060 regex/exhaust_test: Skip flaky 'regcomp_too_big' testcase on all archs
PR: 259971
Signed-off-by: Siva Mahadevan <[email protected]>
Sponsored by: The FreeBSD Foundation
2025-10-17 10:24:01 -04:00
K Rin 65cda8a11d bin/cat: add test for reading data from stdin
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1671
Closes: https://github.com/freebsd/freebsd-src/pull/1671
2025-06-13 08:25:54 -06:00
Enji Cooper 19fb56b192 Revert "Mark several getaddrinfo tests as XFAIL"
This change was unreviewed and should not have been committed to :main.

This reverts commit 9b37d84c87.
2025-05-28 15:18:51 -07:00
Enji Cooper 9b37d84c87 Mark several getaddrinfo tests as XFAIL
These tests were recently enabled on main and have failed consistently
since they were enabled.

- lib.libc.net.getaddrinfo.getaddrinfo.basic
- lib.libc.net.getaddrinfo.getaddrinfo.nofamily
- lib.libc.net.getaddrinfo.getaddrinfo_test.basic
- lib.libc.net.getaddrinfo.getaddrinfo_test.empty_servname
- lib.libc.net.getaddrinfo.getaddrinfo_test.sock_raw

Mark them as expected failures so they no longer count as failures in
Jenkins CI.

PR:		285826
MFC with:	5313457780, 0b773a94ab
2025-05-28 15:15:08 -07:00
Craig Leres 1070477cc8 Fix remaining zgrep(1) wrapper script regressions
Summary:
Fix short flags without whitespace, e.g:

    zgrep -wefoo test

Fix multiple -e flags:

    zgrep -e foo -e xxx test

Previously only the last pattern would be used.

Clean up possible leading blank in ${grep_args}.

Update comment: 2.51 -> 2.6.0

Add a test case for the last known zgrep wrapper issue: recursion
(-r) not implemented.

Reviewers: markj, kevans, ngie, bapt

Reviewed By: markj

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D48873
2025-02-09 10:45:03 -08:00
Mark Johnston 4ff291ebe8 vfs: Fix vop_stdis_text()
atomic(9) primitives are documented as operating on unsigned types.
Here, we need a cast to avoid a tautological comparison.

Add a regression test for access(2), which was affected by the bug.

Reported by:	NetApp
Reviewed by:	kib
Fixes:		e511bd1406 ("vfs: fully lockless v_writecount adjustment")
MFC after:	1 week
Sponsored by:	Klara, Inc.
Sponsored by:	NetApp, Inc.
Differential Revision:	https://reviews.freebsd.org/D47672
2024-11-19 21:03:14 +00:00
Mark Johnston a700bef1e4 netbsd-tests: Update a test case to chase grep symlink handling changes
This test case verifies that grep detects symlink loops when traversing
a directory hierarchy.

Fixes:		fc12c191c0 ("grep: Default to -p instead of -S.")
Reviewed by:	ngie, jhb
Reported by:	Jenkins
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D46544
2024-09-07 19:39:49 +00:00
Mark Johnston 460464b2e0 netbsd-tests: Remove an xfail annotation
The test passes after commit 5ab6ed93cd
("faccessat(2): Honor AT_SYMLINK_NOFOLLOW").

Reported by:	Jenkins
2024-08-29 16:48:18 +00:00
Alexander Ziaee 088cc7d221 man filesystems: fix more xrefs after move to s4
Fixes: 1a720cbec5
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1282
2024-06-27 18:32:05 -06:00
Warner Losh d37eb51047 contrib: Remove various $FreeBSD$ tags not upstream
Sponsored by:		Netflix
2024-05-31 13:49:17 -06:00
Kyle Evans e55512504d Prepare the system for _FORTIFY_SOURCE
Notably:
- libc needs to #undef some of the macros from ssp/* for underlying
  implementations
- ssp/* wants a __RENAME() macro (snatched more or less from NetBSD)

There's some extra hinkiness included for read(), since libc spells it
as "_read" while the rest of the world spells it "read."

Reviewed by:	imp, ngie
Sponsored by:	Stormshield
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D32307
2024-05-13 00:23:50 -05:00
Mark Johnston 8eb21b4ff0 tmpfs tests: Remove an xfail annotation
This test passes after commit 08f3d5b60c ("copy_file_range: Call
vn_rdwr() at least once").

PR:		274615
MFC after:	1 month
2024-04-04 17:04:30 -04:00
Dag-Erling Smørgrav 8311bc5f17 tmpfs: Improve file time tests.
* The empty test case no longer fails because 89f1dcb3eb causes empty
  files to bypass the bug.
* The bug still exists, so add a test case which exercises it.
* While here, tighten up some of the checks.

A similar patch has been submitted upstream.

PR:		274615
X-MFC-With:	89f1dcb3eb
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D44609
2024-04-04 15:40:54 +02:00
Ed Maste 63f5375513 Add expected failure for tmpfs atime test failing on FreeBSD
PR:		274615
Reviewed by:	ngie
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D42321
2023-10-22 10:58:52 -04:00
Dag-Erling Smørgrav b9385720f3 libc: Add unit tests for N2630 and possible collateral damage.
Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D41512
2023-08-28 15:34:05 +00:00
Kyle Evans 79e6ffb695 netbsd-tests: libc: fix strvis(3) overflow tests
These tests weren't run on x86 until CI grabbed them.  It turns out,
there's a sign extension bug that surfaces on x86 with char being a
signed type.

NetBSD unearthed this when they took and improved the patch, so just
grab their solution until we get to merging in the latest version of
the test.

Reported by:	CI (via ngie)
Fixes:	2f489a509e ("libc: fix some overflow scenarios in vis(3)")
2023-08-20 00:36:23 -05:00
Kyle Evans 2f489a509e libc: fix some overflow scenarios in vis(3)
The previous incarnation of this would call wcrtomb() on the destination
buffer, and only check for overflow *after* it's happened.
Additionally, the conversion error / VIS_NOLOCALE path also didn't check
for overflow, and the overflow check at the end didn't account for the
fact that we still need to write a NUL terminator afterward.

Start by only doing the multibyte conversion into mbdst directly if we
have enough buffer space to guarantee it'll fit.  An additional
MB_CUR_MAX buffer has been stashed on the stack to write into if we're
cutting it close at the end of the buffer, since we don't really have a
good way to determine the length of the wchar_t without just doing the
conversion.  We'll do the conversion into the buffer that's guaranteed
to fit, then copy it over if the copy won't overflow.

The byte-for-byte overflow is a little bit easier, as we simply check
for overflow with each byte written and make sure we can still NUL
terminate after.

Tests added to exercise these edge cases.

Reviewed by:	des
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D41328
2023-08-08 12:01:52 -05:00
Dmitry Chagin a18b956b73 libexecinfo: Enable backtrace_test.backtrace_fmt_basic on amd64 again
Due to unwind tables generation enabled after c969310c for csu.

PR:			241562, 246322, 246537
Reviewed by:		kib, ngie
Differential Revision:	https://reviews.freebsd.org/D40758
2023-06-29 19:53:07 +03:00
Mark Johnston 478de7f8e2 netbsd-tests: Remove some pointless sleeps from message queue tests
- In the msgctl tests, there is no point in sleeping after a fork().
  Just block immediately in wait().
- In non-blocking send/recv tests, just wait for the child to exit once
  it's reached a message limit.  If a bug prevents the child from
  exiting promptly, the test will time out.

MFC after:	1 week
2023-03-10 17:06:46 -05:00
Dag-Erling Smørgrav 606d0e4a9a libc: Add tests for strchrnul(3).
MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	allanjude
Differential Revision:	https://reviews.freebsd.org/D38286
2023-02-02 15:45:45 +01:00
Dag-Erling Smørgrav d8c9f80891 libc: Update mktime(3) / timegm(3) tests.
Sponsored by:	Klara, Inc.
Reviewed by:	ngie
Differential Revision:	https://reviews.freebsd.org/D38177
2023-01-25 07:22:46 +01:00
Jessica Clarke 9fb118bebc libc: Fix longjmp/_longjmp(buf, 0) for AArch64 and RISC-V
These architectures fail to handle this special case, and will cause the
corresponding setjmp/_setjmp to return 0 rather than 1. Fix this and add
regression tests (also committed upstream).

PR:		268684
Reviewed by:	arichardson, jhb
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D29363
2023-01-09 18:34:43 +00:00
John Baldwin d131218534 h_resolv: Fix a buffer overflow in load().
fgetln() returns a pointer to an array of characters that is 'len'
characters long, not 'len + 1'.  While here, overwriting the contents
of the buffer returned by fgetln isn't really safe, so switch to using
getline() instead.

Note that these fixes are a subset of those applied to a
near-identical copy of this function in libc's resolv_test.c in commit
2afeaad315.

Reviewed by:	ngie
Reported by:	CHERI (buffer overflow)
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D37886
2022-12-28 09:39:18 -08:00
Eric van Gyzen 20917cac7b sysv test: properly wait for children
In the msg and shm tests, if the child exited before the parent
entered sigsuspend(), the test would hang and time out.  This was
also a problem in the sem test, but the misuse of atf_tc_pass()
masked it.  Adding a short sleep before the sigsuspend() calls made
the hang 100% reliable.  With the same sleep in the new version,
the test passes reliably.

Remove calls to atf_tc_pass().  The call in the sem test broke the test
by exiting prematurely, after only one child out of five had finished.
The other two were harmless but unhelpful.

Reduce a one-second sleep to a more reasonable duration so I can quickly
run many iterations of the test.

Where feasible, assert that wait() returns the child PID.  While I'm here,
use the more succinct ATF_REQUIRE* instead of if/atf_tc_fail/else.

Flush stdout before forking to avoid double-flush.

Use errx() when errno is irrelevant.

Don't use ATF_REQUIRE* in children.  Apparently, the output doesn't
get saved.  The exit status works, so it fails correctly, but silently.

Re-enable the test in CI.

PR:		233649
Reviewed by:	markj (previous version)
MFC after:	1 week
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D35187
2022-05-13 11:38:26 -05:00
Eric van Gyzen 4e71258227 newfs_msdos: connect the ATF test from NetBSD
NetBSD has an ATF test for newfs_msdos.  Connect it to the build.
Adapt it for FreeBSD.  This would have caught the bug fixed by my
previous commit.

Reviewed by:	delphij, emaste
MFC after:	1 week
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D34116
2022-02-16 09:56:16 -06:00
Mark Johnston 95c75073d3 netbsd-tests: Fix the libc stat_socket test
The test tries to connect a socket to a closed port at 127.0.0.1.  It
sets O_NONBLOCK on the socket first and expects to get EINPROGRESS from
connect(2), but this is not guaranteed, ECONNREFUSED is possible.
Handle both cases, and re-enable the test.

PR:		240621
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2022-01-14 15:01:41 -05:00