Commit Graph

258 Commits

Author SHA1 Message Date
Florian Weimer
c9154cad66 support: Fix Hurd build of tst-support_readdir
Check for the availability of the d_off member at compile time, not
run time.

Fixes commit 1251e9ea49
("support: Add <support/readdir.h>").
2024-09-12 18:26:04 +02:00
Florian Weimer
1251e9ea49 support: Add <support/readdir.h>
It allows to read directories using the six readdir variants
without writing type-specific code or using skeleton files
that are compiled four times.

The readdir_r subtest for support_readdir_expect_error revealed
bug 32124.

Reviewed-by: DJ Delorie <dj@redhat.com>
2024-09-12 09:40:45 +02:00
Florian Weimer
f169509ded support: Add FUSE-based file system test framework to support/
This allows to monitor the exact file system operations
performed by glibc and inject errors.

Hurd does not have <sys/mount.h>.  To get the sources to compile
at least, the same approach as in support/test-container.c is used.

Reviewed-by: DJ Delorie <dj@redhat.com>
2024-09-05 12:05:32 +02:00
Florian Weimer
3b1d321776 support: Add <support/xdirent.h>
Use static functions for readdir/readdir_r, so that
-D_FILE_OFFSET_BITS=64 does not improperly redirect calls to the wrong
implementation.

Reviewed-by: DJ Delorie <dj@redhat.com>
2024-09-05 12:05:32 +02:00
Florian Weimer
b09a520bb6 Bundle <linux/fuse.h> userspace header from Linux 6.10
And include the required licensing information.  The only
change is a removed trailing empty line in
LICENSES/exceptions/Linux-syscall-note.

Bundling <linux/fuse.h> is the recommended way to deal with
the evolution of the FUSE userspace interface because
structs change sizes over time.  The kernel maintains
compatibility, but source-level compatibility on recompilation
may require additional code that is aware of older struct sizes.

Signed-off-by: Florian Weimer <fweimer@redhat.com>
Reviewed-by: DJ Delorie <dj@redhat.com>
2024-09-05 11:34:31 +02:00
Joseph Myers
96d0bf98ca Add support/ code for checking file contents
For use in freopen tests, add various support/ helper interfaces for
use in checking file contents.

Tested for x86_64.
2024-09-03 13:53:01 +00:00
Florian Weimer
34e52acd55 support: Report errno constants in TEST_COMPARE failures
If the expression is errno, decode it as an errno constant
using strerrorname_np.

Reviewed-by: Arjun Shankar <arjun@redhat.com>
2024-08-26 16:46:45 +02:00
Florian Weimer
e7c14e542d support: Use macros for *stat wrappers
Macros will automatically use the correct types, without
having to fiddle with internal glibc macros.  It's also
impossible to get the types wrong due to aliasing because
support_check_stat_fd and support_check_stat_path do not
depend on the struct stat* types.

The changes reveal some inconsistencies in tests.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-08-16 16:05:20 +02:00
Florian Weimer
9216905129 support: Add the xstatx function
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-08-16 16:05:19 +02:00
Florian Weimer
34bb581e77 support: Include <string.h> for strcmp in support_format_addrinfo.c
This is currently implied by the internal headers, but it makes
sense not to rely on this.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-08-16 16:05:19 +02:00
Florian Weimer
91ae020f5a support: Remove #include <config.h>
This is not needed: include/intprops.h has its own detection logic.
It makes building these files outside of glibc easer.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-08-16 16:05:19 +02:00
Florian Weimer
c2a474f461 support: Add options list terminator to the test driver
This avoids crashes if a test is passed unknown options.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-08-09 17:01:19 +02:00
Maciej W. Rozycki
1b97a9f23b support: Add FAIL test failure helper
Add a FAIL test failure helper analogous to FAIL_RET, that does not
cause the current function to return, providing a standardized way to
report a test failure with a message supplied while permitting the
caller to continue executing, for further reporting, cleaning up, etc.

Update existing test cases that provide a conflicting definition of FAIL
by removing the local FAIL definition and then as follows:

- tst-fortify-syslog: provide a meaningful message in addition to the
  file name already added by <support/check.h>; 'support_record_failure'
  is already called by 'support_print_failure_impl' invoked by the new
  FAIL test failure helper.

