From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32228 invoked by alias); 5 Nov 2003 17:56:21 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 32221 invoked from network); 5 Nov 2003 17:56:20 -0000 Received: from unknown (HELO concert.shout.net) (204.253.184.25) by sources.redhat.com with SMTP; 5 Nov 2003 17:56:20 -0000 Received: from duracef.shout.net (duracef.shout.net [204.253.184.12]) by concert.shout.net (8.12.10/8.12.10) with ESMTP id hA5HuKDc016858 for ; Wed, 5 Nov 2003 11:56:20 -0600 Received: from duracef.shout.net (localhost [127.0.0.1]) by duracef.shout.net (8.12.10/8.12.9) with ESMTP id hA5HuKfa018764 for ; Wed, 5 Nov 2003 11:56:20 -0600 Received: (from mec@localhost) by duracef.shout.net (8.12.10/8.12.9/Submit) id hA5HuKXP018763 for gdb-patches@sources.redhat.com; Wed, 5 Nov 2003 12:56:20 -0500 Date: Wed, 05 Nov 2003 17:56:00 -0000 From: Michael Elizabeth Chastain Message-Id: <200311051756.hA5HuKXP018763@duracef.shout.net> To: gdb-patches@sources.redhat.com Subject: [rfc/testsuite/mi/thread] fix call to sleep in pthreads.c X-SW-Source: 2003-11/txt/msg00061.txt.bz2 This patch changes gdb.mi/pthreads.c so that it gives repeatable results under gdb. Currently, the gdb.mi/mi*-pthreads.exp tests give irregular results because the call to sleep() will often return prematurely. Thus, many of the threads exit before the test script can see them. All the results are PASS, but there are different PASSes on different test runs. With this patch, all the threads live as long as they are intended to live, so that the test script sees all the threads. This patch has a disadvantage. gdb is supposed to work with all kinds of inferior programs, not just well-written inferior programs. Arguably, I should live pthreads.c alone, and change the *.exp files to be more flexible about what they recognize. I thought about that approach and decided that I like it better if the test program covers what it is intended to cover (thread backtraces) even at the expense of other coverage (of nothing particularly useful). Also, gdb.threads/pthreads.c still has the broken call to sleep() with no return value checking, so we do still have an instance of this programming idiom in the test corpus. My motivation for doing this is that I'm processing two million test results on every spin, so the more uniform and regular they are, the less work I have to do. This also helps anyone who compares test runs with 'diff' or with Andrew's script. Testing: I'm in the process of testing this. So far it looks okay but I won't say anything until the test bed finishes. Anyways ... comments? Michael C 2003-11-05 Michael Chastain * gdb.mi/pthreads.c (routine): Handle early return from sleep. Index: pthreads.c =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.mi/pthreads.c,v retrieving revision 1.4 diff -c -3 -p -r1.4 pthreads.c *** pthreads.c 24 Oct 2003 19:55:09 -0000 1.4 --- pthreads.c 5 Nov 2003 17:43:00 -0000 *************** static pthread_attr_t null_attr; *** 42,48 **** void * routine (void *arg) { ! sleep (9); printf ("hello thread\n"); } --- 42,55 ---- void * routine (void *arg) { ! /* When gdb is running, it sets hidden breakpoints in the thread ! library. The signals caused by these hidden breakpoints can ! cause system calls such as 'sleep' to return early. Pay attention ! to the return value from 'sleep' to get the full sleep. */ ! int unslept = 9; ! while (unslept > 0) ! unslept = sleep (unslept); ! printf ("hello thread\n"); }