]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
* mi-pthreads.exp (check_mi_thread_command_set): New tests.
authorKeith Seitz <keiths@redhat.com>
Thu, 5 Sep 2002 14:53:43 +0000 (14:53 +0000)
committerKeith Seitz <keiths@redhat.com>
Thu, 5 Sep 2002 14:53:43 +0000 (14:53 +0000)
        (check_mi_and_console_threads): Moved contents dealing with
        getting MI thread list...
        (get_mi_threads): ...to here.
        (check_mi_and_console_threads): New tests.
        (check_console_thread_commands): New tests.
        * pthreads.c (done_making_threads): New marker function.
        (create_thread): New function to create threads.
        (main): Make several threads using create_thread.
        Call marker function done_making_threads when done making
        threads.

gdb/testsuite/gdb.mi/ChangeLog
gdb/testsuite/gdb.mi/mi-pthreads.exp
gdb/testsuite/gdb.mi/pthreads.c

index 77298c8ada3052e98e493b40091c66d82f8601e8..41ce9d898bac7a081a51c29db420d006c2fd0270 100644 (file)
@@ -1,3 +1,17 @@
+2002-09-05  Keith Seitz  <keiths@redhat.com>
+
+       * mi-pthreads.exp (check_mi_thread_command_set): New tests.
+       (check_mi_and_console_threads): Moved contents dealing with
+       getting MI thread list...
+       (get_mi_threads): ...to here.
+       (check_mi_and_console_threads): New tests.
+       (check_console_thread_commands): New tests.
+       * pthreads.c (done_making_threads): New marker function.
+       (create_thread): New function to create threads.
+       (main): Make several threads using create_thread.
+       Call marker function done_making_threads when done making
+       threads.
+
 2002-09-04  Keith Seitz  <keiths@redhat.com>
 
        * configure.in: Add config header.
index 56ca182df50932e048bec517e70c41c524f71ec3..33b84ca3b0fa1d84990fe3d8668a776a9cfe55d5 100644 (file)
@@ -36,9 +36,7 @@ if {[mi_gdb_start]} {
     continue
 }
 
