[PATCH 3/3] tests: add a test for -Y option
Masatake YAMATO
yamato at redhat.com
Wed Aug 18 11:00:42 UTC 2021
From: <yamato at redhat.com>
From: Masatake YAMATO <yamato at redhat.com>
* tests/strace-Y-0123456789.c: New file.
* tests/gen_tests.in (strace-Y-0123456789): New test.
* tests/Makefile.am (CHECK_PROGRAMS): Add strace-Y-0123456789.
Signed-off-by: Masatake YAMATO <yamato at redhat.com>
---
tests/.gitignore | 1 +
tests/Makefile.am | 1 +
tests/gen_tests.in | 1 +
tests/strace-Y-0123456789.c | 88 +++++++++++++++++++++++++++++++++++++
4 files changed, 91 insertions(+)
create mode 100644 tests/strace-Y-0123456789.c
diff --git a/tests/.gitignore b/tests/.gitignore
index fd37cc375..b42a3c829 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -858,6 +858,7 @@ strace--strings-in-hex-non-ascii
strace-n
strace-x
strace-xx
+strace-Y-0123456789
swap
sxetmask
symlink
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 274cc3bf3..64fa2cada 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -301,6 +301,7 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \
stack-fcall-mangled \
status-none-threads \
status-unfinished-threads \
+ strace-Y-0123456789 \
syslog-success \
tgkill--pidns-translation \
threads-execve \
diff --git a/tests/gen_tests.in b/tests/gen_tests.in
index bb5410892..5ef9acd49 100644
--- a/tests/gen_tests.in
+++ b/tests/gen_tests.in
@@ -831,6 +831,7 @@ strace--timestamps-unix-us +strace-ttt.test 6 --timestamps=unix,us
strace-n -e trace=listen -n -qq -a 12
strace-x -e trace=chdir -x -a 12
strace-xx -e trace=chdir -xx -a 18
+strace-Y-0123456789 -e trace=getppid -e signal='!SIGCHLD' -q -f -Y -a 18
swap -a23 -e trace=swapon,swapoff
sxetmask -a11 -e trace=sgetmask,ssetmask
symlink -a34
diff --git a/tests/strace-Y-0123456789.c b/tests/strace-Y-0123456789.c
new file mode 100644
index 000000000..b0250b37c
--- /dev/null
+++ b/tests/strace-Y-0123456789.c
@@ -0,0 +1,88 @@
+/*
+ * Test strace's -Y option
+ * Copyright (c) 2021 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+/* The executable built from this source file should
+ * have a long name (> 16) to test how strace reports
+ * the initial value of /proc/$pid/comm.
+ * Even if linux returns a longer name, strace should
+ * not crash. */
+
+#include "tests.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/prctl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#define NEW_NAME "0123456789abcdefghijklmnopqrstuvwxyz"
+
+static int
+do_default_action(int argc, char **argvZ)
+{
+ pid_t pid = getpid();
+ pid_t ppid = getppid();
+
+ char comm[sizeof(NEW_NAME)];
+ prctl(PR_GET_NAME, comm);
+
+ printf("%-5d<%s> getppid() = %d\n", pid, comm, ppid);
+
+ fflush(stdout);
+
+ pid_t child = fork();
+ if (child < 0)
+ return 1;
+ else if (child == 0) {
+ pid = getpid();
+ ppid = getppid();
+ prctl(PR_GET_NAME, comm);
+ printf("%-5d<%s> getppid() = %d\n", pid, comm, ppid);
+ strcpy(comm, NEW_NAME);
+ prctl(PR_SET_NAME, comm);
+ prctl(PR_GET_NAME, comm);
+ ppid = getppid();
+ printf("%-5d<%s> getppid() = %d\n", pid, comm, ppid);
+ fflush(stdout);
+
+ char * self_argv[] = { (char *)"unused", (char *)"execve", NULL };
+ if (execve("/proc/self/exe", self_argv, NULL) != 0)
+ perror_msg_and_fail("execve");
+
+ }
+ else {
+ int status;
+ wait(&status);
+ printf("%-5d<exe> +++ exited with 0 +++\n", child);
+
+ ppid = getppid();
+ printf("%-5d<%s> getppid() = %d\n", pid, comm, ppid);
+ printf("%-5d<%s> +++ exited with 0 +++\n", pid, comm);
+ return WEXITSTATUS(status);
+ }
+ return 0;
+}
+
+static int
+do_execve_action(int argc, char **argvZ)
+{
+ return 0;
+}
+
+int
+main(int argc, char **argv)
+{
+ if (argc < 2)
+ return do_default_action(argc, argv);
+ else if (strcmp(argv[1], "execve") == 0)
+ return do_execve_action(argc, argv);
+ else
+ error_msg_and_fail("unexpected argument: %s", argv[1]);
+}
--
2.31.1
More information about the Strace-devel
mailing list