- tst-ctype: no update to FAIL calls required, with the name of the file
  and the line number within of the failure site additionally included
  by the new FAIL test failure helper, and error counting plus count
  reporting upon test program termination also already provided by
  'support_record_failure' and 'support_report_failure' respectively,
  called by 'support_print_failure_impl' and 'adjust_exit_status' also
  respectively.  However in a number of places 'printf' is called and
  the error count adjusted by hand, so update these places to make use
  of FAIL instead.  And last but not least adjust the final summary just
  to report completion, with any error count following as reported by
  the test driver.

- test-tgmath2: no update to FAIL calls required, with the name of the
  file of the failure site additionally included by the new FAIL test
  failure helper.  Also there is no need to track the return status by
  hand as any call to FAIL will eventually cause the test case to return
  an unsuccesful exit status regardless of the return status from the
  test function, via a call to 'adjust_exit_status' made by the test
  driver.

Reviewed-by: DJ Delorie <dj@redhat.com>
2024-07-26 13:21:34 +01:00
Florian Weimer
ca38eff280 support: Include <limits.h> for NAME_MAX use in temp_file.c 2024-06-17 15:14:05 +02:00
Florian Weimer
cb65d66104 support: Include <stdlib.h> for atoi use in support_wait_for_thread_exit 2024-06-17 15:14:05 +02:00
Avinal Kumar
54c1efdac5 support: Fix typo in xgetsockname error message
The error message in xgetsockname was incorrectly referring to a
different function.  This commit fixes that.

Suggested-by: Arjun Shankar <arjun@redhat.com>
Signed-off-by: Avinal Kumar <avinal.xlvii@gmail.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2024-06-05 09:58:55 -04:00
Adhemerval Zanella
1e1ad714ee support: Add envp argument to support_capture_subprogram
So tests can specify a list of environment variables.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2024-05-07 12:16:36 -03:00
Sergey Kolosov
6687a6e3f9 libsupport: Add xgetpeername
The patch adds redirections for getpeername.

Reviewed-by: Arjun Shankar <arjun@redhat.com>
2024-04-10 18:10:22 +02:00
Adhemerval Zanella
a4ed0471d7 Always define __USE_TIME_BITS64 when 64 bit time_t is used
It was raised on libc-help [1] that some Linux kernel interfaces expect
the libc to define __USE_TIME_BITS64 to indicate the time_t size for the
kABI.  Different than defined by the initial y2038 design document [2],
the __USE_TIME_BITS64 is only defined for ABIs that support more than
one time_t size (by defining the _TIME_BITS for each module).

The 64 bit time_t redirects are now enabled using a different internal
define (__USE_TIME64_REDIRECTS). There is no expected change in semantic
or code generation.

Checked on x86_64-linux-gnu, i686-linux-gnu, aarch64-linux-gnu, and
arm-linux-gnueabi

[1] https://sourceware.org/pipermail/libc-help/2024-January/006557.html
[2] https://sourceware.org/glibc/wiki/Y2038ProofnessDesign

Reviewed-by: DJ Delorie <dj@redhat.com>
2024-04-02 15:28:36 -03:00
Simon Chopin
59e0441d4a tests: gracefully handle AppArmor userns containment
Recent AppArmor containment allows restricting unprivileged user
namespaces, which is enabled by default on recent Ubuntu systems.
When this happens, as is common with Linux Security Modules, the syscall
will fail with -EACCESS.

When that happens, the affected tests will now be considered unsupported
rather than simply failing.

Further information:

* https://gitlab.com/apparmor/apparmor/-/wikis/unprivileged_userns_restriction
* https://ubuntu.com/blog/ubuntu-23-10-restricted-unprivileged-user-namespaces
* https://manpages.ubuntu.com/manpages/jammy/man5/apparmor.d.5.html (for
  the return code)

V2:
* Fix duplicated line in check_unshare_hints
* Also handle similar failure in tst-pidfd_getpid

V3:
* Comment formatting
* Aded some more documentation on syscall return value

Signed-off-by: Simon Chopin <simon.chopin@canonical.com>
2024-02-23 08:50:00 -03:00
Adhemerval Zanella
460860f457 Remove ia64-linux-gnu
Linux 6.7 removed ia64 from the official tree [1], following the general
principle that a glibc port needs upstream support for the architecture
in all the components it depends on (binutils, GCC, and the Linux
kernel).

Apart from the removal of sysdeps/ia64 and sysdeps/unix/sysv/linux/ia64,
there are updates to various comments referencing ia64 for which removal
of those references seemed appropriate. The configuration is removed
from README and build-many-glibcs.py.

