Commit graph

295 commits

Author SHA1 Message Date
Mark Johnston da925fcebf libc/tests: Further refine the condition for installing h_raw
See 8164d511d6 ("libc/tests: Fix installation without MK_TOOLCHAIN")
for some background.  Here we should really be testing MK_CLANG instead,
since that's what gates compilation of libclang_rt.

Fixes:	8164d511d6 ("libc/tests: Fix installation without MK_TOOLCHAIN")
2024-06-09 10:08:31 -04:00
Mark Johnston 8164d511d6 libc/tests: Fix installation without MK_TOOLCHAIN
There is some exotic conditional logic here to avoid building a
particular test if a certain UBSAN library isn't present in the
toolchain sysroot.  This causes build failures for me when doing an
"installworld WITHOUT_TOOLCHAIN=", which I do frequently during tests.

I believe the problem is that SYSROOT is unset during installworld, so
the build sees the host's copy of libclang_rt.ubsan_standalone.a and
then tries to install a binary that wasn't built during buildworld.  Try
to make the check a bit less fragile.

Reviewed by:	dim
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D45035
2024-05-28 08:24:43 -04:00
Baptiste Daroussin 3a9ddfa1ab pkgbase: install all libc test files into the tests package 2024-03-20 17:13:56 +01:00
Konstantin Belousov 32fdcff870 libc/sys: add errno test
Despite looking trivial, it requires proper split of exports from libsys
and libc, proper filtering work in rtld, and operational libsys.

Reviewed by:	emaste, imp
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D44075
2024-02-25 22:35:17 +02:00
Brooks Davis 99ea675731 lib{c,sys}: move auxargs more firmly into libsys
Continue to filter the public interface (elf_aux_info()), but entierly
relocate the private interfaces (_elf_aux_info(),
__init_elf_aux_vector(), and __elf_aux_vector) to libsys.

This ensures that rtld updates the correct (only) copy of
__elf_aux_vector.  After 968a18975a
updates were confused and __getosreldate was failing, causing
the system to fall back to compat compat12 syscalls in some cases.

Return to explicitly linking libc to libsys and link libthr with libc
and libsys (in that order).

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D43910
2024-02-19 22:44:08 +00:00
Robert Clausecker 691ff1832e lib/libc/tests/string: add memrchr unit tests
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
2023-12-25 14:59:58 +01:00
Robert Clausecker e4b7b0bcbc lib/libc/tests/string: add unit tests for memccpy()
Adapted from the strlcpy() unit tests.

Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
2023-12-25 14:59:40 +01:00
Robert Clausecker f7098b8659 lib/libc/tests/string: add unit test for strlcpy
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
2023-12-25 14:56:02 +01:00
Robert Clausecker 6fa9e7d873 lib/libc/tests/string/stpncpy_test.c: extend for upcoming SSE implementation
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
2023-12-25 14:55:37 +01:00
Robert Clausecker 459ddefcc9 lib/libc/tests/string: add unit tests for strncmp(3)
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
2023-12-25 14:55:08 +01:00
Bill Sommerfeld 8f7ed58a15 regex: mixed sets are misidentified as singletons
Fix "singleton" function used by regcomp() to turn character set matches
into exact character matches if a character set has exactly one
element.

The underlying cset representation is complex; most critically it
records"small" characters (codepoint less than either 128
or 256 depending on locale) in a bit vector, and "wide" characters in
a secondary array.

Unfortunately the "singleton" function uses to identify singleton sets
treated a cset as a singleton if either the "small" or the "wide" sets
had exactly one element (it would then ignore the other set).

The easiest way to demonstrate this bug:

	$ export LANG=C.UTF-8
	$ echo 'a' | grep '[abà]'

It should match (and print "a") but instead it doesn't match because the
single accented character in the set is misinterpreted as a singleton.

Reviewed by:	kevans, yuripv
Obtained from:	illumos
Differential Revision:	https://reviews.freebsd.org/D43149
2023-12-22 12:19:59 +07:00
Robert Clausecker a0ecf2224e lib/libc/tests/string/strcspn_test.c: add test for correct match order
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
2023-12-21 03:16:57 +01:00
Robert Clausecker b49596de26 lib/libc/tests/string: add extended unit tests for strcmp()
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
2023-11-14 12:37:06 -05:00
Dag-Erling Smørgrav b8dbfb0a6c fflush: Add test for buffer handling in __sflush
Sponsored by:	Klara, Inc.
2023-11-07 08:21:12 -05:00
Warner Losh 559a218c9b libc: Purge unneeded cdefs.h
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
2023-11-01 16:44:30 -06:00
Robert Clausecker c6cc06d465 lib/libc/tests/string: expand memcmp test to bcmp, timingsafe_{b,mem}cmp
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
2023-10-02 15:25:31 -04:00
Robert Clausecker b166580681 lib/libc/tests/string/memcmp_test.c: extend test to support custom memcmp 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
2023-10-02 15:25:21 -04:00
Dag-Erling Smørgrav c7dd4601ae libc: Add a rudimentary test for quick_exit(3).
Sponsored by:	Klara, Inc.
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D41937
2023-09-26 22:07:10 +02:00
John Baldwin 16837d353c Remove a few more stray __FBSDID uses
Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D41954
2023-09-25 07:49:52 -07:00
Robert Clausecker 601fd768cf lib/libc/tests/string/strcspn_test.c: extend tests to catch previous bug
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:	52d4a4d4e0
Sponsored by:	The FreeBSD Foundation
Approved by:	imp
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D41821
2023-09-16 20:40:13 -04:00
Dag-Erling Smørgrav 88a9b6e1ed libc: Don't assume signed char.
MFC after:	3 days
Reviewed by:	andrew
Differential Revision:	https://reviews.freebsd.org/D41814
2023-09-11 13:18:25 +00:00
Robert Clausecker 468adddd75 lib/libc/tests/string: derive strspn(3) tests from strcspn(3) tests
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
2023-09-08 17:21:59 -04:00
Robert Clausecker 35a5359406 lib/libc/tests/string: add unit tests for strcspn(3)
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
2023-09-08 17:21:31 -04:00
Dag-Erling Smørgrav 12b1c1e3fb libc: Add test cases for N2680.
This adds test cases for %wN and %wfN to the printf(3) and scanf(3) tests.

