hw/i2c/omap_i2c.c: Don't use old_mmio
[qemu/ar7.git] / tests / test-filter-mirror.c
blobd569d27657f78a09fa7ea2076f8daa14ee400ea4
1 /*
2 * QTest testcase for filter-mirror
4 * Copyright (c) 2016 FUJITSU LIMITED
5 * Author: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
7 * This work is licensed under the terms of the GNU GPL, version 2 or
8 * later. See the COPYING file in the top-level directory.
9 */
11 #include "qemu/osdep.h"
12 #include "libqtest.h"
13 #include "qemu/iov.h"
14 #include "qemu/sockets.h"
15 #include "qemu/error-report.h"
16 #include "qemu/main-loop.h"
18 static void test_mirror(void)
20 int send_sock[2], recv_sock;
21 char *cmdline;
22 uint32_t ret = 0, len = 0;
23 char send_buf[] = "Hello! filter-mirror~";
24 char sock_path[] = "filter-mirror.XXXXXX";
25 char *recv_buf;
26 uint32_t size = sizeof(send_buf);
27 size = htonl(size);
28 const char *devstr = "e1000";
30 if (g_str_equal(qtest_get_arch(), "s390x")) {
31 devstr = "virtio-net-ccw";
34 ret = socketpair(PF_UNIX, SOCK_STREAM, 0, send_sock);
35 g_assert_cmpint(ret, !=, -1);
37 ret = mkstemp(sock_path);
38 g_assert_cmpint(ret, !=, -1);
40 cmdline = g_strdup_printf("-netdev socket,id=qtest-bn0,fd=%d "
41 "-device %s,netdev=qtest-bn0,id=qtest-e0 "
42 "-chardev socket,id=mirror0,path=%s,server,nowait "
43 "-object filter-mirror,id=qtest-f0,netdev=qtest-bn0,queue=tx,outdev=mirror0 "
44 , send_sock[1], devstr, sock_path);
45 qtest_start(cmdline);
46 g_free(cmdline);
48 recv_sock = unix_connect(sock_path, NULL);
49 g_assert_cmpint(recv_sock, !=, -1);
51 struct iovec iov[] = {
53 .iov_base = &size,
54 .iov_len = sizeof(size),
55 }, {
56 .iov_base = send_buf,
57 .iov_len = sizeof(send_buf),
61 /* send a qmp command to guarantee that 'connected' is setting to true. */
62 qmp_discard_response("{ 'execute' : 'query-status'}");
63 ret = iov_send(send_sock[0], iov, 2, 0, sizeof(size) + sizeof(send_buf));
64 g_assert_cmpint(ret, ==, sizeof(send_buf) + sizeof(size));
65 close(send_sock[0]);
67 ret = qemu_recv(recv_sock, &len, sizeof(len), 0);
68 g_assert_cmpint(ret, ==, sizeof(len));
69 len = ntohl(len);
71 g_assert_cmpint(len, ==, sizeof(send_buf));
72 recv_buf = g_malloc(len);
73 ret = qemu_recv(recv_sock, recv_buf, len, 0);
74 g_assert_cmpstr(recv_buf, ==, send_buf);
76 g_free(recv_buf);
77 close(recv_sock);
78 unlink(sock_path);
81 int main(int argc, char **argv)
83 int ret;
85 g_test_init(&argc, &argv, NULL);
87 qtest_add_func("/netfilter/mirror", test_mirror);
88 ret = g_test_run();
89 qtest_end();
91 return ret;