summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPeter Maydell2021-03-16 11:53:47 +0100
committerPeter Maydell2021-03-16 11:53:47 +0100
commit6e31b3a5c34c6e5be7ef60773e607f189eaa15f3 (patch)
treed12963d6df1819264b349159e6ed49b41f9e3eb0 /tests
parentMerge remote-tracking branch 'remotes/stefanha-gitlab/tags/block-pull-request... (diff)
parentnet: Do not fill legacy info_str for backends (diff)
downloadqemu-6e31b3a5c34c6e5be7ef60773e607f189eaa15f3.tar.gz
qemu-6e31b3a5c34c6e5be7ef60773e607f189eaa15f3.tar.xz
qemu-6e31b3a5c34c6e5be7ef60773e607f189eaa15f3.zip
Merge remote-tracking branch 'remotes/jasowang/tags/net-pull-request' into staging
# gpg: Signature made Mon 15 Mar 2021 08:42:25 GMT # gpg: using RSA key EF04965B398D6211 # gpg: Good signature from "Jason Wang (Jason Wang on RedHat) <jasowang@redhat.com>" [marginal] # gpg: WARNING: This key is not certified with sufficiently trusted signatures! # gpg: It is not certain that the signature belongs to the owner. # Primary key fingerprint: 215D 46F4 8246 689E C77F 3562 EF04 965B 398D 6211 * remotes/jasowang/tags/net-pull-request: net: Do not fill legacy info_str for backends hmp: Use QAPI NetdevInfo in hmp_info_network net: Move NetClientState.info_str to dynamic allocations tests: Add tests for query-netdev command qapi: net: Add query-netdev command pvrdma: wean code off pvrdma_ring.h kernel header lan9118: switch to use qemu_receive_packet() for loopback cadence_gem: switch to use qemu_receive_packet() for loopback pcnet: switch to use qemu_receive_packet() for loopback rtl8139: switch to use qemu_receive_packet() for loopback tx_pkt: switch to use qemu_receive_packet_iov() for loopback sungem: switch to use qemu_receive_packet() for loopback msf2-mac: switch to use qemu_receive_packet() for loopback dp8393x: switch to use qemu_receive_packet() for loopback packet e1000: switch to use qemu_receive_packet() for loopback net: introduce qemu_receive_packet() e1000: fail early for evil descriptor net: validate that ids are well formed net: Fix build error when DEBUG_NET is on virtio-net: calculating proper msix vectors on init Signed-off-by: Peter Maydell <peter.maydell@linaro.org> # Conflicts: # hw/core/machine.c
Diffstat (limited to 'tests')
-rw-r--r--tests/qtest/meson.build3
-rw-r--r--tests/qtest/test-query-netdev.c120
2 files changed, 123 insertions, 0 deletions
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index 2688e1bfad..66ee9fbf45 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -30,6 +30,9 @@ qtests_generic = [
if config_host.has_key('CONFIG_MODULES')
qtests_generic += [ 'modules-test' ]
endif
+if slirp.found()
+ qtests_generic += [ 'test-query-netdev' ]
+endif
qtests_pci = \
(config_all_devices.has_key('CONFIG_VGA') ? ['display-vga-test'] : []) + \
diff --git a/tests/qtest/test-query-netdev.c b/tests/qtest/test-query-netdev.c
new file mode 100644
index 0000000000..1118537a9f
--- /dev/null
+++ b/tests/qtest/test-query-netdev.c
@@ -0,0 +1,120 @@
+/*
+ * QTest testcase for the query-netdev
+ *
+ * Copyright Yandex N.V., 2019
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+
+#include "libqos/libqtest.h"
+#include "qapi/qmp/qdict.h"
+#include "qapi/qmp/qlist.h"
+
+/*
+ * Events can get in the way of responses we are actually waiting for.
+ */
+GCC_FMT_ATTR(2, 3)
+static QObject *wait_command(QTestState *who, const char *command, ...)
+{
+ va_list ap;
+ QDict *response;
+ QObject *result;
+
+ va_start(ap, command);
+ qtest_qmp_vsend(who, command, ap);
+ va_end(ap);
+
+ response = qtest_qmp_receive(who);
+
+ result = qdict_get(response, "return");
+ g_assert(result);
+ qobject_ref(result);
+ qobject_unref(response);
+
+ return result;
+}
+
+static void qmp_query_netdev_no_error(QTestState *qts, size_t netdevs_count)
+{
+ QObject *resp;
+ QList *netdevs;
+
+ resp = wait_command(qts, "{'execute': 'query-netdev'}");
+
+ netdevs = qobject_to(QList, resp);
+ g_assert(netdevs);
+ g_assert(qlist_size(netdevs) == netdevs_count);
+
+ qobject_unref(resp);
+}
+
+static void test_query_netdev(void)
+{
+ const char *arch = qtest_get_arch();
+ QObject *resp;
+ QTestState *state;
+
+ /* Choosing machine for platforms without default one */
+ if (g_str_equal(arch, "arm") ||
+ g_str_equal(arch, "aarch64")) {
+ state = qtest_init(
+ "-nodefaults "
+ "-M virt "
+ "-netdev user,id=slirp0");
+ } else if (g_str_equal(arch, "tricore")) {
+ state = qtest_init(
+ "-nodefaults "
+ "-M tricore_testboard "
+ "-netdev user,id=slirp0");
+ } else if (g_str_equal(arch, "avr")) {
+ state = qtest_init(
+ "-nodefaults "
+ "-M mega2560 "
+ "-netdev user,id=slirp0");
+ } else if (g_str_equal(arch, "rx")) {
+ state = qtest_init(
+ "-nodefaults "
+ "-M gdbsim-r5f562n8 "
+ "-netdev user,id=slirp0");
+ } else {
+ state = qtest_init(
+ "-nodefaults "
+ "-netdev user,id=slirp0");
+ }
+ g_assert(state);
+
+ qmp_query_netdev_no_error(state, 1);
+
+ resp = wait_command(state,
+ "{'execute': 'netdev_add', 'arguments': {"
+ " 'id': 'slirp1',"
+ " 'type': 'user'}}");
+ qobject_unref(resp);
+
+ qmp_query_netdev_no_error(state, 2);
+
+ resp = wait_command(state,
+ "{'execute': 'netdev_del', 'arguments': {"
+ " 'id': 'slirp1'}}");
+ qobject_unref(resp);
+
+ qmp_query_netdev_no_error(state, 1);
+
+ qtest_quit(state);
+}
+
+int main(int argc, char **argv)
+{
+ int ret = 0;
+ g_test_init(&argc, &argv, NULL);
+
+ qtest_add_func("/net/qapi/query_netdev", test_query_netdev);
+
+ ret = g_test_run();
+
+ return ret;
+}