]> git.proxmox.com Git - mirror_qemu.git/blame - tests/test-announce-self.c
docker: trivial changes to `make docker` help
[mirror_qemu.git] / tests / test-announce-self.c
CommitLineData
4b9b7000
DDAG
1/*
2 * QTest testcase for qemu_announce_self
3 *
4 * Copyright (c) 2017 Red hat, Inc.
5 * Copyright (c) 2014 SUSE LINUX Products GmbH
6 *
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 */
10
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"
19
20#ifndef ETH_P_RARP
21#define ETH_P_RARP 0x8035
22#endif
23
4b9b7000 24
6415c2d0 25static void test_announce(QTestState *qs, int socket)
4b9b7000
DDAG
26{
27 char buffer[60];
28 int len;
29 QDict *rsp;
30 int ret;
31 uint16_t *proto = (uint16_t *)&buffer[12];
32
6415c2d0 33 rsp = qtest_qmp(qs, "{ 'execute' : 'announce-self', "
4b9b7000
DDAG
34 " 'arguments': {"
35 " 'initial': 50, 'max': 550,"
36 " 'rounds': 10, 'step': 50 } }");
37 assert(!qdict_haskey(rsp, "error"));
38 qobject_unref(rsp);
39
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);
44
45 ret = qemu_recv(socket, buffer, len, 0);
46 g_assert_cmpint(*proto, ==, htons(ETH_P_RARP));
47}
48
49static void setup(gconstpointer data)
50{
51 QTestState *qs;
6415c2d0 52 void (*func) (QTestState *qs, int socket) = data;
4b9b7000
DDAG
53 int sv[2], ret;
54
55 ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sv);
56 g_assert_cmpint(ret, !=, -1);
57
6415c2d0
LQ
58 qs = qtest_initf("-netdev socket,fd=%d,id=hs0 -device "
59 "virtio-net-pci,netdev=hs0", sv[1]);
60 func(qs, sv[0]);
4b9b7000
DDAG
61
62 /* End test */
63 close(sv[0]);
64 qtest_quit(qs);
65}
66
67int main(int argc, char **argv)
68{
69 g_test_init(&argc, &argv, NULL);
70 qtest_add_data_func("/virtio/net/test_announce_self", test_announce, setup);
71
72 return g_test_run();
73}