aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/tests/gen
Commit message (Collapse)AuthorAgeFilesLines
* realpath: Report correct path on failureDag-Erling Smørgrav11 days1-9/+2
| | | | | | | | | | | If lstat() fails with EACCES or ENOTDIR, the path we need to return in the caller-provided buffer is that of the parent directory (which is either unreadable or not a directory; the latter can only happen in the case of a race) rather than that of the child we attempted to stat. Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D53025
* realpath: Additional test casesDag-Erling Smørgrav11 days1-12/+101
| | | | | | | | | | | | * Passing NULL should result in EINVAL * Passing an empty path should result in ENOENT * Failure with a non-null buffer should leave a partial result. As pointed out in a comment in the test case, this reveals a discrepancy between the documentation and reality. Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D53024
* libc: gen: refactor execvPe() for readabilityKyle Evans2025-08-031-0/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The current incarnation of execvPe() is a bit messy, and it can be rather difficult to reason about whether we're actually doing the right thing with our errors. We have two cases in which we may enter the loop: 1.) We have a name that has no slashes in it, and we enter the loop normally through our strsep() logic to process $PATH 2.) We have a name with at least one slash, in which case we jump into the middle of the loop then bail after precisely the one iteration if we failed Both paths will exit the loop if we failed, either via jumping to the `done` label to preserve an errno or into the path that clobbers errno. Clobbering errno for case #2 above would seem to be wrong, as we did not actually search -- this would seem to be what POSIX expects, as well, based on expectations of the conformance test suite. Simplify reasoning about the two paths by splitting out an execvPe_prog that does the execve(2) call specifically, and returns based on whether the error would be fatal in a PATH search or not. For the relative/absolute case, we can just ignore the return value and keep errno intact. The search case gets simplified to return early if we hit a fatal error, or continue until the end and clobber errno if we did not find a suitable candidate. Another posix_spawnp() test is added to confirm that we didn't break our EACCES behavior in the process. Reviewed by: des, markj Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D51629
* readdir: Fix error check.Dag-Erling Smørgrav2025-07-112-7/+6
| | | | | | | | | | | | | Now that dd_size is unsigned, we need to check if the return value from getdirentries() was negative before assigning it to dd_size. While here, simplify the scandir_error test case slightly, and verify that calling readdir() again after EOF still returns NULL. Fixes: 42e613018da5 Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D51266
* wordexp(3): Handle ECHILD from waitpidKenny Levinsen2025-07-081-0/+26
| | | | | | | | | | | | | | If the calling process has used SIG_IGN as handler or set the SA_NOCLDWAIT flag for SIGCHLD, processes will be automatically reaped on exit and calls to waitpid(3) will therefore fail with ECHILD. We waitpid primarily to reap our child so that the caller does not have to worry about it. ECHILD indicates that there is no child to reap, so we can just treat that as a success and move on. Signed-off-by: Kenny Levinsen <kl@kl.wtf> Tested by: Jan Beich Pull Request: https://github.com/freebsd/freebsd-src/pull/1675
* opendir, fdopendir: Add tests, clean up.Dag-Erling Smørgrav2025-07-082-0/+145
| | | | | | | | | | | | * Add test cases for opendir() and fdopendir(). * Drop O_NONBLOCK from opendir(); it was added a long time ago to avoid blocking if given a closed named pipe, but now we use O_DIRECTORY, which ensures that we get ENOTDIR in that case. * While here, remove unused #includes left over from the split. Sponsored by: Klara, Inc. Reviewed by: kevans, markj Differential Revision: https://reviews.freebsd.org/D51126
* fts: Add test cases for unreadable directories.Dag-Erling Smørgrav2025-07-024-72/+180
| | | | | | Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D51098
* scandir: Propagate errors from readdir().Dag-Erling Smørgrav2025-06-261-0/+63
| | | | | | | | | | | | | | Currently, if `readdir()` fails, `scandir()` simply returns a partial result (or a null result if it fails before any entries were selected). There is no way within the current API design to return both a partial result and an error indicator, so err on the side of caution: if an error occurs, discard any partial result and return the error instead. MFC after: 1 week Reported by: Maxim Suhanov <dfirblog@gmail.com> Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D51046
* libc: Rename fscandir{,_b}() to fdscandir{,_b}().Dag-Erling Smørgrav2025-06-232-12/+12
| | | | | | | | | | | | | This seems to fit the pattern better (e.g. fdopendir()). I've added weak references to ease the transition, but since it's only been a few days, we can remove them (and the ObsoleteFiles entries for the manual pages) before we branch stable/15. Fixes: deeebfdecab5 Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D50980
* glob: Improve callback tests.Dag-Erling Smørgrav2025-06-232-35/+63
| | | | | | | | | | | Most importantly, they need to run without privileges, since root is allowed to read a directory regardless of its permission bits. PR: 287694 Fixes: 4d7c31bca252 Sponsored by: Klara, Inc. Reviewed by: bnovkov Differential Revision: https://reviews.freebsd.org/D50965
* scandir: Fix behavior when no entries match.Dag-Erling Smørgrav2025-06-201-0/+22
| | | | | | | | | | | | In the previous commit, I removed the initial initialization of the `names` array, not realizing that `scandir()` is expected to return a non-null (but empty) array of entries if no entries matched. Restore the historical behavior, document it, and add a test. Fixes: deeebfdecab5 Sponsored by: Klara, Inc. Reviewed by: kevans, allanjude, markj Differential Revision: https://reviews.freebsd.org/D50949
* libc: Add fscandir(), fscandir_b(), scandirat_b().Dag-Erling Smørgrav2025-06-203-1/+235
| | | | | | | | | While here, clean up scandir() a bit and improve the documentation. MFC after: never Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D50935
* Add tests for sig2str() / str2sig()Ricardo Branco2025-06-112-0/+214
| | | | | Reviewed by: imp, kib, des, jilles Pull Request: https://github.com/freebsd/freebsd-src/pull/1696
* glob2_test: Add tests for error callback functions and blocksBojan Novković2025-06-023-2/+112
| | | | | | | | | This change adds tests that check basic callback functionality for blocks and function pointers. The tests also make sure that GLOB_ERR overrides the callback's return value. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D50486
* fts: Rename fts_options to fts_options_testDag-Erling Smørgrav2025-05-082-1/+1
| | | | Sponsored by: Klara, Inc.
* fts: Give the blocks test a description.Dag-Erling Smørgrav2025-05-081-1/+6
| | | | | | Sponsored by: Klara, Inc. Reviewed by: kevans, imp Differential Revision: https://reviews.freebsd.org/D50235
* fts: Add tests for most FTS options.Dag-Erling Smørgrav2025-05-082-0/+455
| | | | | | Sponsored by: Klara, Inc. Reviewed by: kevans, imp Differential Revision: https://reviews.freebsd.org/D50234
* bsd.compiler.mk: Add a blocks compiler feature.Dag-Erling Smørgrav2025-04-221-1/+1
| | | | | | Sponsored by: Klara, Inc. Reviewed by: jrtc27 Differential Revision: https://reviews.freebsd.org/D49963
* fts: Add blocks support.Dag-Erling Smørgrav2025-04-222-0/+72
| | | | | | | | | | | | | | | | | | | | | | This adds an `fts_open_b()` variant of `fts_open()` which takes a block instead of a function pointer. This was inspired by, and is intended to be compatible with, Apple's implementation; however, although our FTS and theirs share a common ancestor, they have diverged significantly. That and the fact that we still target compilers which don't support blocks means Apple's implementation was not directly reusable. This is the second use case for blocks in FreeBSD (the first being `qsort_b()`, which we use here). This suggest we might want to add a `COMPILER_FEATURE` for blocks to avoid hardcoding any further `COMPILER_TYPE` checks. MFC after: never Relnotes: yes Sponsored by: Klara, Inc. Reviewed by: kevans, theraven, imp Differential Revision: https://reviews.freebsd.org/D49877
* fnmatch: Add support for collating symbols, equivalence classes, and ↵Bojan Novković2025-04-101-0/+81
| | | | | | | | | | | | | | character classes This change extends fnmatch to support collating symbol expressions, equivalence class expressions, and character class expressions (as defined by POSIX.1, section 9.3.5), along with the corresponding tests. Sponsored by: Klara, Inc. Obtained from: https://github.com/apple-oss-distributions/Libc Differential Revision: https://reviews.freebsd.org/D49660 Reviewed by: markj, ziaee (manpages)
* getentropy tests: Update after commit 473681a1a506daMark Johnston2025-01-191-5/+6
| | | | | | | - Use GETENTROPY_MAX instead of hard-coding the value. - Check for EINVAL instead of EIO Fixes: 473681a1a506 ("libc: Fix getentropy POSIX 2024 conformance issues")
* lib/libc/tests: add unit test for arc4random_uniform()Robert Clausecker2024-12-021-0/+26
| | | | | | | | | | The new unit test validates that the range reduction works correctly. We do not currently validate that there is no bias as that would take too much time and memory for a unit test. Reviewed by: cem Approved by: emaste Differential Revision: https://reviews.freebsd.org/D47659
* Remove residual blank line at start of MakefileWarner Losh2024-07-153-3/+0
| | | | | | | This is a residual of the $FreeBSD$ removal. MFC After: 3 days (though I'll just run the command on the branches) Sponsored by: Netflix
* libc: Purge unneeded cdefs.hWarner Losh2023-11-0118-18/+0
| | | | | | | | | These sys/cdefs.h are not needed. Purge them. They are mostly left-over from the $FreeBSD$ removal. A few in libc are still required for macros that cdefs.h defines. Keep those. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D42385
* Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-167-7/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-1618-36/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-161-2/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-123-3/+3
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* tests: fix posix_spawnp_enoexec_fallback_null_argv0Kyle Evans2022-01-271-6/+3
| | | | | | | | | | | | This test was written because execvp was found to improperly handle the argc == 0 case when it falls back from an ENOEXEC. We could probably mostly revert it now, but let's just fix the test for the time being and circle back later to decide if we want to simplify execvp. The test will likely remain either way just to make sure execvp isn't working around the newly enforced restriction with the fallback. Fixes: 301cb491ea41 ("execvp: fix up the ENOEXEC fallback") Reported by: jenkins via lwhsu@
* libc: tests: hook CPUSET(9) test up to the buildKyle Evans2020-12-311-1/+2
| | | | | | | | | Add shims to map NetBSD's API to CPUSET(9). Obviously the invalid input parts of these tests are relatively useless since we're just testing the shims that aren't used elsewhere, there's still some amount of value in the parts testing valid inputs. Differential Revision: https://reviews.freebsd.org/D27307
* Revert r351416 to let lib.libc.gen.getmntinfo_test.getmntinfo_test get more testLi-Wen Hsu2020-07-131-3/+0
| | | | | | | | | | This is supposed to be fixed by r363068 PR: 240049 Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=363165
* Enable long double tests on RISC-VMitchell Horne2020-06-241-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | Some of the NetBSD contributed tests are gated behind the __HAVE_LONG_DOUBLE flag. This flag seems to be defined only for platforms whose long double is larger than their double. I could not find this explicitly documented anywhere, but it is implied by the definitions in NetBSD's sys/arch/${arch}/include/math.h headers, and the following assertion from the UBSAN code: #ifdef __HAVE_LONG_DOUBLE long double LD; ASSERT(sizeof(LD) > sizeof(uint64_t)); #endif RISC-V has 128-bit long doubles, so enable the tests on this platform, and update the comments to better explain the purpose of this flag. Reviewed by: ngie MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D25419 Notes: svn path=/head/; revision=362576
* Add missing shell script from r361995Kyle Evans2020-06-101-0/+4
| | | | | | | | | Pointy hat: kevans Reported by: rpokala X-MFC-With: r361995 Notes: svn path=/head/; revision=361999
* execvp: fix up the ENOEXEC fallbackKyle Evans2020-06-102-0/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If execve fails with ENOEXEC, execvp is expected to rebuild the command with /bin/sh instead and try again. The previous version did this, but overlooked two details: argv[0] can conceivably be NULL, in which case memp would never get terminated. We must allocate no less than three * sizeof(char *) so we can properly terminate at all times. For the non-NULL argv standard case, we count all the non-NULL elements and actually skip the first argument, so we end up capturing the NULL terminator in our bcopy(). The second detail is that the spec is actually worded such that we should have been preserving argv[0] as passed to execvp: "[...] executed command shall be as if the process invoked the sh utility using execl() as follows: execl(<shell path>, arg0, file, arg1, ..., (char *)0); where <shell path> is an unspecified pathname for the sh utility, file is the process image file, and for execvp(), where arg0, arg1, and so on correspond to the values passed to execvp() in argv[0], argv[1], and so on." So we make this change at this time as well, while we're already touching it. We decidedly can't preserve a NULL argv[0] as this would be incredibly, incredibly fragile, so we retain our legacy behavior of using "sh" for argv[] in this specific instance. Some light tests are added to try and detect some components of handling the ENOEXEC fallback; posix_spawnp_enoexec_fallback_null_argv0 is likely not 100% reliable, but it at least won't raise false-alarms and it did result in useful failures with pre-change libc on my machine. This is a secondary change in D25038. Reported by: Andrew Gierth <andrew_tao173.riddles.org.uk> Reviewed by: jilles, kib, Andrew Gierth MFC after: 1 week Notes: svn path=/head/; revision=361995
* Avoid using non-portable dd status=none flagAlex Richardson2020-06-051-1/+5
| | | | | | | | | | | | | | | | | Copying the approach chosen in r309412. This fixes building the libc tests on a macOS host since the macOS /bin/dd binary does not support status=none. As there only seem to be two uses, this commit changes the two Makefiles. If this becomes more common, we could also add a wrapper bootstrap script that ignores status= and forwards the remaining args to the real dd. Another alternative would be to remove the status flag and pipe stderr to /dev/null, but them we lose error messages. Reviewed By: brooks Differential Revision: https://reviews.freebsd.org/D24785 Notes: svn path=/head/; revision=361829
* Add sigsetop extensions commonly found in musl libc and glibcKyle Evans2019-12-122-0/+192
| | | | | | | | | | | | | | These functions (sigandset, sigisemptyset, sigorset) are commonly available in at least musl libc and glibc; sigorset, at least, has proven quite useful in qemu-bsd-user work for tracking the current process signal mask in a more self-documenting/aesthetically pleasing manner. Reviewed by: bapt, jilles, pfg MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D22187 Notes: svn path=/head/; revision=355641
* lib.libc.gen.getmntinfo_test.getmntinfo_test is unstable since 8/20, skip itLi-Wen Hsu2019-08-231-0/+3
| | | | | | | | | | in CI env temporarily for more offline diagnosis PR: 240049 Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=351416
* Include a mode when creating files with openat().Brooks Davis2019-07-181-2/+2
| | | | | | | | | | | Reviewed by: asomers Obtained from: CheriBSD MFC after: 1 week Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D20989 Notes: svn path=/head/; revision=350117
* Drop "All rights reserved" from my copyright statements.John Baldwin2019-03-061-1/+0
| | | | | | | | | Reviewed by: rgrimes MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D19485 Notes: svn path=/head/; revision=344855
* getentropy(3): Fallback to kern.arandom sysctl on older kernelsConrad Meyer2018-03-211-0/+3
| | | | | | | | | | | | | | | | | | | On older kernels, when userspace program disables SIGSYS, catch ENOSYS and emulate getrandom(2) syscall with the kern.arandom sysctl (via existing arc4_sysctl wrapper). Special care is taken to faithfully emulate EFAULT on NULL pointers, because sysctl(3) as used by kern.arandom ignores NULL oldp. (This was caught by getentropy(3) ATF tests.) Reported by: kib Reviewed by: kib Discussed with: delphij Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D14785 Notes: svn path=/head/; revision=331334
* Implement getrandom(2) and getentropy(3)Conrad Meyer2018-03-212-0/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The general idea here is to provide userspace programs with well-defined sources of entropy, in a fashion that doesn't require opening a new file descriptor (ulimits) or accessing paths (/dev/urandom may be restricted by chroot or capsicum). getrandom(2) is the more general API, and comes from the Linux world. Since our urandom and random devices are identical, the GRND_RANDOM flag is ignored. getentropy(3) is added as a compatibility shim for the OpenBSD API. truss(1) support is included. Tests for both system calls are provided. Coverage is believed to be at least as comprehensive as LTP getrandom(2) test coverage. Additionally, instructions for running the LTP tests directly against FreeBSD are provided in the "Test Plan" section of the Differential revision linked below. (They pass, of course.) PR: 194204 Reported by: David CARLIER <david.carlier AT hardenedbsd.org> Discussed with: cperciva, delphij, jhb, markj Relnotes: maybe Differential Revision: https://reviews.freebsd.org/D14500 Notes: svn path=/head/; revision=331279
* Add a new set of simple tests for makecontext().John Baldwin2018-01-312-0/+190
| | | | | | | | | | | | In contrast to the existing NetBSD setcontext_link test, these tests verify that passing from 1 to 6 arguments through to the callback function work correctly which can be useful for testing ABIs which split arguments between registers and the stack. Sponsored by: DARPA / AFRL Notes: svn path=/head/; revision=328633
* Optimize telldir(3)Alan Somers2017-12-062-2/+192
| | | | | | | | | | | | | | | | | | | | | | | | | Currently each call to telldir() requires a malloc and adds an entry to a linked list which must be traversed on future telldir(), seekdir(), closedir(), and readdir() calls. Applications that call telldir() for every directory entry incur O(n^2) behavior in readdir() and O(n) in telldir() and closedir(). This optimization eliminates the malloc() and linked list in most cases by packing the relevant information into a single long. On 64-bit architectures msdosfs, NFS, tmpfs, UFS, and ZFS can all use the packed representation. On 32-bit architectures msdosfs, NFS, and UFS can use the packed representation, but ZFS and tmpfs can only use it for about the first 128 files per directory. Memory savings is about 50 bytes per telldir(3) call. Speedup for telldir()-heavy directory traversals is about 20-30x for one million files per directory. Reviewed by: kib, mav, mckusick MFC after: 3 weeks Sponsored by: Spectra Logic Corp Differential Revision: https://reviews.freebsd.org/D13385 Notes: svn path=/head/; revision=326640
* DIRDEPS_BUILD: Update dependencies.Bryan Drewery2017-10-313-3/+0
| | | | | | | Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=325188
* getmntinfo(3): Scale faster, and return soonerConrad Meyer2017-08-252-0/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | | | getmntinfo(3) is designed around a relatively static or slow growing set of current mounts. It tried to detect a race with somewhat concurrent mount and re-call getfsstat(2) in that case, looping indefinitely. It also allocated space for a single extra mount as slop. In the case where the user has a large number of mounts and is adding them at a rapid pace, it fell over. This patch makes two functional changes: 1. Allocate even more slop. Double whatever the last getfsstat(2) returned. 2. Abort and return some known results after looping a few times (arbitrarily, 3). If the list is constantly changing, we can't guarantee we return a full result to the user at any point anyways. While here, add very basic functional tests for getmntinfo(3) to the libc suite. PR: 221743 Submitted by: Peter Eriksson <peter AT ifm.liu.se> (earlier version) Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=322895
* fnmatch(3): Update testcase for r322368.Pedro F. Giffuni2017-08-101-1/+1
| | | | Notes: svn path=/head/; revision=322371
* Fix cleanup in lib/libc/gen/setdomainname_testAlan Somers2017-07-061-0/+1
| | | | | | | | | | | | | | | | | ATF cleanup routines run in separate processes from the tests themselves, so they can't share global variables. Also, setdomainname_test needs to be is_exclusive because the test cases access a global resource. PR: 219967 Reviewed by: ngie MFC after: 3 weeks Sponsored by: Spectra Logic Corp Differential Revision: https://reviews.freebsd.org/D11188 Notes: svn path=/head/; revision=320737
* Add tests for some cases in r318298.Konstantin Belousov2017-05-182-0/+103
| | | | | | | | | | | | | | | | The first test triggers the out of bounds read of the 'left' array. It only fails when realpath.c is compiled with '-fsanitize=address'. The other test checks for ENOENT when running into an empty symlink. This matches NetBSD's realpath(3) semantics. Previously, empty symlinks were treated like ".". Submitted by: Jan Kokemц╪ller <jan.kokemueller@gmail.com> PR: 219154 MFC after: 2 weeks Notes: svn path=/head/; revision=318450
* libc glob: Avoid pathological exponential behaviorConrad Meyer2017-05-032-0/+115
| | | | | | | | | | | | | | | Adapt glob's match() routine to use a greedy algorithm that avoids exponential runtime in byzantine inputs. While here, add a testcase for the byzantine input. Prompted by: https://research.swtch.com/glob Authored by: Yves Orton <demerphq at gmail.com> Obtained from: Perl (33252c318625f3c6c89b816ee88481940e3e6f95) Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=317749
* Upgrade NetBSD tests to 01.11.2017_23.20 snapshotEnji Cooper2017-01-131-1/+11
| | | | | | | | | | | | | | | This contains some new testcases in /usr/tests/...: - .../lib/libc - .../lib/libthr - .../lib/msun - .../sys/kern Tested on: amd64, i386 MFC after: 1 month Notes: svn path=/head/; revision=312008