Blame SOURCES/strace-rhbz1610774-0001-tests-check-tracing-of-looping-threads.patch

6cf6ff
From 1e497a53b82bae846618e3b9064d6c4a63024aea Mon Sep 17 00:00:00 2001
6cf6ff
From: "Dmitry V. Levin" <ldv@altlinux.org>
6cf6ff
Date: Wed, 4 Jul 2018 02:11:27 +0000
6cf6ff
Subject: [PATCH 1/3] tests: check tracing of looping threads
6cf6ff
6cf6ff
* test/many_looping_threads.c: Remove.
6cf6ff
* test/.gitignore: Remove many_looping_threads.
6cf6ff
* test/Makefile (PROGS): Likewise.
6cf6ff
(many_looping_threads): Remove.
6cf6ff
* tests/looping_threads.c: New file.
6cf6ff
* tests/looping_threads.test: New test.
6cf6ff
* tests/.gitignore: Add looping_threads.
6cf6ff
* tests/Makefile.am (check_PROGRAMS): Likewise.
6cf6ff
(looping_threads_LDADD): New variable.
6cf6ff
(MISC_TESTS, XFAIL_TESTS): Add looping_threads.test.
6cf6ff
---
6cf6ff
 test/.gitignore             |   1 -
6cf6ff
 test/Makefile               |   5 +-
6cf6ff
 test/many_looping_threads.c |  49 --------------------
6cf6ff
 tests/.gitignore            |   1 +
6cf6ff
 tests/Makefile.am           |   6 ++-
6cf6ff
 tests/looping_threads.c     | 110 ++++++++++++++++++++++++++++++++++++++++++++
6cf6ff
 tests/looping_threads.test  |  37 +++++++++++++++
6cf6ff
 7 files changed, 154 insertions(+), 55 deletions(-)
6cf6ff
 delete mode 100644 test/many_looping_threads.c
6cf6ff
 create mode 100644 tests/looping_threads.c
6cf6ff
 create mode 100755 tests/looping_threads.test
6cf6ff
6cf6ff
Index: strace-4.24/tests/Makefile.am
6cf6ff
===================================================================
6cf6ff
--- strace-4.24.orig/tests/Makefile.am	2018-09-12 23:52:54.858953939 +0200
6cf6ff
+++ strace-4.24/tests/Makefile.am	2018-09-13 00:44:12.638097032 +0200
6cf6ff
@@ -127,6 +127,7 @@
6cf6ff
 	ksysent \
6cf6ff
 	list_sigaction_signum \
6cf6ff
 	localtime \
6cf6ff
+	looping_threads \
6cf6ff
 	mmsg-silent \
6cf6ff
 	mmsg_name-v \
6cf6ff
 	msg_control-v \
6cf6ff
@@ -190,6 +191,7 @@
6cf6ff
 fstatat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
6cf6ff
 ftruncate64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
6cf6ff
 localtime_LDADD = $(clock_LIBS) $(LDADD)
6cf6ff
+looping_threads_LDADD = -lpthread $(LDADD)
6cf6ff
 lstat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
6cf6ff
 mmap64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
6cf6ff
 mmap64_Xabbrev_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
6cf6ff
@@ -321,6 +323,7 @@
6cf6ff
 	interactive_block.test \
6cf6ff
 	ksysent.test \
6cf6ff
 	localtime.test \
6cf6ff
+	looping_threads.test \
6cf6ff
 	opipe.test \
6cf6ff
 	options-syntax.test \
6cf6ff
 	pc.test \
6cf6ff
@@ -364,7 +367,8 @@
6cf6ff
 XFAIL_TESTS_mx32 = $(STACKTRACE_TESTS)
6cf6ff
 XFAIL_TESTS_x86_64 = int_0x80.gen.test
6cf6ff
 XFAIL_TESTS_x32 = int_0x80.gen.test
6cf6ff
-XFAIL_TESTS = $(XFAIL_TESTS_$(MPERS_NAME)) $(XFAIL_TESTS_$(ARCH))
6cf6ff
+XFAIL_TESTS = $(XFAIL_TESTS_$(MPERS_NAME)) $(XFAIL_TESTS_$(ARCH)) \
6cf6ff
+	      looping_threads.test
6cf6ff
 
6cf6ff
 TEST_LOG_COMPILER = env
6cf6ff
 AM_TEST_LOG_FLAGS = STRACE_ARCH=$(ARCH) STRACE_NATIVE_ARCH=$(NATIVE_ARCH) \
