summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDmitry V. Levin <ldv@strace.io>2022-12-29 08:00:00 +0000
committerDmitry V. Levin <ldv@strace.io>2022-12-29 08:00:00 +0000
commitd9a576d2366963fd1306055582b3678a3ebb1052 (patch)
tree4cc0218fac17549befe717d548f460e5cf300ff8 /tests
parent2a4fced23a34617404a98b099f6a861bbbda7c01 (diff)
downloadstrace-d9a576d2366963fd1306055582b3678a3ebb1052.tar.gz
printleader: do not mark output as unfinished unnecessarily
* src/strace.c (printleader): Do not mark staged output in other processes as unfinished. * tests/status-successful-threads.c: New file. * tests/status-successful-threads.test: New test. * tests/.gitignore: Add status-successful-threads. * tests/Makefile.am (check_PROGRAMS): Likewise. (status_successful_threads_LDADD): New variable. (MISC_TESTS): Add status-successful-threads.test.
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/Makefile.am3
-rw-r--r--tests/status-successful-threads.c71
-rwxr-xr-xtests/status-successful-threads.test16
4 files changed, 91 insertions, 0 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 83c5b60c0..5935c39d9 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1010,6 +1010,7 @@ status-none-threads
status-successful
status-successful-long
status-successful-status
+status-successful-threads
status-unfinished
status-unfinished-threads
statx
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0cb4c09bf..577d4c637 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -378,6 +378,7 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \
stack-fcall-mangled \
status-detached-threads \
status-none-threads \
+ status-successful-threads \
status-unfinished-threads \
strace--decode-pids-comm \
strace-Y-0123456789 \
@@ -438,6 +439,7 @@ stat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
statfs_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
status_detached_threads_LDADD = -lpthread $(LDADD)
status_none_threads_LDADD = -lpthread $(LDADD)
+status_successful_threads_LDADD = -lpthread $(LDADD)
status_unfinished_threads_LDADD = -lpthread $(LDADD)
threads_execve_LDADD = -lpthread $(clock_LIBS) $(LDADD)
threads_execve__quiet_thread_execve_LDADD = -lpthread $(clock_LIBS) $(LDADD)
@@ -604,6 +606,7 @@ MISC_TESTS = \
status-detached.test \
status-detached-threads.test \
status-none-threads.test \
+ status-successful-threads.test \
status-unfinished-threads.test \
strace--tips.test \
strace--tips-full.test \
diff --git a/tests/status-successful-threads.c b/tests/status-successful-threads.c
new file mode 100644
index 000000000..bed68952f
--- /dev/null
+++ b/tests/status-successful-threads.c
@@ -0,0 +1,71 @@
+/*
+ * Check status=successful filtering when a non-leader thread invokes execve.
+ *
+ * Copyright (c) 2019 Paul Chaignon <paul.chaignon@gmail.com>
+ * Copyright (c) 2022 Dmitry V. Levin <ldv@strace.io>
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+#include "scno.h"
+
+#include <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/uio.h>
+
+static pid_t leader;
+
+static void *
+thread_exec(void *arg)
+{
+ pid_t tid = syscall(__NR_gettid);
+ printf("%-5d +++ superseded by execve in pid %u +++\n",
+ leader, tid);
+
+ char *argv[] = {((char **) arg)[0], (char *) "0", NULL};
+ execve(argv[0], argv, NULL);
+ perror_msg_and_fail("execve");
+}
+
+int
+main(int ac, char **av)
+{
+ if (ac > 1)
+ return 0;
+
+ int fds[2];
+ if (pipe(fds))
+ perror_msg_and_fail("pipe");
+
+ pid_t child = fork();
+ if (child < 0)
+ perror_msg_and_fail("fork");
+
+ leader = getpid();
+ setvbuf(stdout, NULL, _IONBF, 0);
+
+ if (!child) {
+ close(fds[0]);
+ pthread_t thre;
+ errno = pthread_create(&thre, NULL, thread_exec, av);
+ if (errno)
+ perror_msg_and_fail("pthread_create");
+ for (;;) { /* wait for execve */ }
+ return 1;
+ }
+
+ close(fds[1]);
+ unsigned int len = sizeof(fds[1]);
+ struct iovec rio = { .iov_base = &fds[1], .iov_len = len };
+ if (readv(fds[0], &rio, 1))
+ perror_msg_and_fail("readv");
+
+ printf("%-5d readv(%d, [{iov_base=\"\", iov_len=%u}], 1) = 0\n"
+ "%-5d +++ exited with 0 +++\n",
+ leader, fds[0], len, leader);
+ return 0;
+}
diff --git a/tests/status-successful-threads.test b/tests/status-successful-threads.test
new file mode 100755
index 000000000..54bb0dc3b
--- /dev/null
+++ b/tests/status-successful-threads.test
@@ -0,0 +1,16 @@
+#!/bin/sh
+#
+# Check status=successful filtering when a non-leader thread invokes execve.
+#
+# Copyright (c) 2019-2022 The strace developers.
+# All rights reserved.
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+. "${srcdir=.}/init.sh"
+
+# Check that PTRACE_EVENT_EXEC support in kernel is good enough.
+# The kernel before commit v3.1-rc1~308^2~7 reported 0 instead of old pid.
+require_min_kernel_version_or_skip 3.1
+
+run_strace_match_diff -f -z --signal=none --trace=readv