While here, fix a few nits in the N2630 test cases.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D41743
2023-09-07 06:40:14 +00:00
Dag-Erling Smørgrav 294bd2827e libc: Suppress format checks on printf() / scanf() tests.
Reviewed by:	jrtc27, markj, emaste
Differential Revision:	https://reviews.freebsd.org/D41727
2023-09-07 06:40:14 +00:00
Dag-Erling Smørgrav 4ec9ee9912 libc: Add a wide version of snprintf_test.
Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D41726
2023-09-07 06:40:14 +00:00
Dag-Erling Smørgrav aca3bd1602 libc: Fix fixed-width case in the new integer parser.
Fixes:		d9dc1603d6
Differential Revision:	https://reviews.freebsd.org/D41622
2023-08-28 23:38:19 +00:00
Li-Wen Hsu e0752f431b
Revert "libc/locale tests: temporarily skip lib.libc.locale.c16rtomb_test.c16rtomb_utf_8_test"
This reverts commit b80572fe3b.

This has been fixed in e2030ca246.

PR:		265871
2023-08-29 01:18:42 +08: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
Warner Losh d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh 1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Warner Losh 2a63c3be15 Remove $FreeBSD$: one-line .c comment pattern
Remove /^/[*/]\s*\$FreeBSD\$.*\n/
2023-08-16 11:54:29 -06:00
Warner Losh b3e7694832 Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:16 -06:00
Robert Clausecker 49390697b9 lib/libc/tests/string: add unit tests for ffs, ffsl, ffsll, fls, flsl, and flsll
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
2023-07-03 22:18:27 +02:00
Warner Losh 4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
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
2023-05-12 10:44:03 -06:00
Yuri Pankov 269dea90d6 libc: use separate collate objects for C, POSIX, and C.UTF-8
Fix newlocale() overwriting the locale name in collate object
when same instance was used for those locales, and querylocale()
reporting unexpected value for LC_COLLATE_MASK.

PR:		255646, 269375
Reviewed by:	markj, bapt (previous version)
Differential Revision:	https://reviews.freebsd.org/D30146
2023-03-28 17:16:30 +02:00
Mark Johnston e1ccf64b88 netbsd-tests: Serialize message queue tests
They can fail when run in parallel since they all share a global queue
key.

MFC after:	1 week
2023-03-10 17:07:06 -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
Jose Luis Duran 621bf91893 strfmon_l: Use specified locale for number formatting
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
2022-10-30 00:09:11 +03:00
Jose Luis Duran 29972f06f9 strfmon_test: Add a test for strfmon_l
Attempt to test the correctness of strfmon_l(3).

Items marked with XXX represent an invalid output.

Obtained from:	e7eba0044f

Reviewed by:	kib
PR:	267410
Github PR:	#620
MFC after:	1 week
2022-10-30 00:08:54 +03:00
Jose Luis Duran edcee003e5 strfmon_test: Reserve space for the null terminator
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
2022-10-30 00:08:33 +03:00
Jose Luis Duran 34f88528ed strfmon: Fix formatting of a second fixed-width value
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
2022-10-26 00:40:17 +03:00
Jose Luis Duran 750fe3e6a4 strfmon: Fix an edge case when sep_by_space is 2
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
2022-10-26 00:40:17 +03:00
Jose Luis Duran 947efadc3d strfmon: Fix alignment when enclosed by parentheses
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
2022-10-26 00:40:17 +03:00
Jose Luis Duran 6da51e19e3 strfmon: Trim the SPACE from international currency symbol
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
2022-10-26 00:40:17 +03:00
Jose Luis Duran 9e03b903e3 strfmon: Avoid an out-of-bounds access
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]: 3d7b5d498a

Reviewed by:	kib
PR:	267282
Github PR:	#619
MFC after:	1 week
2022-10-26 00:40:17 +03:00
Jose Luis Duran 3f97d37ac5 strfmon_test: Add some tests
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
2022-10-26 00:29:26 +03:00
Jose Luis Duran f91301cc79 strfmon_test: Fix typo and remove extra space
Reviewed by:	kib
PR:	267282
Github PR:	#619
MFC after:	1 week
2022-10-26 00:28:33 +03:00
John Baldwin ab9293239c qsort_b_test: Only build on clang.
GCC doesn't support -fblocks.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D36809
2022-10-03 16:14:39 -07:00
Ed Schouten af3c78886f Alter the prototype of qsort_r(3) to match POSIX, which adopted the
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
2022-09-30 15:26:30 -07:00