Patchwork [8/8] add non-stop test that stresses thread starvation issues

login
register
mail settings
Submitter Yao Qi
Date April 7, 2015, 10:10 a.m.
Message ID <86d23gxn8r.fsf@gmail.com>
Download mbox | patch
Permalink /patch/6040/
State New
Headers show

Comments

Yao Qi - April 7, 2015, 10:10 a.m.
Pedro Alves <palves@redhat.com> writes:

> Yes, the test runs forever otherwise.  See:
>
>   https://sourceware.org/gdb/wiki/GDBTestcaseCookbook#Don.27t_write_tests_that_run_forever
>
> How about fixing this like attach-many-short-lived-threads.exp was
> fixed here:
>
>   https://sourceware.org/ml/gdb-patches/2015-02/msg00152.html
>
> ?
>

OK, how about the patch below?

>> It causes some fails on
>> arm-linux, that is, the board is slow, and alarm is triggered.
>> Then thread is disappeared and current_thread is set to NULL.
>> GDB/GDBserver doesn't know about that.  When the inferior memory is
>> accessed, current_thread is dereferenced, and GDBserver is crashed.
>
> Sounds like we should have a test that explicitly covers that.
> GDBserver shouldn't crash.

Yes, let me think about a test case to cover that.
Pedro Alves - April 7, 2015, 10:22 a.m.
On 04/07/2015 11:10 AM, Yao Qi wrote:
> Pedro Alves <palves@redhat.com> writes:
> 
>> Yes, the test runs forever otherwise.  See:
>>
>>   https://sourceware.org/gdb/wiki/GDBTestcaseCookbook#Don.27t_write_tests_that_run_forever
>>
>> How about fixing this like attach-many-short-lived-threads.exp was
>> fixed here:
>>
>>   https://sourceware.org/ml/gdb-patches/2015-02/msg00152.html
>>
>> ?
>>
> 
> OK, how about the patch below?

Looks good.  Thanks!

Thanks,
Pedro Alves
Yao Qi - April 7, 2015, 10:31 a.m.
Pedro Alves <palves@redhat.com> writes:

>> OK, how about the patch below?
>
> Looks good.  Thanks!

Thanks, patch is pushed in.

Patch

diff --git a/gdb/testsuite/gdb.threads/non-stop-fair-events.c b/gdb/testsuite/gdb.threads/non-stop-fair-events.c
index 6a9d31d..f82c366 100644
--- a/gdb/testsuite/gdb.threads/non-stop-fair-events.c
+++ b/gdb/testsuite/gdb.threads/non-stop-fair-events.c
@@ -22,6 +22,9 @@ 
 
 #define NUM_THREADS 10
 const int num_threads = NUM_THREADS;
+/* Allow for as much timeout as DejaGnu wants, plus a bit of
+   slack.  */
+#define SECONDS (TIMEOUT + 20)
 
 pthread_t child_thread[NUM_THREADS];
 volatile pthread_t signal_thread;
@@ -53,6 +56,8 @@  child_function (void *arg)
 
   while (1)
     {
+      /* Reset the timer before going to INF_LOOP.  */
+      alarm (SECONDS);
       INF_LOOP; /* set thread breakpoint here */
       loop_broke ();
     }
@@ -64,8 +69,6 @@  main (void)
   int res;
   int i;
 
-  alarm (60);
-
   signal (SIGUSR1, handler);
 
   for (i = 0; i < NUM_THREADS; i++)
@@ -76,6 +79,8 @@  main (void)
   while (1)
     {
       pthread_kill (signal_thread, SIGUSR1); /* set kill breakpoint here */
+      /* Reset the timer before going to INF_LOOP.  */
+      alarm (SECONDS);
       INF_LOOP;
       loop_broke ();
     }
diff --git a/gdb/testsuite/gdb.threads/non-stop-fair-events.exp b/gdb/testsuite/gdb.threads/non-stop-fair-events.exp
index 9b7b9ca..e2d3f7d 100644
--- a/gdb/testsuite/gdb.threads/non-stop-fair-events.exp
+++ b/gdb/testsuite/gdb.threads/non-stop-fair-events.exp
@@ -24,7 +24,8 @@  if [target_info exists gdb,nosignals] {
     return -1
 }
 
-if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug pthreads}] == -1} {
+set options { "additional_flags=-DTIMEOUT=$timeout" debug pthreads }
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile $options] == -1} {
     return -1
 }