6cf6ff
Index: strace-4.24/tests/looping_threads.c
6cf6ff
===================================================================
6cf6ff
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
6cf6ff
+++ strace-4.24/tests/looping_threads.c	2018-09-12 23:53:31.739527473 +0200
6cf6ff
@@ -0,0 +1,110 @@
6cf6ff
+/*
6cf6ff
+ * Check tracing of looping threads.
6cf6ff
+ *
6cf6ff
+ * Copyright (c) 2009-2018 The strace developers.
6cf6ff
+ * All rights reserved.
6cf6ff
+ *
6cf6ff
+ * Redistribution and use in source and binary forms, with or without
6cf6ff
+ * modification, are permitted provided that the following conditions
6cf6ff
+ * are met:
6cf6ff
+ * 1. Redistributions of source code must retain the above copyright
6cf6ff
+ *    notice, this list of conditions and the following disclaimer.
6cf6ff
+ * 2. Redistributions in binary form must reproduce the above copyright
6cf6ff
+ *    notice, this list of conditions and the following disclaimer in the
6cf6ff
+ *    documentation and/or other materials provided with the distribution.
6cf6ff
+ * 3. The name of the author may not be used to endorse or promote products
6cf6ff
+ *    derived from this software without specific prior written permission.
6cf6ff
+ *
6cf6ff
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
6cf6ff
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
6cf6ff
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
6cf6ff
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
6cf6ff
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
6cf6ff
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
6cf6ff
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
6cf6ff
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
6cf6ff
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
6cf6ff
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6cf6ff
+ */
6cf6ff
+
6cf6ff
+#include "tests.h"
6cf6ff
+#include <assert.h>
6cf6ff
+#include <errno.h>
6cf6ff
+#include <pthread.h>
6cf6ff
+#include <signal.h>
6cf6ff
+#include <stdio.h>
6cf6ff
+#include <stdlib.h>
6cf6ff
+#include <unistd.h>
6cf6ff
+#include <sys/wait.h>
6cf6ff
+
6cf6ff
+static void *
6cf6ff
+thread(void *arg)
6cf6ff
+{
6cf6ff
+	for (;;)
6cf6ff
+		getuid();
6cf6ff
+	return arg;
6cf6ff
+}
6cf6ff
+
6cf6ff
+int
6cf6ff
+main(int ac, const char *av[])
6cf6ff
+{
6cf6ff
+	assert(ac == 3);
6cf6ff
+
6cf6ff
+	int timeout = atoi(av[1]);
6cf6ff
+	assert(timeout > 0);
6cf6ff
+
6cf6ff
+	int num_threads = atoi(av[2]);
6cf6ff
+	assert(num_threads > 0);
6cf6ff
+
6cf6ff
+	/* Create a new process group.  */
6cf6ff
+	if (setpgid(0, 0))
6cf6ff
+		perror_msg_and_fail("setpgid");
6cf6ff
+
6cf6ff
+	/*
6cf6ff
+	 * When the main process terminates, the process group becomes orphaned.
6cf6ff
+	 * If any member of the orphaned process group is stopped, then
6cf6ff
+	 * a SIGHUP signal followed by a SIGCONT signal is sent to each process
6cf6ff
+	 * in the orphaned process group.
6cf6ff
+	 * Create a process in a stopped state to activate this behaviour.
6cf6ff
+	 */
6cf6ff
+	pid_t stopped = fork();
6cf6ff
+	if (stopped < 0)
6cf6ff
+		perror_msg_and_fail("fork");
6cf6ff
+	if (!stopped) {
6cf6ff
+		raise(SIGSTOP);
6cf6ff
+		_exit(0);
6cf6ff
+	}
6cf6ff
+
6cf6ff
+	const sigset_t set = {};
6cf6ff
+	const struct sigaction act = { .sa_handler = SIG_DFL };
6cf6ff
+	if (sigaction(SIGALRM, &act, NULL))
6cf6ff
+		perror_msg_and_fail("sigaction");
6cf6ff
+	if (sigprocmask(SIG_SETMASK, &set, NULL))
6cf6ff
+		perror_msg_and_fail("sigprocmask");
6cf6ff
+	alarm(timeout);
6cf6ff
+
6cf6ff
+	/*
6cf6ff
+	 * Create all threads in a subprocess, this guarantees that
6cf6ff
+	 * their tracer will not be their parent.
6cf6ff
+	 */
6cf6ff
+	pid_t pid = fork();
6cf6ff
+	if (pid < 0)
6cf6ff
+		perror_msg_and_fail("fork");
6cf6ff
+	if (!pid) {
6cf6ff
+		for (int i = 0; i < num_threads; i++) {
6cf6ff
+			pthread_t t;
6cf6ff
+			if ((errno = pthread_create(&t, NULL, thread, NULL)))
6cf6ff
+				perror_msg_and_fail("pthread_create #%d", i);
6cf6ff
+		}
6cf6ff
+
6cf6ff
+		/* This terminates all threads.  */
6cf6ff
+		_exit(0);
6cf6ff
+	}
6cf6ff
+
6cf6ff
+	int s;
6cf6ff
+	if (waitpid(pid, &s, 0) != pid)
6cf6ff
+		perror_msg_and_fail("waitpid");
6cf6ff
+
6cf6ff
+	assert(WIFEXITED(s));
6cf6ff
+	return WEXITSTATUS(s);
6cf6ff
+}
6cf6ff
Index: strace-4.24/tests/looping_threads.test
6cf6ff
new file mode 0755
6cf6ff
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
6cf6ff
+++ strace-4.24/tests/looping_threads.test	2018-09-12 23:53:31.740527461 +0200
6cf6ff
@@ -0,0 +1,37 @@
6cf6ff
+#!/bin/sh
6cf6ff
+#
6cf6ff
+# Check tracing of looping threads.
6cf6ff
+#
6cf6ff
+# Copyright (c) 2009-2018 The strace developers.
6cf6ff
+# All rights reserved.
6cf6ff
+#
6cf6ff
+# Redistribution and use in source and binary forms, with or without
6cf6ff
+# modification, are permitted provided that the following conditions
6cf6ff
+# are met:
6cf6ff
+# 1. Redistributions of source code must retain the above copyright
6cf6ff
+#    notice, this list of conditions and the following disclaimer.
6cf6ff
+# 2. Redistributions in binary form must reproduce the above copyright
6cf6ff
+#    notice, this list of conditions and the following disclaimer in the
6cf6ff
+#    documentation and/or other materials provided with the distribution.
6cf6ff
+# 3. The name of the author may not be used to endorse or promote products
6cf6ff
+#    derived from this software without specific prior written permission.
6cf6ff
+#
6cf6ff
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
6cf6ff
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
6cf6ff
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
6cf6ff
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
6cf6ff
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
6cf6ff
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
6cf6ff
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
6cf6ff
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
6cf6ff
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
6cf6ff
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6cf6ff
+
6cf6ff
+. "${srcdir=.}/init.sh"
6cf6ff
+
6cf6ff
+check_prog nproc
6cf6ff
+timeout="$(($TIMEOUT_DURATION/10))"
6cf6ff
+nproc="$((64+$timeout+$(nproc)))"
6cf6ff
+
6cf6ff
+run_prog "../$NAME" "$timeout" "$nproc"
6cf6ff
+run_strace -f -qq -enone -esignal=none $args
6cf6ff
Index: strace-4.24/tests/Makefile.in
6cf6ff
===================================================================
6cf6ff
--- strace-4.24.orig/tests/Makefile.in	2018-08-14 02:44:39.000000000 +0200
6cf6ff
+++ strace-4.24/tests/Makefile.in	2018-09-13 00:51:18.191618128 +0200
6cf6ff
@@ -155,7 +155,7 @@
6cf6ff
 	ioctl_perf-success$(EXEEXT) ioctl_rtc-v$(EXEEXT) \
