diff mbox

[06/38] ivshmem-test: Clean up wait for devices to become operational

Message ID 1456771254-17511-7-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_ivshmem_server() waits until the first byte in BAR 2 contains the
0x42 we put into shared memory.  Works because the byte reads zero
until the device maps the shared memory gotten from the server.

Check the IVPosition register instead: it's initially -1, and becomes
non-negative right when the device maps the share memory, so no
change, just cleaner, because it's what guest software is supposed to
do.

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

Comments

Marc-André Lureau March 1, 2016, 11:10 a.m. UTC | #1
On Mon, Feb 29, 2016 at 7:40 PM, Markus Armbruster <armbru@redhat.com> wrote:
> test_ivshmem_server() waits until the first byte in BAR 2 contains the
> 0x42 we put into shared memory.  Works because the byte reads zero
> until the device maps the shared memory gotten from the server.
>
> Check the IVPosition register instead: it's initially -1, and becomes
> non-negative right when the device maps the share memory, so no
> change, just cleaner, because it's what guest software is supposed to
> do.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

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

> ---
>  tests/ivshmem-test.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/tests/ivshmem-test.c b/tests/ivshmem-test.c
> index ba4d9f1..f40c3497 100644
> --- a/tests/ivshmem-test.c
> +++ b/tests/ivshmem-test.c
> @@ -301,7 +301,6 @@ static void test_ivshmem_server(bool msi)
>      int nvectors = 2;
>      guint64 end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND;
>
> -    memset(tmpshmem, 0x42, TMPSHMSIZE);
>      ret = ivshmem_server_init(&server, tmpserver, tmpshm,
>                                TMPSHMSIZE, nvectors,
>                                g_test_verbose());
> @@ -315,9 +314,9 @@ static void test_ivshmem_server(bool msi)
>      setup_vm_with_server(&state2, nvectors, msi);
>      s2 = &state2;
>
> +    /* check state before server sends stuff */
>      g_assert_cmpuint(in_reg(s1, IVPOSITION), ==, 0xffffffff);
>      g_assert_cmpuint(in_reg(s2, IVPOSITION), ==, 0xffffffff);
> -
>      g_assert_cmpuint(qtest_readb(s1->qtest, (uintptr_t)s1->mem_base), ==, 0x00);
>
>      thread.server = &server;
> @@ -326,12 +325,11 @@ static void test_ivshmem_server(bool msi)
>      thread.thread = g_thread_new("ivshmem-server", server_thread, &thread);
>      g_assert(thread.thread != NULL);
>
> -    /* waiting until mapping is done */
> +    /* waiting for devices to become operational */
>      while (g_get_monotonic_time() < end_time) {
>          g_usleep(1000);
> -
> -        if (qtest_readb(s1->qtest, (uintptr_t)s1->mem_base) == 0x42 &&
> -            qtest_readb(s2->qtest, (uintptr_t)s2->mem_base) == 0x42) {
> +        if ((int)in_reg(s1, IVPOSITION) >= 0 &&
> +            (int)in_reg(s2, IVPOSITION) >= 0) {
>              break;
>          }
>      }
> --
> 2.4.3
>
>
diff mbox

Patch

diff --git a/tests/ivshmem-test.c b/tests/ivshmem-test.c
index ba4d9f1..f40c3497 100644
--- a/tests/ivshmem-test.c
+++ b/tests/ivshmem-test.c
@@ -301,7 +301,6 @@  static void test_ivshmem_server(bool msi)
     int nvectors = 2;
     guint64 end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND;
 
-    memset(tmpshmem, 0x42, TMPSHMSIZE);
     ret = ivshmem_server_init(&server, tmpserver, tmpshm,
                               TMPSHMSIZE, nvectors,
                               g_test_verbose());
@@ -315,9 +314,9 @@  static void test_ivshmem_server(bool msi)
     setup_vm_with_server(&state2, nvectors, msi);
     s2 = &state2;
 
+    /* check state before server sends stuff */
     g_assert_cmpuint(in_reg(s1, IVPOSITION), ==, 0xffffffff);
     g_assert_cmpuint(in_reg(s2, IVPOSITION), ==, 0xffffffff);
-
     g_assert_cmpuint(qtest_readb(s1->qtest, (uintptr_t)s1->mem_base), ==, 0x00);
 
     thread.server = &server;
@@ -326,12 +325,11 @@  static void test_ivshmem_server(bool msi)
     thread.thread = g_thread_new("ivshmem-server", server_thread, &thread);
     g_assert(thread.thread != NULL);
 
-    /* waiting until mapping is done */
+    /* waiting for devices to become operational */
     while (g_get_monotonic_time() < end_time) {
         g_usleep(1000);
-
-        if (qtest_readb(s1->qtest, (uintptr_t)s1->mem_base) == 0x42 &&
-            qtest_readb(s2->qtest, (uintptr_t)s2->mem_base) == 0x42) {
+        if ((int)in_reg(s1, IVPOSITION) >= 0 &&
+            (int)in_reg(s2, IVPOSITION) >= 0) {
             break;
         }
     }