The CONTRIBUTED-BY, elf/elf.h, manual/contrib.texi (the porting
mention), *.po files, config.guess, and longlong.h are not changed.

For Linux it allows cleanup some clone2 support on multiple files.

The following bug can be closed as WONTFIX: BZ 22634 [2], BZ 14250 [3],
BZ 21634 [4], BZ 10163 [5], BZ 16401 [6], and BZ 11585 [7].

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=43ff221426d33db909f7159fdf620c3b052e2d1c
[2] https://sourceware.org/bugzilla/show_bug.cgi?id=22634
[3] https://sourceware.org/bugzilla/show_bug.cgi?id=14250
[4] https://sourceware.org/bugzilla/show_bug.cgi?id=21634
[5] https://sourceware.org/bugzilla/show_bug.cgi?id=10163
[6] https://sourceware.org/bugzilla/show_bug.cgi?id=16401
[7] https://sourceware.org/bugzilla/show_bug.cgi?id=11585
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2024-01-08 17:09:36 -03:00
Paul Eggert
dff8da6b3e Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
Adhemerval Zanella
ed318beab9 support: Add support_set_vma_name
Check if kernel supports prctl (PR_SET_VMA, PR_SET_VMA_ANON_NAME, ...).
Reviewed-by: DJ Delorie <dj@redhat.com>
2023-11-07 10:27:20 -03:00
Stefan Liebler
4a829d70ab Fix WAIT_FOR_DEBUGGER for container tests.
For container tests, gdb needs to set the sysroot to the corresponding
testroot.root directory.  The assumption was that PIDs < 3 means that
we are running within a container.

Starting with commit 2fe64148a8
"Allow for unpriviledged nested containers", the default is to use
the PID namespace of the parent.  Thus support_test_main.c does not
recognize our container anymore.

This patch now assumes that we are running inside a container if
test-container.c has set PID_OUTSIDE_CONTAINER and always uses this
PID independent of having a new PID namespace or not.
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2023-10-16 09:51:00 +02:00
Adhemerval Zanella
aea4ddb871 test-container: Use nftw instead of rm -rf
If the binary to run is 'env', test-containers skips it and adds
any required environment variable on the process envs variables.
This simplifies the required code to spawn new process (no need
to build an env-like program).

However, this is an issue for recursive_remove if there is any
LD_PRELOAD, since test-container will not prepend the loader command
along with required paths.  If the required preloaded library can
not be loaded by the system glibc, the 'post-clean rsync' will
eventually fail.

One example is if system glibc does not support DT_RELR and the
built glibc does, the nss/tst-nss-gai-hv2-canonname test fails
with:

../scripts/evaluate-test.sh nss/tst-nss-gai-hv2-canonname $? false false
86_64-linux-gnu/nss/tst-nss-gai-hv2-canonname.test-result
rm: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_ABI_DT_RELR' not
found (required by x86_64-linux-gnu/malloc/libc_malloc_debug.so)

Instead trying to figure out the required loader arguments on how
to spawn the 'rm -rf', replace the command with a nftw call.