6cf6ff
 	is_linux_mips_n64$(EXEEXT) ksysent$(EXEEXT) \
6cf6ff
 	list_sigaction_signum$(EXEEXT) localtime$(EXEEXT) \
6cf6ff
-	mmsg-silent$(EXEEXT) mmsg_name-v$(EXEEXT) \
6cf6ff
+	looping_threads$(EXEEXT) mmsg-silent$(EXEEXT) mmsg_name-v$(EXEEXT) \
6cf6ff
 	msg_control-v$(EXEEXT) net-accept-connect$(EXEEXT) \
6cf6ff
 	net-tpacket_stats-success$(EXEEXT) netlink_inet_diag$(EXEEXT) \
6cf6ff
 	netlink_netlink_diag$(EXEEXT) netlink_unix_diag$(EXEEXT) \
6cf6ff
@@ -1221,6 +1221,9 @@
6cf6ff
 lookup_dcookie_OBJECTS = lookup_dcookie.$(OBJEXT)
6cf6ff
 lookup_dcookie_LDADD = $(LDADD)
6cf6ff
 lookup_dcookie_DEPENDENCIES = libtests.a
6cf6ff
+looping_threads_SOURCES = looping_threads.c
6cf6ff
+looping_threads_OBJECTS = looping_threads.$(OBJEXT)
6cf6ff
+looping_threads_DEPENDENCIES = $(LDADD)
6cf6ff
 lseek_SOURCES = lseek.c
