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

01917d
Test various forms of threads tracking across exec(2).
01917d
01917d
diff -up -u -X /root/jkratoch/.diffi.list -rup gdb-6.8/gdb/testsuite/gdb.threads/threaded-exec.c gdb-6.8-patched/gdb/testsuite/gdb.threads/threaded-exec.c
01917d
--- gdb-6.8/gdb/testsuite/gdb.threads/threaded-exec.c	2008-04-16 17:05:19.000000000 -0400
01917d
+++ gdb-6.8-patched/gdb/testsuite/gdb.threads/threaded-exec.c	2008-04-16 14:43:50.000000000 -0400
01917d
@@ -18,21 +18,95 @@
01917d
    Boston, MA 02111-1307, USA.  */
01917d
 
01917d
 #include <stddef.h>
01917d
-#include <pthread.h>
01917d
 #include <assert.h>
01917d
 #include <stdlib.h>
01917d
 #include <unistd.h>
01917d
+#include <stdio.h>
01917d
 
01917d
+#ifdef THREADS
01917d
+
01917d
+# include <pthread.h>
01917d
 
01917d
 static void *
01917d
 threader (void *arg)
01917d
 {
01917d
-	return NULL;
01917d
+  return NULL;
01917d
 }
01917d
 
01917d
+#endif
01917d
+
01917d
 int
01917d
-main (void)
01917d
+main (int argc, char **argv)
01917d
 {
01917d
+  char *exec_nothreads, *exec_threads, *cmd;
01917d
+  int phase;
01917d
+  char phase_s[8];
01917d
+
01917d
+  setbuf (stdout, NULL);
01917d
+
01917d
+  if (argc != 4)
01917d
+    {
01917d
+      fprintf (stderr, "%s <non-threaded> <threaded> <phase>\n", argv[0]);
01917d
+      return 1;
01917d
+    }
01917d
+
01917d
+#ifdef THREADS
01917d
+  puts ("THREADS: Y");
01917d
+#else
01917d
+  puts ("THREADS: N");
01917d
+#endif
01917d
+  exec_nothreads = argv[1];
01917d
+  printf ("exec_nothreads: %s\n", exec_nothreads);
01917d
+  exec_threads = argv[2];
01917d
+  printf ("exec_threads: %s\n", exec_threads);
01917d
+  phase = atoi (argv[3]);
01917d
+  printf ("phase: %d\n", phase);
01917d
+
01917d
+  /* Phases: threading
01917d
+     0: N -> N
01917d
+     1: N -> Y
01917d
+     2: Y -> Y
01917d
+     3: Y -> N
01917d
+     4: N -> exit  */
01917d
+
01917d
+  cmd = NULL;
01917d
+
01917d
+#ifndef THREADS
01917d
+  switch (phase)
01917d
+    {
01917d
+    case 0:
01917d
+      cmd = exec_nothreads;
01917d
+      break;
01917d
+    case 1:
01917d
+      cmd = exec_threads;
01917d
+      break;
01917d
+    case 2:
01917d
+      fprintf (stderr, "%s: We should have threads for phase %d!\n", argv[0],
01917d
+	       phase);
01917d
+      return 1;
01917d
+    case 3:
01917d
+      fprintf (stderr, "%s: We should have threads for phase %d!\n", argv[0],
01917d
+	       phase);
01917d
+      return 1;
01917d
+    case 4:
01917d
+      return 0;
01917d
+    default:
01917d
+      assert (0);
01917d
+    }
01917d
+#else	/* THREADS */
01917d
+  switch (phase)
01917d
+    {
01917d
+    case 0:
01917d
+      fprintf (stderr, "%s: We should not have threads for phase %d!\n",
01917d
+	       argv[0], phase);
01917d
+      return 1;
01917d
+    case 1:
01917d
+      fprintf (stderr, "%s: We should not have threads for phase %d!\n",
01917d
+	       argv[0], phase);
01917d
+      return 1;
01917d
+    case 2:
01917d
+      cmd = exec_threads;
01917d
+      {
01917d
 	pthread_t t1;
01917d
 	int i;
01917d
 
01917d
@@ -40,7 +114,34 @@ main (void)
01917d
 	assert (i == 0);
01917d
 	i = pthread_join (t1, NULL);
01917d
 	assert (i == 0);
01917d
+      }
01917d
+      break;
01917d
+    case 3:
01917d
+      cmd = exec_nothreads;
01917d
+      {
01917d
+	pthread_t t1;
01917d
+	int i;
01917d
+
01917d
+	i = pthread_create (&t1, NULL, threader, (void *) NULL);
01917d
+	assert (i == 0);
01917d
+	i = pthread_join (t1, NULL);
01917d
+	assert (i == 0);
01917d
+      }
01917d
+      break;
01917d
+    case 4:
01917d
+      fprintf (stderr, "%s: We should not have threads for phase %d!\n",
01917d
+	       argv[0], phase);
01917d
+      return 1;
01917d
+    default:
01917d
+      assert (0);
01917d
+    }
01917d
+#endif	/* THREADS */
01917d
+
01917d
+  assert (cmd != NULL);
01917d
+
01917d
+  phase++;
01917d
+  snprintf (phase_s, sizeof phase_s, "%d", phase);
01917d
 
01917d
-	execl ("/bin/true", "/bin/true", NULL);
01917d
-	abort ();
01917d
+  execl (cmd, cmd, exec_nothreads, exec_threads, phase_s, NULL);
01917d
+  assert (0);
01917d
 }
01917d
diff -up -u -X /root/jkratoch/.diffi.list -rup gdb-6.8/gdb/testsuite/gdb.threads/threaded-exec.exp gdb-6.8-patched/gdb/testsuite/gdb.threads/threaded-exec.exp
01917d
--- gdb-6.8/gdb/testsuite/gdb.threads/threaded-exec.exp	2008-04-16 17:05:19.000000000 -0400
01917d
+++ gdb-6.8-patched/gdb/testsuite/gdb.threads/threaded-exec.exp	2008-04-16 14:42:49.000000000 -0400
01917d
@@ -20,9 +20,14 @@
01917d
 
01917d
 set testfile threaded-exec
01917d
 set srcfile ${testfile}.c
01917d
-set binfile ${objdir}/${subdir}/${testfile}
01917d
+set binfile_nothreads ${objdir}/${subdir}/${testfile}N
01917d
+set binfile_threads ${objdir}/${subdir}/${testfile}Y
01917d
 
01917d
-if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable []] != "" } {
01917d
+if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile_nothreads}" executable {additional_flags=-UTHREADS}] != "" } {
01917d
+    return -1
01917d
+}
01917d
+
01917d
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile_threads}" executable {additional_flags=-DTHREADS}] != "" } {
01917d
     return -1
01917d
 }
01917d
 
01917d
@@ -30,9 +35,9 @@ gdb_exit
01917d
 gdb_start
01917d
 gdb_reinitialize_dir $srcdir/$subdir
01917d
 
01917d
-gdb_load ${binfile}
01917d
+gdb_load ${binfile_nothreads}
01917d
 
01917d
-gdb_run_cmd
01917d
+gdb_run_cmd ${binfile_nothreads} ${binfile_threads} 0
01917d
 
01917d
 gdb_test_multiple {} "Program exited" {
01917d
    -re "\r\n\\\[Inferior .* exited normally\\\]\r\n$gdb_prompt $" {