[PATCH v5 4/4] tests: check status qualifier

Dmitry V. Levin ldv at altlinux.org
Tue Jul 2 00:01:55 UTC 2019


On Fri, Jun 28, 2019 at 11:34:40AM +0200, Paul Chaignon wrote:
> This patch adds 6 test cases for -e status with unfinished, failed, none,
> successful, detached, and the whole set.  The test cases for failed,
> successful, and the whole set use chdir(2).  The test cases for unfinished
> and none rely on a child thread execve'ing the lead thread.  The test case
> for detached interrupts strace while attached to a sleeping process.
> 
> * tests/status-all.c: New test.
> * tests/status-detached.test: New test.
> * tests/status-detached.expected: New file.
> * tests/status-failed.c: New test.
> * tests/status-none.c: New test.
> * tests/status-successful.c: New test.
> * tests/status-unfinished.c: New test.
> * tests/status.c: New file.
> * tests/tests.h (test_status_chdir): New prototype.
> * tests/.gitignore: Add status-all, status-failed, status-none,
> status-successful, and status-unfinished.
> * tests/gen_tests.in: Likewise.
> * tests/pure_executables.list: Likewise.
> * tests/Makefile.am: Add status.c, status_none_LDADD,
> status_unfinished_LDADD, and status-detached.test.
[...]
> @@ -190,6 +191,8 @@ preadv_pwritev_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
>  pwritev_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
>  stat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
>  statfs_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
> +status_none_LDADD = -lpthread $(LDADD)
> +status_unfinished_LDADD = -lpthread $(LDADD)
>  threads_execve_LDADD = -lpthread $(clock_LIBS) $(LDADD)

All tests that invoke clock_nanosleep should be linked with $(clock_LIBS)
like threads_execve_LDADD, otherwise the build fails on legacy systems
with the following diagnostics:

status-none.c:35: undefined reference to `clock_nanosleep'
status-unfinished.c:36: undefined reference to `clock_nanosleep'

[...]
> diff --git a/tests/status-unfinished.c b/tests/status-unfinished.c
> new file mode 100644
> index 00000000..b751daf7
> --- /dev/null
> +++ b/tests/status-unfinished.c
> @@ -0,0 +1,72 @@
> +/*
> + * Check status filtering when a non-leader thread invokes execve.
> + *
> + * Copyright (c) 2019 Paul Chaignon <paul.chaignon at gmail.com>
> + * All rights reserved.
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#include "tests.h"
> +#include <asm/unistd.h>
> +#include <errno.h>
> +#include <pthread.h>
> +#include <stdio.h>
> +#include <unistd.h>
> +
> +static pid_t leader;
> +static pid_t tid;
> +
> +static pid_t
> +k_gettid(void)
> +{
> +	return syscall(__NR_gettid);
> +}
> +
> +static void *
> +thread(void *arg)
> +{
> +	tid = k_gettid();
> +
> +	printf("%-5d <... nanosleep resumed> <unfinished ...>) = ?\n"
> +	       "%-5d +++ superseded by execve in pid %u +++\n",
> +	       leader, leader, tid);
> +
> +	struct timespec ts = { .tv_nsec = 100000000 };
> +	(void) clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL);
> +
> +	ts.tv_nsec = 12345;
> +	(void) nanosleep(&ts, NULL);
> +
> +	char *argv[] = {((char **) arg)[0], (char *) "0", NULL};
> +	execve(argv[0], argv, NULL);
> +	perror_msg_and_fail("execve");
> +}
> +
> +int
> +main(int ac, char **av)
> +{
> +	setvbuf(stdout, NULL, _IONBF, 0);
> +	leader = getpid();
> +
> +	if (ac > 1) {
> +		printf("%-5d exit_group(0) = ?\n"
> +		       "%-5d +++ exited with 0 +++\n", leader, leader);
> +		return 0;
> +	}
> +
> +	pthread_t t;
> +	errno = pthread_create(&t, NULL, thread, av);
> +	if (errno)
> +		perror_msg_and_fail("pthread_create");
> +
> +	struct timespec ts = { .tv_sec = 123 };
> +	static char leader_str[sizeof(leader) * 3];
> +	snprintf(leader_str, sizeof(leader_str), "%-5d", leader);
> +	printf("%s nanosleep({tv_sec=%u, tv_nsec=0}"
> +	       ",  <unfinished ...>\n",
> +	       leader_str, (unsigned int) ts.tv_sec);
> +	(void) nanosleep(&ts, 0);
> +
> +	return 1;
> +}

This test is racy, sometimes it fails with the following diagnostics:

+23456 nanosleep({tv_sec=123, tv_nsec=0},  <unfinished ...>
 23456 <... nanosleep resumed> <unfinished ...>) = ?
 23456 +++ superseded by execve in pid 23457 +++
-23456 nanosleep({tv_sec=123, tv_nsec=0},  <unfinished ...>
 23456 exit_group(0) = ?
 23456 +++ exited with 0 +++


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20190702/5ffaf258/attachment.bin>


More information about the Strace-devel mailing list