6cf6ff
 lseek_OBJECTS = lseek.$(OBJEXT)
6cf6ff
 lseek_LDADD = $(LDADD)
6cf6ff
@@ -2743,7 +2746,7 @@
6cf6ff
 	kexec_file_load.c kexec_load.c keyctl.c keyctl-Xabbrev.c \
6cf6ff
 	keyctl-Xraw.c keyctl-Xverbose.c kill.c ksysent.c lchown.c \
6cf6ff
 	lchown32.c link.c linkat.c list_sigaction_signum.c llseek.c \
6cf6ff
-	localtime.c lookup_dcookie.c lseek.c lstat.c lstat64.c \
6cf6ff
+	localtime.c lookup_dcookie.c looping_threads.c lseek.c lstat.c lstat64.c \
6cf6ff
 	madvise.c mbind.c membarrier.c memfd_create.c migrate_pages.c \
6cf6ff
 	mincore.c mkdir.c mkdirat.c mknod.c mknodat.c mlock.c mlock2.c \
6cf6ff
 	mlockall.c mmap.c mmap-Xabbrev.c mmap-Xraw.c mmap-Xverbose.c \
6cf6ff
@@ -2888,7 +2891,7 @@
6cf6ff
 	kexec_file_load.c kexec_load.c keyctl.c keyctl-Xabbrev.c \
6cf6ff
 	keyctl-Xraw.c keyctl-Xverbose.c kill.c ksysent.c lchown.c \
6cf6ff
 	lchown32.c link.c linkat.c list_sigaction_signum.c llseek.c \
6cf6ff
-	localtime.c lookup_dcookie.c lseek.c lstat.c lstat64.c \
6cf6ff
+	localtime.c lookup_dcookie.c looping_threads.c lseek.c lstat.c lstat64.c \
6cf6ff
 	madvise.c mbind.c membarrier.c memfd_create.c migrate_pages.c \
6cf6ff
 	mincore.c mkdir.c mkdirat.c mknod.c mknodat.c mlock.c mlock2.c \
6cf6ff
 	mlockall.c mmap.c mmap-Xabbrev.c mmap-Xraw.c mmap-Xverbose.c \
6cf6ff
@@ -3911,6 +3914,7 @@
6cf6ff
 fstatat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
6cf6ff
 ftruncate64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
6cf6ff
 localtime_LDADD = $(clock_LIBS) $(LDADD)
6cf6ff
+looping_threads_LDADD = -lpthread $(LDADD)
6cf6ff
 lstat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
6cf6ff
 mmap64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
6cf6ff
 mmap64_Xabbrev_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
6cf6ff
@@ -4229,6 +4233,7 @@
6cf6ff
 	interactive_block.test \
6cf6ff
 	ksysent.test \
6cf6ff
 	localtime.test \
6cf6ff
+	looping_threads.test \
6cf6ff
 	opipe.test \
6cf6ff
 	options-syntax.test \
6cf6ff
 	pc.test \
6cf6ff
@@ -5226,6 +5231,10 @@
6cf6ff
 	@rm -f lookup_dcookie$(EXEEXT)
6cf6ff
 	$(AM_V_CCLD)$(LINK) $(lookup_dcookie_OBJECTS) $(lookup_dcookie_LDADD) $(LIBS)
6cf6ff
 
6cf6ff
+looping_threads$(EXEEXT): $(looping_threads_OBJECTS) $(looping_threads_DEPENDENCIES) $(EXTRA_looping_threads_DEPENDENCIES) 
6cf6ff
+	@rm -f looping_threads$(EXEEXT)
6cf6ff
+	$(AM_V_CCLD)$(LINK) $(looping_threads_OBJECTS) $(looping_threads_LDADD) $(LIBS)
6cf6ff
+
6cf6ff
 lseek$(EXEEXT): $(lseek_OBJECTS) $(lseek_DEPENDENCIES) $(EXTRA_lseek_DEPENDENCIES) 
6cf6ff
 	@rm -f lseek$(EXEEXT)
6cf6ff
 	$(AM_V_CCLD)$(LINK) $(lseek_OBJECTS) $(lseek_LDADD) $(LIBS)
6cf6ff
@@ -6890,6 +6899,7 @@
6cf6ff
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/llseek.Po@am__quote@
6cf6ff
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/localtime.Po@am__quote@
6cf6ff
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lookup_dcookie.Po@am__quote@
6cf6ff
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/looping_threads.Po@am__quote@
6cf6ff
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lseek.Po@am__quote@
6cf6ff
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lstat.Po@am__quote@
6cf6ff
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lstat64-lstat64.Po@am__quote@