-# Check that MI and the console know of the same threads.
-# Appends NAME to all test names.
-proc check_mi_and_console_threads {name} {
+proc get_mi_thread_list {name} {
   global expect_out
 
   # MI will return a list of thread ids:
@@ -46,6 +44,35 @@ proc check_mi_and_console_threads {name} {
   # -thread-list-ids
   # ^done,thread-ids=[thread-id="1",thread-id="2",...],number-of-threads="N"
   # (gdb)
+  mi_gdb_test "-thread-list-ids" \
+    {\^done,thread-ids=\[(thread-id="[0-9]+"(,)*)+\],number-of-threads="[0-9]+"} \
+    "-thread_list_ids ($name)"
+
+  set thread_list {}
+  if {![regexp {thread-ids=\[(thread-id="[0-9]+"(,)?)*\]} $expect_out(buffer) threads]} {
+    fail "finding threads in MI output ($name)"
+  } else {
+    pass "finding threads in MI output ($name)"
+
+    # Make list of console threads
+    set start [expr {[string first \[ $threads] + 1}]
+    set end   [expr {[string first \] $threads] - 1}]
+    set threads [string range $threads $start $end]
+    foreach thread [split $threads ,] {
+      if {[scan $thread {thread-id="%d"} num]} {
+       lappend thread_list $num
+      }
+    }
+  }
+
+  return $thread_list
+}
+
+# Check that MI and the console know of the same threads.
+# Appends NAME to all test names.
+proc check_mi_and_console_threads {name} {
+  global expect_out
+
   mi_gdb_test "-thread-list-ids" \
     {\^done,thread-ids=\[(thread-id="[0-9]+"(,)*)+\],number-of-threads="[0-9]+"} \
     "-thread-list-ids ($name)"
@@ -109,22 +136,7 @@ proc check_mi_and_console_threads {name} {
        pass "console and MI have same number of threads ($name)"
 
        # Get MI thread list
-       set mi_thread_list ""
-       if {![regexp {thread-ids=\[(thread-id="[0-9]+"(,)?)*\]} $mi_result threads]} {
-         fail "finding threads in MI output ($name)"
-       } else {
-         pass "finding threads in MI output ($name)"
-
-         # Make list of console threads
-         set start [expr {[string first \[ $threads] + 1}]
-         set end   [expr {[string first \] $threads] - 1}]
-         set threads [string range $threads $start $end]
-         foreach thread [split $threads ,] {
-           if {[scan $thread {thread-id="%d"} num]} {
-             lappend mi_thread_list $num
-           }
-         }
-       }
+       set mi_thread_list [get_mi_thread_list $name]
 
        # Check if MI and console have the same threads
        set fails 0
@@ -147,6 +159,9 @@ proc check_mi_and_console_threads {name} {
   }
 }
 
+# This procedure checks for the bug gdb/669, where the console
+# command "info threads" and the MI command "-thread-list-ids"
+# return different threads in the system.
 proc check_for_gdb669_bug {} {
   mi_run_to_main
   check_mi_and_console_threads "at main"
@@ -157,6 +172,41 @@ proc check_for_gdb669_bug {} {
   }
 }
 
+# This procedure tests the various thread commands in MI.
+proc check_mi_thread_command_set {} {
+
+  mi_runto done_making_threads
+
+  set thread_list [get_mi_thread_list "in check_mi_thread_command_set"]
+  
+  mi_gdb_test "-thread-select" \
+    {\^error,msg="mi_cmd_thread_select: USAGE: threadnum."} \
+    "check_mi_thread_command_set: -thread-select"
+
+  mi_gdb_test "-thread-select 123456789" \
+    {\^error,msg="Thread ID 123456789 not known\."} \
+    "check_mi_thread_command_set: -thread-select 123456789"
+
+  foreach thread $thread_list {
+    mi_gdb_test "-thread-select $thread" \
+      "=context-changed,thread=\"$thread\"\r\n\\^done,new-thread-id=\"$thread\",frame={.*},line=\"(-)?\[0-9\]+\",file=\".*\"" \
+      "check_mi_thread_command_set: -thread-select $thread"
+  }
+}
+
+# This procedure checks that the console and MI don't get out
+# of sync with each other.
+proc check_console_thread_commands {} {
+
+  # Assumed that we're at done_making_threads
+  set thread_list [get_mi_thread_list "in check_console_thread_commands"]
+  foreach thread $thread_list {
+    mi_gdb_test "-interpreter-exec console \"thread $thread\"" \
+      "(\\~\".*\"\r\n)*=context-changed,thread=\"$thread\"\r\n\\^done" \
+      "-interpreter-exec console \"thread $thread\""
+  }
+}
+
 #
 # Start here
 #
@@ -172,8 +222,11 @@ if  {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" $binfile executable $optio
 }
 
 mi_gdb_reinitialize_dir $srcdir/$subdir
+mi_gdb_load $binfile
 
+check_mi_thread_command_set
+check_console_thread_commands
 check_for_gdb669_bug
 
 mi_gdb_exit
-return 0
+
index df64e21e3e51c6879c3e6a5008494063198a2b08..c3e17bc6ace608d406909cbba49d0fdf92ce1116 100644 (file)
@@ -43,8 +43,15 @@ routine (void *arg)
   printf ("hello thread\n");
 }
 
-int
-main (int argc, char *argv[])
+/* Marker function for the testsuite */
+void
+done_making_threads (void)
+{
+  /* Nothing */
+};
+
+void
+create_thread (void)
 {
   pthread_t tid;
 
@@ -53,10 +60,20 @@ main (int argc, char *argv[])
       perror ("pthread_create 1");
       exit (1);
     }
-    
+}
+
+int
+main (int argc, char *argv[])
+{
+  int i;
+
+  /* Create a few threads */
+  for (i = 0; i < 5; i++)
+    create_thread ();
+  done_making_threads ();
+
   printf ("hello\n");
   printf ("hello\n");
-  pthread_join (tid, NULL);
   return 0;
 }