Commit graph

140 commits

Author SHA1 Message Date
Thomas Weißschuh
4a40129087 selftests/nolibc: correctly report errors from printf() and friends
When an error is encountered by printf() it needs to be reported.
errno() is already set by the callback.

sprintf() is different, but that keeps working and is already tested.

Also add a new test.

Fixes: 7e4346f4a3 ("tools/nolibc/stdio: add a minimal [vf]printf() implementation")
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250704-nolibc-printf-error-v1-2-74b7a092433b@linutronix.de
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-07-06 11:02:40 +02:00
Thomas Weißschuh
2b1ed5f7f8 selftests/nolibc: create /dev/full when running as PID 1
An upcoming testcase will use /dev/full.

Make sure it is always present.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250704-nolibc-printf-error-v1-1-74b7a092433b@linutronix.de
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-07-06 11:02:39 +02:00
Thomas Weißschuh
7c02bc4088 tools/nolibc: add support for clock_nanosleep() and nanosleep()
Also add some tests.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250704-nolibc-nanosleep-v1-1-d79c19701952@linutronix.de
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-07-06 11:02:38 +02:00
Mark Brown
696bf15792 selftests/nolibc: Add coverage of vfork()
Generalise the existing fork() test to also cover the newly added vfork()
implementation.

Signed-off-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20250703-arm64-gcs-vfork-exit-v3-4-1e9a9d2ddbbe@kernel.org
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-07-04 13:26:13 +02:00
Thomas Weißschuh
fb1cacdbac selftests/nolibc: avoid GCC 15 -Wunterminated-string-initialization
On GCC 15 the following warnings is emitted:

nolibc-test.c: In function ‘run_stdlib’:
nolibc-test.c:1416:32: warning: initializer-string for array of ‘char’ truncates NUL terminator but destination lacks ‘nonstring’ attribute (11 chars into 10 available) [-Wunterminated-string-initialization]
 1416 |                 char buf[10] = "test123456";
      |                                ^~~~~~~~~~~~

Increase the size of buf to avoid the warning.

It would also be possible to use __attribute__((nonstring)) but that
would require some ifdeffery to work with older compilers.

Fixes: 1063649cf5 ("selftests/nolibc: Add tests for strlcat() and strlcpy()")
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250623-nolibc-nonstring-v1-1-11282204766a@weissschuh.net
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-06-23 23:49:07 +02:00
Thomas Weißschuh
2011097c17 selftests/nolibc: drop include guards around standard headers
Nolibc now provides all the headers required by nolibc-test.c.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/r/20250515-nolibc-sys-v1-9-74f82eea3b59@weissschuh.net
Acked-by: Willy Tarreau <w@1wt.eu>
2025-05-21 15:32:27 +02:00
Thomas Weißschuh
a009a0c6fa tools/nolibc: add fopen()
This is used in various selftests and will be handy when integrating
those with nolibc.

Only the standard POSIX modes are supported.
No extensions nor the (noop) "b" from ISO C are accepted.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250428-nolibc-misc-v2-13-3c043eeab06c@linutronix.de
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-05-21 15:32:14 +02:00
Thomas Weißschuh
256dc7339d tools/nolibc: add namespace functionality
This is used in various selftests and will be handy when integrating
those with nolibc.

