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

Dmitry V. Levin ldv at altlinux.org
Tue Jun 18 00:06:07 UTC 2019


On Sat, Jun 15, 2019 at 07:33:44PM +0200, Paul Chaignon wrote:
> This patch adds 5 test cases for -e status with unfinished, failed, none,
> successful, 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.
> 
> Signed-off-by: Paul Chaignon <paul.chaignon at gmail.com>
> Co-Authored-by: Burkhard Kohl <burkhard.kohl at intel.com>
> ---
>  tests/.gitignore            |  5 +++
>  tests/Makefile.am           |  2 ++
>  tests/gen_tests.in          |  5 +++
>  tests/pure_executables.list |  5 +++
>  tests/status-all.c          | 29 +++++++++++++++
>  tests/status-failed.c       | 33 +++++++++++++++++
>  tests/status-none.c         | 65 +++++++++++++++++++++++++++++++++
>  tests/status-successful.c   | 33 +++++++++++++++++
>  tests/status-unfinished.c   | 71 +++++++++++++++++++++++++++++++++++++
>  9 files changed, 248 insertions(+)
>  create mode 100644 tests/status-all.c
>  create mode 100644 tests/status-failed.c
>  create mode 100644 tests/status-none.c
>  create mode 100644 tests/status-successful.c
>  create mode 100644 tests/status-unfinished.c

Looks good, thanks.
There are a few minor issues that should be addressed, see below.

> diff --git a/tests/.gitignore b/tests/.gitignore
> index fb3fa928..06a61f91 100644
> --- a/tests/.gitignore
> +++ b/tests/.gitignore
> @@ -558,6 +558,11 @@ stat
>  stat64
>  statfs
>  statfs64
> +status-all
> +status-unfinished
> +status-failed
> +status-none
> +status-successful
>  statx
>  swap
>  sxetmask

Please keep this list sorted.

> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index 9e99aff2..d7d75346 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -190,6 +190,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_unfinished_LDADD = -lpthread $(LDADD)
> +status_none_LDADD = -lpthread $(LDADD)
>  threads_execve_LDADD = -lpthread $(clock_LIBS) $(LDADD)
>  times_LDADD = $(clock_LIBS) $(LDADD)
>  truncate64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64

Please keep this list sorted.

> diff --git a/tests/gen_tests.in b/tests/gen_tests.in
> index 487b9608..fe752aa9 100644
> --- a/tests/gen_tests.in
> +++ b/tests/gen_tests.in
> @@ -465,6 +465,11 @@ stat	-a32 -v -P stat.sample -P /dev/full
>  stat64	-a32 -v -P stat.sample -P /dev/full
>  statfs	-a17
>  statfs64	-a23
> +status-all	-a11 -e trace=chdir -e status=failed,successful,unfinished,unavailable,unfinished,detached

Is there any reason to mention "unfinished" twice?

> +status-unfinished	-f -e trace=exit,nanosleep,execve -e status=unfinished

Why exit?  _exit() invokes exit_group nowadays.

Please keep this list sorted.

> +status-failed	-a10 -e trace=chdir -Z
> +status-none	-f -e trace=exit,nanosleep,execve -e status=none
> +status-successful	-a11 -e trace=chdir -z
>  statx	-a32 -v -P stat.sample -P /dev/full
>  swap	-a23 -e trace=swapon,swapoff
>  sxetmask	-a11 -e trace=sgetmask,ssetmask
> diff --git a/tests/pure_executables.list b/tests/pure_executables.list
> index 37225209..731279af 100755
> --- a/tests/pure_executables.list
> +++ b/tests/pure_executables.list
> @@ -470,6 +470,11 @@ stat
>  stat64
>  statfs
>  statfs64
> +status-all
> +status-unfinished
> +status-failed
> +status-none
> +status-successful
>  statx
>  swap
>  sxetmask

Please keep this list sorted.

[...]
> --- /dev/null
> +++ b/tests/status-unfinished.c
> @@ -0,0 +1,71 @@
> +/*
> + * 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 +++ exited with 0 +++\n", 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;
> +}

As exit_group is also unfinished syscall, adding it to the trace set would
allow to check that it's properly printed by status=unfinished.

BTW, do you plan to add a test for status=detached?

It could be something simple, e.g.
../strace -e trace=nanosleep -e status=detached ./sleep 2 & ./sleep 1 && kill $!


-- 
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/20190618/f6d7eff8/attachment.bin>


More information about the Strace-devel mailing list