Checked on x86_64-linux-gnu.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Stefan Liebler <stli@linux.ibm.com>
2023-09-28 09:41:05 -03:00
John David Anglin
1d5024f4f0 support: Build with exceptions and asynchronous unwind tables [BZ #30587]
Changing tst-cleanup4.c to use xread instead of read caused
the nptl/tst-cleanupx4 test to fail.  The routines in libsupport.a
need to be built with exception handling and asynchronous unwind
table support.

v2: Use "CFLAGS-.oS" instead of "override CFLAGS".
2023-07-01 13:29:53 +00:00
Frédéric Bérat
8022fc7d51 tests: replace system by xsystem
With fortification enabled, system calls return result needs to be checked,
has it gets the __wur macro enabled.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2023-06-19 09:15:05 -04:00
Frédéric Bérat
20b6b8e8a5 tests: replace read by xread
With fortification enabled, read calls return result needs to be checked,
has it gets the __wur macro enabled.

Note on read call removal from  sysdeps/pthread/tst-cancel20.c and
sysdeps/pthread/tst-cancel21.c:
It is assumed that this second read call was there to overcome the race
condition between pipe closure and thread cancellation that could happen
in the original code. Since this race condition got fixed by
d0e3ffb7a5 the second call seems
superfluous. Hence, instead of checking for the return value of read, it
looks reasonable to simply remove it.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2023-06-19 09:14:56 -04:00
Frederic Berat
7ba426a111 tests: replace fgets by xfgets
With fortification enabled, fgets calls return result needs to be checked,
has it gets the __wur macro enabled.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2023-06-13 19:59:08 -04:00
Frederic Berat
a84dcb4bdf tests: replace fread by xfread
With fortification enabled, fread calls return result needs to be checked,
has it gets the __wur macro enabled.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2023-06-13 19:59:08 -04:00
Florian Weimer
047703fbb8 support: Add delayed__exit (with two underscores)
It calls _exit instead of exit once the timeout expires.
2023-06-06 11:37:30 +02:00
Paul Pluzhnikov
7f0d9e61f4 Fix all the remaining misspellings -- BZ 25337 2023-06-02 01:39:48 +00:00
Frédéric Bérat
29e25f6f13 tests: fix warn unused results
With fortification enabled, few function calls return result need to be
checked, has they get the __wur macro enabled.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2023-06-01 13:01:32 -04:00
Frédéric Bérat
026a84a54d tests: replace write by xwrite
Using write without cheks leads to warn unused result when __wur is
enabled.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2023-06-01 12:40:05 -04:00
Siddhesh Poyarekar
6286cca2cb support: Don't fail on fchown when spawning sgid processes
In some cases (e.g. when podman creates user containers), the only other
group assigned to the executing user is nobody and fchown fails with it
because the group is not mapped.  Do not fail the test in this case,
instead exit as unsupported.

Reported-by: Frédéric Bérat <fberat@redhat.com>
Tested-by: Frédéric Bérat <fberat@redhat.com>
Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2023-06-01 07:23:42 -04:00
Carlos O'Donell
da55fae9e2 support: Reformat Makefile.
Add list end markers.
Sort text using scripts/sort-makefile-lines.py.

No code generation changes observed in non-test binary artifacts.
No regressions on x86_64 and i686.
2023-05-23 22:03:41 -04:00
Joe Simmons-Talbott
868506eb42 system: Add "--" after "-c" for sh (BZ #28519)
Prevent sh from interpreting a user string as shell options if it
starts with '-' or '+'.  Since the version of /bin/sh used for testing
system() is different from the full-fledged system /bin/sh add support
to it for handling "--" after "-c".  Add a testcase to ensure the
expected behavior.

Signed-off-by: Joe Simmons-Talbott <josimmon@redhat.com>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2023-03-28 10:12:30 -03:00
Romain Geissler
57ce87a940 support: introduce support_sysconfdir_prefix
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2023-03-27 16:58:08 -03:00
Adam Yi
436a604b7d posix: Fix system blocks SIGCHLD erroneously [BZ #30163]
Fix bug that SIGCHLD is erroneously blocked forever in the following
scenario:

1. Thread A calls system but hasn't returned yet
2. Thread B calls another system but returns

SIGCHLD would be blocked forever in thread B after its system() returns,
even after the system() in thread A returns.

Although POSIX does not require, glibc system implementation aims to be
thread and cancellation safe. This bug was introduced in
5fb7fc9635 when we moved reverting signal
mask to happen when the last concurrently running system returns,
despite that signal mask is per thread. This commit reverts this logic
and adds a test.

Signed-off-by: Adam Yi <ayi@janestreet.com>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2023-03-07 09:54:50 -03:00
Joseph Myers
dee2bea048 C2x scanf binary constant handling
C2x adds binary integer constants starting with 0b or 0B, and supports
those constants for the %i scanf format (in addition to the %b format,
which isn't yet implemented for scanf in glibc).  Implement that scanf
support for glibc.

As with the strtol support, this is incompatible with previous C
standard versions, in that such an input string starting with 0b or 0B
was previously required to be parsed as 0 (with the rest of the input
potentially matching subsequent parts of the scanf format string).
Thus this patch adds 12 new __isoc23_* functions per long double
format (12, 24 or 36 depending on how many long double formats the
glibc configuration supports), with appropriate header redirection
support (generally very closely following that for the __isoc99_*
scanf functions - note that __GLIBC_USE (DEPRECATED_SCANF) takes
precedence over __GLIBC_USE (C2X_STRTOL), so the case of GNU
extensions to C89 continues to get old-style GNU %a and does not get
this new feature).  The function names would remain as __isoc23_* even
if C2x ends up published in 2024 rather than 2023.

When scanf %b support is added, I think it will be appropriate for all
versions of scanf to follow C2x rules for inputs to the %b format
(given that there are no compatibility concerns for a new format).

Tested for x86_64 (full glibc testsuite).  The first version was also
tested for powerpc (32-bit) and powerpc64le (stdio-common/ and wcsmbs/
tests), and with build-many-glibcs.py.
2023-03-02 19:10:37 +00:00
Andreas Schwab
3bfdc4e2bc support: use 64-bit time_t (bug 30111)
Ensure to use 64-bit time_t in the test infrastructure.
2023-03-02 13:01:32 +01:00
Joseph Myers
6d7e8eda9b Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
Shahab Vahedi
987f8647e8 scripts: Add "|" operator support to glibcpp's parsing
From the tests point of view, this is a necessary step for another
patch [1] and allows parsing macros such as "#define A | B".  Without
it, a few tests [2] choke when the other patch [1] is applied:

/src/glibc/scripts/../elf/elf.h:4167: error: uninterpretable macro
token sequence: ( EF_ARC_MACH_MSK | EF_ARC_OSABI_MSK )
Traceback (most recent call last):
    File "/src/glibc/elf/tst-glibcelf.py", line 23, in <module>
      import glibcelf
    File "/src/glibc/scripts/glibcelf.py", line 226, in <module>
      _elf_h = _parse_elf_h()
               ^^^^^^^^^^^^^^
    File "/src/glibc/scripts/glibcelf.py", line 223, in _parse_elf_h
      raise IOError('parse error in elf.h')
  OSError: parse error in elf.h

[1] ARC: update definitions in elf/elf.h
https://sourceware.org/pipermail/libc-alpha/2022-November/143503.html

[2]
tst-glibcelf, tst-relro-ldso, and tst-relro-libc

Reviewed-by: Florian Weimer <fweimer@redhat.com>
Signed-off-by: Shahab Vahedi <shahab@synopsys.com>
2022-11-29 14:33:56 -08:00
Yu Chien Peter Lin
3bea50ccbc support: Add xpthread_cond_signal wrapper
Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2022-10-03 11:19:36 -03:00
Florian Weimer
e6e6184bed scripts: Enhance glibcpp to do basic macro processing
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2022-09-22 12:10:41 +02:00
Xi Ruoyao
bd0b58837c test-container: return UNSUPPORTED for ENOSPC on clone()
Since Linux 4.9, the kernel provides
/proc/sys/user/max_{mnt,pid,user}_namespace as a limitation of number of
namespaces.  Some distros (for example, Slint Linux 14.2.1) set them (or
only max_user_namespace) to zero as a "security policy" for disabling
namespaces.

The clone() call will set errno to ENOSPC under such a limitation.  We
didn't check ENOSPC in the code so the test will FAIL, and report:

    unable to unshare user/fs: No space left on device

This message is, unfortunately, very unhelpful.  It leads people to
check the memory or disk space, instead of finding the real issue.

To improve the situation, we should check for ENOSPC and return
UNSUPPORTED as the test result.  Also refactor check_for_unshare_hints()
to emit a proper message telling people how to make the test work, if
they really need to run the namespaced tests.

Reported-by: Philippe Delavalade <philippe.delavalade@orange.fr>
URL: https://lists.linuxfromscratch.org/sympa/arc/lfs-support/2022-06/msg00022.html
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
Reviewed-by: DJ Delorie <dj@redhat.com>
2022-07-05 22:34:51 -04:00
Florian Weimer
62a321b12d support: Change non-address output format of support_format_dns_packet
It makes sense to include the owner name (LHS) and record type in the
output, so that they can be checked for correctness.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2022-06-24 18:18:41 +02:00
Adhemerval Zanella
e3fdbe9f39 support: Add xmkfifo
Wrapper support mkfifo.
2022-04-15 09:59:33 -03:00
DJ Delorie
d2263bf50a test-container: Fix "unused code" warnings on HURD
Comment out bits of code that are only used when we *have* pid
namespaces, to avoid "unused code" warnings.

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

Message-Id: <xno817tnds.fsf@greed.delorie.com>
2022-04-12 01:28:41 +02:00
DJ Delorie
2fe64148a8 Allow for unpriviledged nested containers
If the build itself is run in a container, we may not be able to
fully set up a nested container for test-container testing.
Notably is the mounting of /proc, since it's critical that it
be mounted from within the same PID namespace as its users, and
thus cannot be bind mounted from outside the container like other
mounts.

This patch defaults to using the parent's PID namespace instead of
creating a new one, as this is more likely to be allowed.

If the test needs an isolated PID namespace, it should add the "pidns"
command to its init script.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2022-04-04 14:17:08 -04:00