From patchwork Mon Jul 16 14:35:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 171213 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C32552C00E0 for ; Tue, 17 Jul 2012 00:36:30 +1000 (EST) Received: from localhost ([::1]:43640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SqmPU-00023a-QS for incoming@patchwork.ozlabs.org; Mon, 16 Jul 2012 10:36:28 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43083) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SqmPF-0001tF-PY for qemu-devel@nongnu.org; Mon, 16 Jul 2012 10:36:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SqmP7-0006c8-GR for qemu-devel@nongnu.org; Mon, 16 Jul 2012 10:36:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36866) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SqmP7-0006c1-94 for qemu-devel@nongnu.org; Mon, 16 Jul 2012 10:36:05 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q6GEa4OJ006579 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 16 Jul 2012 10:36:04 -0400 Received: from dhcp-5-188.str.redhat.com (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q6GEa1dH004634; Mon, 16 Jul 2012 10:36:03 -0400 From: Kevin Wolf To: phrdina@redhat.com Date: Mon, 16 Jul 2012 16:35:59 +0200 Message-Id: <1342449360-15227-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1342449360-15227-1-git-send-email-kwolf@redhat.com> References: <1342449360-15227-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 1/2] fdc-test: Clean up a bit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Readability of the test code has suffered as the test case evolved. This should improve it a bit again. Signed-off-by: Kevin Wolf --- tests/fdc-test.c | 36 ++++++++++++++++++++---------------- 1 files changed, 20 insertions(+), 16 deletions(-) diff --git a/tests/fdc-test.c b/tests/fdc-test.c index 10d11a4..fa74411 100644 --- a/tests/fdc-test.c +++ b/tests/fdc-test.c @@ -93,17 +93,21 @@ static uint8_t floppy_recv(void) return inb(FLOPPY_BASE + reg_fifo); } -static uint8_t ack_irq(void) +/* pcn: Present Cylinder Number */ +static void ack_irq(uint8_t *pcn) { uint8_t ret; g_assert(get_irq(FLOPPY_IRQ)); floppy_send(CMD_SENSE_INT); floppy_recv(); + ret = floppy_recv(); - g_assert(!get_irq(FLOPPY_IRQ)); + if (pcn != NULL) { + *pcn = ret; + } - return ret; + g_assert(!get_irq(FLOPPY_IRQ)); } static uint8_t send_read_command(void) @@ -162,7 +166,7 @@ static uint8_t send_read_command(void) return ret; } -static void send_step_pulse(int cyl) +static void send_seek(int cyl) { int drive = 0; int head = 0; @@ -171,7 +175,7 @@ static void send_step_pulse(int cyl) floppy_send(head << 2 | drive); g_assert(!get_irq(FLOPPY_IRQ)); floppy_send(cyl); - ack_irq(); + ack_irq(NULL); } static uint8_t cmos_read(uint8_t reg) @@ -198,7 +202,7 @@ static void test_no_media_on_start(void) assert_bit_set(dir, DSKCHG); dir = inb(FLOPPY_BASE + reg_dir); assert_bit_set(dir, DSKCHG); - send_step_pulse(1); + send_seek(1); dir = inb(FLOPPY_BASE + reg_dir); assert_bit_set(dir, DSKCHG); dir = inb(FLOPPY_BASE + reg_dir); @@ -229,14 +233,14 @@ static void test_media_change(void) dir = inb(FLOPPY_BASE + reg_dir); assert_bit_set(dir, DSKCHG); - send_step_pulse(0); + send_seek(0); dir = inb(FLOPPY_BASE + reg_dir); assert_bit_set(dir, DSKCHG); dir = inb(FLOPPY_BASE + reg_dir); assert_bit_set(dir, DSKCHG); /* Step to next track should clear DSKCHG bit. */ - send_step_pulse(1); + send_seek(1); dir = inb(FLOPPY_BASE + reg_dir); assert_bit_clear(dir, DSKCHG); dir = inb(FLOPPY_BASE + reg_dir); @@ -252,13 +256,13 @@ static void test_media_change(void) dir = inb(FLOPPY_BASE + reg_dir); assert_bit_set(dir, DSKCHG); - send_step_pulse(0); + send_seek(0); dir = inb(FLOPPY_BASE + reg_dir); assert_bit_set(dir, DSKCHG); dir = inb(FLOPPY_BASE + reg_dir); assert_bit_set(dir, DSKCHG); - send_step_pulse(1); + send_seek(1); dir = inb(FLOPPY_BASE + reg_dir); assert_bit_set(dir, DSKCHG); dir = inb(FLOPPY_BASE + reg_dir); @@ -292,10 +296,10 @@ static void test_relative_seek(void) uint8_t drive = 0; uint8_t head = 0; uint8_t cyl = 1; - uint8_t ret; + uint8_t pcn; /* Send seek to track 0 */ - send_step_pulse(0); + send_seek(0); /* Send relative seek to increase track by 1 */ floppy_send(CMD_RELATIVE_SEEK_IN); @@ -303,8 +307,8 @@ static void test_relative_seek(void) g_assert(!get_irq(FLOPPY_IRQ)); floppy_send(cyl); - ret = ack_irq(); - g_assert(ret == 1); + ack_irq(&pcn); + g_assert(pcn == 1); /* Send relative seek to decrease track by 1 */ floppy_send(CMD_RELATIVE_SEEK_OUT); @@ -312,8 +316,8 @@ static void test_relative_seek(void) g_assert(!get_irq(FLOPPY_IRQ)); floppy_send(cyl); - ret = ack_irq(); - g_assert(ret == 0); + ack_irq(&pcn); + g_assert(pcn == 0); } /* success if no crash or abort */