Not all configurations support namespaces, so skip the tests where
necessary.  Also if the tests are running without privileges.
Enable the namespace configuration for those architectures where it is not
enabled by default.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250428-nolibc-misc-v2-12-3c043eeab06c@linutronix.de
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-05-21 15:32:12 +02:00
Thomas Weißschuh
7ff3c71a47 tools/nolibc: add difftime()
This is used in various selftests and will be handy when integrating
those with nolibc.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250428-nolibc-misc-v2-11-3c043eeab06c@linutronix.de
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-05-21 15:32:12 +02:00
Thomas Weißschuh
da69cfb17b tools/nolibc: add timerfd functionality
This is used in various selftests and will be handy when integrating
those with nolibc.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250428-nolibc-misc-v2-10-3c043eeab06c@linutronix.de
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-05-21 15:32:10 +02:00
Thomas Weißschuh
fa7bf84486 tools/nolibc: add timer functions
This is used in various selftests and will be handy when integrating
those with nolibc.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250428-nolibc-misc-v2-9-3c043eeab06c@linutronix.de
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-05-21 15:32:09 +02:00
Thomas Weißschuh
50647213e1 tools/nolibc: add clock_getres(), clock_gettime() and clock_settime()
This is used in various selftests and will be handy when integrating
those with nolibc.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250428-nolibc-misc-v2-8-3c043eeab06c@linutronix.de
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-05-21 15:32:07 +02:00
Thomas Weißschuh
1e10b8534f tools/nolibc: add support for access() and faccessat()
This is used in various selftests and will be handy when integrating
those with nolibc.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250428-nolibc-misc-v2-7-3c043eeab06c@linutronix.de
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-05-21 15:32:06 +02:00
Thomas Weißschuh
bf5e8a78be tools/nolibc: add abs() and friends
This is used in various selftests and will be handy when integrating
those with nolibc.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250428-nolibc-misc-v2-6-3c043eeab06c@linutronix.de
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-05-21 15:32:05 +02:00
Thomas Weißschuh
801f020b5f tools/nolibc: add getrandom()
This is used in various selftests and will be handy when integrating
those with nolibc.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250428-nolibc-misc-v2-5-3c043eeab06c@linutronix.de
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-05-21 15:32:04 +02:00
Thomas Weißschuh
55175d8659 tools/nolibc: add mremap()
This is used in various selftests and will be handy when integrating
those with nolibc.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250428-nolibc-misc-v2-4-3c043eeab06c@linutronix.de
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-05-21 15:32:03 +02:00
Thomas Weißschuh
7a7cd445d9 tools/nolibc: add %m printf format
The %m format can be used to format the current errno.
It is non-standard but supported by other commonly used libcs like glibc and
musl, so applications do rely on them.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250428-nolibc-misc-v2-2-3c043eeab06c@linutronix.de
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-05-21 15:32:01 +02:00
Thomas Weißschuh
05b6b2a9ef tools/nolibc: add strstr()
This is used in various selftests and will be handy when integrating
those with nolibc.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250428-nolibc-misc-v2-1-3c043eeab06c@linutronix.de
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-05-21 15:32:00 +02:00
Thomas Weißschuh
e90ce42e81 tools/nolibc: implement width padding in printf()
printf can pad each argument to a certain width.
Implement this for compatibility with the kselftest harness.
Currently only padding with spaces is supported.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
2025-04-22 10:59:06 +02:00
Thomas Weißschuh
b0bd7760df selftests/nolibc: add test for snprintf() truncation
Now that we have a proper snprintf() implementation,
make sure truncation is handled properly.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
2025-04-22 10:59:06 +02:00
Thomas Weißschuh
6311e4893a selftests/nolibc: rename vfprintf test suite
With the addition of snprintf() and its usage in nolibc-test, the name of
the "vfprintf" test suite is not accurate anymore.

Rename the suite to be more generic.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
2025-04-22 10:59:05 +02:00
Thomas Weißschuh
c685cd6db5 selftests/nolibc: use snprintf() for printf tests
With a proper snprintf() implementation in place, the ugly pipe usage is
not necessary anymore.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
2025-04-22 10:59:04 +02:00
Thomas Weißschuh
4175b55845 Revert "selftests/nolibc: use waitid() over waitpid()"
nolibc's waitpid() now uses the waitid() syscall internally.
This removes the original reasoning for the reverted commit as
waitpid() is now available on all platforms and has an easier interface.

Switch back to waitpid().

