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

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