hw/arm/armsse: Make number of SRAM banks parameterised
[qemu/ar7.git] / tests / test-filter-mirror.c
blob7ab2aed8a0d706962c18dec322c06ce3c77a5d02
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 "qapi/qmp/qdict.h"
14 #include "qemu/iov.h"
15 #include "qemu/sockets.h"
16 #include "qemu/error-report.h"
17 #include "qemu/main-loop.h"
19 /* TODO actually test the results and get rid of this */
20 #define qmp_discard_response(qs, ...) qobject_unref(qtest_qmp(qs, __VA_ARGS__))
22 static void test_mirror(void)
24 int send_sock[2], recv_sock;
25 uint32_t ret = 0, len = 0;
26 char send_buf[] = "Hello! filter-mirror~";
27 char sock_path[] = "filter-mirror.XXXXXX";
28 char *recv_buf;
29 uint32_t size = sizeof(send_buf);
30 size = htonl(size);
31 const char *devstr = "e1000";
32 QTestState *qts;
34 if (g_str_equal(qtest_get_arch(), "s390x")) {
35 devstr = "virtio-net-ccw";
38 ret = socketpair(PF_UNIX, SOCK_STREAM, 0, send_sock);
39 g_assert_cmpint(ret, !=, -1);
41 ret = mkstemp(sock_path);
42 g_assert_cmpint(ret, !=, -1);
44 qts = qtest_initf(
45 "-netdev socket,id=qtest-bn0,fd=%d "
46 "-device %s,netdev=qtest-bn0,id=qtest-e0 "
47 "-chardev socket,id=mirror0,path=%s,server,nowait "
48 "-object filter-mirror,id=qtest-f0,netdev=qtest-bn0,queue=tx,outdev=mirror0 "
49 , send_sock[1], devstr, sock_path);
51 recv_sock = unix_connect(sock_path, NULL);
52 g_assert_cmpint(recv_sock, !=, -1);
54 struct iovec iov[] = {
56 .iov_base = &size,
57 .iov_len = sizeof(size),
58 }, {
59 .iov_base = send_buf,
60 .iov_len = sizeof(send_buf),
64 /* send a qmp command to guarantee that 'connected' is setting to true. */
65 qmp_discard_response(qts, "{ 'execute' : 'query-status'}");
66 ret = iov_send(send_sock[0], iov, 2, 0, sizeof(size) + sizeof(send_buf));
67 g_assert_cmpint(ret, ==, sizeof(send_buf) + sizeof(size));
68 close(send_sock[0]);
70 ret = qemu_recv(recv_sock, &len, sizeof(len), 0);
71 g_assert_cmpint(ret, ==, sizeof(len));
72 len = ntohl(len);
74 g_assert_cmpint(len, ==, sizeof(send_buf));
75 recv_buf = g_malloc(len);
76 ret = qemu_recv(recv_sock, recv_buf, len, 0);
77 g_assert_cmpstr(recv_buf, ==, send_buf);
79 g_free(recv_buf);
80 close(recv_sock);
81 unlink(sock_path);
82 qtest_quit(qts);
85 int main(int argc, char **argv)
87 int ret;
89 g_test_init(&argc, &argv, NULL);
91 qtest_add_func("/netfilter/mirror", test_mirror);
92 ret = g_test_run();
94 return ret;