]>
Commit | Line | Data |
---|---|---|
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 | ||
24 | static QTestState *test_init(int socket) | |
25 | { | |
26 | char *args; | |
27 | ||
28 | args = g_strdup_printf("-netdev socket,fd=%d,id=hs0 -device " | |
29 | "virtio-net-pci,netdev=hs0", socket); | |
30 | ||
31 | return qtest_start(args); | |
32 | } | |
33 | ||
34 | ||
35 | static void test_announce(int socket) | |
36 | { | |
37 | char buffer[60]; | |
38 | int len; | |
39 | QDict *rsp; | |
40 | int ret; | |
41 | uint16_t *proto = (uint16_t *)&buffer[12]; | |
42 | ||
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); | |
49 | ||
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); | |
54 | ||
55 | ret = qemu_recv(socket, buffer, len, 0); | |
56 | g_assert_cmpint(*proto, ==, htons(ETH_P_RARP)); | |
57 | } | |
58 | ||
59 | static void setup(gconstpointer data) | |
60 | { | |
61 | QTestState *qs; | |
62 | void (*func) (int socket) = data; | |
63 | int sv[2], ret; | |
64 | ||
65 | ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sv); | |
66 | g_assert_cmpint(ret, !=, -1); | |
67 | ||
68 | qs = test_init(sv[1]); | |
69 | func(sv[0]); | |
70 | ||
71 | /* End test */ | |
72 | close(sv[0]); | |
73 | qtest_quit(qs); | |
74 | } | |
75 | ||
76 | int main(int argc, char **argv) | |
77 | { | |
78 | g_test_init(&argc, &argv, NULL); | |
79 | qtest_add_data_func("/virtio/net/test_announce_self", test_announce, setup); | |
80 | ||
81 | return g_test_run(); | |
82 | } |