Browse Source

tests: check tracing of looping threads

* test/many_looping_threads.c: Remove.
* test/.gitignore: Remove many_looping_threads.
* test/Makefile (PROGS): Likewise.
(many_looping_threads): Remove.
* tests/looping_threads.c: New file.
* tests/looping_threads.test: New test.
* tests/.gitignore: Add looping_threads.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(looping_threads_LDADD): New variable.
(MISC_TESTS, XFAIL_TESTS): Add looping_threads.test.
Dmitry V. Levin 1 year ago
parent
commit
6d587b6389
7 changed files with 154 additions and 55 deletions
  1. 0
    1
      test/.gitignore
  2. 1
    4
      test/Makefile
  3. 0
    49
      test/many_looping_threads.c
  4. 1
    0
      tests/.gitignore
  5. 5
    1
      tests/Makefile.am
  6. 110
    0
      tests/looping_threads.c
  7. 37
    0
      tests/looping_threads.test

+ 0
- 1
test/.gitignore View File

@@ -1,7 +1,6 @@
1 1
 childthread
2 2
 clone
3 3
 leaderkill
4
-many_looping_threads
5 4
 mmap_offset_decode
6 5
 mtd
7 6
 seccomp

+ 1
- 4
test/Makefile View File

@@ -3,8 +3,7 @@ CFLAGS += -Wall
3 3
 PROGS = \
4 4
     sig skodic clone leaderkill childthread \
5 5
     sigkill_rain wait_must_be_interruptible threaded_execve \
6
-    mtd ubi seccomp sfd mmap_offset_decode x32_lseek x32_mmap \
7
-    many_looping_threads
6
+    mtd ubi seccomp sfd mmap_offset_decode x32_lseek x32_mmap
8 7
 
9 8
 all: $(PROGS)
10 9
 
@@ -12,8 +11,6 @@ leaderkill: LDFLAGS += -pthread
12 11
 
13 12
 childthread: LDFLAGS += -pthread
14 13
 
15
-many_looping_threads: LDFLAGS += -pthread
16
-
17 14
 clean distclean:
18 15
 	rm -f *.o core $(PROGS) *.gdb
19 16
 

+ 0
- 49
test/many_looping_threads.c View File

@@ -1,49 +0,0 @@
1
-// This testcase, when run with large number of threads
2
-// under stace -f, may never finish because strace does not
3
-// ensure any fairness in thread scheduling:
4
-// it restarts threads as they stop. If daughter threads crowd out
5
-// the "mother" and _they_ get continually restarted by strace,
6
-// the end of spawning loop will never be reached.
7
-//
8
-// Also, it is a testcase which triggers the
9
-// "strace: Exit of unknown pid 32457 seen"
10
-// message when on testcase exit, strace sees deaths of newly-attached
11
-// threads _before_ their first syscall stop.
12
-//
13
-#include <stdio.h>
14
-#include <pthread.h>
15
-#include <unistd.h>
16
-#include <sys/types.h>
17
-#include <signal.h>
18
-#include <stdlib.h>
19
-
20
-static int thd_no;
21
-
22
-static void *sub_thd(void *c)
23
-{
24
-	dprintf(1, "sub-thread %d created\n", ++thd_no);
25
-	for (;;)
26
-		getuid();
27
-	return NULL;
28
-}
29
-
30
-int main(int argc, char *argv[])
31
-{
32
-	int i;
33
-	pthread_t *thd;
34
-	int num_threads = 1;
35
-
36
-	if (argv[1])
37
-		num_threads = atoi(argv[1]);
38
-
39
-	thd = malloc(num_threads * sizeof(thd[0]));
40
-	dprintf(1, "test start, num_threads:%d...\n", num_threads);
41
-
42
-	for (i = 0; i < num_threads; i++) {
43
-		pthread_create(&thd[i], NULL, sub_thd, NULL);
44
-		dprintf(1, "after pthread_create\n");
45
-	}
46
-
47
-	/* Exit. This kills all threads */
48
-	return 0;
49
-}

+ 1
- 0
tests/.gitignore View File

@@ -224,6 +224,7 @@ list_sigaction_signum
224 224
 llseek
225 225
 localtime
226 226
 lookup_dcookie
227
+looping_threads
227 228
 lseek
228 229
 lstat
229 230
 lstat64

+ 5
- 1
tests/Makefile.am View File

@@ -110,6 +110,7 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \
110 110
 	ksysent \
111 111
 	list_sigaction_signum \
112 112
 	localtime \
113
+	looping_threads \
113 114
 	mmsg-silent \
114 115
 	mmsg_name-v \
115 116
 	msg_control-v \
@@ -173,6 +174,7 @@ fstat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
173 174
 fstatat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
174 175
 ftruncate64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
175 176
 localtime_LDADD = $(clock_LIBS) $(LDADD)
177
+looping_threads_LDADD = -lpthread $(LDADD)
176 178
 lstat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
177 179
 mmap64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
178 180
 mmap64_Xabbrev_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
@@ -309,6 +311,7 @@ MISC_TESTS = \
309 311
 	kill_child.test \
310 312
 	ksysent.test \
311 313
 	localtime.test \
314
+	looping_threads.test \
312 315
 	opipe.test \
313 316
 	options-syntax.test \
314 317
 	pc.test \
@@ -350,7 +353,8 @@ TESTS = $(GEN_TESTS) $(DECODER_TESTS) $(MISC_TESTS) $(STACKTRACE_TESTS)
350 353
 XFAIL_TESTS_ =
