diff mbox

[v6,6/6] fdc_test: introduce test_sense_interrupt

Message ID eeb5545b7f850631a792dcbf20bc84129031414c.1340360906.git.phrdina@redhat.com
State New
Headers show

Commit Message

Pavel Hrdina June 22, 2012, 10:33 a.m. UTC
Calling sense interrupt status while there is no interrupt should
return invalid command (0x80).

Read command should always returns in st0 seek_end bit set to 1.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 tests/fdc-test.c |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)

Comments

Kevin Wolf June 25, 2012, 11:52 a.m. UTC | #1
Am 22.06.2012 12:33, schrieb Pavel Hrdina:
> Calling sense interrupt status while there is no interrupt should
> return invalid command (0x80).
> 
> Read command should always returns in st0 seek_end bit set to 1.
> 
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
>  tests/fdc-test.c |   25 ++++++++++++++++++++++++-
>  1 files changed, 24 insertions(+), 1 deletions(-)
> 
> diff --git a/tests/fdc-test.c b/tests/fdc-test.c
> index 5280eff..be14d83 100644
> --- a/tests/fdc-test.c
> +++ b/tests/fdc-test.c
> @@ -142,7 +142,7 @@ static uint8_t send_read_command(void)
>      }
>  
>      st0 = floppy_recv();
> -    if (st0 != 0x40) {
> +    if (st0 != 0x60) {
>          ret = 1;
>      }
>  
> @@ -263,6 +263,28 @@ static void test_media_change(void)
>      assert_bit_set(dir, DSKCHG);
>  }
>  
> +static void test_sense_interrupt(void)
> +{
> +    int drive = 0;
> +    int head = 0;
> +    int cyl = 0;
> +    int ret = 0;
> +
> +    floppy_send(CMD_SENSE_INT);
> +    ret = floppy_recv();
> +    g_assert(ret == 0x80);

If I'm not mistakes, CMD_SENSE_INT returns two bytes (not just one), the
first of which is ST0 and the second one the Present Cylinder Number.

0x80 for ST0 would mean "invalid command", which is the right return
value if there is no active interrupt condition. So you seem to check
the right value and just miss a second floppy_recv().

> +
> +    floppy_send(CMD_SEEK);
> +    floppy_send(head << 2 | drive);
> +    g_assert(!get_irq(FLOPPY_IRQ));
> +    floppy_send(cyl);

Maybe add another assertion here that the IRQ is now active?

> +
> +    floppy_send(CMD_SENSE_INT);
> +    ret = floppy_recv();
> +    g_assert(ret != 0x80);

I think we can do better and tell the exact value that should result. I
believe g_assert(ret == 0x20); would be right.

Kevin
Pavel Hrdina June 27, 2012, 3:19 p.m. UTC | #2
On 06/25/2012 01:52 PM, Kevin Wolf wrote:
> Am 22.06.2012 12:33, schrieb Pavel Hrdina:
>> Calling sense interrupt status while there is no interrupt should
>> return invalid command (0x80).
>>
>> Read command should always returns in st0 seek_end bit set to 1.
>>
>> Signed-off-by: Pavel Hrdina<phrdina@redhat.com>
>> ---
>>   tests/fdc-test.c |   25 ++++++++++++++++++++++++-
>>   1 files changed, 24 insertions(+), 1 deletions(-)
>>
>> diff --git a/tests/fdc-test.c b/tests/fdc-test.c
>> index 5280eff..be14d83 100644
>> --- a/tests/fdc-test.c
>> +++ b/tests/fdc-test.c
>> @@ -142,7 +142,7 @@ static uint8_t send_read_command(void)
>>       }
>>
>>       st0 = floppy_recv();
>> -    if (st0 != 0x40) {
>> +    if (st0 != 0x60) {
>>           ret = 1;
>>       }
>>
>> @@ -263,6 +263,28 @@ static void test_media_change(void)
>>       assert_bit_set(dir, DSKCHG);
>>   }
>>
>> +static void test_sense_interrupt(void)
>> +{
>> +    int drive = 0;
>> +    int head = 0;
>> +    int cyl = 0;
>> +    int ret = 0;
>> +
>> +    floppy_send(CMD_SENSE_INT);
>> +    ret = floppy_recv();
>> +    g_assert(ret == 0x80);
> If I'm not mistakes, CMD_SENSE_INT returns two bytes (not just one), the
> first of which is ST0 and the second one the Present Cylinder Number.
>
> 0x80 for ST0 would mean "invalid command", which is the right return
> value if there is no active interrupt condition. So you seem to check
> the right value and just miss a second floppy_recv().
>
In case you send this command but there is no interrupt waiting you 
receive invalid command which is only one byte.
>> +
>> +    floppy_send(CMD_SEEK);
>> +    floppy_send(head<<  2 | drive);
>> +    g_assert(!get_irq(FLOPPY_IRQ));
>> +    floppy_send(cyl);
> Maybe add another assertion here that the IRQ is now active?
I think that is not needed, because the next command check it anyway.
>> +
>> +    floppy_send(CMD_SENSE_INT);
>> +    ret = floppy_recv();
>> +    g_assert(ret != 0x80);
> I think we can do better and tell the exact value that should result. I
> believe g_assert(ret == 0x20); would be right.
> Kevin
Well, this code tests only if sense interrupt status returns invalid 
command or not depends on if there is interrupt waiting or not. But it 
won't hurts if we change it.

Pavel
diff mbox

Patch

diff --git a/tests/fdc-test.c b/tests/fdc-test.c
index 5280eff..be14d83 100644
--- a/tests/fdc-test.c
+++ b/tests/fdc-test.c
@@ -142,7 +142,7 @@  static uint8_t send_read_command(void)
     }
 
     st0 = floppy_recv();
-    if (st0 != 0x40) {
+    if (st0 != 0x60) {
         ret = 1;
     }
 
@@ -263,6 +263,28 @@  static void test_media_change(void)
     assert_bit_set(dir, DSKCHG);
 }
 
+static void test_sense_interrupt(void)
+{
+    int drive = 0;
+    int head = 0;
+    int cyl = 0;
+    int ret = 0;
+
+    floppy_send(CMD_SENSE_INT);
+    ret = floppy_recv();
+    g_assert(ret == 0x80);
+
+    floppy_send(CMD_SEEK);
+    floppy_send(head << 2 | drive);
+    g_assert(!get_irq(FLOPPY_IRQ));
+    floppy_send(cyl);
+
+    floppy_send(CMD_SENSE_INT);
+    ret = floppy_recv();
+    g_assert(ret != 0x80);
+    floppy_recv();
+}
+
 /* success if no crash or abort */
 static void fuzz_registers(void)
 {
@@ -310,6 +332,7 @@  int main(int argc, char **argv)
     qtest_add_func("/fdc/no_media_on_start", test_no_media_on_start);
     qtest_add_func("/fdc/read_without_media", test_read_without_media);
     qtest_add_func("/fdc/media_change", test_media_change);
+    qtest_add_func("/fdc/sense_interrupt", test_sense_interrupt);
     qtest_add_func("/fdc/fuzz-registers", fuzz_registers);
 
     ret = g_test_run();