2 * QTest testcase for qemu_announce_self
4 * Copyright (c) 2017 Red hat, Inc.
5 * Copyright (c) 2014 SUSE LINUX Products GmbH
7 * This work is licensed under the terms of the GNU GPL, version 2 or later.
8 * See the COPYING file in the top-level directory.
11 #include "qemu/osdep.h"
13 #include "qapi/qmp/qdict.h"
14 #include "qemu-common.h"
15 #include "qemu/sockets.h"
17 #include "libqos/libqos-pc.h"
18 #include "libqos/libqos-spapr.h"
21 #define ETH_P_RARP 0x8035
24 static QTestState *test_init(int socket)
28 args = g_strdup_printf("-netdev socket,fd=%d,id=hs0 -device "
29 "virtio-net-pci,netdev=hs0", socket);
31 return qtest_start(args);
35 static void test_announce(int socket)
41 uint16_t *proto = (uint16_t *)&buffer[12];
43 rsp = qmp("{ 'execute' : 'announce-self', "
45 " 'initial': 50, 'max': 550,"
46 " 'rounds': 10, 'step': 50 } }");
47 assert(!qdict_haskey(rsp, "error"));
50 /* Catch the packet and make sure it's a RARP */
51 ret = qemu_recv(socket, &len, sizeof(len), 0);
52 g_assert_cmpint(ret, ==, sizeof(len));
55 ret = qemu_recv(socket, buffer, len, 0);
56 g_assert_cmpint(*proto, ==, htons(ETH_P_RARP));
59 static void setup(gconstpointer data)
62 void (*func) (int socket) = data;
65 ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sv);
66 g_assert_cmpint(ret, !=, -1);
68 qs = test_init(sv[1]);
76 int main(int argc, char **argv)
78 g_test_init(&argc, &argv, NULL);
79 qtest_add_data_func("/virtio/net/test_announce_self", test_announce, setup);