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

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