aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/tests/string
Commit message (Collapse)AuthorAgeFilesLines
* libc: Have memcmp test what the standard requiresEd Maste2025-09-131-6/+6
| | | | | | | | | | | | | | | | libc's C memcmp currently returns the difference in byte values rather than just -1/0/1 as the AArch64 assembly implementation, many non- FreeBSD implementations, and compiler built-in optimizations do. It is a bug for a user to expect memcmp to return the difference in the byte values as the compiler is free to inline memcmp() with an implementation that does not do this. Change the test to validate only what the standard requires. PR: 289084 Reviewed by: markj, fuz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D52502
* lib/libc/tests/string: add test for strnlen()Strahinja Stanišić2024-10-152-0/+142
| | | | | | | | | | Tests for strnlen, checks alignments from up to 16 and buffer sizes up to 64, also checks that passing SIZE_MAX as maxlen works, because it can cause a wraparound error if strnlen is incorrect. Reviewed by: fuz, emaste (GSoC mentors), kib Sponsored by: Google LLC (GSoC 2024) Differential Revision: https://reviews.freebsd.org/D46275
* lib/libc/tests/string: improve memccpy "bounds" unit testRobert Clausecker2024-09-141-13/+37
| | | | | | | | | | | | | | | | | | The purpose of the "bounds" test is to check that the function does not overread the array bounds. The old unit test, copied from the strlcpy() one, always ensured that we see the character c memccpy() is looking for in the source array before the array ends. While this is correct for strlcpy(), memccpy()'s specification does not guarantee that c is present within the given size limit. The updated test handles this case better, ensuring that the source array ends early if c is not supposed to be present. Reported by: getz Approved by: emaste See also: D46052 Event: GSoC 2024 Differential Revision: https://reviews.freebsd.org/D46051
* Remove residual blank line at start of MakefileWarner Losh2024-07-151-1/+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: Add memset test for int-to-char conversionStrahinja Stanišić2024-07-132-0/+31
| | | | | | | | | | Test case to check if an implementation of memset correctly handles the value passed being wider than a byte Approved by: emaste Reviewed By: fuz (GSoC mentor), emaste Sponsored by: Google LLC (GSoC 2024) Differential Revision: https://reviews.freebsd.org/D45738
* lib/libc/tests/string: add memrchr unit testsRobert Clausecker2023-12-252-0/+117
| | | | | | | | | | | | The "values" test case is specifically crafted to detect the off-by-one error previous discovered in the scalar strchrnul implementation. Tested by: developers@, exp-run Approved by: mjg MFC after: 1 month MFC to: stable/14 PR: 275785 Differential Revision: https://reviews.freebsd.org/D42925
* lib/libc/tests/string: add unit tests for memccpy()Robert Clausecker2023-12-252-0/+206
| | | | | | | | | | Adapted from the strlcpy() unit tests. Tested by: developers@, exp-run Approved by: mjg MFC after: 1 month MFC to: stable/14 PR: 275785
* lib/libc/tests/string: add unit test for strlcpyRobert Clausecker2023-12-252-0/+184
| | | | | | | | | | | | A straightforward derivation from the stpncpy unit test. Sponsored by: The FreeBSD Foundation Tested by: developers@, exp-run Approved by: mjg MFC after: 1 month MFC to: stable/14 PR: 275785 Differential Revision: https://reviews.freebsd.org/D42863
* lib/libc/tests/string/stpncpy_test.c: extend for upcoming SSE implementationRobert Clausecker2023-12-251-14/+85
| | | | | | | | | | | | | | | | | This adds additional unit tests validating the function for All possible alignment offsets of source and destination. Also extend the test to allow testing of an external stpncpy implementation, which greatly simplifies the development of custom implementations. Sponsored by: The FreeBSD Foundation Tested by: developers@, exp-run Approved by: mjg MFC after: 1 month MFC to: stable/14 PR: 275785 Differential Revision: https://reviews.freebsd.org/D42519
* lib/libc/tests/string: add unit tests for strncmp(3)Robert Clausecker2023-12-252-0/+166
| | | | | | | | | | | | | | These are patterned after the previously added (D41970) strcmp tests, but are extended to check for various length conditions. Sponsored by: The FreeBSD Foundation Tested by: developers@, exp-run Approved by: mjg MFC after: 1 month MFC to: stable/14 PR: 275785 Differential Revision: https://reviews.freebsd.org/D42122
* lib/libc/tests/string/strcspn_test.c: add test for correct match orderRobert Clausecker2023-12-211-1/+50
| | | | | | | | | | This new unit test verifies that if there are multiple matches, the first match is returned, ignoring later matches. Approved by: mjg (blanket, via IRC) MFC after: 1 week MFC to: stable/14
* lib/libc/tests/string: add extended unit tests for strcmp()Robert Clausecker2023-11-142-0/+134
| | | | | | | | | | | This changeset add a new set of tests that comprehensively test strcmp() on various alignments of the input. This made it easy to smoke out many exciting new bugs in the new SSE strcmp() implementation from D41971. MFC after: 1 week Reviewed by: ngie Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D41970
* libc: Purge unneeded cdefs.hWarner Losh2023-11-0110-10/+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
* lib/libc/tests/string: expand memcmp test to bcmp, timingsafe_{b,mem}cmpRobert Clausecker2023-10-025-26/+155
| | | | | | | | | | | | The four functions more or less perform the same operation. Reuse the same unit test with slight changes so we can cover them all. Constant-time operation is not verified for the timingsafe_* functions. Sponsored by: The FreeBSD Foundation Approved by: ngie MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D41528
* lib/libc/tests/string/memcmp_test.c: extend test to support custom memcmp ↵Robert Clausecker2023-10-021-24/+33
| | | | | | | | | | | | | | | | | function Extend the tests to permit loading an external memcmp function and testing it over using the libc version. This was added by the example of other tests in the test suite doing the same thing and helped tremendously in development. This change was originally part of D41442 but was taken out to permit separate review as extrapolated from @ngie's request in D41349. Sponsored by: FreeBSD Foundation Approved by: ngie Differential Revision: https://reviews.freebsd.org/D41528
* lib/libc/tests/string/strcspn_test.c: extend tests to catch previous bugRobert Clausecker2023-09-171-0/+64
| | | | | | | | | | | | This extends the strcspn() unit tests to catch mistakes in the implementation that only appear when a mismatch occurs in a certain position of the string against a certain position of the set. See also: 52d4a4d4e0dedc72bc33082a3f84c2d0fd6f2cbb Sponsored by: The FreeBSD Foundation Approved by: imp MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D41821
* lib/libc/tests/string: derive strspn(3) tests from strcspn(3) testsRobert Clausecker2023-09-083-4/+54
| | | | | | | | | | | To cover the new optimised amd64 strspn(3) SIMD implementation, extend the previously written strcspn(3) unit test to also cover strspn(3). Sponsored by: The FreeBSD Foundation Approved by: mjg MFC after: 1 week MFC to: stable/14 Differential Revision: https://reviews.freebsd.org/D41567
* lib/libc/tests/string: add unit tests for strcspn(3)Robert Clausecker2023-09-082-1/+138
| | | | | | | | | | | | | We currently use the NetBSD test suite to cover strcspn(3). It only contains a very rudimentary test of this function. This all new set of unit tests for the FreeBSD test suite should cover many more edge cases relating to alignment issues. Sponsored by: The FreeBSD Foundation Approved by: mjg MFC after: 1 week MFC to: stable/14 Differential Revision: https://reviews.freebsd.org/D41557
* Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-162-2/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-167-14/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-161-2/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* lib/libc/tests/string: add unit tests for ffs, ffsl, ffsll, fls, flsl, and flsllRobert Clausecker2023-07-037-0/+313
| | | | | | | | | | Also supply CFLAGS+=-fno-builtin to ensure our unit tests actually test libc functions and not clang's builtins. Sponsored by: FreeBSD Foundation Approved by: kevans MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D40729
* libc: Add tests for strchrnul(3).Dag-Erling Smørgrav2023-02-021-0/+1
| | | | | | | MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D38286
* libc: Add strverscmp(3) and versionsort(3)Aymeric Wibo2022-08-252-2/+96
| | | | | | | | | | | | | | | Add a strverscmp(3) function to libc, a GNU extension I implemented by reading its glibc manual page. It orders strings following a much more natural ordering (e.g. "ent1 < ent2 < ent10" as opposed to "ent1 < ent10 < ent2" with strcmp(3)'s lexicographic ordering). Also add versionsort(3) for use as scandir(3)'s compar argument. Update manual page for scandir(3) and add one for strverscmp(3). Reviewed by: pstef, gbe, kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D35807
* Have stpncpy tests ask the kernel for the page sizeAndrew Turner2022-04-072-10/+16
| | | | | It may be dynamic so we can't rely on PAGE_SIZE being present or correct.
* Avoid copying too much from the input string.Brooks Davis2019-07-191-1/+1
| | | | | | | | | | | | | | This avoids reading past the end of the static strings. On a system with bounds checking these tests fault. Reviewed by: asomers Obtained from: CheriBSD MFC after: 1 week Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D21004 Notes: svn path=/head/; revision=350160
* DIRDEPS_BUILD: Update dependencies.Bryan Drewery2017-10-311-1/+0
| | | | | | | Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=325188
* Improve standard compliance for memset_s() and abort_handler_s().Konstantin Belousov2017-08-121-2/+7
| | | | | | | | | | | | | | | | | | | | abort_handler_s() currently simply calls abort(), though the standard specifies more: "Writes an implementation-defined message to stderr which must include the string pointed to by msg and calls abort()." memset_s() is missing error condition "n > smax", and does not invoke the constraint handler after filling the buffer: "following errors are detected at runtime and call the currently installed constraint handler function after storing ch in every location of the destination range [dest, dest+destsz) if dest and destsz are themselves valid", one of the errors is "n > smax" itself. Submitted by: Yuri Pankov <yuripv@gmx.com> MFC after: 1 week Differential revision: https://reviews.freebsd.org/D11991 Notes: svn path=/head/; revision=322427
* Fix strcoll_l disagreeing with strxfrm by reworking the forward order case inBaptiste Daroussin2017-04-161-0/+93
| | | | | | | | | | | | | | | | | | | | wcscoll_l(). Illumos fixed this while grabbing back our patches: https://www.illumos.org/rb/r/402/ This does not 100% fix what postgresql folks reported as there is still a remaining issue: https://www.illumos.org/issues/7962, it improves the situation The initial issue was reported in postgresql mailing lists: https://www.postgresql.org/message-id/flat/111D0E27-A8F3-4A84-A4E0-B0FB703863DF@s24.com#111D0E27-A8F3-4A84-A4E0-B0FB703863DF@s24.com Submitted by: Yuri Pankov <yuri.pankov@nexenta.com> Obtained from: Illumos MFC after: 2 weeks Notes: svn path=/head/; revision=317034
* Implement the memset_s(3) function as specified by the C11 ISO/IECKonstantin Belousov2017-03-302-0/+196
| | | | | | | | | | | | | | | | | 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
* Add a regression test to make sure the Russian collation is actually workingBaptiste Daroussin2016-07-152-0/+64
| | | | | | | | | | | | | | | when importing collation support from Dragonfly/Illumos amdmi3@ tested the collation branch and reported an issue with Russian collation. John Marino fixed the issue in Dragonfly and I merged it back to FreeBSD. Now that Illumos is working on merging our fixes they (Lauri Tirkkonen) found issues with the commit that fixes the russian collation in UTF-8 that resulted in a crash with strxfrm(3) and the ISO-8859-5 locale (fixed in FreeBSD r302916). This small test was written to ensure we do not bring back the old issue with russian collation while fixing the other issue. Notes: svn path=/head/; revision=302920
* Add a regression test about the crash with strxfrm and ISO8859-5 localesBaptiste Daroussin2016-07-152-0/+52
| | | | Notes: svn path=/head/; revision=302918
* Merge ^/user/ngie/release-pkg-fix-tests to unbreak how test files are installedEnji Cooper2016-05-041-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | after r298107 Summary of changes: - Replace all instances of FILES/TESTS with ${PACKAGE}FILES. This ensures that namespacing is kept with FILES appropriately, and that this shouldn't need to be repeated if the namespace changes -- only the definition of PACKAGE needs to be changed - Allow PACKAGE to be overridden by callers instead of forcing it to always be `tests`. In the event we get to the point where things can be split up enough in the base system, it would make more sense to group the tests with the blocks they're a part of, e.g. byacc with byacc-tests, etc - Remove PACKAGE definitions where possible, i.e. where FILES wasn't used previously. - Remove unnecessary TESTSPACKAGE definitions; this has been elided into bsd.tests.mk - Remove unnecessary BINDIRs used previously with ${PACKAGE}FILES; ${PACKAGE}FILESDIR is now automatically defined in bsd.test.mk. - Fix installation of files under data/ subdirectories in lib/libc/tests/hash and lib/libc/tests/net/getaddrinfo - Remove unnecessary .include <bsd.own.mk>s (some opportunistic cleanup) Document the proposed changes in share/examples/tests/tests/... via examples so it's clear that ${PACKAGES}FILES is the suggested way forward in terms of replacing FILES. share/mk/bsd.README didn't seem like the appropriate method of communicating that info. MFC after: never probably X-MFC with: r298107 PR: 209114 Relnotes: yes Tested with: buildworld, installworld, checkworld; buildworld, packageworld Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=299094
* MFHGlen Barber2016-03-101-0/+21
|\ | | | | | | | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/projects/release-pkg/; revision=296625
| * DIRDEPS_BUILD: Connect MK_TESTS.Bryan Drewery2016-03-091-0/+21
| | | | | | | | | | | | | | Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=296587
* | MFHGlen Barber2016-03-072-0/+125
|\| | | | | | | | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/projects/release-pkg/; revision=296457
| * libc: Add some tests for memcmp().Jilles Tjoelker2016-03-062-0/+125
| | | | | | | | Notes: svn path=/head/; revision=296434
* | First pass to fix the 'tests' packages.Glen Barber2016-02-021-0/+4
|/ | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/projects/release-pkg/; revision=295171
* Fix LDADD/DPADD that should be LIBADD.Bryan Drewery2015-12-041-5/+2
| | | | | | | Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=291738
* Integrate tools/regression/lib/libc/string into the FreeBSD test suiteEnji Cooper2015-11-085-1/+554
| | | | | | | | | | as lib/libc/tests/string MFC after: 1 week Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=290539
* Add _test suffix to multiple tests in lib/libc to conform to the design notedEnji Cooper2015-11-021-19/+19
| | | | | | | | | | in the FreeBSD Test Suite wiki MFC after: 3 days Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=290255
* Refactor the test/ Makefiles after recent changes to bsd.test.mk (r289158) andEnji Cooper2015-10-121-2/+0
| | | | | | | | | | | | | | | netbsd-tests.test.mk (r289151) - Eliminate explicit OBJTOP/SRCTOP setting - Convert all ad hoc NetBSD test integration over to netbsd-tests.test.mk - Remove unnecessary TESTSDIR setting - Use SRCTOP where possible for clarity MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Divison Notes: svn path=/head/; revision=289172
* Add reachover Makefiles for contrib/netbsd-tests/lib/libc; this adds ↵Enji Cooper2014-11-041-0/+33
approximately 500 new testcases Various TODOs have been sprinkled around the Makefiles for items that even need to be ported (missing features), testcases have issues with building/linking, or issues at runtime. A variant of this code has been tested extensively on amd64 and i386 10-STABLE/11-CURRENT for several months without issue. It builds on other architectures, but the code will remain off until I have prove it works on virtual hardware or real hardware on other architectures In collaboration with: pho, Casey Peel <casey.peel@isilon.com> Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=274075