tests/qtest: Only run fuzz-virtio-scsi when virtio-scsi is available
[qemu/ar7.git] / tests / qtest / test-query-netdev.c
blob1118537a9fa59a444984e7520309ca6ad4ec5361
1 /*
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.
9 */
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.
20 GCC_FMT_ATTR(2, 3)
21 static QObject *wait_command(QTestState *who, const char *command, ...)
23 va_list ap;
24 QDict *response;
25 QObject *result;
27 va_start(ap, command);
28 qtest_qmp_vsend(who, command, ap);
29 va_end(ap);
31 response = qtest_qmp_receive(who);
33 result = qdict_get(response, "return");
34 g_assert(result);
35 qobject_ref(result);
36 qobject_unref(response);
38 return result;
41 static void qmp_query_netdev_no_error(QTestState *qts, size_t netdevs_count)
43 QObject *resp;
44 QList *netdevs;
46 resp = wait_command(qts, "{'execute': 'query-netdev'}");
48 netdevs = qobject_to(QList, resp);
49 g_assert(netdevs);
50 g_assert(qlist_size(netdevs) == netdevs_count);
52 qobject_unref(resp);
55 static void test_query_netdev(void)
57 const char *arch = qtest_get_arch();
58 QObject *resp;
59 QTestState *state;
61 /* Choosing machine for platforms without default one */
62 if (g_str_equal(arch, "arm") ||
63 g_str_equal(arch, "aarch64")) {
64 state = qtest_init(
65 "-nodefaults "
66 "-M virt "
67 "-netdev user,id=slirp0");
68 } else if (g_str_equal(arch, "tricore")) {
69 state = qtest_init(
70 "-nodefaults "
71 "-M tricore_testboard "
72 "-netdev user,id=slirp0");
73 } else if (g_str_equal(arch, "avr")) {
74 state = qtest_init(
75 "-nodefaults "
76 "-M mega2560 "
77 "-netdev user,id=slirp0");
78 } else if (g_str_equal(arch, "rx")) {
79 state = qtest_init(
80 "-nodefaults "
81 "-M gdbsim-r5f562n8 "
82 "-netdev user,id=slirp0");
83 } else {
84 state = qtest_init(
85 "-nodefaults "
86 "-netdev user,id=slirp0");
88 g_assert(state);
90 qmp_query_netdev_no_error(state, 1);
92 resp = wait_command(state,
93 "{'execute': 'netdev_add', 'arguments': {"
94 " 'id': 'slirp1',"
95 " 'type': 'user'}}");
96 qobject_unref(resp);
98 qmp_query_netdev_no_error(state, 2);
100 resp = wait_command(state,
101 "{'execute': 'netdev_del', 'arguments': {"
102 " 'id': 'slirp1'}}");
103 qobject_unref(resp);
105 qmp_query_netdev_no_error(state, 1);
107 qtest_quit(state);
110 int main(int argc, char **argv)
112 int ret = 0;
113 g_test_init(&argc, &argv, NULL);
115 qtest_add_func("/net/qapi/query_netdev", test_query_netdev);
117 ret = g_test_run();
119 return ret;