Blame SOURCES/gdb-6.8-bz442765-threaded-exec-test.patch

689258
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
689258
From: Fedora GDB patches <invalid@email.com>
689258
Date: Fri, 27 Oct 2017 21:07:50 +0200
689258
Subject: gdb-6.8-bz442765-threaded-exec-test.patch
689258
689258
;; Test various forms of threads tracking across exec() (BZ 442765).
689258
;;=fedoratest
689258
689258
Test various forms of threads tracking across exec(2).
689258
689258
diff --git a/gdb/testsuite/gdb.threads/threaded-exec.c b/gdb/testsuite/gdb.threads/threaded-exec.c
689258
--- a/gdb/testsuite/gdb.threads/threaded-exec.c
689258
+++ b/gdb/testsuite/gdb.threads/threaded-exec.c
689258
@@ -18,21 +18,95 @@
689258
    Boston, MA 02111-1307, USA.  */
689258
 
689258
 #include <stddef.h>
689258
-#include <pthread.h>
689258
 #include <assert.h>
689258
 #include <stdlib.h>
689258
 #include <unistd.h>
689258
+#include <stdio.h>
689258
 
689258
+#ifdef THREADS
689258
+
689258
+# include <pthread.h>
689258
 
689258
 static void *
689258
 threader (void *arg)
689258
 {
689258
-	return NULL;
689258
+  return NULL;
689258
 }
689258
 
689258
+#endif
689258
+
689258
 int
689258
-main (void)
689258
+main (int argc, char **argv)
689258
 {
689258
+  char *exec_nothreads, *exec_threads, *cmd;
689258
+  int phase;
689258
+  char phase_s[8];
689258
+
689258
+  setbuf (stdout, NULL);
689258
+
689258
+  if (argc != 4)
689258
+    {
689258
+      fprintf (stderr, "%s <non-threaded> <threaded> <phase>\n", argv[0]);
689258
+      return 1;
689258
+    }
689258
+
689258
+#ifdef THREADS
689258
+  puts ("THREADS: Y");
689258
+#else
689258
+  puts ("THREADS: N");
689258
+#endif
689258
+  exec_nothreads = argv[1];
689258
+  printf ("exec_nothreads: %s\n", exec_nothreads);
689258
+  exec_threads = argv[2];
689258
+  printf ("exec_threads: %s\n", exec_threads);
689258
+  phase = atoi (argv[3]);
689258
+  printf ("phase: %d\n", phase);
689258
+
689258
+  /* Phases: threading
689258
+     0: N -> N
689258
+     1: N -> Y
689258
+     2: Y -> Y
689258
+     3: Y -> N
689258
+     4: N -> exit  */
689258
+
689258
+  cmd = NULL;
689258
+
689258
+#ifndef THREADS
689258
+  switch (phase)
689258
+    {
689258
+    case 0:
689258
+      cmd = exec_nothreads;
689258
+      break;
689258
+    case 1:
689258
+      cmd = exec_threads;
689258
+      break;
689258
+    case 2:
689258
+      fprintf (stderr, "%s: We should have threads for phase %d!\n", argv[0],
689258
+	       phase);
689258
+      return 1;
689258
+    case 3:
689258
+      fprintf (stderr, "%s: We should have threads for phase %d!\n", argv[0],
689258
+	       phase);
689258
+      return 1;
689258
+    case 4:
689258
+      return 0;
689258
+    default:
689258
+      assert (0);
689258
+    }
689258
+#else	/* THREADS */
689258
+  switch (phase)
689258
+    {
689258
+    case 0:
689258
+      fprintf (stderr, "%s: We should not have threads for phase %d!\n",
689258
+	       argv[0], phase);
689258
+      return 1;
689258
+    case 1:
689258
+      fprintf (stderr, "%s: We should not have threads for phase %d!\n",
689258
+	       argv[0], phase);
689258
+      return 1;
689258
+    case 2:
689258
+      cmd = exec_threads;
689258
+      {
689258
 	pthread_t t1;
689258
 	int i;
689258
 
689258
@@ -40,7 +114,34 @@ main (void)
689258
 	assert (i == 0);
689258
 	i = pthread_join (t1, NULL);
689258
 	assert (i == 0);
689258
+      }
689258
+      break;
689258
+    case 3:
689258
+      cmd = exec_nothreads;
689258
+      {
689258
+	pthread_t t1;
689258
+	int i;
689258
+
689258
+	i = pthread_create (&t1, NULL, threader, (void *) NULL);
689258
+	assert (i == 0);
689258
+	i = pthread_join (t1, NULL);
689258
+	assert (i == 0);
689258
+      }
689258
+      break;
689258
+    case 4:
689258
+      fprintf (stderr, "%s: We should not have threads for phase %d!\n",
689258
+	       argv[0], phase);
689258
+      return 1;
689258
+    default:
689258
+      assert (0);
689258
+    }
689258
+#endif	/* THREADS */
689258
+
689258
+  assert (cmd != NULL);
689258
+
689258
+  phase++;
689258
+  snprintf (phase_s, sizeof phase_s, "%d", phase);
689258
 
689258
-	execl ("/bin/true", "/bin/true", NULL);
689258
-	abort ();
689258
+  execl (cmd, cmd, exec_nothreads, exec_threads, phase_s, NULL);
689258
+  assert (0);
689258
 }
689258
diff --git a/gdb/testsuite/gdb.threads/threaded-exec.exp b/gdb/testsuite/gdb.threads/threaded-exec.exp
689258
--- a/gdb/testsuite/gdb.threads/threaded-exec.exp
689258
+++ b/gdb/testsuite/gdb.threads/threaded-exec.exp
689258
@@ -20,9 +20,14 @@
689258
 
689258
 set testfile threaded-exec
689258
 set srcfile ${testfile}.c
689258
-set binfile [standard_output_file ${testfile}]
689258
+set binfile_nothreads [standard_output_file ${testfile}N]
689258
+set binfile_threads [standard_output_file ${testfile}Y]
689258
 
689258
-if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable []] != "" } {
689258
+if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile_nothreads}" executable {additional_flags=-UTHREADS}] != "" } {
689258
+    return -1
689258
+}
689258
+
689258
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile_threads}" executable {additional_flags=-DTHREADS}] != "" } {
689258
     return -1
689258
 }
689258
 
689258
@@ -30,9 +35,9 @@ gdb_exit
689258
 gdb_start
689258
 gdb_reinitialize_dir $srcdir/$subdir
689258
 
689258
-gdb_load ${binfile}
689258
+gdb_load ${binfile_nothreads}
689258
 
689258
-gdb_run_cmd
689258
+gdb_run_cmd ${binfile_nothreads} ${binfile_threads} 0
689258
 
689258
 gdb_test_multiple {} "Program exited" {
689258
    -re "\r\n\\\[Inferior .* exited normally\\\]\r\n$gdb_prompt $" {