aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/tests/stdlib
Commit message (Collapse)AuthorAgeFilesLines
* 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: Add getenv_r() function.Dag-Erling Smørgrav2025-04-272-0/+70
| | | | | | | | | | 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-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-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | 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
* 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
* 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
* libc tests: Add some test cases for recursive exitingMark Johnston2024-08-072-0/+70
| | | | | | | | | Derived from tests posted by kib in D46108. I made one of them use a pthread barrier instead of sleeping. Reviewed by: kib MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D46176
* libc tests: Rename the quick_exit test file, fix styleMark Johnston2024-08-072-8/+12
| | | | | | | | Call it libc_exit_test instead of exit_test because the NetBSD test suite already has a file with the latter name. This is in preparation for adding other exit()-related tests. MFC after: 2 weeks
* Remove residual blank line at start of MakefileWarner Losh2024-07-152-2/+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
* pkgbase: install all libc test files into the tests packageBaptiste Daroussin2024-03-201-0/+1
|
* libc: Purge unneeded cdefs.hWarner Losh2023-11-0114-14/+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
* libc: Add a rudimentary test for quick_exit(3).Dag-Erling Smørgrav2023-09-262-0/+82
| | | | | | Sponsored by: Klara, Inc. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D41937
* Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-163-3/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-1614-28/+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-121-1/+1
| | | | | | | | | 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
* strfmon_l: Use specified locale for number formattingJose Luis Duran2022-10-291-2/+2
| | | | | | | | | | | | | strfmon_l does not take fully into consideration the explicitly passed locale to perform the formatting. Parallel universe bug report: https://sourceware.org/bugzilla/show_bug.cgi?id=19633 Obtained from: Darwin Reviewed by: kib PR: 267410 Github PR: #620 MFC after: 1 week
* strfmon_test: Add a test for strfmon_lJose Luis Duran2022-10-291-0/+33
| | | | | | | | | | | | | Attempt to test the correctness of strfmon_l(3). Items marked with XXX represent an invalid output. Obtained from: https://github.com/NetBSD/src/commit/e7eba0044fe6128291cbb7e5923c7cf7d87318cc Reviewed by: kib PR: 267410 Github PR: #620 MFC after: 1 week
* strfmon_test: Reserve space for the null terminatorJose Luis Duran2022-10-291-5/+5
| | | | | | | | | | | | Otherwise strfmon(3) could overflow the buffer. Here is mostly done for correctness and illustrative purposes, as there is no chance it could actually happen. Reviewed by: kib PR: 267410 Github PR: #620 MFC after: 1 week
* strfmon: Fix formatting of a second fixed-width valueJose Luis Duran2022-10-251-1/+1
| | | | | | | | | | | | | | There is a bug when formatting two consecutive values using fixed-widths and the values need padding. This was because the value of pad_size was zeroed only every other time. Format Before After [%8n] [%8n] [ $123.45] [ $123.45] [ $123.45] [ $123.45] Reviewed by: kib PR: 267282 Github PR: #619 MFC after: 1 week
* strfmon: Fix an edge case when sep_by_space is 2Jose Luis Duran2022-10-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix an edge case by printing the required space when, the currency symbol succeeds the value, a space separates the sign from the value and the sign position precedes the quantity and the currency symbol. In other words: n_cs_precedes = 0 n_sep_by_space = 2 n_sign_posn = 1 From The Open Group's localeconv[1]: > When {p,n,int_p,int_n}_sep_by_space is 2: > If the currency symbol and sign string are adjacent, a space separates > them; otherwise, a space separates the sign string from the value. Format Before After [%n] [-123.45¤] [- 123.45¤] [1]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/localeconv.html Obtained from: Darwin Reviewed by: kib PR: 267282 Github PR: #619 MFC after: 1 week
* strfmon: Fix alignment when enclosed by parenthesesJose Luis Duran2022-10-251-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Take into consideration the possibility of quantities enclosed by parentheses when aligning. Matches the examples from The Open Group's: Format Before After %(#5n [$ 123.45] [ $ 123.45 ] Use an alternative pos/neg style [($ 123.45)] [($ 123.45)] [$ 3,456.78] [ $ 3,456.78 ] %!(#5n [ 123.45] [ 123.45 ] Disable the currency symbol [( 123.45)] [( 123.45)] [ 3,456.78] [ 3,456.78 ] https://pubs.opengroup.org/onlinepubs/9699919799/functions/strfmon.html SD5-XSH-ERN-29 is applied, updating the examples for %(#5n and %!(#5n. Obtained from: Darwin Reviewed by: kib PR: 267282 Github PR: #619 MFC after: 1 week
* strfmon: Trim the SPACE from international currency symbolJose Luis Duran2022-10-251-2/+2
| | | | | | | | | | | | | | | | | | | | | | | The international currency symbol (int_curr_symbol) has a mandatory SPACE character as the last character. Trim this space after reading it, otherwise this extra space will always be printed when displaying the int_curr_symbol. Fixes the output when the international currency format is selected (%i). Locale Format Before After en_US.UTF-8 [%i] [USD 123.45] [USD123.45] fr_FR.UTF-8 [%i] [123,45 EUR ] [123,45 EUR] Note that the en_US.UTF-8 locale states that no space should be printed between the currency symbol and the value (sep_by_space = 0). Reviewed by: kib PR: 267282 Github PR: #619 MFC after: 1 week
* strfmon: Avoid an out-of-bounds accessJose Luis Duran2022-10-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Avoid an out-of-bounds access when trying to set the space_char using an international currency format (%i) and the C/POSIX locale. The current code tries to read the SPACE from int_curr_symbol[3]: currency_symbol = strdup(lc->int_curr_symbol); space_char = *(currency_symbol+3); But on C/POSIX locales, int_curr_symbol is empty. Three implementations have been examined: NetBSD[1], Darwin[2], and Illumos[3]. Only NetBSD has fixed it[4]. Darwin and NetBSD also trim the mandatory final SPACE character after reading it. Locale Format Darwin/NetBSD FreeBSD/Illumos en_US.UTF-8 [%i] [USD123.45] [USD 123.45] fr_FR.UTF-8 [%i] [123,45 EUR] [123,45 EUR ] This commit only fixes the out-of-bounds access. [1]: https://github.com/NetBSD/src/blob/trunk/lib/libc/stdlib/strfmon.c [2]: https://opensource.apple.com/source/Libc/Libc-1439.141.1/stdlib/NetBSD/strfmon.c.auto.html [3]: https://github.com/illumos/illumos-gate/blob/master/usr/src/lib/libc/port/locale/strfmon.c [4]: https://github.com/NetBSD/src/commit/3d7b5d498aa9609f2bc9ece9c734c5f493a8e239 Reviewed by: kib PR: 267282 Github PR: #619 MFC after: 1 week
* strfmon_test: Add some testsJose Luis Duran2022-10-251-0/+151
| | | | | | | | | | | | | | Attempt to test the correctness of strfmon(3). Some of them were inspired from the examples section at: https://pubs.opengroup.org/onlinepubs/9699919799/functions/strfmon.html Items marked with XXX represent an invalid output. Reviewed by: kib PR: 267282 Github PR: #619 MFC after: 1 week
* strfmon_test: Fix typo and remove extra spaceJose Luis Duran2022-10-251-2/+2
| | | | | | | Reviewed by: kib PR: 267282 Github PR: #619 MFC after: 1 week
* qsort_b_test: Only build on clang.John Baldwin2022-10-031-0/+2
| | | | | | | GCC doesn't support -fblocks. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D36809
* Alter the prototype of qsort_r(3) to match POSIX, which adopted theEd Schouten2022-09-303-3/+96
| | | | | | | | | | | | | | | | | | | | | | | | | | | | glibc-based interface. Unfortunately, the glibc maintainers, despite knowing the existence of the FreeBSD qsort_r(3) interface in 2004 and refused to add the same interface to glibc based on grounds of the lack of standardization and portability concerns, has decided it was a good idea to introduce their own qsort_r(3) interface in 2007 as a GNU extension with a slightly different and incompatible interface. With the adoption of their interface as POSIX standard, let's switch to the same prototype, there is no need to remain incompatible. C++ and C applications written for the historical FreeBSD interface get source level compatibility when building in C++ mode, or when building with a C compiler with C11 generics support, provided that the caller passes a fifth parameter of qsort_r() that exactly matches the historical FreeBSD comparator function pointer type and does not redefine the historical qsort_r(3) prototype in their source code. Symbol versioning is used to keep old binaries working. MFC: never Relnotes: yes Reviewed by: cem, imp, hps, pauamma Differential revision: https://reviews.freebsd.org/D17083
* libc: add test case for qsort_b(3)Xin LI2022-09-072-0/+83
| | | | | | Reviewed by: markj MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D36463
* libc/tests/stdlib/dynthr_mod/dynthr_mod.c: mark dummy as usedKonstantin Belousov2021-11-291-0/+1
| | | | | | | | | It receives the malloc() result, and we do not want the malloc() call to be optimized out, which is allowed for hosted compiler. Use dummy for actual write though. Sponsored by: The FreeBSD Foundation MFC after: 1 week
* libc: fix the testMariusz Zaborski2021-11-081-1/+1
| | | | | | | Currently after cleaning the variables the environment will be always set to the intEnviron as documented in __rebuild_environ. Reported by: lwhsu@, jenkins
* libc: add clearenv functionMariusz Zaborski2021-11-072-0/+177
| | | | | | | | | | The clearenv(3) function allows us to clear all environment variable in one shot. This may be useful for security programs that want to control the environment or what variables are passed to new spawned programs. Reviewed by: scf, markj (secteam), 0mp (manpages) Differential Revision: https://reviews.freebsd.org/D28223
* Remove remaining uses of ${COMPILER_FEATURES:Mc++11}Alex Richardson2021-01-191-2/+0
| | | | | | | | | | All supported compilers have C++11 support so these checks can be replaced with MK_CXX guards. See also https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=252759 PR: 252759 Reviewed By: emaste Differential Revision: https://reviews.freebsd.org/D28234
* libc tests: dynthr_mod: fix some WARNS issuesKyle Evans2020-09-091-1/+3
| | | | | | | | | | | | | | This is being addressed as part of a side-patch I'm working on that builds all the things with WARNS=6, instead of relying on it being supplied in just shallow parts of the build with higher-level Makefile.inc. Provide a prototype for mod_main and annotate the thread function argument as unused. MFC after: 1 week Notes: svn path=/head/; revision=365494
* 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 qsort_r(3) regression test.Edward Tomasz Napierala2020-01-202-0/+93
| | | | | | | | | MFC after: 2 weeks Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D23206 Notes: svn path=/head/; revision=356910
* Add qsort_s(3). Apart from the constraints, it also makes it easierEdward Tomasz Napierala2020-01-202-0/+258
| | | | | | | | | | | | | to port software written for Linux variant of qsort_r(3). Reviewed by: kib, arichardson MFC after: 2 weeks Relnotes: yes Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D23174 Notes: svn path=/head/; revision=356909
* Unskip test cases from netbsd-tests by defining __HAVE_FENVLi-Wen Hsu2019-08-311-0/+3
| | | | | | | | | | | | | | | This unskips: - lib.libc.stdlib.strtod_test.strtod_round - lib.msun.fe_round_test.t_nofe_round In lib/msun/tests/Makefile only define on fe_round_test.c because lib.msun.ilogb_test.ilogb will get wrong results and needs more examination. MFC after: 1 week Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=351648
* Allow users to override CSTD/CXXSTD on a per-prog basisEnji Cooper2019-03-291-2/+2
| | | | | | | | | | | | | | | | | | | | | The current logic for CSTD/CXXSTD requires homogenity as far as the supported C/C++ standards, which is a sensible default. However, when dealing with differing versions of C++, some code may compile with C++11, but not C++17 (for instance). So in order to avoid having people convert over their code to the new standard, give the users the ability to specify the standard on a per-program basis. This will allow a user to override the supporting standard for a set of programs, mixing C++11 with C++14 (for instance). Reviewed by: asomers Apprved by: emaste (mentor) MFC after: 1 month MFC with: r345708 Differential Revision: https://reviews.freebsd.org/D19738 Notes: svn path=/head/; revision=345709
* Revert r345706: the third time will be the charmEnji Cooper2019-03-291-2/+2
| | | | | | | | | | | | | | | | When a review is closed via Phabricator it updates the patch attached to the review. I downloaded the raw patch from Phabricator, applied it, and repeated my mistake from r345704 by accident mixing content from D19732 and D19738. For my own personal sanity, I will try not to mix reviews like this in the future. MFC after: 1 month MFC with: r345706 Approved by: emaste (mentor, implicit) Notes: svn path=/head/; revision=345707
* Standardize `-std=c++* as `CXXSTD`Enji Cooper2019-03-291-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | CXXSTD was added as the C++ analogue to CSTD. CXXSTD defaults to `-std=c++11` with supporting compilers; `-std=gnu++98`, otherwise for older versions of g++. This change standardizes the CXXSTD variable, originally added to googletest.test.inc.mk as part of r345203. As part of this effort, convert all `CXXFLAGS+= -std=*` calls to use `CXXSTD`. Notes: This value is not sanity checked in bsd.sys.mk, however, given the two most used C++ compilers on FreeBSD (clang++ and g++) support both modes, it is likely to work with both toolchains. This method will be refined in the future to support more variants of C++, as not all versions of clang++ and g++ (for instance) support C++14, C++17, etc. Any manual appending of `-std=*` to `CXXFLAGS` should be replaced with CXXSTD. Example: Before this commit: ``` CXXFLAGS+= -std=c++14 ``` After this commit: ``` CXXSTD= c++14 ``` Reviewed by: asomers Approved by: emaste (mentor) MFC after: 1 month MFC with: r345203, r345704, r345705 Relnotes: yes Tested with: make tinderbox Differential Revision: https://reviews.freebsd.org/D19732 Notes: svn path=/head/; revision=345706
* Revert r345704Enji Cooper2019-03-291-2/+2
| | | | | | | | | | | | I accidentally committed code from two reviews. I will reintroduce the code to bsd.progs.mk as part of a separate commit from r345704. Approved by: emaste (mentor, implicit) MFC after: 2 months MFC with: r345704 Notes: svn path=/head/; revision=345705
* CXXSTD is the C++ analogue to CSTD.Enji Cooper2019-03-291-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | CXXSTD defaults to `-std=c++11` with supporting compilers; `-std=gnu++98`, otherwise for older versions of g++. This change standardizes the CXXSTD variable, originally added to googletest.test.inc.mk as part of r345203. As part of this effort, convert all `CXXFLAGS+= -std=*` calls to use `CXXSTD`. Notes: This value is not sanity checked in bsd.sys.mk, however, given the two most used C++ compilers on FreeBSD (clang++ and g++) support both modes, it is likely to work with both toolchains. This method will be refined in the future to support more variants of C++, as not all versions of clang++ and g++ (for instance) support C++14, C++17, etc. Any manual appending of `-std=*` to `CXXFLAGS` should be replaced with CXXSTD. Example: Before this commit: ``` CXXFLAGS+= -std=c++14 ``` After this commit: ``` CXXSTD= c++14 ``` Reviewed by: asomers Approved by: emaste (mentor) MFC after: 1 month Relnotes: yes Differential Revision: https://reviews.freebsd.org/D19732 Notes: svn path=/head/; revision=345704
* libc/tests: Add test case for jemalloc/libthr bug fixed in r343566Kyle Evans2019-01-314-0/+178
| | | | | | | | | | | Submitted by: Andrew Gierth (original reproducer; kevans massaged for atf) Reviewed by: kib MFC after: 2 weeks X-MFC-with: r343566 (or after) Differential Revision: https://reviews.freebsd.org/D19027 Notes: svn path=/head/; revision=343599
* Allow multi-byte thousands separators in strfmon(3)Conrad Meyer2018-12-192-0/+72
| | | | | | | | | | PR: 234010 Reported by: Jon Tejnung <jon AT herrskogen.se> Reviewed by: yuripv Differential Revision: https://reviews.freebsd.org/D18605 Notes: svn path=/head/; revision=342260
* DIRDEPS_BUILD: Update dependencies.Bryan Drewery2017-10-311-1/+0
| | | | | | | Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=325188
* tsearch_test: Test twalk & add some determinism.Will Andrews2017-06-061-1/+29
| | | | Notes: svn path=/head/; revision=319613
* Implement the memset_s(3) function as specified by the C11 ISO/IECKonstantin Belousov2017-03-302-0/+64
| | | | | | | | | | | | | | | | | 9899:2011 Appendix K 3.7.4.1. Other needed supporting types, defines and constraint_handler infrastructure is added as specified in the C11 spec. Submitted by: Tom Rix <trix@juniper.net> Sponsored by: Juniper Networks Discussed with: ed MFC after: 3 weeks Differential revision: https://reviews.freebsd.org/D9903 Differential revision: https://reviews.freebsd.org/D10161 Notes: svn path=/head/; revision=316213
* Remove __HAVE_LONG_DOUBLE #define from t_strtod.c and place it in MakefileEnji Cooper2017-01-121-0/+8
| | | | | | | | | | | This is to enable support in other testcases Inspired by lib/msun/tests/Makefile . MFC after: 1 week Notes: svn path=/head/; revision=311969
* Improve typing of POSIX search tree functions.Ed Schouten2016-10-131-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Back in 2015 when I reimplemented these functions to use an AVL tree, I was annoyed by the weakness of the typing of these functions. Both tree nodes and keys are represented by 'void *', meaning that things like the documentation for these functions are an absolute train wreck. To make things worse, users of these functions need to cast the return value of tfind()/tsearch() from 'void *' to 'type_of_key **' in order to access the key. Technically speaking such casts violate aliasing rules. I've observed actual breakages as a result of this by enabling features like LTO. I've filed a bug report at the Austin Group. Looking at the way the bug got resolved, they made a pretty good step in the right direction. A new type 'posix_tnode' has been added to correspond to tree nodes. It is still defined as 'void' for source-level compatibility, but in the very far future it could be replaced by a proper structure type containing a key pointer. MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D8205 Notes: svn path=/head/; revision=307227