From 9c53604dfe1f2625c81c34fe0270bd3ef9083262 Mon Sep 17 00:00:00 2001 From: lace <> Date: Fri, 15 Jun 2007 09:23:25 +0000 Subject: [PATCH] Handle less threads caught during the inferior's initialization. --- testsuite.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/testsuite.c b/testsuite.c index fce7c79..9fa2a64 100644 --- a/testsuite.c +++ b/testsuite.c @@ -20,6 +20,11 @@ #include "debugger.c" +#define TIMEOUT_SECS 4 +#undef LOOPS_MIN +#define LOOPS_MIN 1000 + + #define tkill(tid, sig) syscall (SYS_tkill, (tid), (sig)) @@ -28,16 +33,32 @@ static volatile int spawned_threads_count; /* Set for the specific spawner. */ static struct attach_state_struct *attach_checked (pid_t pid, int redelivered_expect) { struct attach_state_struct *attach_state; + time_t timeout = time (NULL) + TIMEOUT_SECS; + unsigned loops = 0; STATE (pid, (1 << STATE_SLEEPING) | (1 << STATE_RUNNING) | (1 << STATE_STOPPED)); - attach_state = attach (pid); - if (redelivered_expect != attach_state_redelivered_get (attach_state)) + do { - fprintf (stderr, "Expecting redelivery of %d but found %d\n", - redelivered_expect, attach_state_redelivered_get (attach_state)); - abort (); + attach_state = attach (pid); + if (redelivered_expect != attach_state_redelivered_get (attach_state)) + { + fprintf (stderr, "Expecting redelivery of %d but found %d\n", + redelivered_expect, + attach_state_redelivered_get (attach_state)); + abort (); + } + if (attach_state_threads_count_get (attach_state) + == spawned_threads_count) + break; + /* During the inferior's initialization we may catch less threads. */ + assert (attach_state_threads_count_get (attach_state) + < spawned_threads_count); + /* WARNING: Currently we never use REDELIVERED_EXPECT but we would have to + probably reset it back to 0 otherwise. */ + assert (redelivered_expect == 0); } - assert (spawned_threads_count == attach_state_threads_count_get (attach_state)); + while (loops++ < LOOPS_MIN || time (NULL) < timeout); + /* FIXME: Why also STATE_STOPPED? */ STATE (pid, (1 << STATE_PTRACED) | (1 << STATE_STOPPED)); return attach_state; -- 1.8.3.1