diff mbox

[05/38] ivshmem-test: Improve test case /ivshmem/single

Message ID 1456771254-17511-6-git-send-email-armbru@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Markus Armbruster Feb. 29, 2016, 6:40 p.m. UTC
Test state of registers after reset.

Test reading Interrupt Status clears it.

Test (invalid) read of Doorbell.

Add more comments.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 tests/ivshmem-test.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

Comments

Marc-André Lureau March 1, 2016, 11:06 a.m. UTC | #1
On Mon, Feb 29, 2016 at 7:40 PM, Markus Armbruster <armbru@redhat.com> wrote:
> Test state of registers after reset.
>
> Test reading Interrupt Status clears it.
>
> Test (invalid) read of Doorbell.
>
> Add more comments.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


> ---
>  tests/ivshmem-test.c | 23 ++++++++++++++++-------
>  1 file changed, 16 insertions(+), 7 deletions(-)
>
> diff --git a/tests/ivshmem-test.c b/tests/ivshmem-test.c
> index e118377..ba4d9f1 100644
> --- a/tests/ivshmem-test.c
> +++ b/tests/ivshmem-test.c
> @@ -143,32 +143,41 @@ static void test_ivshmem_single(void)
>      setup_vm(&state);
>      s = &state;
>
> -    /* valid io */
> -    out_reg(s, INTRMASK, 0);
> -    in_reg(s, INTRSTATUS);
> -    in_reg(s, IVPOSITION);
> +    /* initial state of readable registers */
> +    g_assert_cmpuint(in_reg(s, INTRMASK), ==, 0);
> +    g_assert_cmpuint(in_reg(s, INTRSTATUS), ==, 0);
> +    g_assert_cmpuint(in_reg(s, IVPOSITION), ==, 0);
>
> +    /* trigger interrupt via registers */
>      out_reg(s, INTRMASK, 0xffffffff);
>      g_assert_cmpuint(in_reg(s, INTRMASK), ==, 0xffffffff);
>      out_reg(s, INTRSTATUS, 1);
> -    /* XXX: intercept IRQ, not seen in resp */
> +    /* check interrupt status */
>      g_assert_cmpuint(in_reg(s, INTRSTATUS), ==, 1);
> +    /* reading clears */
> +    g_assert_cmpuint(in_reg(s, INTRSTATUS), ==, 0);
> +    /* TODO intercept actual interrupt (needs qtest work) */
>
> -    /* invalid io */
> +    /* invalid register access */
>      out_reg(s, IVPOSITION, 1);
> +    in_reg(s, DOORBELL);
> +
> +    /* ring the (non-functional) doorbell */
>      out_reg(s, DOORBELL, 8 << 16);
>
> +    /* write shared memory */
>      for (i = 0; i < G_N_ELEMENTS(data); i++) {
>          data[i] = i;
>      }
>      qtest_memwrite(s->qtest, (uintptr_t)s->mem_base, data, sizeof(data));
>
> +    /* verify write */
>      for (i = 0; i < G_N_ELEMENTS(data); i++) {
>          g_assert_cmpuint(((uint32_t *)tmpshmem)[i], ==, i);
>      }
>
> +    /* read it back and verify read */
>      memset(data, 0, sizeof(data));
> -
>      qtest_memread(s->qtest, (uintptr_t)s->mem_base, data, sizeof(data));
>      for (i = 0; i < G_N_ELEMENTS(data); i++) {
>          g_assert_cmpuint(data[i], ==, i);
> --
> 2.4.3
>
>
diff mbox

Patch

diff --git a/tests/ivshmem-test.c b/tests/ivshmem-test.c
index e118377..ba4d9f1 100644
--- a/tests/ivshmem-test.c
+++ b/tests/ivshmem-test.c
@@ -143,32 +143,41 @@  static void test_ivshmem_single(void)
     setup_vm(&state);
     s = &state;
 
-    /* valid io */
-    out_reg(s, INTRMASK, 0);
-    in_reg(s, INTRSTATUS);
-    in_reg(s, IVPOSITION);
+    /* initial state of readable registers */
+    g_assert_cmpuint(in_reg(s, INTRMASK), ==, 0);
+    g_assert_cmpuint(in_reg(s, INTRSTATUS), ==, 0);
+    g_assert_cmpuint(in_reg(s, IVPOSITION), ==, 0);
 
+    /* trigger interrupt via registers */
     out_reg(s, INTRMASK, 0xffffffff);
     g_assert_cmpuint(in_reg(s, INTRMASK), ==, 0xffffffff);
     out_reg(s, INTRSTATUS, 1);
-    /* XXX: intercept IRQ, not seen in resp */
+    /* check interrupt status */
     g_assert_cmpuint(in_reg(s, INTRSTATUS), ==, 1);
+    /* reading clears */
+    g_assert_cmpuint(in_reg(s, INTRSTATUS), ==, 0);
+    /* TODO intercept actual interrupt (needs qtest work) */
 
-    /* invalid io */
+    /* invalid register access */
     out_reg(s, IVPOSITION, 1);
+    in_reg(s, DOORBELL);
+
+    /* ring the (non-functional) doorbell */
     out_reg(s, DOORBELL, 8 << 16);
 
+    /* write shared memory */
     for (i = 0; i < G_N_ELEMENTS(data); i++) {
         data[i] = i;
     }
     qtest_memwrite(s->qtest, (uintptr_t)s->mem_base, data, sizeof(data));
 
+    /* verify write */
     for (i = 0; i < G_N_ELEMENTS(data); i++) {
         g_assert_cmpuint(((uint32_t *)tmpshmem)[i], ==, i);
     }
 
+    /* read it back and verify read */
     memset(data, 0, sizeof(data));
-
     qtest_memread(s->qtest, (uintptr_t)s->mem_base, data, sizeof(data));
     for (i = 0; i < G_N_ELEMENTS(data); i++) {
         g_assert_cmpuint(data[i], ==, i);