Commit Graph

245 Commits

Author SHA1 Message Date
H.J. Lu
f896fc0f2b Correct timespec implementation [BZ #26232]
commit 04deeaa9ea
Author: Lucas A. M. Magalhaes <lamm@linux.ibm.com>
Date:   Fri Jul 10 19:41:06 2020 -0300

    Fix time/tst-cpuclock1 intermitent failures

has 2 issues:

1. It assumes time_t == long which is false on x32.
2. tst-timespec.c is compiled without -fexcess-precision=standard which
generates incorrect results on i686 in support_timespec_check_in_range:

  double ratio = (double)observed_norm / expected_norm;
  return (lower_bound <= ratio && ratio <= upper_bound);

This patch does

1. Compile tst-timespec.c with -fexcess-precision=standard.
2. Replace long with time_t.
3. Replace LONG_MIN and LONG_MAX with TYPE_MINIMUM (time_t) and
TYPE_MAXIMUM (time_t).
2020-07-14 04:42:58 -07:00
Lucas A. M. Magalhaes
04deeaa9ea Fix time/tst-cpuclock1 intermitent failures
This test fails intermittently in systems with heavy load as
CLOCK_PROCESS_CPUTIME_ID is subject to scheduler pressure.  Thus the
test boundaries were relaxed to keep it from failing on such systems.

A refactor of the spent time checking was made with some support
functions.  With the advantage to representing time jitter in percent
of the target.

The values used by the test boundaries are all empirical.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2020-07-10 19:41:06 -03:00
Adhemerval Zanella
653200ef42 string: Add strerror, strerror_r, and strerror_l test
Checked on x86-64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu,
and s390x-linux-gnu.

Tested-by: Carlos O'Donell <carlos@redhat.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2020-07-07 14:10:58 -03:00
Samuel Thibault
3f6e4fc454 support: Fix detecting hole support on >2KB-block filesystems
When detecting hole support, we write at 16MiB, and filesystems will
typically need two levels of data to record that. On filesystems with
8KB block, the two indirection blocks will require a total of 16KB
overhead, thus 32 512-byte sectors.

Spotted on GNU/Hurd with a 4KB blocks filesystem, but also happens on Linux
with 4KB or 8KB blocks filesystems.

* support/support_descriptor_supports_holes.c
(support_descriptor_supports_holes): Set block_headroom to 32.
2020-06-04 21:27:05 +02:00
Girish Joshi
9e2dc874e6 build: Use FAIL_EXIT1 () on failure to exec child [BZ #23990]
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2020-05-29 10:15:26 -03:00
Florian Weimer
0e28cfff9d support: Add support_blob_repeat_allocate_shared
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2020-05-12 19:02:44 +02:00
Carlos O'Donell
183083c359 support: Set errno before testing it.
In test-conainer we should set errno to 0 before calling strtol,
and check after with TEST_COMPARE.

In tst-support_capture_subprocess we should set errno to 0 before
checking it after the call to strtol.

Tested on x86_64.

Reviewed-by: DJ Delorie <dj@redhat.com>
2020-04-30 16:28:07 -04:00
Carlos O'Donell
033362cfd7 test-container: Support $(complocaledir) and mkdirp.
Expand the support infrastructure:
- Create $(complocaledir) in the testroot.pristine to support localedef.
- Add the variable $complocaledir to script support.
- Add the script command 'mkdirp'.

All localedef tests which run with default paths need to have the
$(complocaledir) created in testroot.pristine. The localedef binary
will not by itself create the default path, but it will write into
the path. By adding this we can simplify the localedef tests.

The variable $complocaledir is the value of the configured
$(complocaledir) which is the location of the compiled locales that
will be searched by the runtime by default.

The command mkdirp will be available in script setup and will
be equivalent to running `mkdir -p`.

The variable and command can be used to write more complex tests.

Reviewed-by: DJ Delorie <dj@redhat.com>
2020-04-30 16:28:07 -04:00
Mathieu Desnoyers
a9bfa4353c support: Implement <support/xthread.h> key create/delete
Expose xpthread_key_create and xpthread_key_delete wrappers
for tests.
2020-04-27 21:40:24 +02:00
Carlos O'Donell
92954ffa5a localedef: Add verbose messages for failure paths.
During testing of localedef running in a minimal container
there were several error cases which were hard to diagnose
since they appeared as strerror (errno) values printed by the
higher level functions.  This change adds three new verbose
messages for potential failure paths.  The new messages give
the user the opportunity to use -v and display additional
information about why localedef might be failing.  I found
these messages useful myself while writing a localedef
container test for --no-hard-links.

Since the changes cleanup the code that handle codeset
normalization we add tst-localedef-path-norm which contains
many sub-tests to verify the correct expected normalization of
codeset strings both when installing to default paths (the
only time normalization is enabled) and installing to absolute
paths.  During the refactoring I created at least one
buffer-overflow which valgrind caught, but these tests did not
catch because the exec in the container had a very clean heap
with zero-initialized memory. However, between valgrind and
the tests the results are clean.

The new tst-localedef-path-norm passes without regression on
x86_64.

Change-Id: I28b9f680711ff00252a2cb15625b774cc58ecb9d
2020-04-26 13:55:58 -04:00
Florian Weimer
cea56af185 support: Change xgetline to return 0 on EOF
The advantage is that the buffer will always contain the number
of characters as returned from the function, which allows one to use
a sequence like

  /* No more audit module output.  */
  line_length = xgetline (&buffer, &buffer_length, fp);
  TEST_COMPARE_BLOB ("", 0, buffer, line_length);

to check for an expected EOF, while also reporting any unexpected
extra data encountered.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2020-04-03 16:26:10 +02:00
Adhemerval Zanella
1c17100c43 support/shell-container.c: Add builtin kill
No options supported.

Reviewed-by: DJ Delorie <dj@redhat.com>
2020-03-25 09:50:45 -03:00
Adhemerval Zanella
5a5a3a3234 support/shell-container.c: Add builtin exit
Reviewed-by: DJ Delorie <dj@redhat.com>
2020-03-25 09:50:45 -03:00
Adhemerval Zanella
5fce0e095b support/shell-container.c: Return 127 if execve fails
Reviewed-by: DJ Delorie <dj@redhat.com>
2020-03-25 09:50:45 -03:00
Michael Hudson-Doyle
083d644d42 test-container: print errno when execvp fails
I'm debugging a situation where lots of tests using test-container fail
and it's possible knowing errno would help understand why.

Reviewed-by: DJ Delorie <dj@redhat.com>
2020-03-11 16:00:58 -04:00
Girish Joshi
542160f0b6 Fixed typo in run_command_array() in support/shell-container.c
https://sourceware.org/bugzilla/show_bug.cgi?id=23991
2020-03-02 15:58:16 -05:00
Adhemerval Zanella
dfe9aa9156 support: Add support_process_state_wait
It allows parent process to wait for child state using a polling
strategy over procfs on Linux.  The polling is used over ptrace to
avoid the need to handle signals on the target pid and to handle some
system specific limitation (such as YAMA).

The polling has some limitations, such as resource consumption due
the procfs read in a loop and the lack of synchronization after the
state is obtained.

The interface idea is to simplify some sleep synchronization waitid
tests and is to reduce timeouts by replacing arbitrary waits.
2020-02-27 15:52:35 -03:00
Florian Weimer
173ec37bb2 support: Add the xlstat function 2020-02-09 11:50:44 +01:00
DJ Delorie
4f79b3e2fb test-container: add exec, cwd
exec <path_to_test_binary> [optional_argv_0]

  copies test binary to specified location and runs it from
  there.  If the second argument is provided, that will
  be used for argv[0]

cwd <directory>

  attempts to chdir(directory) before running test

Note: "cwd" not "cd" as it takes effect just before the
test binary runs, not when it's encountered in the script,
so it can't be used as a path shortcut like "cd" would imply.

cleanup: use xstrdup() instead of strdup()

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2020-02-03 14:49:25 -05:00
Joseph Myers
d614a75396 Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
Florian Weimer
446997ff14 resolv: Implement trust-ad option for /etc/resolv.conf [BZ #20358]
This introduces a concept of trusted name servers, for which the
AD bit is passed through to applications.  For untrusted name
servers (the default), the AD bit in responses are cleared, to
provide a safe default.

This approach is very similar to the one suggested by Pavel Šimerda
in <https://bugzilla.redhat.com/show_bug.cgi?id=1164339#c15>.

The DNS test framework in support/ is enhanced with support for
setting the AD bit in responses.

Tested on x86_64-linux-gnu.

Change-Id: Ibfe0f7c73ea221c35979842c5c3b6ed486495ccc
2019-11-27 20:54:37 +01:00
Florian Weimer
02132c0f4c support: Fix support_set_small_thread_stack_size to build on Hurd
PTHREAD_STACK_MIN comes from <limits.h>, so include it explicitly.
However, it is not defined on Hurd, so compensate for that as well.

Built on x86_64-linux-gnu, i686-linux-gnu, i686-gnu.

Change-Id: Ifacc888ef86731c2639721b0932ae59583bd6b3e
Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-11-13 14:10:11 +01:00
Arjun Shankar
cce35a50c1 support: Add xsetlocale function 2019-11-11 17:40:46 +01:00
Florian Weimer
36ada9ee2c support: Add support_set_small_thread_stack_size
And support_small_stack_thread_attribute

Change-Id: I1cf79a469984f8f30a4a947ee9ec2a5e74de8926
2019-11-11 13:40:55 +01:00
Adhemerval Zanella
c1dac8f83e Sync timespec-{add,sub} with gnulib
It sync with gnulib commit 06011ed74e978613422aca43c0bd92dc44213933.

Reviewed-by: Paul Eggert <eggert@cs.ucla.edu>
2019-10-31 17:03:04 -03:00
Zack Weinberg
4a39c34c4f Change most internal uses of __gettimeofday to __clock_gettime.
Since gettimeofday will shortly be implemented in terms of
clock_gettime on all platforms, internal code should use clock_gettime
directly; in addition to removing a layer of indirection, this will
allow us to remove the PLT-bypass gunk for gettimeofday.  (We can't
quite do that yet, but it'll be coming later in this patch series.)
In many cases, the changed code does fewer conversions.

The changed code always assumes __clock_gettime (CLOCK_REALTIME)
cannot fail.  Most of the call sites were assuming gettimeofday could
not fail, but a few places were checking for errors.  POSIX says
clock_gettime can only fail if the clock constant is invalid or
unsupported, and CLOCK_REALTIME is the one and only clock constant
that's required to be supported.  For consistency I grepped the entire
source tree for any other places that checked for errors from
__clock_gettime (CLOCK_REALTIME), found one, and changed it too.

(For the record, POSIX also says gettimeofday can never fail.)

(It would be nice if we could declare that GNU systems will always
support CLOCK_MONOTONIC as well as CLOCK_REALTIME; there are several
places where we are using CLOCK_REALTIME where _MONOTONIC would be
more appropriate, and/or trying to use _MONOTONIC and then falling
back to _REALTIME.  But the Hurd doesn't support CLOCK_MONOTONIC yet,
and it looks like adding it would involve substantial changes to
gnumach's internals and API.  Oh well.)

A few Hurd-specific files were changed to use __host_get_time instead
of __clock_gettime, as this seemed tidier.  We also assume this cannot
fail.  Skimming the code in gnumach leads me to believe the only way
it could fail is if __mach_host_self also failed, and our
Hurd-specific code consistently assumes that can't happen, so I'm
going with that.

With the exception of support/support_test_main.c, test cases are not
modified, mainly because I didn't want to have to figure out which
test cases were testing gettimeofday specifically.

The definition of GETTIME in sysdeps/generic/memusage.h had a typo and
was not reading tv_sec at all.  I fixed this.  It appears nobody has been
generating malloc traces on a machine that doesn't have a superseding
definition.

There are a whole bunch of places where the code could be simplified
by factoring out timespec subtraction and/or comparison logic, but I
want to keep this patch as mechanical as possible.

Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu,
powerpc64-linux-gnu, powerpc-linux-gnu, and aarch64-linux-gnu.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Lukasz Majewski <lukma@denx.de>
2019-10-30 17:04:10 -03:00
DJ Delorie
4052fa22f6 Add wait-for-debugger test harness hooks
If WAIT_FOR_DEBUGGER is set to a non-zero value in the environment,
any test that runs will print some useful gdb information and wait
for gdb to attach to it and clear the "wait_for_debugger" variable.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2019-10-24 16:32:32 -04:00
Stefan Liebler
64fab3633a Fix building support_ptrace.c on i686-gnu.
On i686-gnu the build is broken:
In file included from support_ptrace.c:22:
../include/sys/prctl.h:2:15: fatal error: sys/prctl.h: No such file or directory
 #include_next <sys/prctl.h>

This patch just removes the unused prctl.h inclusion.

ChangeLog:

	* support/support_ptrace.c: Remove inclusion of sys/prctl.h.
2019-09-19 12:26:18 +02:00
Stefan Liebler
2f9046fb05 Add UNSUPPORTED check in elf/tst-pldd.
The testcase forks a child process and runs pldd with PID of
this child.  On systems where /proc/sys/kernel/yama/ptrace_scope
differs from zero, pldd will fail with
/usr/bin/pldd: cannot attach to process 3: Operation not permitted

This patch checks if ptrace_scope exists, is zero "classic ptrace permissions"
or one "restricted ptrace".  If ptrace_scope exists and has a higher
restriction, then the test is marked as UNSUPPORTED.

The case "restricted ptrace" is handled by rearranging the processes involved
during the test.  Now we have the following process tree:
-parent: do_test (performs output checks)
--subprocess 1: pldd_process (becomes pldd via execve)
---subprocess 2: target_process (ptraced via pldd)

ChangeLog:

	* elf/tst-pldd.c (do_test): Add UNSUPPORTED check.
	Rearrange subprocesses.
	(pldd_process): New function.
	* support/Makefile (libsupport-routines): Add support_ptrace.
	* support/xptrace.h: New file.
	* support/support_ptrace.c: Likewise.
2019-09-18 12:42:39 +02:00
Paul Eggert
5a82c74822 Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:

sed -ri '
  s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
  s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
  $(find $(git ls-files) -prune -type f \
      ! -name '*.po' \
      ! -name 'ChangeLog*' \
      ! -path COPYING ! -path COPYING.LIB \
      ! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
      ! -path manual/texinfo.tex ! -path scripts/config.guess \
      ! -path scripts/config.sub ! -path scripts/install-sh \
      ! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
      ! -path INSTALL ! -path  locale/programs/charmap-kw.h \
      ! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
      ! '(' -name configure \
            -execdir test -f configure.ac -o -f configure.in ';' ')' \
      ! '(' -name preconfigure \
            -execdir test -f preconfigure.ac ';' ')' \
      -print)

and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:

  chmod a+x sysdeps/unix/sysv/linux/riscv/configure
  # Omit irrelevant whitespace and comment-only changes,
  # perhaps from a slightly-different Autoconf version.
  git checkout -f \
    sysdeps/csky/configure \
    sysdeps/hppa/configure \
    sysdeps/riscv/configure \
    sysdeps/unix/sysv/linux/csky/configure
  # Omit changes that caused a pre-commit check to fail like this:
  # remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
  git checkout -f \
    sysdeps/powerpc/powerpc64/ppc-mcount.S \
    sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
  # Omit change that caused a pre-commit check to fail like this:
  # remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
  git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 02:43:31 -07:00
Florian Weimer
c54d864903 support: Include <support/descriptors.h> in support_descriptors.c 2019-08-14 16:24:46 +02:00
DJ Delorie
99135114ba nss_db: fix endent wrt NULL mappings [BZ #24695] [BZ #24696]
nss_db allows for getpwent et al to be called without a set*ent,
but it only works once.  After the last get*ent a set*ent is
required to restart, because the end*ent did not properly reset
the module.  Resetting it to NULL allows for a proper restart.

If the database doesn't exist, however, end*ent erroniously called
munmap which set errno.

The test case runs "makedb" inside the testroot, so needs selinux
DSOs installed.
2019-07-10 14:51:18 -04:00
Florian Weimer
17432d7150 support: Add xdlvsym function 2019-06-28 10:15:38 +02:00
Mike Crowe
8bf225d583 support: Invent verbose_printf macro
Make it easier for tests to emit progress messages only when --verbose is
specified.

* support/test-driver.h: Add verbose_printf macro.
2019-06-21 09:59:50 -03:00
Mike Crowe
db13e32cb8 support: Add xclock_now helper function.
It's easier to read and write tests with:

 const struct timespec ts = xclock_now(CLOCK_REALTIME);

than

 struct timespec ts;
 xclock_gettime(CLOCK_REALTIME, &ts);

	* support/xtime.h: Add xclock_now() helper function.
2019-06-21 09:59:50 -03:00
Florian Weimer
75c51570c7 support: Expose sbindir as support_sbindir_prefix 2019-05-20 21:15:35 +02:00
Mike Crowe
b62bb3bc68 support: Add missing EOL terminators on timespec
The original implementations of test_timespec_before_impl and
test_timespec_equal_or_after in 5198399651
were missing the backslash required for a newline.

Checked on x86_64-linux-gnu.

	* support/timespec.c: Add backslash to correct newline in failure
	message.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2019-05-20 15:06:17 -03:00
Mike Crowe
ff6bec7d47 support: Correct confusing comment
* support/timespec.h: Correct confusing comment.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2019-05-20 15:05:35 -03:00
Florian Weimer
85b0e1e8a6 support: Report NULL blobs explicitly in TEST_COMPARE
Provide an explicit diagnostic if the length is positive, and
do not just crash with a null pointer dereference.  Null pointers
are only valid if the length is zero, so this can only happen with
a faulty test.
2019-05-16 14:50:15 +02:00
Alexandra Hájková
d50f09181e support: Add support_install_rootsbindir
Reviewed by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2019-05-15 11:37:26 +02:00
Adhemerval Zanella
c7ac9caaae support: Export bindir path on support_path
Checked on x86_64-linux-gnu.

	* support/Makefile (CFLAGS-support_paths.c): Add -DBINDIR_PATH.
	* support/support.h (support_bindir_prefix): New variable.
	* support/support_paths.c [BINDIR_PATH] (support_bindir_prefix):

Reviewed-by: DJ Delorie <dj@redhat.com>
2019-05-14 11:04:37 -03:00
Adhemerval Zanella
eb669ff5bf support: Fix timespec printf
The patch print timespec members as intmax_t instead of long int.
It avoid the -Werror=format= build issue on x32:

  timespec.c: In function 'test_timespec_before_impl':
  timespec.c:32:23: error: format '%ld' expects argument of type 'long int',
  but argument 4 has type '__time_t' {aka 'const long long int'} [-Werror=format=]

Checked on x86_64-linux-gnu-x32, x86_64-linux-gnu, and i686-linux-gnu.

	* support/timespec.c (test_timespec_before_impl,
	test_timespec_equal_or_after_impl): print timespec member as intmax_t
	insted of long int.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2019-05-10 09:39:19 -03:00
Mike Crowe
5198399651 support: Add timespec.h
It adds useful functions for tests that use struct timespec.

Checked on x86_64-linux-gnu and i686-linux-gnu.

	* support/timespec.h: New file.  Provide timespec helper functions
	along with macros in the style of those in check.h.
	* support/timespec.c: New file.  Implement check functions declared
	in support/timespec.h.
	* support/timespec-add.c: New file from gnulib containing
	timespec_add implementation that handles overflow.
	* support/timespec-sub.c: New file from gnulib containing
	timespec_sub implementation that handles overflow.
	* support/README: Mention timespec.h.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2019-05-09 14:33:53 -03:00
Mike Crowe
33647a7294 support: Add xclock_gettime
* support/xclock_gettime.c (xclock_gettime): New file. Provide
	clock_gettime wrapper for use in tests that fails the test rather
	than returning failure.

	* support/xtime.h: New file to declare xclock_gettime.

	* support/Makefile: Add xclock_gettime.c.

	* support/README: Mention xtime.h.
2019-05-08 16:58:17 +02:00
Adhemerval Zanella
0e16969129 support: Add support_capture_subprogram
Its API is similar to support_capture_subprocess, but rather creates a
new process based on the input path and arguments.  Under the hoods it
uses posix_spawn to create the new process.

It also allows the use of other support_capture_* functions to check
for expected results and free the resources.

Checked on x86_64-linux-gnu.

	* support/Makefile (libsupport-routines): Add support_subprocess,
	xposix_spawn, xposix_spawn_file_actions_addclose, and
	xposix_spawn_file_actions_adddup2.
	(tst-support_capture_subprocess-ARGS): New rule.
	* support/capture_subprocess.h (support_capture_subprogram): New
	prototype.
	* support/support_capture_subprocess.c (support_capture_subprocess):
	Refactor to use support_subprocess and support_capture_poll.
	(support_capture_subprogram): New function.
	* support/tst-support_capture_subprocess.c (write_mode_to_str,
	str_to_write_mode, test_common, parse_int, handle_restart,
	do_subprocess, do_subprogram, do_multiple_tests): New functions.
	(do_test): Add support_capture_subprogram tests.
	* support/subprocess.h: New file.
	* support/support_subprocess.c: Likewise.
	* support/xposix_spawn.c: Likewise.
	* support/xposix_spawn_file_actions_addclose.c: Likewise.
	* support/xposix_spawn_file_actions_adddup2.c: Likewise.
	* support/xspawn.h: Likewise.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2019-04-17 11:35:59 -03:00
Joseph Myers
86140c6223 Avoid fall-through in test-container if execlp fails.
One of the implicit-fallthrough warnings from compiling glibc with
-Wextra appears to indicate an actual bug: the test-container code
could fall through inappropriately if execlp returns (which only
occurs on error).  This patch adds appropriate error handling in this
case to avoid that fall-through.

Tested for x86_64.

	* support/test-container.c (recursive_remove): Use FAIL_EXIT1 if
	execlp returns.
2019-02-13 13:34:24 +00:00
Florian Weimer
94b63e6620 support: Implement xdlmopen
Put xdlmopen into its own file, to avoid disturbing static linking
tests (where dlmopen pulls in additional code).
2019-02-07 09:02:01 +01:00
Florian Weimer
3b93559585 support: Use dlerror to detect NULL symbols in xdlsym 2019-02-06 16:45:25 +01:00
Stefan Liebler
bc79db3fd4 Fix alignment of TLS variables for tls variant TLS_TCB_AT_TP [BZ #23403]
The alignment of TLS variables is wrong if accessed from within a thread
for architectures with tls variant TLS_TCB_AT_TP.
For the main thread the static tls data is properly aligned.
For other threads the alignment depends on the alignment of the thread
pointer as the static tls data is located relative to this pointer.

This patch adds this alignment for TLS_TCB_AT_TP variants in the same way
as it is already done for TLS_DTV_AT_TP. The thread pointer is also already
properly aligned if the user provides its own stack for the new thread.

This patch extends the testcase nptl/tst-tls1.c in order to check the
alignment of the tls variables and it adds a pthread_create invocation
with a user provided stack.
The test itself is migrated from test-skeleton.c to test-driver.c
and the missing support functions xpthread_attr_setstack and xposix_memalign
are added.

ChangeLog:

	[BZ #23403]
	* nptl/allocatestack.c (allocate_stack): Align pointer pd for
	TLS_TCB_AT_TP tls variant.
	* nptl/tst-tls1.c: Migrate to support/test-driver.c.
	Add alignment checks.
	* support/Makefile (libsupport-routines): Add xposix_memalign and
	xpthread_setstack.
	* support/support.h: Add xposix_memalign.
	* support/xthread.h: Add xpthread_attr_setstack.
	* support/xposix_memalign.c: New File.
	* support/xpthread_attr_setstack.c: Likewise.
2019-02-06 09:06:34 +01:00
Florian Weimer
6175507c06 support: Correct error message for TEST_COMPARE_STRING
It should say "string", not "blob".
2019-02-01 14:15:50 +01:00
Florian Weimer
baef194387 support: Handle AF_LOCAL, AF_UNSPEC in support_format_address_family 2019-02-01 14:15:50 +01:00
Carlos O'Donell
5fc9ed4c40 nptl: Fix pthread_rwlock_try*lock stalls (Bug 23844)
For a full analysis of both the pthread_rwlock_tryrdlock() stall
and the pthread_rwlock_trywrlock() stall see:
https://sourceware.org/bugzilla/show_bug.cgi?id=23844#c14

In the pthread_rwlock_trydlock() function we fail to inspect for
PTHREAD_RWLOCK_FUTEX_USED in __wrphase_futex and wake the waiting
readers.

In the pthread_rwlock_trywrlock() function we write 1 to
__wrphase_futex and loose the setting of the PTHREAD_RWLOCK_FUTEX_USED
bit, again failing to wake waiting readers during unlock.

The fix in the case of pthread_rwlock_trydlock() is to check for
PTHREAD_RWLOCK_FUTEX_USED and wake the readers.

The fix in the case of pthread_rwlock_trywrlock() is to only write
1 to __wrphase_futex if we installed the write phase, since all other
readers would be spinning waiting for this step.

We add two new tests, one exercises the stall for
pthread_rwlock_trywrlock() which is easy to exercise, and one exercises
the stall for pthread_rwlock_trydlock() which is harder to exercise.

The pthread_rwlock_trywrlock() test fails consistently without the fix,
and passes after. The pthread_rwlock_tryrdlock() test fails roughly
5-10% of the time without the fix, and passes all the time after.

Signed-off-by: Carlos O'Donell <carlos@redhat.com>
Signed-off-by: Torvald Riegel <triegel@redhat.com>
Signed-off-by: Rik Prohaska <prohaska7@gmail.com>
Co-authored-by: Torvald Riegel <triegel@redhat.com>
Co-authored-by: Rik Prohaska <prohaska7@gmail.com>
2019-01-31 20:47:55 -05:00
Florian Weimer
2bac7daa58 nss_files: Fix /etc/aliases null pointer dereference [BZ #24059]
If /etc/aliases ends with a continuation line (a line that starts
with whitespace) which does not have a trailing newline character,
the file parser would crash due to a null pointer dereference.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2019-01-31 18:49:58 +01:00
Adhemerval Zanella
3367acdb34 hurd: Fix libsupport xsigstack build
Hurd does not support MAP_NORESERVE and MAP_STACK.

Checked on i686-gnu build.

	* support/xsigstack.c (MAP_NORESERVE, MAP_STACK): Define if they
	are not defined.
2019-01-24 09:38:49 -02:00
Zack Weinberg
fbbc9a4e34 Tests for minimal signal handler functionality in MINSIGSTKSZ space.
There is general agreement that the very short list of things that ISO
C says you can do in an async signal handler should all work when the
handler is running on an alternate signal stack with only MINSIGSTKSZ
space.  This patch adds tests to make sure those things do work.

To facilitate this, there is a new set of test support routines for
setting up alternate signal stacks; see support/xsignal.h for the API.

         * support/xsignal.h (xalloc_sigstack, xfree_sigstack)
         (xget_sigstack_location): New test support functions.
         * support/xsigstack.c: New file, implementing them.
         * support/tst-xsigstack.c: New test for them.
         * support/Makefile: Update.

         * signal/tst-minsigstksz-1.c
         * signal/tst-minsigstksz-2.c
         * signal/tst-minsigstksz-3.c
         * signal/tst-minsigstksz-3a.c
         * signal/tst-minsigstksz-4.c: New tests.
         * signal/Makefile: Run them.
2019-01-16 09:04:10 -05:00
Joseph Myers
04277e02d7 Update copyright dates with scripts/update-copyrights.
* All files with FSF copyright notices: Update copyright dates
	using scripts/update-copyrights.
	* locale/programs/charmap-kw.h: Regenerated.
	* locale/programs/locfile-kw.h: Likewise.
2019-01-01 00:11:28 +00:00
Adhemerval Zanella
0253580a75 Replace check_mul_overflow_size_t with __builtin_mul_overflow
Checked on x86_64-linux-gnu and i686-linux-gnu.

	* malloc/alloc_buffer_alloc_array.c (__libc_alloc_buffer_alloc_array):
	Use __builtin_mul_overflow in place of check_mul_overflow_size_t.
	* malloc/dynarray_emplace_enlarge.c (__libc_dynarray_emplace_enlarge):
	Likewise.
	* malloc/dynarray_resize.c (__libc_dynarray_resize): Likewise.
	* malloc/reallocarray.c (__libc_reallocarray): Likewise.
	* malloc/malloc-internal.h (check_mul_overflow_size_t): Remove
	function.
	* support/blob_repeat.c (check_mul_overflow_size_t,
	(minimum_stride_size, support_blob_repeat_allocate): Likewise.
2018-12-28 15:39:45 -02:00
Florian Weimer
0c1719e65b support: Do not require overflow builtin in support/blob_repeat.c
It is only available in GCC 5 and later.

Tested-by: Romain Naour <romain.naour@gmail.com>
2018-12-15 18:58:56 +01:00
DJ Delorie
304c61a24f test-container: move postclean outside of namespace changes
During postclean.req testing it was found that the fork in the
parent process (after the unshare syscall) would fail with ENOMEM
(see recursive_remove() in test-container.c).  While failing with
ENOMEM is certainly unexpected, it is simply easier to refactor
the design and have the parent remain outside of the namespace.
This change moves the postclean.req processing to a distinct
process (the parent) that then forks the test process (which will
have to fork once more to complete uid/gid transitions). When the
test process exists the cleanup process will ensure all files are
deleted when a post clean is requested.

Signed-off-by: DJ Delorie <dj@redhat.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>

[BZ #23948]
* support/test-container.c: Move postclean step to before we
change namespaces.
2018-12-10 22:37:58 -05:00
Florian Weimer
f255336a93 support: Implement <support/descriptors.h> to track file descriptors 2018-12-06 15:39:42 +01:00
DJ Delorie
b2e93de0ff test-container: add "su" command to run test as root, add unshare hints
* support/test-container.c (check_for_unshare_hints): New.
(main): Call it if unshare fails.  Add support for "su" scriptlet
command.
2018-12-04 00:03:12 -05:00
Florian Weimer
02cd5c1a8d support: Close original descriptors in support_capture_subprocess 2018-12-01 22:41:46 +01:00
Florian Weimer
96cd0558bc support: Add signal support to support_capture_subprocess_check
Signal zero does not terminate a process, so it is safe to use negative
values for signal numbers.

Adjust libio/tst-vtables-common.c to use this new functionality,
instead of determining the termination status for a signal indirectly.
2018-11-28 20:57:18 +01:00
Florian Weimer
47d8d9a217 support_quote_string: Do not use str parameter name
This avoids a build failure if this identifier is used as a macro
in a test.
2018-11-28 07:16:48 +01:00
Florian Weimer
c74a91deaa support: Implement support_quote_string
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
2018-11-27 21:35:56 +01:00
Florian Weimer
35e3fbc451 support: Print timestamps in timeout handler
This is sometimes useful to determine if a test truly got stuck, or if
it was making progress (logging information to standard output) and
was merely slow to finish.
2018-11-19 15:35:03 +01:00
Adhemerval Zanella
00c86a37d1 support: Fix printf format for TEST_COMPARE_STRING
Fix the following on 32 bits targets:

support_test_compare_string.c: In function ‘support_test_compare_string’:
support_test_compare_string.c:80:37: error: format ‘%lu’ expects argument of
type ‘long unsigned int’, but argument 2 has type ‘size_t’ {aka ‘unsigned int’}
[-Werror=format=]
         printf ("  string length: %lu bytes\n", left_length);
                                   ~~^           ~~~~~~~~~~~
                                   %u
Checked on arm-linux-gnueabihf.

	* support/support_test_compare_string.c
	(support_test_compare_string): Fix printf format.
2018-11-07 11:11:06 -02:00
Florian Weimer
1df872fd74 support: Implement TEST_COMPARE_STRING 2018-11-07 12:42:44 +01:00
Florian Weimer
6e36266cec support/shell-container.c: Use support_copy_file_range
Reviewed-by: DJ Delorie <dj@redhat.com>
2018-11-02 18:15:04 +01:00
Florian Weimer
599f7beee7 support/test-container.c: Include <libc-pointer-arith.h>
Reviewed-by: DJ Delorie <dj@redhat.com>
2018-11-02 18:14:58 +01:00
Florian Weimer
a91e9301c4 support_blob_repeat: Call mkstemp directory for the backing file
This avoids a warning during post-test cleanup.
2018-10-30 13:55:50 +01:00
Florian Weimer
f5e7e95921 stdlib/test-bz22786: Avoid spurious test failures using alias mappings
On systems without enough random-access memory, stdlib/test-bz22786
will go deeply into swap and time out, even with a substantial
TIMEOUTFACTOR.  This commit adds a facility to construct repeating
strings with alias mappings, so that the requirement for physical
memory, and uses it in stdlib/test-bz22786.
2018-10-30 13:17:36 +01:00
Stefan Liebler
e7624d708d Adjust name of ld.so in test-container.c.
The test-container.c file assumes that ld.so is always named
something like /elf/ld-linux-*.
But e.g. on s390x it is named ld64.so.1 or ld.so.1 on s390.
There are other architectures like power or mips with similar names.

This patch introduces the new global variable support_objdir_elf_ldso
which contains the absolute path to the runtime linker used by the
testsuite, e.g. OBJDIR_PATH/elf/ld-linux-x86-64.so.2.
The check in test-container.c is now comparing against this path.
Without this patch, test-container.c is searching invalid files / directories
and fails to find glibc/nss/tst-nss-test3.root/tst-nss-test3.script.
Then the test tst-nss-test3 fails!

Reviewed-by: Carlos O'Donell <carlos@redhat.com>

ChangeLog:

	* support/support.h (support_objdir_elf_ldso): New variable.
	* support/support_paths.c (support_objdir_elf_ldso): Likewise.
	* support/Makefile (CFLAGS-support_paths.c): Add definition
	for OBJDIR_ELF_LDSO_PATH.
	* support/test-container.c (main): Search for the ld.so
	which is also used by the testsuite.
2018-10-04 13:07:29 +02:00
H.J. Lu
81b9d87bae test-container: Use xcopy_file_range for cross-device copy [BZ #23597]
copy_file_range can't be used to copy a file from glibc source directory
to glibc build directory since they may be on different filesystems.
This patch adds xcopy_file_range for cross-device copy.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>

	[BZ #23597]
	* support/Makefile (libsupport-routines): Add
	support_copy_file_range and xcopy_file_range.
	* support/support.h: Include <sys/types.h>.
	(support_copy_file_range): New prototype.
	* support/support_copy_file_range.c: New file.  Copied and
	modified from io/copy_file_range-compat.c.
	* support/test-container.c (copy_one_file): Call xcopy_file_rang
	instead of copy_file_range.
	* support/xcopy_file_range.c: New file.
	* support/xunistd.h (xcopy_file_range): New prototype.
2018-08-31 13:08:02 -07:00
Florian Weimer
d6c44c3d0c test-container: EPERM from unshare is UNSUPPORTED
For example, the security policy on the Fedora build daemons results in
this EPERM error.
2018-08-28 14:02:47 +02:00
DJ Delorie
86de0499c3 links-dso-program: Fix build-programs=no build case.
* support/Makefile (others): Don't list programs explicitly as a
dependency of "others".
2018-08-27 16:31:33 -04:00
DJ Delorie
acc2842ace Fix IA64 links-dso-program link.
* support/Makefile (LDLIBS-links-dso-program): Add -lgcc and
$(libunwind).
2018-08-24 22:10:00 -04:00
DJ Delorie
561b0bec44 Add test-in-container infrastructure.
* Makefile (testroot.pristine): New rules to initialize the
test-in-container "testroot".
* Makerules (all-testsuite): Add tests-container.
* Rules (tests-expected): Add tests-container.
(binaries-all-tests): Likewise.
(tests-container): New, run these tests in the testroot container.
* support/Makefile (others): Add *-container, support_paths.c,
xmkdirp, and links-dso-program.
* support/links-dso-program-c.c: New.
* support/links-dso-program.cc: New.
* support/test-container.c: New.
* support/shell-container.c: New.
* support/echo-container.c: New.
* support/true-container.c: New.
* support/xmkdirp.c: New.
* support/xsymlink.c: New.
* support/support_paths.c: New.
* support/support.h: Add support paths prototypes.
* support/xunistd.h: Add xmkdirp () and xsymlink ().

* nss/tst-nss-test3.c: Convert to test-in-container.
* nss/tst-nss-test3.root/: New.
2018-08-22 21:20:37 -04:00
Florian Weimer
aa42b3dbcb Avoid running some tests if the file system does not support holes
Otherwise, these tests fills up the entire disk (or just run very
slowly and eventually time out).
2018-08-21 12:56:53 +02:00
Florian Weimer
5c0202af4b support: Add TEST_NO_SETVBUF
This is sometimes needed for testing stdio streams, where the
setvbuf call in the test driver could interfere with the test.
2018-06-26 12:30:50 +02:00
Florian Weimer
0ce2fa6973 support: Add wrappers for pthread_barrierattr_t 2018-05-29 15:37:00 +02:00
Florian Weimer
7f9f1ecb71 Switch IDNA implementation to libidn2 [BZ #19728] [BZ #19729] [BZ #22247]
This provides an implementation of the IDNA2008 standard and fixes
CVE-2016-6261, CVE-2016-6263, CVE-2017-14062.
2018-05-23 15:27:24 +02:00
Florian Weimer
2afece36f6 support: Add TEST_COMPARE_BLOB, support_quote_blob
The declaration of support_test_compare_blob uses unsigned long int,
to avoid including <stddef.h>.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2018-05-16 17:00:36 +02:00
Florian Weimer
1aa52ced5d support_format_addrinfo: Include unknown error number in result 2018-04-01 19:41:01 +02:00
Zack Weinberg
2cc7bad0ae [BZ 1190] Make EOF sticky in stdio.
C99 specifies that the EOF condition on a file is "sticky": once EOF
has been encountered, all subsequent reads should continue to return
EOF until the file is closed or something clears the "end-of-file
indicator" (e.g. fseek, clearerr).  This is arguably a change from
C89, where the wording was ambiguous; the BSDs always had sticky EOF,
but the System V lineage would attempt to read from the underlying fd
again.  GNU libc has followed System V for as long as we've been
using libio, but nowadays C99 conformance and BSD compatibility are
more important than System V compatibility.

You might wonder if changing the _underflow impls is sufficient to
apply the C99 semantics to all of the many stdio functions that
perform input.  It should be enough to cover all paths to _IO_SYSREAD,
and the only other functions that call _IO_SYSREAD are the _seekoff
impls, which is OK because seeking clears EOF, and the _xsgetn impls,
which, as far as I can tell, are unused within glibc.

The test programs in this patch use a pseudoterminal to set up the
necessary conditions.  To facilitate this I added a new test-support
function that sets up a pair of pty file descriptors for you; it's
almost the same as BSD openpty, the only differences are that it
allocates the optionally-returned tty pathname with malloc, and that
it crashes if anything goes wrong.

	[BZ #1190]
        [BZ #19476]
	* libio/fileops.c (_IO_new_file_underflow): Return EOF immediately
	if the _IO_EOF_SEEN bit is already set; update commentary.
	* libio/oldfileops.c (_IO_old_file_underflow): Likewise.
	* libio/wfileops.c (_IO_wfile_underflow): Likewise.

	* support/support_openpty.c, support/tty.h: New files.
	* support/Makefile (libsupport-routines): Add support_openpty.

	* libio/tst-fgetc-after-eof.c, wcsmbs/test-fgetwc-after-eof.c:
	New test cases.
	* libio/Makefile (tests): Add tst-fgetc-after-eof.
	* wcsmbs/Makefile (tests): Add tst-fgetwc-after-eof.
2018-03-13 08:31:56 -04:00
Florian Weimer
1a51e46e4a support: Preserve errno in write_message, TEST_VERIFY and other checks
These facilities could clobber errno, which makes it difficult to write
certain checks because a specific order has to be used.
2018-01-12 13:35:01 +01:00
Florian Weimer
401311cfba resolv: Support binary labels in test framework
The old implementation based on hsearch_r used an ad-hoc C string
encoding and produced an incorrect format on the wire for domain
names which contained bytes which needed escaping when printed.

This commit switches to ns_name_pton for the wire format conversion
(now that we have separate tests for it) and uses a tsearch tree
with a suitable comparison function to locate compression targets.
2018-01-08 20:07:24 +01:00
Florian Weimer
2b3aa44656 support: Increase usability of TEST_COMPARE
The previous implementation of the TEST_COMPARE macro would fail
to compile code like this:

  int ret = res_send (query, sizeof (query), buf, sizeof (buf));
  TEST_COMPARE (ret,
                sizeof (query)
                + 2             /* Compression reference.  */
                + 2 + 2 + 4 + 2 /* Type, class, TTL, RDATA length.  */
                + 1             /* Pascal-style string length.  */
                + strlen (expected_name));

This resulted in a failed static assertion, "integer conversions
may alter sign of operands".  A user of the TEST_COMPARE would have
to add a cast to fix this.

This patch reverts to the original proposed solution of a run-time
check, making TEST_COMPARE usable for comparisons of numbers with
types with different signedness in more contexts.
2018-01-08 20:07:24 +01:00
Florian Weimer
dabd75b6a1 support: Define support_static_assert for use with C and C++
And update TEST_COMPARE to use it, to make it usable from C++.
2018-01-08 14:39:51 +01:00
Samuel Thibault
7abf02f3ee support_enter_mount_namespace: Fix indentation
* support/support_enter_mount_namespace.c: Fix indentation.
2018-01-04 15:11:41 +01:00
Samuel Thibault
1714fc06e0 hurd: Fix support/support_enter_mount_namespace.c build
* support/support_enter_mount_namespace.c [!CLONE_NEWNS]: Do not
	include <sys/mount.h>.
2018-01-04 00:54:13 +01:00
Joseph Myers
688903eb3e Update copyright dates with scripts/update-copyrights.
* All files with FSF copyright notices: Update copyright dates
	using scripts/update-copyrights.
	* locale/programs/charmap-kw.h: Regenerated.
	* locale/programs/locfile-kw.h: Likewise.
2018-01-01 00:32:25 +00:00
Florian Weimer
bad7a0c81f copy_file_range: New function to copy file data
The semantics are based on the Linux system call, but a very close
emulation in user space is provided.
2017-12-22 10:55:40 +01:00
Florian Weimer
f58bd7f055 support: Simplify compiling most of support/ outside of glibc
Some include files were missing because they are implied by the
in-tree build process.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2017-12-14 13:48:56 +01:00
Florian Weimer
446d22e91d Linux: Implement interfaces for memory protection keys
This adds system call wrappers for pkey_alloc, pkey_free, pkey_mprotect,
and x86-64 implementations of pkey_get and pkey_set, which abstract over
the PKRU CPU register and hide the actual number of memory protection
keys supported by the CPU.  pkey_mprotect with a -1 key is implemented
using mprotect, so it will work even if the kernel does not support the
pkey_mprotect system call.

The system call wrapers use unsigned int instead of unsigned long for
parameters, so that no special treatment for x32 is needed.  The flags
argument is currently unused, and the access rights bit mask is limited
to two bits by the current PKRU register layout anyway.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2017-12-05 15:20:35 +01:00
Florian Weimer
da616c1496 support/tst-test_compare: Fix 32-bit/64-bit expected output mismatch
The use of a long type resulted in test output differences between
32-bit and 64-bit architectures, causing the test to fail on 32-bit
architectures.
2017-12-05 15:08:59 +01:00
Florian Weimer
934855246d support: Add TEST_COMPARE macro 2017-12-04 20:56:08 +01:00
Christian Brauner
5f9d19490b
support_become_root: Fix comment style 2017-11-18 17:54:24 +01:00
Christian Brauner
ea69a5c874
support_become_root: Don't fail when /proc/<pid/setgroups is missing
The requirement to write "deny" to /proc/<pid>/setgroups for a given user
namespace before being able to write a gid mapping was introduced in Linux
3.19.  Before that this requirement including the file did not exist.
So don't fail when errno == ENOENT.
2017-11-18 16:23:01 +01:00
Florian Weimer
273a0c4983 support_enter_mount_namespace: Unshare with mount --make-rprivate
System defaults vary, and a mere unshare (CLONE_NEWNS) (which is part of
support_become_root) is no longer sufficient.

Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-18 14:30:20 +01:00
Florian Weimer
8adfb0eeff support_create_temp_directory: Align behavior with create_temp_file
create_temp_file automatically supplies the test directory and the
XXXXXX suffix.  support_create_temp_directory required the caller to
specify them, which was confusing.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
2017-11-18 14:11:09 +01:00
Florian Weimer
ce003e5d4c support_become_root: Enable file creation in user namespaces
Without UID/GID maps, file creation will file with EOVERFLOW.

This patch is based on DJ Delorie's work on container testing.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
2017-11-17 22:11:28 +01:00
Florian Weimer
cae87e64dc support: Add <support/next_to_fault.h>
Based on the implementation in resolv/tst-inet_pton.c.
2017-11-13 19:29:32 +01:00
Florian Weimer
1ffe1ccb6e support: Add xstrndup, xunlink, xreadlink, support_create_temp_directory 2017-11-12 09:53:06 +01:00
Florian Weimer
84d0e6f052 support_format_hostent: Add more error information for NETDB_INTERNAL 2017-10-05 12:20:19 +02:00
Samuel Thibault
5af1e931bf Revert "resolv_test.c: also cope with CONNREFUSED errors returned by recvfrom"
This reverts commit 6174537c24.
2017-09-25 20:47:51 +02:00
Samuel Thibault
6174537c24 resolv_test.c: also cope with CONNREFUSED errors returned by recvfrom
server_thread_udp_process_one already takes care of calling sendto()
instead of xsendto to be able to ignore the case where the client has
closed the socket.  Depending on the TCP/IP stack behavior, this error
could be notified later through recvfrom(), so we need to ignore it
there too.

* support/resolv_test.c (server_thread_udp_process_one): Call recvfrom
instead of xrecvfrom, and ignore ECONNREFUSED errors.
2017-09-25 01:11:43 +02:00
Paul Pluzhnikov
1cc9e59a93 Implement xdlopen, xdlsym and xdlclose routines which terminate test
program with appropriate message if the corresponding dlfcn.h routine
returns an error.

Use them in stdlib/tst-tls-atexit.c
2017-09-20 19:37:45 -07:00
Florian Weimer
65329bd233 support_chroot_create: Add support for /etc/hosts, /etc/host.conf 2017-09-01 08:58:07 +02:00
Carlos O'Donell
faf8c066df rwlock: Fix explicit hand-over (bug 21298)
Without this fix, the rwlock can fail to execute the explicit hand-over
in certain cases (e.g., empty critical sections that switch quickly between
read and write phases).  This can then lead to errors in how __wrphase_futex
is accessed, which in turn can lead to deadlocks.
2017-07-28 00:23:58 -04:00
Florian Weimer
cb3c27e87b support: Add resolver testing mode which does not patch _res 2017-07-05 19:04:40 +02:00
Florian Weimer
d4165eedf5 support: Add support_chroot_create and support_chroot_free 2017-07-05 19:04:40 +02:00
Florian Weimer
76637a921f support: Check isolation of loopback addresses in tst-support-namespace 2017-07-05 19:04:39 +02:00
Florian Weimer
5f17245d3e support: Report actual exit status in support_capture_subprocess_check 2017-06-30 11:30:48 +02:00
Florian Weimer
60149b2859 __inet_pton_length: Implement new internal helper function 2017-06-21 13:09:08 +02:00
Adhemerval Zanella
244361ebae support: Add optstring support
This patch adds an option to test to add small command line option
through CMDLINE_OPTSTRING define.  For instance:

  #define CMDLINE_OPTSTRING "vd"

  static void
  cmdline_process_function (int c)
  {
    switch (c):
      'v':
        /* process '-v' option.  */
      break;
      'd':
        /* process '-d' option.  */
      break;
  }
  #define CMDLINE_PROCESS cmdline_process_function

It will add both '-v' and '-d' along with already default long options.

	* support/support_test_main.c (support_test_main):  Use optstring
	member for option string in getopt_long.
	* support/test-driver.c: Add comment about CMDLINE_OPTSTRING.
	(CMDLINE_OPTSTRING): New define.
	* support/test-driver.h (test_config): Add optstring member.
2017-06-15 16:01:38 -03:00
Adhemerval Zanella
0edbf12301 nptl: Invert the mmap/mprotect logic on allocated stacks (BZ#18988)
Current allocate_stack logic for create stacks is to first mmap all
the required memory with the desirable memory and then mprotect the
guard area with PROT_NONE if required.  Although it works as expected,
it pessimizes the allocation because it requires the kernel to actually
increase commit charge (it counts against the available physical/swap
memory available for the system).

The only issue is to actually check this change since side-effects are
really Linux specific and to actually account them it would require a
kernel specific tests to parse the system wide information.  On the kernel
I checked /proc/self/statm does not show any meaningful difference for
vmm and/or rss before and after thread creation.  I could only see
really meaningful information checking on system wide /proc/meminfo
between thread creation: MemFree, MemAvailable, and Committed_AS shows
large difference without the patch.  I think trying to use these
kind of information on a testcase is fragile.

The BZ#18988 reports shows that the commit pages are easily seen with
mlockall (MCL_FUTURE) (with lock all pages that become mapped in the
process) however a more straighfoward testcase shows that pthread_create
could be faster using this patch:

--
static const int inner_count = 256;
static const int outer_count = 128;

static
void *thread1(void *arg)
{
  return NULL;
}

static
void *sleeper(void *arg)
{
  pthread_t ts[inner_count];
  for (int i = 0; i < inner_count; i++)
    pthread_create (&ts[i], &a, thread1, NULL);
  for (int i = 0; i < inner_count; i++)
    pthread_join (ts[i], NULL);

  return NULL;
}

int main(void)
{
  pthread_attr_init(&a);
  pthread_attr_setguardsize(&a, 1<<20);
  pthread_attr_setstacksize(&a, 1134592);

  pthread_t ts[outer_count];
  for (int i = 0; i < outer_count; i++)
    pthread_create(&ts[i], &a, sleeper, NULL);
  for (int i = 0; i < outer_count; i++)
    pthread_join(ts[i], NULL);
    assert(r == 0);
  }
  return 0;
}

--

On x86_64 (4.4.0-45-generic, gcc 5.4.0) running the small benchtests
I see:

$ time ./test

real	0m3.647s
user	0m0.080s
sys	0m11.836s

While with the patch I see:

$ time ./test

real	0m0.696s
user	0m0.040s
sys	0m1.152s

So I added a pthread_create benchtest (thread_create) which check
the thread creation latency.  As for the simple benchtests, I saw
improvements in thread creation on all architectures I tested the
change.

Checked on x86_64-linux-gnu, i686-linux-gnu, aarch64-linux-gnu,
arm-linux-gnueabihf, powerpc64le-linux-gnu, sparc64-linux-gnu,
and sparcv9-linux-gnu.

	[BZ #18988]
	* benchtests/thread_create-inputs: New file.
	* benchtests/thread_create-source.c: Likewise.
	* support/xpthread_attr_setguardsize.c: Likewise.
	* support/Makefile (libsupport-routines): Add
	xpthread_attr_setguardsize object.
	* support/xthread.h: Add xpthread_attr_setguardsize prototype.
	* benchtests/Makefile (bench-pthread): Add thread_create.
	* nptl/allocatestack.c (allocate_stack): Call mmap with PROT_NONE and
	then mprotect the required area.
2017-06-14 17:22:35 -03:00
Florian Weimer
48bd8cda09 support: Expose TEST_VERIFY_EXIT behavior to GCC optimizers
Previously, the implementation would conditionally exit based on the
status argument, which GCC did not know about.  This leads to
false uninitialized variable warnings when data is accessed after a
TEST_VERIFY_EXIT failure (from code which would never execute).
2017-06-09 14:08:13 +02:00
Florian Weimer
2714c5f3c9 resolv: Tests for various versions of res_init 2017-06-02 15:50:36 +02:00
Florian Weimer
91b6eb1140 Add internal facility for dynamic array handling
This is intended as a type-safe alternative to obstacks and
hand-written realloc constructs.  The implementation avoids
writing function pointers to the heap.
2017-06-02 11:59:28 +02:00
Florian Weimer
8ec69bb7ec support_format_addrinfo: Fix flags and canonname formatting
The address family splitting via format_ai_family made unpredictable
the place where the canonname field was printed.  This commit adjusts
the implementation so that the ai_flags is checked for consistency
across the list, and ai_canonname must only be present on the first
list element.

Tests for AI_CANONNAME are added to resolv/tst-resolv-basic.
2017-05-11 11:51:34 +02:00
Florian Weimer
c22553effb support: Prevent multiple deletion of temporary files
Otherwise, another user might recreate these files after the first
deletion.  Particularly with temporary directories, this could result
in the removal of unintended files through symbol link attacks.
2017-05-08 16:20:40 +02:00
Florian Weimer
706256afb6 support: Delete temporary files in LIFO order
This is required to remove temporary directories which contain
temporary files.  Previously, FIFO order meant that directory
removal was attempted when the directory still contained files,
which meant that temporary directory cleanup was essentially
unsupported.
2017-05-08 15:54:10 +02:00
Joseph Myers
9fe3c80c7c Fix sys/socket.h namespace issues from sys/uio.h inclusion (bug 21426).
sys/socket.h includes sys/uio.h to get the definition of the iovec
structure.

POSIX allows sys/socket.h to make all sys/uio.h symbols visible.
However, all of sys/uio.h is XSI-shaded, so for non-XSI POSIX this
results in conformtest failures (for sys/socket.h and other headers
that include it):

    Namespace violation: "UIO_MAXIOV"
    Namespace violation: "readv"
    Namespace violation: "writev"

Now, there is some ambiguity in POSIX about what namespace
reservations apply in this case - see
http://austingroupbugs.net/view.php?id=1127 - but glibc convention
would still avoid declaring readv and writev, for example, for feature
test macros that don't include them (if only headers from the relevant
standard are included), even if such declarations are permitted, so
there is a bug here according to glibc conventions.

This patch moves the struct iovec definition to a new
bits/types/struct_iovec.h header and includes that from sys/socket.h
instead of including the whole of sys/uio.h.  This fixes the namespace
issue; however, three files in glibc that were relying on the implicit
inclusion needed to be updated to include sys/uio.h explicitly.  So
there is a question of whether sys/socket.h should continue to include
sys/uio.h under some conditions, such as __USE_XOPEN or __USE_MISC or
__USE_XOPEN || __USE_MISC, for greater compatibility with code that
(wrongly) expects this optional inclusion to be present there.  (I
think the three affected files in glibc should still have explicit
sys/uio.h inclusions added in any case, however.)

Tested for x86_64.

	[BZ #21426]
	* misc/bits/types/struct_iovec.h: New file.
	* misc/Makefile (headers): Add bits/types/struct_iovec.h.
	* include/bits/types/struct_iovec.h: New file.
	* bits/uio.h (struct iovec): Replace by inclusion of
	<bits/types/struct_iovec.h>.
	* sysdeps/unix/sysv/linux/bits/uio.h (struct iovec): Likewise.
	* socket/sys/socket.h: Include <bits/types/struct_iovec.h> instead
	of <sys/uio.h>.
	* nptl/tst-cancel4.c: Include <sys/uio.h>
	* posix/test-errno.c: Likewise.
	* support/resolv_test.c: Likewise.
	* conform/Makefile (test-xfail-POSIX2008/arpa/inet.h/conform):
	Remove.
	(test-xfail-POSIX2008/netdb.h/conform): Likewise.
	(test-xfail-POSIX2008/netinet/in.h/conform): Likewise.
	(test-xfail-POSIX2008/sys/socket.h/conform): Likewise.
2017-04-25 17:52:47 +00:00
Florian Weimer
e92030239a Assume that accept4 is always available and works
Simplify the Linux accept4 implementation based on the assumption
that it is available in some way.  __ASSUME_ACCEPT4_SOCKETCALL was
previously unused, so remove it.

For ia64, the accept4 system call (and socket call) were backported
in kernel version 3.2.18.  Reflect this in the installation
instructions.
2017-04-19 07:44:48 +02:00
Florian Weimer
e14a27723c resolv: Reduce EDNS payload size to 1200 bytes [BZ #21361]
This hardens the stub resolver against fragmentation-based attacks.
2017-04-13 13:09:38 +02:00
Zack Weinberg
b9e8c90875 Another round of inclusion fixes for _ISOMAC testsuite.
* stdio-common/bug25.c: Include stdlib.h.
	* support/tst-support_format_dns_packet.c: Include stdio.h,
	stdlib.h, and string.h.
	* support/tst-support_record_failure.c: Include string.h.
	* support/tst-support_record_failure-2.sh: Adjust line number
	expectations and correct a typo in an error message.
2017-03-22 08:44:32 -04:00
Florian Weimer
2bda2d820d support: Explain ignored failures of temporary file removal [BZ #21243] 2017-03-15 13:33:40 +01:00
Florian Weimer
ed3ea040ba support: Add error checking to close system calls [BZ #21244] 2017-03-15 13:33:40 +01:00
Florian Weimer
f889e73f60 support_format_dns_packet: Fix CNAME and multiple RR handling
Before this change, the loop iterating over RRs in the answer
section stopped at the first CNAME record, never printing them.
The CNAME and PTR record contents was extracted from the wrong
buffer (whole packet instead RDATA).  This desynced the parsing
after the first CNAME or PTR record.

Also fix the AAAA record parsing by checking their sizes.
2017-03-15 13:33:40 +01:00
Carlos O'Donell
f8bf15febc Bug 20116: Fix use after free in pthread_create()
The commit documents the ownership rules around 'struct pthread' and
when a thread can read or write to the descriptor. With those ownership
rules in place it becomes obvious that pd->stopped_start should not be
touched in several of the paths during thread startup, particularly so
for detached threads. In the case of detached threads, between the time
the thread is created by the OS kernel and the creating thread checks
pd->stopped_start, the detached thread might have already exited and the
memory for pd unmapped. As a regression test we add a simple test which
exercises this exact case by quickly creating detached threads with
large enough stacks to ensure the thread stack cache is bypassed and the
stacks are unmapped. Before the fix the testcase segfaults, after the
fix it works correctly and completes without issue.

For a detailed discussion see:
https://www.sourceware.org/ml/libc-alpha/2017-01/msg00505.html
2017-01-28 19:21:44 -05:00
Florian Weimer
faf0e9c841 nptl: Add tst-robust-fork 2017-01-27 06:53:20 +01:00
Florian Weimer
73dfd08893 support: struct netent portability fix for support_format_netent 2017-01-01 09:35:45 +01:00
Florian Weimer
8e2c31b57f support: Use %td for pointer difference in xwrite 2017-01-01 09:27:54 +01:00
Joseph Myers
bfff8b1bec Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
Florian Weimer
5840c75c2d resolv: Add beginnings of a libresolv test suite 2016-12-31 18:52:32 +01:00
Florian Weimer
f47ae51866 support: Implement --verbose option for test programs
Some tests can produce rather verbose tracing information,
and the --verbose option provides a standardized way to enable
such logging output.
2016-12-31 18:51:15 +01:00
Florian Weimer
039c5a05cc support: Use support_record_failure consistently
This causes more test programs to link in the support_record_failure
function, which triggers an early call to mmap from an ELF
constructor, but this should not have side effects intefering
with the functionality actually under test (unlike, say, a call
to malloc).
2016-12-31 18:51:15 +01:00
Florian Weimer
5707a64d94 support: Helper functions for entering namespaces 2016-12-31 18:51:07 +01:00
Joseph Myers
ef83c83a25 Fix tst-support_record_failure-2 for run-built-tests = no.
The support/tst-support_record_failure-2.out test attempts to run
built code even if run-built-tests = no, so failing with
build-many-glibcs.py for all architectures whose code cannot be run on
the system running the script.  This patch disables the test in that
case.

Tested for x86_64 (native), and for aarch64 with build-many-glibcs.py.

	* support/Makefile (tests-special): Make definition conditional on
	[$(run-built-tests) = yes].
	($(objpfx)tst-support_record_failure-2.out): Make rule conditional
	on [$(run-built-tests) = yes].
2016-12-30 13:01:44 +00:00
Adhemerval Zanella
59c900c54b Add SYSV message queue test
This patch adds a simple SYSV message queue test to check for correct
argument passing on kernel.  The idea is neither to be an extensive
testing nor to check for any specific Linux test.

	* sysvipc/Makefile (tests): Add test-sysvmsg.
	* sysvipc/test-sysvmsg.c: New file.
	* test-skeleton.c (FAIL_UNSUPPORTED): New define.
2016-12-28 20:30:59 -02:00
Florian Weimer
5f0b843790 support: Add support for delayed test failure reporting
The new functions support_record_failure records a test failure,
but does not terminate the process.  The macros TEST_VERIFY
and TEST_VERIFY_EXIT check that a condition is true.
2016-12-28 13:37:18 +01:00
Andreas Schwab
67f779f1ea Fix assertion failure on test timeout 2016-12-15 17:25:12 +01:00
Andreas Schwab
fea34d51e0 Fix testsuite timeout handling 2016-12-10 16:22:01 +01:00
Florian Weimer
c23de0aacb support: Introduce new subdirectory for test infrastructure
The new test driver in <support/test-driver.c> has feature parity with
the old one.  The main difference is that its hooking mechanism is
based on functions and function pointers instead of macros.  This
commit also implements a new environment variable, TEST_COREDUMPS,
which disables the code which disables coredumps (that is, it enables
them if the invocation environment has not disabled them).

<test-skeleton.c> defines wrapper functions so that it is possible to
use existing macros with the new-style hook functionality.

This commit changes only a few test cases to the new test driver, to
make sure that it works as expected.
2016-12-09 08:18:27 +01:00