351 354
 XFAIL_TESTS_m32 = $(STACKTRACE_TESTS)
352 355
 XFAIL_TESTS_mx32 = $(STACKTRACE_TESTS)
353
-XFAIL_TESTS = $(XFAIL_TESTS_$(MPERS_NAME)) $(XFAIL_TESTS_$(ARCH))
356
+XFAIL_TESTS = $(XFAIL_TESTS_$(MPERS_NAME)) $(XFAIL_TESTS_$(ARCH)) \
357
+	      looping_threads.test
354 358
 
355 359
 TEST_LOG_COMPILER = env
356 360
 AM_TEST_LOG_FLAGS = STRACE_ARCH=$(ARCH) STRACE_NATIVE_ARCH=$(NATIVE_ARCH) \

+ 110
- 0
tests/looping_threads.c View File

@@ -0,0 +1,110 @@
1
+/*
2
+ * Check tracing of looping threads.
3
+ *
4
+ * Copyright (c) 2009-2018 The strace developers.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions
9
+ * are met:
10
+ * 1. Redistributions of source code must retain the above copyright
11
+ *    notice, this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright
13
+ *    notice, this list of conditions and the following disclaimer in the
14
+ *    documentation and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ *    derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ */
29
+
30
+#include "tests.h"
31
+#include <assert.h>
32
+#include <errno.h>
33
+#include <pthread.h>
34
+#include <signal.h>
35
+#include <stdio.h>
36
+#include <stdlib.h>
37
+#include <unistd.h>
38
+#include <sys/wait.h>
39
+
40
+static void *
41
+thread(void *arg)
42
+{
43
+	for (;;)
44
+		getuid();
45
+	return arg;
46
+}
47
+
48
+int
49
+main(int ac, const char *av[])
50
+{
51
+	assert(ac == 3);
52
+
53
+	int timeout = atoi(av[1]);
54
+	assert(timeout > 0);
55
+
56
+	int num_threads = atoi(av[2]);
57
+	assert(num_threads > 0);
58
+
59
+	/* Create a new process group.  */
60
+	if (setpgid(0, 0))
61
+		perror_msg_and_fail("setpgid");
62
+
63
+	/*
64
+	 * When the main process terminates, the process group becomes orphaned.
65
+	 * If any member of the orphaned process group is stopped, then
66
+	 * a SIGHUP signal followed by a SIGCONT signal is sent to each process
67
+	 * in the orphaned process group.
68
+	 * Create a process in a stopped state to activate this behaviour.
69
+	 */
70
+	pid_t stopped = fork();
71
+	if (stopped < 0)
72
+		perror_msg_and_fail("fork");
73
+	if (!stopped) {
74
+		raise(SIGSTOP);
75
+		_exit(0);
76
+	}
77
+
78
+	const sigset_t set = {};
79
+	const struct sigaction act = { .sa_handler = SIG_DFL };
80
+	if (sigaction(SIGALRM, &act, NULL))
81
+		perror_msg_and_fail("sigaction");
82
+	if (sigprocmask(SIG_SETMASK, &set, NULL))
83
+		perror_msg_and_fail("sigprocmask");
84
+	alarm(timeout);
85
+
86
+	/*
87
+	 * Create all threads in a subprocess, this guarantees that
88
+	 * their tracer will not be their parent.
89
+	 */
90
+	pid_t pid = fork();
91
+	if (pid < 0)
92
+		perror_msg_and_fail("fork");
93
+	if (!pid) {
94
+		for (int i = 0; i < num_threads; i++) {
95
+			pthread_t t;
96
+			if ((errno = pthread_create(&t, NULL, thread, NULL)))
97
+				perror_msg_and_fail("pthread_create #%d", i);
98
+		}
99
+
100
+		/* This terminates all threads.  */
101
+		_exit(0);
102
+	}
103
+
104
+	int s;
105
+	if (waitpid(pid, &s, 0) != pid)
106
+		perror_msg_and_fail("waitpid");
107
+
108
+	assert(WIFEXITED(s));
109
+	return WEXITSTATUS(s);
110
+}

+ 37
- 0
tests/looping_threads.test View File

@@ -0,0 +1,37 @@
1
+#!/bin/sh
2
+#
3
+# Check tracing of looping threads.
4
+#
5
+# Copyright (c) 2009-2018 The strace developers.
6
+# All rights reserved.
7
+#
8
+# Redistribution and use in source and binary forms, with or without
9
+# modification, are permitted provided that the following conditions
10
+# are met:
11
+# 1. Redistributions of source code must retain the above copyright
12
+#    notice, this list of conditions and the following disclaimer.
13
+# 2. Redistributions in binary form must reproduce the above copyright
14
+#    notice, this list of conditions and the following disclaimer in the
15
+#    documentation and/or other materials provided with the distribution.
16
+# 3. The name of the author may not be used to endorse or promote products
17
+#    derived from this software without specific prior written permission.
18
+#
19
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+
30
+. "${srcdir=.}/init.sh"
31
+
32
+check_prog nproc
33
+timeout="$(($TIMEOUT_DURATION/10))"
34
+nproc="$((64+$timeout+$(nproc)))"
35
+
36
+run_prog "../$NAME" "$timeout" "$nproc"
37
+run_strace -f -qq -enone -esignal=none $args

Loading…
Cancel
Save