2 * QTest testcase for the query-netdev
4 * Copyright Yandex N.V., 2019
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
11 #include "qemu/osdep.h"
13 #include "libqos/libqtest.h"
14 #include "qapi/qmp/qdict.h"
15 #include "qapi/qmp/qlist.h"
18 * Events can get in the way of responses we are actually waiting for.
21 static QObject
*wait_command(QTestState
*who
, const char *command
, ...)
27 va_start(ap
, command
);
28 qtest_qmp_vsend(who
, command
, ap
);
31 response
= qtest_qmp_receive(who
);
33 result
= qdict_get(response
, "return");
36 qobject_unref(response
);
41 static void qmp_query_netdev_no_error(QTestState
*qts
, size_t netdevs_count
)
46 resp
= wait_command(qts
, "{'execute': 'query-netdev'}");
48 netdevs
= qobject_to(QList
, resp
);
50 g_assert(qlist_size(netdevs
) == netdevs_count
);
55 static void test_query_netdev(void)
57 const char *arch
= qtest_get_arch();
61 /* Choosing machine for platforms without default one */
62 if (g_str_equal(arch
, "arm") ||
63 g_str_equal(arch
, "aarch64")) {
67 "-netdev user,id=slirp0");
68 } else if (g_str_equal(arch
, "tricore")) {
71 "-M tricore_testboard "
72 "-netdev user,id=slirp0");
73 } else if (g_str_equal(arch
, "avr")) {
77 "-netdev user,id=slirp0");
78 } else if (g_str_equal(arch
, "rx")) {
82 "-netdev user,id=slirp0");
86 "-netdev user,id=slirp0");
90 qmp_query_netdev_no_error(state
, 1);
92 resp
= wait_command(state
,
93 "{'execute': 'netdev_add', 'arguments': {"
98 qmp_query_netdev_no_error(state
, 2);
100 resp
= wait_command(state
,
101 "{'execute': 'netdev_del', 'arguments': {"
102 " 'id': 'slirp1'}}");
105 qmp_query_netdev_no_error(state
, 1);
110 int main(int argc
, char **argv
)
113 g_test_init(&argc
, &argv
, NULL
);
115 qtest_add_func("/net/qapi/query_netdev", test_query_netdev
);