]> Git Repo - qemu.git/blame - tests/test-filter-mirror.c
tests: add tests for hbitmap_next_dirty_area
[qemu.git] / tests / test-filter-mirror.c
CommitLineData
06809ecf
ZC
1/*
2 * QTest testcase for filter-mirror
3 *
4 * Copyright (c) 2016 FUJITSU LIMITED
5 * Author: Zhang Chen <[email protected]>
6 *
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 */
10
11#include "qemu/osdep.h"
06809ecf 12#include "libqtest.h"
055a1efc 13#include "qapi/qmp/qdict.h"
06809ecf
ZC
14#include "qemu/iov.h"
15#include "qemu/sockets.h"
16#include "qemu/error-report.h"
17#include "qemu/main-loop.h"
055a1efc
MA
18
19/* TODO actually test the results and get rid of this */
a2569b00 20#define qmp_discard_response(qs, ...) qobject_unref(qtest_qmp(qs, __VA_ARGS__))
06809ecf
ZC
21
22static void test_mirror(void)
23{
06809ecf 24 int send_sock[2], recv_sock;
06809ecf
ZC
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);
ea5bef49 31 const char *devstr = "e1000";
a2569b00 32 QTestState *qts;
ea5bef49
TH
33
34 if (g_str_equal(qtest_get_arch(), "s390x")) {
35 devstr = "virtio-net-ccw";
36 }
06809ecf
ZC
37
38 ret = socketpair(PF_UNIX, SOCK_STREAM, 0, send_sock);
39 g_assert_cmpint(ret, !=, -1);
40
41 ret = mkstemp(sock_path);
42 g_assert_cmpint(ret, !=, -1);
43
a2569b00 44 qts = qtest_initf(
78b27bad
EB
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);
06809ecf
ZC
50
51 recv_sock = unix_connect(sock_path, NULL);
52 g_assert_cmpint(recv_sock, !=, -1);
53
54 struct iovec iov[] = {
55 {
56 .iov_base = &size,
57 .iov_len = sizeof(size),
58 }, {
59 .iov_base = send_buf,
60 .iov_len = sizeof(send_buf),
61 },
62 };
63
64 /* send a qmp command to guarantee that 'connected' is setting to true. */
a2569b00 65 qmp_discard_response(qts, "{ 'execute' : 'query-status'}");
06809ecf
ZC
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]);
69
70 ret = qemu_recv(recv_sock, &len, sizeof(len), 0);
71 g_assert_cmpint(ret, ==, sizeof(len));
72 len = ntohl(len);
73
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);
78
79 g_free(recv_buf);
80 close(recv_sock);
81 unlink(sock_path);
a2569b00 82 qtest_quit(qts);
06809ecf
ZC
83}
84
85int main(int argc, char **argv)
86{
87 int ret;
88
89 g_test_init(&argc, &argv, NULL);
90
91 qtest_add_func("/netfilter/mirror", test_mirror);
92 ret = g_test_run();
06809ecf
ZC
93
94 return ret;
95}
This page took 0.155579 seconds and 4 git commands to generate.