This reverts commit a0bc8947ac.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
2025-04-22 10:58:22 +02:00
Thomas Weißschuh
9b070d97d9 tools/nolibc: add tolower() and toupper()
The kselftest harness uses these functions.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
2025-04-22 10:56:26 +02:00
Thomas Weißschuh
4c99fbc6a0 tools/nolibc: handle intmax_t/uintmax_t in printf
In nolibc intmax_t and uintmax_t are always the same as
(unsigned) long long/uint64_t as 128bit numbers are not supported.
Even libcs that do support 128bit numbers often fix intmax_t to 64bit
as it is used in ABIs and any change would break those.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
2025-04-22 10:56:23 +02:00
Thomas Weißschuh
6478251f95 selftests/nolibc: disable ubsan for smash_stack()
smash_stack() intentionally crashes.

Prevent UBSAN from tripping over it.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250419-nolibc-ubsan-v2-6-060b8a016917@weissschuh.net
2025-04-19 14:18:11 +02:00
Thomas Weißschuh
5f40eef1c7 selftests/nolibc: drop unnecessary sys/io.h include
The include of sys/io.h is not necessary anymore since
commit 67eb617a8e ("selftests/nolibc: simplify call to ioperm").
It's existence is also problematic as the header does not exist on all
architectures.

Reported-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250324-nolibc-ioperm-v1-1-8a7cfb2876ae@weissschuh.net
2025-04-10 22:02:30 +02:00
Thomas Weißschuh
a782d45c86 selftests/nolibc: stop testing constructor order
The execution order of constructors in undefined and depends on the
toolchain.  While recent toolchains seems to have a stable order, it
doesn't work for older ones and may also change at any time.

Stop validating the order and instead only validate that all
constructors are executed.

Reported-by: Willy Tarreau <w@1wt.eu>
Closes: https://lore.kernel.org/lkml/20250301110735.GA18621@1wt.eu/
Link: https://lore.kernel.org/r/20250306-nolibc-constructor-order-v1-1-68fd161cc5ec@weissschuh.net
Acked-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-03-07 07:34:12 +01:00
Louis Taylor
6e406202a4 selftests/nolibc: use O_RDONLY flag instead of 0
This doesn't matter much, but is what the standard says.

Signed-off-by: Louis Taylor <louis@kragniz.eu>
Link: https://lore.kernel.org/r/20250306184147.208723-5-louis@kragniz.eu
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-03-06 22:30:21 +01:00
Louis Taylor
b2edaad7f5 tools/nolibc: add support for openat(2)
openat is useful to avoid needing to construct relative paths, so expose
a wrapper for using it directly.

Signed-off-by: Louis Taylor <louis@kragniz.eu>
Link: https://lore.kernel.org/r/20250306184147.208723-1-louis@kragniz.eu
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-03-06 22:30:20 +01:00
Thomas Weißschuh
22edf1f8d4 tools/nolibc: add support for [v]sscanf()
These functions are used often, also in selftests.
sscanf() itself is also used by kselftest.h itself.

The implementation is limited and only supports numeric arguments.

Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250209-nolibc-scanf-v2-1-c29dea32f1cd@weissschuh.net
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-02-26 22:13:48 +01:00
Thomas Weißschuh
00ddf4cc97 selftests/nolibc: only run constructor tests on nolibc
The nolibc testsuite can be run against other libcs to test for
interoperability. Some aspects of the constructor execution are not
standardized and musl does not provide all tested feature, for one it
does not provide arguments to the constructors, anymore?

Skip the constructor tests on non-nolibc configurations.

Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250212-nolibc-test-constructor-v1-1-c963875b3da4@weissschuh.net
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-02-20 22:04:12 +01:00
Thomas Weißschuh
665fa8dea9 tools/nolibc: add support for directory access
Add an implementation for directory access operations.
To keep nolibc itself allocation-free, a "DIR *" does not point to any
data, but directly encodes a filedescriptor number, equivalent to "FILE *".
Without any per-directory storage it is not possible to implement
readdir() POSIX confirming. Instead only readdir_r() is provided.
While readdir_r() is deprecated in glibc, the reasons for that are
not applicable to nolibc.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Link: https://lore.kernel.org/r/20250209-nolibc-dir-v2-2-57cc1da8558b@weissschuh.net
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-02-09 16:46:50 +01:00
Thomas Weißschuh
69ccba67d7 selftests/nolibc: ignore -Wmissing-prototypes
To make sure nolibc itself is compatible with -Wmissing-prototypes the
compiler flag should be enabled when building nolibc-test.
However some of its functions are non-static to ease debugging [0],
triggering the compiler warning.

