]> granicus.if.org Git - strace/commitdiff
New test: test/many_looping_threads.c
authorDenys Vlasenko <dvlasenk@redhat.com>
Sat, 21 Mar 2015 19:59:39 +0000 (20:59 +0100)
committerDenys Vlasenko <dvlasenk@redhat.com>
Sat, 21 Mar 2015 19:59:39 +0000 (20:59 +0100)
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
test/.gitignore
test/Makefile
test/many_looping_threads.c [new file with mode: 0644]

index 10ee4ed33f3904612c8a74052b63dd12c3d0c8df..fba8c9d47267ddecdf2771726057445090ca2ae6 100644 (file)
@@ -2,6 +2,7 @@ childthread
 clone
 fork
 leaderkill
+many_looping_threads
 mmap_offset_decode
 mtd
 seccomp
index 715c4c1f7cb0b048a80591a80fa9a06d2733a62f..dbc5008b4f580d33052b47092bb8cf61fab8a4ee 100644 (file)
@@ -3,7 +3,8 @@ CFLAGS += -Wall
 PROGS = \
     vfork fork sig skodic clone leaderkill childthread \
     sigkill_rain wait_must_be_interruptible threaded_execve \
-    mtd ubi seccomp sfd mmap_offset_decode x32_lseek x32_mmap
+    mtd ubi seccomp sfd mmap_offset_decode x32_lseek x32_mmap \
+    many_looping_threads
 
 all: $(PROGS)
 
@@ -11,6 +12,8 @@ leaderkill: LDFLAGS += -pthread
 
 childthread: LDFLAGS += -pthread
 
+many_looping_threads: LDFLAGS += -pthread
+
 clean distclean:
        rm -f *.o core $(PROGS) *.gdb
 
diff --git a/test/many_looping_threads.c b/test/many_looping_threads.c
new file mode 100644 (file)
index 0000000..918bd9d
--- /dev/null
@@ -0,0 +1,49 @@
+// This testcase, when run with large number of threads
+// under stace -f, may never finish because strace does not
+// ensure any fairness in thread scheduling:
+// it restarts threads as they stop. If daughter threads crowd out
+// the "mother" and _they_ get continually restarted by strace,
+// the end of spawning loop will never be reached.
+//
+// Also, it is a testcase which triggers the
+// "strace: Exit of unknown pid 32457 seen"
+// message when on testcase exit, strace sees deaths of newly-attached
+// threads _before_ their first syscall stop.
+//
+#include <stdio.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <signal.h>
+#include <stdlib.h>
+
+static int thd_no;
+
+static void *sub_thd(void *c)
+{
+       dprintf(1, "sub-thread %d created\n", ++thd_no);
+       for (;;)
+               getuid();
+       return NULL;
+}
+
+int main(int argc, char *argv[])
+{
+       int i;
+       pthread_t *thd;
+       int num_threads = 1;
+
+       if (argv[1])
+               num_threads = atoi(argv[1]);
+
+       thd = malloc(num_threads * sizeof(thd[0]));
+       dprintf(1, "test start, num_threads:%d...\n", num_threads);
+
+       for (i = 0; i < num_threads; i++) {
+               pthread_create(&thd[i], NULL, sub_thd, NULL);
+               dprintf(1, "after pthread_create\n");
+       }
+
+       /* Exit. This kills all threads */
+       return 0;
+}