MAINTAINERS: PPC: add a PowerNV machine entry
[qemu/ar7.git] / tests / test-announce-self.c
blob0e6d466aa4a4d6b045822601d6858a6ebc6a8472
1 /*
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.
9 */
11 #include "qemu/osdep.h"
12 #include "libqtest.h"
13 #include "qapi/qmp/qdict.h"
14 #include "qemu-common.h"
15 #include "qemu/sockets.h"
16 #include "qemu/iov.h"
17 #include "libqos/libqos-pc.h"
18 #include "libqos/libqos-spapr.h"
20 #ifndef ETH_P_RARP
21 #define ETH_P_RARP 0x8035
22 #endif
25 static void test_announce(QTestState *qs, int socket)
27 char buffer[60];
28 int len;
29 QDict *rsp;
30 int ret;
31 uint16_t *proto = (uint16_t *)&buffer[12];
33 rsp = qtest_qmp(qs, "{ 'execute' : 'announce-self', "
34 " 'arguments': {"
35 " 'initial': 50, 'max': 550,"
36 " 'rounds': 10, 'step': 50 } }");
37 assert(!qdict_haskey(rsp, "error"));
38 qobject_unref(rsp);
40 /* Catch the packet and make sure it's a RARP */
41 ret = qemu_recv(socket, &len, sizeof(len), 0);
42 g_assert_cmpint(ret, ==, sizeof(len));
43 len = ntohl(len);
45 ret = qemu_recv(socket, buffer, len, 0);
46 g_assert_cmpint(*proto, ==, htons(ETH_P_RARP));
49 static void setup(gconstpointer data)
51 QTestState *qs;
52 void (*func) (QTestState *qs, int socket) = data;
53 int sv[2], ret;
55 ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sv);
56 g_assert_cmpint(ret, !=, -1);
58 qs = qtest_initf("-netdev socket,fd=%d,id=hs0 -device "
59 "virtio-net-pci,netdev=hs0", sv[1]);
60 func(qs, sv[0]);
62 /* End test */
63 close(sv[0]);
64 qtest_quit(qs);
67 int main(int argc, char **argv)
69 g_test_init(&argc, &argv, NULL);
70 qtest_add_data_func("/virtio/net/test_announce_self", test_announce, setup);
72 return g_test_run();