Disable the warning inside nolibc-test while still enabling it for
nolibc itself.

[0] https://lore.kernel.org/lkml/ZMjM0UPRAqoC+goY@1wt.eu/

Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250123-nolibc-prototype-v1-2-e1afc5c1999a@weissschuh.net
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-02-03 20:57:38 +01:00
Thomas Weißschuh
349afc8a52 selftests/nolibc: skip tests for unimplemented syscalls
The riscv32 architecture is missing many of the older syscalls.
Instead of providing wrappers for everything at once, introducing a lot
of complexity, skip the tests for those syscalls for now.

Link: https://lore.kernel.org/r/20241221-nolibc-rv32-v1-4-d9ef6dab7c63@weissschuh.net
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-01-13 22:21:34 +01:00
Thomas Weißschuh
4c7f09ab79 selftests/nolibc: use a pipe to in vfprintf tests
Not all architectures implement lseek(), for example riscv32 only
implements llseek() which is not equivalent to normal lseek().
Remove the need for lseek() by using a pipe instead.

Link: https://lore.kernel.org/r/20241221-nolibc-rv32-v1-3-d9ef6dab7c63@weissschuh.net
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-01-13 22:21:34 +01:00
Thomas Weißschuh
a0bc8947ac selftests/nolibc: use waitid() over waitpid()
Newer archs like riscv32 don't provide waitpid() anymore.
Switch to waitid() which is available everywhere.

Link: https://lore.kernel.org/r/20241221-nolibc-rv32-v1-2-d9ef6dab7c63@weissschuh.net
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-01-13 22:21:34 +01:00
Thomas Weißschuh
f1a58f61d8 selftests/nolibc: avoid passing NULL to printf("%s")
Clang on higher optimization levels detects that NULL is passed to
printf("%s") and warns about it.
While printf() from nolibc gracefully handles that NULL,
it is undefined behavior as per POSIX, so the warning is reasonable.
Avoid the warning by transforming NULL into a non-NULL placeholder.

Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20240807-nolibc-llvm-v2-8-c20f2f5fc7c2@weissschuh.net
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2024-08-12 22:22:13 +02:00
Thomas Weißschuh
754283ce83 tools/nolibc: pass argc, argv and envp to constructors
Since 2005 glibc has passed argc, argv, and envp to all constructors.
As it is cheap and easy to do so, mirror that behaviour in nolibc.
This makes it easier to migrate applications to nolibc.

Link: https://lore.kernel.org/r/20240728-nolibc-constructor-args-v1-1-36d0bf5cd4c0@weissschuh.net
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2024-08-09 07:40:18 +02:00
Thomas Weißschuh
d20d0b10f8 tools/nolibc: implement strerror()
strerror() is commonly used.
For example in kselftest which currently needs to do an #ifdef NOLIBC to
handle the lack of strerror().

Keep it simple and reuse the output format of perror() for strerror().

Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2024-06-29 09:44:57 +02:00
Thomas Weißschuh
582facfa5a selftests/nolibc: introduce condition to run tests only on nolibc
Some tests only make sense on nolibc. To avoid gaps in the test numbers
do to inline "#ifdef NOLIBC", add a condition to formally skip these
tests.

Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2024-06-29 09:44:57 +02:00
Thomas Weißschuh
0cf24d36bb tools/nolibc: implement strtol() and friends
The implementation always works on uintmax_t values.

This is inefficient when only 32bit are needed.
However for all functions this only happens for strtol() on 32bit
platforms.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20240425-nolibc-strtol-v1-2-bfeef7846902@weissschuh.net
2024-06-29 09:44:55 +02:00
Thomas Weißschuh
6cada28465 selftests/nolibc: disable brk()/sbrk() tests on musl
On musl calls to brk() and sbrk() always fail with ENOMEM.
Detect this and skip the tests on musl.

