Received: from eggs.gnu.org ([2001:4830:134:3::10]:48571) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1gdS-0002vB-GW for qemu-devel@nongnu.org; Wed, 25 Nov 2015 15:25:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1gdQ-0000WV-6v for qemu-devel@nongnu.org; Wed, 25 Nov 2015 15:25:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48470) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1gdQ-0000WK-1w for qemu-devel@nongnu.org; Wed, 25 Nov 2015 15:25:48 -0500 From: John Snow Date: Wed, 25 Nov 2015 15:25:42 -0500 Message-Id: <1448483142-32658-5-git-send-email-jsnow@redhat.com> In-Reply-To: <1448483142-32658-1-git-send-email-jsnow@redhat.com> References: <1448483142-32658-1-git-send-email-jsnow@redhat.com> Subject: [Qemu-devel] [PULL 4/4] ide-test: fix timeouts List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, jsnow@redhat.com Use explicit timeouts instead of trying to approximate it by counting the cumulative duration of nsleep calls. In practice, the timeout if inb() dwarfed the nsleep delays, and as a result the real timeout value became a lot larger than 5 seconds. So: change the semantics from "Not sooner than 5 seconds" to "no more than 5 seconds" to ensure we don't hang the tester for very long. Signed-off-by: John Snow Reviewed-by: Kevin Wolf Message-id: 1448393771-15483-2-git-send-email-jsnow@redhat.com --- tests/ide-test.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/ide-test.c b/tests/ide-test.c index 46763db..c3aacd2 100644 --- a/tests/ide-test.c +++ b/tests/ide-test.c @@ -642,15 +642,19 @@ static void nsleep(int64_t nsecs) static uint8_t ide_wait_clear(uint8_t flag) { - int i; uint8_t data; + time_t st; /* Wait with a 5 second timeout */ - for (i = 0; i <= 12500000; i++) { + time(&st); + while (true) { data = inb(IDE_BASE + reg_status); if (!(data & flag)) { return data; } + if (difftime(time(NULL), st) > 5.0) { + break; + } nsleep(400); } g_assert_not_reached(); @@ -658,14 +662,18 @@ static uint8_t ide_wait_clear(uint8_t flag) static void ide_wait_intr(int irq) { - int i; + time_t st; bool intr; - for (i = 0; i <= 12500000; i++) { + time(&st); + while (true) { intr = get_irq(irq); if (intr) { return; } + if (difftime(time(NULL), st) > 5.0) { + break; + } nsleep(400); } -- 2.4.3