[PATCH v5 4/4] tests: check status qualifier
Paul Chaignon
paul.chaignon at gmail.com
Tue Jul 2 16:13:42 UTC 2019
On Tue, Jul 02, 2019 at 03:01:55AM +0300, Dmitry V. Levin wrote:
> 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.
[...]
> > 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 +++
It looks like this was happening because I moved the clock_nanosleep call
after the printf call in the thread. I don't see the test failures
anymore.
Paul
More information about the Strace-devel
mailing list