Tested on glibc 2.39 and musl 1.2.5 in addition to nolibc.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20240424-nolibc-musl-brk-v1-1-b49882dd9a93@weissschuh.net
2024-06-29 09:44:53 +02:00
Thomas Weißschuh
92098b1c10 selftests/nolibc: fix printf format mismatch in expect_str_buf_eq()
Fix the following compiler warning on 32bit:

  i386-linux-gcc -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -W -Wall -Wextra -fno-stack-protector -m32 -mstack-protector-guard=global -fstack-protector-all  -o nolibc-test \
    -nostdlib -nostdinc -static -Isysroot/i386/include nolibc-test.c nolibc-test-linkage.c -lgcc
  nolibc-test.c: In function 'expect_str_buf_eq':
  nolibc-test.c:610:30: error: format '%lu' expects argument of type 'long unsigned int', but argument 2 has type 'size_t' {aka 'unsigned int'} [-Werror=format=]
    610 |         llen += printf(" = %lu <%s> ", expr, buf);
        |                            ~~^         ~~~~
        |                              |         |
        |                              |         size_t {aka unsigned int}
        |                              long unsigned int
        |                            %u

Fixes: 1063649cf5 ("selftests/nolibc: Add tests for strlcat() and strlcpy()")
Cc: stable@vger.kernel.org
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2024-06-29 09:44:53 +02:00
Thomas Weißschuh
0adab2b6b7 tools/nolibc: add support for uname(2)
All supported kernels are assumed to use struct new_utsname.
This is validated in test_uname().

uname(2) can for example be used in ksft_min_kernel_version() from the
kernels selftest framework.

Link: https://lore.kernel.org/lkml/20240412123536.GA32444@redhat.com/
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Acked-by: Willy Tarreau <w@1wt.eu>
2024-04-14 20:28:54 +02:00
Rodrigo Campos
1063649cf5 selftests/nolibc: Add tests for strlcat() and strlcpy()
I've verified that the tests matches libbsd's strlcat()/strlcpy()
implementation.

Please note that as strlcat()/strlcpy() are not part of the libc, the
tests are only compiled when using nolibc.

Signed-off-by: Rodrigo Campos <rodrigo@sdfg.com.ar>
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2024-04-10 23:19:02 +02:00
Thomas Weißschuh
d543d9ddf5 selftests/nolibc: disable coredump via setrlimit
qemu-user does has its own implementation of coredumping.
That implementation does not respect the call to
prctl(PR_SET_DUMPABLE, 0) in run_protection().
This leads to a coredump for every test run under qemu-user.

Use also setrlimit() to inhibit coredump creation which is respected by
qemu-user.

Link: https://lore.kernel.org/qemu-devel/20231115-qemu-user-dumpable-v1-2-edbe7f0fbb02@t-8ch.de/
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/lkml/20231123-nolibc-rlimit-v1-3-a428b131de2a@weissschuh.net/
Acked-by: Willy Tarreau <w@1wt.eu>
2023-12-11 22:38:37 +01:00
Thomas Weißschuh
a0bb5f88fc tools/nolibc: add support for getrlimit/setrlimit
The implementation uses the prlimit64 systemcall as that is available on
all architectures.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/lkml/20231123-nolibc-rlimit-v1-2-a428b131de2a@weissschuh.net/
Acked-by: Willy Tarreau <w@1wt.eu>
2023-12-11 22:38:35 +01:00
Thomas Weißschuh
825f404776 tools/nolibc: drop duplicated testcase ioctl_tiocinq
The same testcase is present on the line above.

Fixes: b4844fa0bd ("selftests/nolibc: implement a few tests for various syscalls")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2023-12-11 22:38:33 +01:00
Thomas Weißschuh
b9e64724cd selftests/nolibc: make result alignment more robust
Move the check of the existing length into the function so it can't be
forgotten by the caller.

Also hardcode the padding character as only spaces are ever used.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2023-12-11 22:38:31 +01:00