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

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