ppc/pnv: introduce a new pic_print_info() operation to the chip model
[qemu/ar7.git] / tests / test-announce-self.c
blob1644d34a3f3cc832dad74c53d7053a47e515ae9c
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
24 static QTestState *test_init(int socket)
26 char *args;
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)
37 char buffer[60];
38 int len;
39 QDict *rsp;
40 int ret;
41 uint16_t *proto = (uint16_t *)&buffer[12];
43 rsp = qmp("{ 'execute' : 'announce-self', "
44 " 'arguments': {"
45 " 'initial': 50, 'max': 550,"
46 " 'rounds': 10, 'step': 50 } }");
47 assert(!qdict_haskey(rsp, "error"));
48 qobject_unref(rsp);
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));
53 len = ntohl(len);
55 ret = qemu_recv(socket, buffer, len, 0);
56 g_assert_cmpint(*proto, ==, htons(ETH_P_RARP));
59 static void setup(gconstpointer data)
61 QTestState *qs;
62 void (*func) (int socket) = data;
63 int sv[2], ret;
65 ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sv);
66 g_assert_cmpint(ret, !=, -1);
68 qs = test_init(sv[1]);
69 func(sv[0]);
71 /* End test */
72 close(sv[0]);
73 qtest_quit(qs);
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);
81 return g_test_run();