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

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