This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[commit] Make schedlock.exp more reliable


The schedlock tests (which I wrote) are annoying for three reasons.
One, the test names change from run to run depending on which thread
is active when we send a Control-C.  Two, they run six threads
spinning CPU as fast as they can; my window manager stutters whenever
I get to schedlock.exp.  Three, they fail intermittently under load.

I've checked in this patch which preserves the intention of the tests
but makes them less intensive.  We only need two threads, and the
group did/didn't run tests only need a single pass/fail marker.

I was only able to get this to fail on my desktop once out of about a
hundred runs.  On slower machines and with more load failures will
probably happen more often, but it should be less than previously.

-- 
Daniel Jacobowitz
CodeSourcery

2007-09-17  Daniel Jacobowitz  <dan@codesourcery.com>

	* schedlock.c (NUM): Change to 1.
	(main): Use args[0] for the main thread.
	* schedlock.exp: Only expect two threads.  Only issue one pass or fail
	regardless of the number of threads.

Index: schedlock.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.threads/schedlock.c,v
retrieving revision 1.7
diff -u -p -r1.7 schedlock.c
--- schedlock.c	23 Aug 2007 18:08:50 -0000	1.7
+++ schedlock.c	17 Sep 2007 15:09:41 -0000
@@ -22,7 +22,7 @@
 
 void *thread_function(void *arg); /* Pointer to function executed by each thread */
 
-#define NUM 5
+#define NUM 1
 
 unsigned int args[NUM+1];
 
@@ -32,7 +32,7 @@ int main() {
     void *thread_result;
     long i;
 
-    for (i = 0; i < NUM; i++)
+    for (i = 1; i <= NUM; i++)
       {
 	args[i] = 1;
 	res = pthread_create(&threads[i],
@@ -42,8 +42,8 @@ int main() {
       }
 
     /* schedlock.exp: last thread start.  */
-    args[i] = 1;
-    thread_function ((void *) i);
+    args[0] = 1;
+    thread_function ((void *) 0);
 
     exit(EXIT_SUCCESS);
 }
Index: schedlock.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.threads/schedlock.exp,v
retrieving revision 1.6
diff -u -p -r1.6 schedlock.exp
--- schedlock.exp	23 Aug 2007 18:14:19 -0000	1.6
+++ schedlock.exp	17 Sep 2007 15:09:41 -0000
@@ -32,6 +32,9 @@ set testfile "schedlock"
 set srcfile ${testfile}.c
 set binfile ${objdir}/${subdir}/${testfile}
 
+# The number of threads, including the main thread.
+set NUM 2
+
 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
     return -1
 }
@@ -44,11 +47,11 @@ proc get_args { } {
 
   send_gdb "print args\n"
   gdb_expect {
-    -re "\\\$\[0-9\]+ = {(\[0-9\]+), (\[0-9\]+), (\[0-9\]+), (\[0-9\]+), (\[0-9\]+), (\[0-9\]+)}.*$gdb_prompt"
+    -re "\\\$\[0-9\]+ = {(\[0-9\]+), (\[0-9\]+)}.*$gdb_prompt"
       {
 	set list_count [expr $list_count + 1]
 	pass "listed args ($list_count)"
-	return [list $expect_out(1,string) $expect_out(2,string) $expect_out(3,string) $expect_out(4,string) $expect_out(5,string) $expect_out(6,string)]
+	return [list $expect_out(1,string) $expect_out(2,string)]
       }
     -re "$gdb_prompt"
       {
@@ -112,7 +115,7 @@ proc my_continue { msg } {
   stop_process "stop all threads ($msg)"
 
   # Make sure we're in one of the non-main looping threads.
-  gdb_breakpoint [concat [gdb_get_line_number "schedlock.exp: main loop"] " if arg != 5"]
+  gdb_breakpoint [concat [gdb_get_line_number "schedlock.exp: main loop"] " if arg != 0"]
   gdb_continue_to_breakpoint "return to loop ($msg)"
   delete_breakpoints
 }
@@ -198,13 +201,17 @@ my_continue "initial"
 
 set cont_args [get_args]
 
-for {set i 0} {[expr $i < 6]} {set i [expr $i + 1]} {
+set ok 1
+for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} {
   if {[lindex $start_args $i] == [lindex $cont_args $i]} {
-    fail "thread $i ran (didn't run)"
-  } else {
-    pass "thread $i ran"
+    set ok 0
   }
 }
+if { $ok } {
+  pass "all threads alive"
+} else {
+  fail "all threads alive"
+}
 
 # We can't change threads, unfortunately, in current GDB.  Use
 # whichever we stopped in.
@@ -230,7 +237,7 @@ set start_args $cont_args
 set cont_args [get_args]
 
 set num_other_threads 0
-for {set i 0} {[expr $i < 6]} {set i [expr $i + 1]} {
+for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} {
   if {[lindex $start_args $i] == [lindex $cont_args $i]} {
     if {$i == $curthread} {
       fail "current thread stepped (didn't run)"
@@ -248,9 +255,9 @@ for {set i 0} {[expr $i < 6]} {set i [ex
   }
 }
 if {$num_other_threads > 0} {
-  pass "other threads ran (1)"
+  pass "other threads ran - unlocked"
 } else {
-  fail "other threads ran (no other threads ran) (1)"
+  fail "other threads ran - unlocked"
 }
 
 # Test continue with scheduler locking
@@ -269,21 +276,25 @@ if {$curthread == $newthread} {
 set start_args $cont_args
 set cont_args [get_args]
 
-for {set i 0} {[expr $i < 6]} {set i [expr $i + 1]} {
+set num_other_threads 0
+for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} {
   if {[lindex $start_args $i] == [lindex $cont_args $i]} {
     if {$i == $curthread} {
       fail "current thread ran (didn't run)"
-    } else {
-      pass "other thread $i didn't run"
     }
   } else {
     if {$i == $curthread} {
       pass "current thread ran"
     } else {
-      fail "other thread $i didn't run (ran)"
+      incr num_other_threads
     }
   }
 }
+if {$num_other_threads > 0} {
+  fail "other threads didn't run - locked"
+} else {
+  pass "other threads didn't run - locked"
+}
 
 # Test stepping with scheduler locking
 step_ten_loops "locked"
@@ -299,12 +310,11 @@ if {$curthread == $newthread} {
 set start_args $cont_args
 set cont_args [get_args]
 
-for {set i 0} {[expr $i < 6]} {set i [expr $i + 1]} {
+set num_other_threads 0
+for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} {
   if {[lindex $start_args $i] == [lindex $cont_args $i]} {
     if {$i == $curthread} {
       fail "current thread stepped locked (didn't run)"
-    } else {
-      pass "other thread $i didn't run (stepping)"
     }
   } else {
     if {$i == $curthread} {
@@ -314,9 +324,14 @@ for {set i 0} {[expr $i < 6]} {set i [ex
 	    fail "current thread stepped locked (wrong amount)"
 	}
     } else {
-      fail "other thread $i didn't run (stepping) (ran)"
+      incr num_other_threads
     }
   }
 }
+if {$num_other_threads > 0} {
+  fail "other threads didn't run - step locked"
+} else {
+  pass "other threads didn't run - step locked"
+}
 
 return 0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]