aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/tests
Commit message (Collapse)AuthorAgeFilesLines
* libc: Fix style nits in flushlbuf regression testDag-Erling Smørgrav30 hours1-5/+5
| | | | Sponsored by: Klara, Inc.
* libc: gen: refactor execvPe() for readabilityKyle Evans6 days1-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
* dbm_nextkey: Always return an error if we've reached the end of the databaseBojan Novković8 days2-0/+54
| | | | | | | | | | | | | POSIX.1 states that `dbm_nextkey` must return an invalid key (i.e., `key.dptr == NULL`) after the end of the database was reached. The current implementation of `hash_seq` will incorrectly restart the key sequence after the end of the database is reached. Fix this by checking the "current bucket" index when R_NEXT is passed. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D51635 Reviewed by: markj
* db/hash.c: Allow O_WRONLY in dbm_openBojan Novković9 days3-7/+115
| | | | | | | | | | | | | | The dbm(3) manpage explicitly states that O_WRONLY is not allowed in dbm_open, but a more recent comment in ` __hash_open` suggests otherwise. Furthermore, POSIX.1 allows O_WRONLY in dbm_open and states that the underlying file must be opened for both reading and writing. Fix this by correcting the O_WRONLY check and moving it further into the function to make sure that the original flags are stored in hashp. Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D51514
* dbm: Add tests for dbm_openBojan Novković2025-07-252-0/+45
| | | | | | Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D51492
* libc: Test time zone change detection.Dag-Erling Smørgrav2025-07-182-1/+285
| | | | | | | | | While here, clean the detection code up a bit. Sponsored by: Klara, Inc. Sponsored by: NetApp, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D51343
* libc/powerpc64: Fix swapcontext(3)Timothy Pearson2025-07-132-2/+65
| | | | | | | | | | | | | | | | | | | | | On PowerPC platforms a valid link to the Table of Contents (TOC) is required for PLT lookups to function. This TOC pointer is stored in a dedicated register, and is used along with the stack pointer by both C prologue and PLT lookup code. When calling swapcontext() with uc_link != NULL, a PLT lookup to setcontext(3) is attempted from within the _ctx_done context. The exiting process has usually trashed both r1 and r2 at this point, leading to a crash within the PLT lookup before setcontext(2) is reached to restore the linked context. Save and restore r2 as in a regular function. This ensures the subsequent PLT lookup to setcontext(3) succeeds. Signed-off-by: Timothy Pearson <tpearson@raptorengineering.com> MFC after: 1 week Pull Request: https://github.com/freebsd/freebsd-src/pull/1759
* 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
* include: ssp: fortify <signal.h>Ricardo Branco2025-06-113-0/+329
| | | | | | | | sig2str(3) Reviewed by: imp, kib, des, jilles Pull Request: https://github.com/freebsd/freebsd-src/pull/1696 Closes: https://github.com/freebsd/freebsd-src/pull/1696
* 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
* Revert "Mark several getaddrinfo tests as XFAIL"Enji Cooper2025-05-281-6/+0
| | | | | | This change was unreviewed and should not have been committed to :main. This reverts commit 9b37d84c87e69dabc69d818aa4d2fea718bd8b74.
* Mark several getaddrinfo tests as XFAILEnji Cooper2025-05-281-0/+6
| | | | | | | | | | | | | | | | | 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
* libc: Improve scanfloat test.Dag-Erling Smørgrav2025-05-161-68/+68
|
* link_addr: be more strict about address formatsLexi Winter2025-05-151-1/+151
| | | | | | | | | | | | | | | | | | | | | | instead of accepting any character as a delimiter, only accept ':', '.' and '-', and only permit a single delimiter in an address. this prevents accepting bizarre addresses like: ifconfig epair2a link 10.1.2.200/28 ... which is particularly problematic on an INET6-only system, in which case ifconfig defaults to the 'link' family, meaning that: ifconfig epair2a 10.1.2.200/28 ... changes the Ethernet address of the interface. bump __FreeBSD_version so link_addr() consumers can detect the change. Reviewed by: kp, des Approved by: des (mentor) Differential Revision: https://reviews.freebsd.org/D49936
* 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
* libc: add link_ntoa_r()Lexi Winter2025-05-071-0/+111
| | | | | | | | | | | | this is a re-entrant version of link_ntoa. use an in-out parameter for the buffer size, so the user requires at most two calls to determine the needed size. reimplement link_ntoa using link_ntoa_r with a static buffer. Reviewed by: des Approved by: des (mentor) Differential Revision: https://reviews.freebsd.org/D50202
* link_addr_test: use <cstddef>, not <sys/stddef.h>Lexi Winter2025-05-061-4/+6
| | | | | | | | | | | <cstddef> is the correct header; this fixes the GCC build. while here, sort the headers. Fixes: 757e973fb211 ("libc tests: add tests for link_addr(3) and link_ntoa(3)") Reviewed by: des Approved by: des (mentor) Differential Revision: https://reviews.freebsd.org/D50189
* getenv_r tests: Fix getenv_r_erangeMark Johnston2025-05-061-1/+1
| | | | | | Fixes: 873420ca1e6e ("libc: Add getenv_r() function.") Reviewed by: des Differential Revision: https://reviews.freebsd.org/D50172
* libc tests: add tests for link_addr(3) and link_ntoa(3)Lexi Winter2025-05-052-0/+272
| | | | | | | | | for now, since link_addr() has no way to indicate an error, these are only positive tests which check the outcome of valid inputs. Reviewed by: ngie, des, adrian Approved by: des (mentor) Differential Revision: https://reviews.freebsd.org/D50062
* libc: Add getenv_r() function.Dag-Erling Smørgrav2025-04-274-0/+226
| | | | | | | | | | This is a calque of the NetBSD function of the same name. MFC after: never Relontes: yes Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D49979
* bsd.compiler.mk: Add a blocks compiler feature.Dag-Erling Smørgrav2025-04-222-2/+2
| | | | | | Sponsored by: Klara, Inc. Reviewed by: jrtc27 Differential Revision: https://reviews.freebsd.org/D49963
* fts: Add blocks support.Dag-Erling Smørgrav2025-04-223-1/+73
| | | | | | | | | | | | | | | | | | | | | | 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
* libc: locale: fix EUC shift checkKyle Evans2025-04-201-0/+13
| | | | | | | | | | | | | | wchar_t is unsigned on ARM platforms, and signed pretty much everywhere else. On signed platforms, `nm` ends up with bogus upper bits set if we did in-fact have a valid CS2 or CS3 (MSB set). Mask just the low byte to avoid sign bit garbage. Bare basic test of converting a CS2 widechar in eucCN, which would previously kick back an EILSEQ. Reviewed by: bapt, rew Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D43262
* src: Use gnu++17 as the default C++ standardJohn Baldwin2025-04-111-2/+0
| | | | | | | | | | | | | | | | | | | | | | Previously the compiler's default C++ standard was used unlike C where bsd.sys.mk explicitly sets a default language version. Setting an explicit default version will give a more uniform experience across different compilers and compiler versions. gnu++17 was chosen to match the default C standard. It is well supported by a wide range of clang (5+) and GCC (9+) versions. gnu++17 is also the default C++ standard in recent versions of clang (16+) and GCC (11+). As a result, many of the explicit CXXSTD settings in Makefiles had the effect of lowering the C++ standard instead of raising it as was originally intended and are removed. Note that the remaining explicit CXXSTD settings for atf and liblutok explicitly lower the standard to C++11 due to use of the deprecated auto_ptr<> template which is removed in later versions. Reviewed by: imp, asomers, dim, emaste Differential Revision: https://reviews.freebsd.org/D49223
* 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)
* libc/tests: getaddrinfo_test: use VNET jails for testingK Rin2025-04-081-69/+59
|
* libc/tests: getaddrinfo_test: require root privilegesK Rin2025-04-081-0/+14
|
* libc/tests: rename t_getaddrinfo.sh to getaddrinfo_test.shK Rin2025-04-082-1/+1
| | | | This matches FreeBSD style of test names.
* libc/tests: getaddrinfo_test: test both IPv4 and IPv6 preferred policiesK Rin2025-04-0817-42/+682
|
* libc/tests: move getaddrinfo_test data to a subdirectoryK Rin2025-04-0813-7/+12
|
* libc/tests: fix couple errors for getaddrinfo_testK Rin2025-04-081-1/+2
| | | | | | - The reason our test is flaky is its dependence on ip6addrctl_policy. - While here, fix shell logic. When our diff(1) prints a diff it returns a nonzero status and this is when we want to atf_fail().
* libc/tests: copy t_getaddrinfo out from contrib/netbsd-testsK Rin2025-04-082-3/+199
| | | | It is going to be modified in next commits.
* libc: tests: add some tests for __cxa_atexit handlingKyle Evans2025-04-054-0/+212
| | | | | | | This adds a basic test that __cxa_atexit works, and also adds some tests for __cxa_atexit handlers registered in the middle of __cxa_finalize. PR: 285870
* tests: Require allow_network_access for tests needing name resolutionOlivier Cochard2025-04-021-2/+11
| | | | | | | | | | | | Tests that require working name resolution or network access now mandate that the kuya variable allow_network_access be set. PR: 285826 Reported by: ngie Reviewed by: igoro Approved by: lwhsu Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D49633
* libc/getaddrinfo(2): return EAI_AGAIN on nameserver timeoutGleb Smirnoff2025-03-281-29/+24
| | | | | | | | | | | | | A nameserver timeout is a soft failure, future attempts may succeed. Returning EAI_AGAIN is crucial for API users to tell a soft name resolution failure from negative resolution result. Before the change we would return EAI_ADDRFAMILY, which I believe, is a regression from 144361386696, and before that revision we used to return EAI_NONAME in most of the cases. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D49411
* libc/tests: add getaddrinfo testGleb Smirnoff2025-03-282-0/+268
| | | | | | | | | | | | | | | | | A test suite for getaddrinfo(3) written in C. Unlike NetBSD test, this one will be mostly focused on what the API should return when something isn't good with your DNS. Test emulates bad DNS servers in resolv.conf intercepting fopen(2) and emulates downed network intercepting send(2). Initial version covers three main scenarios: all good, server(s) timed out, network down. For each scenario we test hostname with trailing dot and without, since libc resolver uses quite different code paths, sometimes even yielding with different error codes. All current error codes in the test are what our libc returns right now, meaning the test documents what we have, not what there should be. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D49410
* libc/tests: enable getaddrinfo(1) tests from NetBSDGleb Smirnoff2025-03-2814-4/+294
| | | | | | | | | | | | | | | | | | | | | | Enable running of contrib/netbsd-tests/lib/libc/net/getaddrinfo without modifications to the test program itself. However, create our own version of expected results files. They are produced from the NetBSD files, with the following list of changes: o AF_INET6 value is different, hence: s/family 24/family 28/. o SCTP result (socktype 5 protocol 132) needs to be added to many queries results. o NetBSD libc sorts multiple results first by protocol, then by address family. FreeBSD first sorts on address family, then on protocol. Some results need to be reordered. o Error strings need to be fixed: s/hostname nor servname provided, or not known/Name does not resolve/ s/ai_family not supported/Address family not recognized/ s/servname not supported for ai_socktype/\ Service was not recognized for socket type/. Reviewed by: ngie, kib Differential Revision: https://reviews.freebsd.org/D49409
* libc: tests: fix the gethostname() and getdomainname() testsKyle Evans2025-03-2012-92/+109
| | | | | | | | | | | Instead of relying on any particular domainname and hostname to succeed, spin up a jail before we execute the test with them set to some known, fixed values. This allows them to be meaningfully tested -- previously, they were skipped much more often than not. Reported by: jlduran Reviewed by: jlduran, markj Differential Revision: https://reviews.freebsd.org/D49237
* libc: tests: allow fortified test cases to require rootKyle Evans2025-03-2012-371/+1482
| | | | | | | | | | | | | An upcoming test will require root to create a jail with its own domainname/hostname to avoid external requirements on the test runner as we want to fetch them with valid and plausible sizes. Generate test headers for all cases to reduce churn in future diffs as metadata is added to individual tests, or in case other test options are added to correspond to different metadata to set. Reviewed by: jlduran, markj Differential Revision: https://reviews.freebsd.org/D49236