summary refs log tree commit diff stats
path: root/tests/virtio-net-test.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2019-03-12 17:31:30 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2019-03-20 11:44:13 +0100
commit8b159699d49bf340cad90a3291f6ce631ce58c8c (patch)
tree0666f12c820ff42647f8527b3315bdb4ef0c0c2a /tests/virtio-net-test.c
parent9ad4994661b8e478975475b37488973c5c15116f (diff)
downloadfocaccia-qemu-8b159699d49bf340cad90a3291f6ce631ce58c8c.tar.gz
focaccia-qemu-8b159699d49bf340cad90a3291f6ce631ce58c8c.zip
test-announce-self: convert to qgraph
This removes the duplicated initialization code.

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tests/virtio-net-test.c')
-rw-r--r--tests/virtio-net-test.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c
index c58e670e2f..0d956f36fe 100644
--- a/tests/virtio-net-test.c
+++ b/tests/virtio-net-test.c
@@ -15,6 +15,10 @@
 #include "libqos/qgraph.h"
 #include "libqos/virtio-net.h"
 
+#ifndef ETH_P_RARP
+#define ETH_P_RARP 0x8035
+#endif
+
 #define PCI_SLOT_HP             0x06
 #define PCI_SLOT                0x04
 
@@ -168,6 +172,31 @@ static void hotplug(void *obj, void *data, QGuestAllocator *t_alloc)
     }
 }
 
+static void announce_self(void *obj, void *data, QGuestAllocator *t_alloc)
+{
+    int *sv = data;
+    char buffer[60];
+    int len;
+    QDict *rsp;
+    int ret;
+    uint16_t *proto = (uint16_t *)&buffer[12];
+
+    rsp = qmp("{ 'execute' : 'announce-self', "
+                  " 'arguments': {"
+                      " 'initial': 50, 'max': 550,"
+                      " 'rounds': 10, 'step': 50 } }");
+    assert(!qdict_haskey(rsp, "error"));
+    qobject_unref(rsp);
+
+    /* Catch the packet and make sure it's a RARP */
+    ret = qemu_recv(sv[0], &len, sizeof(len), 0);
+    g_assert_cmpint(ret, ==,  sizeof(len));
+    len = ntohl(len);
+
+    ret = qemu_recv(sv[0], buffer, len, 0);
+    g_assert_cmpint(*proto, ==, htons(ETH_P_RARP));
+}
+
 static void virtio_net_test_cleanup(void *sockets)
 {
     int *sv = sockets;
@@ -233,6 +262,7 @@ static void register_virtio_net_test(void)
     qos_add_test("basic", "virtio-net", send_recv_test, &opts);
     qos_add_test("rx_stop_cont", "virtio-net", stop_cont_test, &opts);
 #endif
+    qos_add_test("announce-self", "virtio-net", announce_self, &opts);
 
     /* These tests do not need a loopback backend.  */
     opts.before = virtio_net_test_setup_nosocket;