All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wen Congyang <wency@cn.fujitsu.com>
To: Yang Hongyang <yanghy@cn.fujitsu.com>, qemu-devel@nongnu.org
Cc: thuth@redhat.com, zhang.zhanghailiang@huawei.com,
	lizhijian@cn.fujitsu.com, jasowang@redhat.com,
	mrhines@linux.vnet.ibm.com, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH v6 10/10] tests: add test cases for netfilter object
Date: Tue, 11 Aug 2015 15:12:29 +0800	[thread overview]
Message-ID: <55C9A05D.3010509@cn.fujitsu.com> (raw)
In-Reply-To: <1438915585-30367-11-git-send-email-yanghy@cn.fujitsu.com>

On 08/07/2015 10:46 AM, Yang Hongyang wrote:
> Using qtest qmp interface to implement following cases:
> 1) add/remove netfilter
> 2) add a netfilter then delete the netdev
> 3) add/remove more than one netfilters
> 4) add more than one netfilters and then delete the netdev
> 
> Signed-off-by: Yang Hongyang <yanghy@cn.fujitsu.com>
> ---
>  tests/.gitignore       |   1 +
>  tests/Makefile         |   2 +
>  tests/test-netfilter.c | 194 +++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 197 insertions(+)
>  create mode 100644 tests/test-netfilter.c
> 
> diff --git a/tests/.gitignore b/tests/.gitignore
> index ccc92e4..395962b 100644
> --- a/tests/.gitignore
> +++ b/tests/.gitignore
> @@ -41,5 +41,6 @@ test-vmstate
>  test-write-threshold
>  test-x86-cpuid
>  test-xbzrle
> +test-netfilter
>  *-test
>  qapi-schema/*.test.*
> diff --git a/tests/Makefile b/tests/Makefile
> index 7494582..e39c7e6 100644
> --- a/tests/Makefile
> +++ b/tests/Makefile
> @@ -185,6 +185,7 @@ check-qtest-i386-y += tests/pc-cpu-test$(EXESUF)
>  check-qtest-i386-y += tests/q35-test$(EXESUF)
>  gcov-files-i386-y += hw/pci-host/q35.c
>  check-qtest-i386-$(CONFIG_LINUX) += tests/vhost-user-test$(EXESUF)
> +check-qtest-i386-y += tests/test-netfilter$(EXESUF)
>  check-qtest-x86_64-y = $(check-qtest-i386-y)
>  gcov-files-i386-y += i386-softmmu/hw/timer/mc146818rtc.c
>  gcov-files-x86_64-y = $(subst i386-softmmu/,x86_64-softmmu/,$(gcov-files-i386-y))
> @@ -409,6 +410,7 @@ tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-char.o qemu-timer.o
>  tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o
>  tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o libqemuutil.a libqemustub.a
>  tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(block-obj-y) libqemuutil.a libqemustub.a
> +tests/test-netfilter$(EXESUF): tests/test-netfilter.o $(qtest-obj-y)
>  
>  ifeq ($(CONFIG_POSIX),y)
>  LIBS += -lutil
> diff --git a/tests/test-netfilter.c b/tests/test-netfilter.c
> new file mode 100644
> index 0000000..acbea4c
> --- /dev/null
> +++ b/tests/test-netfilter.c
> @@ -0,0 +1,194 @@
> +/*
> + * QTest testcase for netfilter
> + *
> + * Copyright (c) 2015 FUJITSU LIMITED
> + * Author: Yang Hongyang <yanghy@cn.fujitsu.com>
> + *
> + * 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 <glib.h>
> +#include "libqtest.h"
> +
> +/* add a netfilter to a netdev and then remove it */
> +static void add_one_netfilter(void)
> +{
> +    QDict *response;
> +
> +    response = qmp("{\"execute\": \"netfilter_add\","
> +                   " \"arguments\": {"
> +                   "   \"type\": \"buffer\","
> +                   "   \"id\": \"qtest-f0\","
> +                   "   \"netdev\": \"qtest-bn0\","
> +                   "   \"chain\": \"in\","
> +                   "   \"interval\": \"1000\""
> +                   "}}");

You can use ' to instead of " in the qmp command:
"{'execute': 'netfilter_add', ...}"

Thanks
Wen Congyang

> +
> +    g_assert(response);
> +    g_assert(!qdict_haskey(response, "error"));
> +    QDECREF(response);
> +
> +    response = qmp("{\"execute\": \"netfilter_del\","
> +                   " \"arguments\": {"
> +                   "   \"id\": \"qtest-f0\""
> +                   "}}");
> +    g_assert(response);
> +    g_assert(!qdict_haskey(response, "error"));
> +    QDECREF(response);
> +}
> +
> +/* add a netfilter to a netdev and then remove the netdev */
> +static void remove_netdev_with_one_netfilter(void)
> +{
> +    QDict *response;
> +
> +    response = qmp("{\"execute\": \"netfilter_add\","
> +                   " \"arguments\": {"
> +                   "   \"type\": \"buffer\","
> +                   "   \"id\": \"qtest-f0\","
> +                   "   \"netdev\": \"qtest-bn0\","
> +                   "   \"chain\": \"in\","
> +                   "   \"interval\": \"1000\""
> +                   "}}");
> +
> +    g_assert(response);
> +    g_assert(!qdict_haskey(response, "error"));
> +    QDECREF(response);
> +
> +    response = qmp("{\"execute\": \"netdev_del\","
> +                   " \"arguments\": {"
> +                   "   \"id\": \"qtest-bn0\""
> +                   "}}");
> +    g_assert(response);
> +    g_assert(!qdict_haskey(response, "error"));
> +    QDECREF(response);
> +
> +    /* add back the netdev */
> +    response = qmp("{\"execute\": \"netdev_add\","
> +                   " \"arguments\": {"
> +                   "   \"type\": \"user\","
> +                   "   \"id\": \"qtest-bn0\""
> +                   "}}");
> +    g_assert(response);
> +    g_assert(!qdict_haskey(response, "error"));
> +    QDECREF(response);
> +}
> +
> +/* add multi(2) netfilters to a netdev and then remove them */
> +static void add_multi_netfilter(void)
> +{
> +    QDict *response;
> +
> +    response = qmp("{\"execute\": \"netfilter_add\","
> +                   " \"arguments\": {"
> +                   "   \"type\": \"buffer\","
> +                   "   \"id\": \"qtest-f0\","
> +                   "   \"netdev\": \"qtest-bn0\","
> +                   "   \"chain\": \"in\","
> +                   "   \"interval\": \"1000\""
> +                   "}}");
> +
> +    g_assert(response);
> +    g_assert(!qdict_haskey(response, "error"));
> +    QDECREF(response);
> +
> +    response = qmp("{\"execute\": \"netfilter_add\","
> +                   " \"arguments\": {"
> +                   "   \"type\": \"buffer\","
> +                   "   \"id\": \"qtest-f1\","
> +                   "   \"netdev\": \"qtest-bn0\","
> +                   "   \"chain\": \"in\","
> +                   "   \"interval\": \"1000\""
> +                   "}}");
> +
> +    g_assert(response);
> +    g_assert(!qdict_haskey(response, "error"));
> +    QDECREF(response);
> +
> +    response = qmp("{\"execute\": \"netfilter_del\","
> +                   " \"arguments\": {"
> +                   "   \"id\": \"qtest-f0\""
> +                   "}}");
> +    g_assert(response);
> +    g_assert(!qdict_haskey(response, "error"));
> +    QDECREF(response);
> +
> +    response = qmp("{\"execute\": \"netfilter_del\","
> +                   " \"arguments\": {"
> +                   "   \"id\": \"qtest-f1\""
> +                   "}}");
> +    g_assert(response);
> +    g_assert(!qdict_haskey(response, "error"));
> +    QDECREF(response);
> +}
> +
> +/* add multi(2) netfilters to a netdev and then remove the netdev */
> +static void remove_netdev_with_multi_netfilter(void)
> +{
> +    QDict *response;
> +
> +    response = qmp("{\"execute\": \"netfilter_add\","
> +                   " \"arguments\": {"
> +                   "   \"type\": \"buffer\","
> +                   "   \"id\": \"qtest-f0\","
> +                   "   \"netdev\": \"qtest-bn0\","
> +                   "   \"chain\": \"in\","
> +                   "   \"interval\": \"1000\""
> +                   "}}");
> +
> +    g_assert(response);
> +    g_assert(!qdict_haskey(response, "error"));
> +    QDECREF(response);
> +
> +    response = qmp("{\"execute\": \"netfilter_add\","
> +                   " \"arguments\": {"
> +                   "   \"type\": \"buffer\","
> +                   "   \"id\": \"qtest-f1\","
> +                   "   \"netdev\": \"qtest-bn0\","
> +                   "   \"chain\": \"in\","
> +                   "   \"interval\": \"1000\""
> +                   "}}");
> +
> +    g_assert(response);
> +    g_assert(!qdict_haskey(response, "error"));
> +    QDECREF(response);
> +
> +    response = qmp("{\"execute\": \"netdev_del\","
> +                   " \"arguments\": {"
> +                   "   \"id\": \"qtest-bn0\""
> +                   "}}");
> +    g_assert(response);
> +    g_assert(!qdict_haskey(response, "error"));
> +    QDECREF(response);
> +
> +    /* add back the netdev */
> +    response = qmp("{\"execute\": \"netdev_add\","
> +                   " \"arguments\": {"
> +                   "   \"type\": \"user\","
> +                   "   \"id\": \"qtest-bn0\""
> +                   "}}");
> +    g_assert(response);
> +    g_assert(!qdict_haskey(response, "error"));
> +    QDECREF(response);
> +}
> +
> +int main(int argc, char **argv)
> +{
> +    int ret;
> +
> +    g_test_init(&argc, &argv, NULL);
> +    qtest_add_func("/netfilter/addremove_one", add_one_netfilter);
> +    qtest_add_func("/netfilter/remove_netdev_one",
> +                   remove_netdev_with_one_netfilter);
> +    qtest_add_func("/netfilter/addremove_multi", add_multi_netfilter);
> +    qtest_add_func("/netfilter/remove_netdev_multi",
> +                   remove_netdev_with_multi_netfilter);
> +
> +    qtest_start("-netdev user,id=qtest-bn0 -device e1000,netdev=qtest-bn0");
> +    ret = g_test_run();
> +
> +    qtest_end();
> +
> +    return ret;
> +}
> 

  reply	other threads:[~2015-08-11  7:12 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-07  2:46 [Qemu-devel] [PATCH v6 00/10] For QEMU 2.5: Add a netfilter object and netbuffer filter Yang Hongyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 01/10] net: add a new object netfilter Yang Hongyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 02/10] init/cleanup of netfilter object Yang Hongyang
2015-08-10  9:18   ` Jason Wang
2015-08-20 16:41     ` Yang Hongyang
2015-08-21  1:35       ` Jason Wang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 03/10] netfilter: add netfilter_{add|del} commands Yang Hongyang
2015-08-10  9:20   ` Jason Wang
2015-08-11  7:07   ` Wen Congyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 04/10] netfilter: hook packets before net queue send Yang Hongyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 05/10] move out net queue structs define Yang Hongyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 06/10] netfilter: add an API to pass the packet to next filter Yang Hongyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 07/10] net/queue: export qemu_net_queue_append_iov Yang Hongyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 08/10] netfilter: add a netbuffer filter Yang Hongyang
2015-08-10  9:21   ` Jason Wang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 09/10] filter/buffer: update command description and help Yang Hongyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 10/10] tests: add test cases for netfilter object Yang Hongyang
2015-08-11  7:12   ` Wen Congyang [this message]
2015-08-10  9:17 ` [Qemu-devel] [PATCH v6 00/10] For QEMU 2.5: Add a netfilter object and netbuffer filter Jason Wang
2015-08-14  1:26   ` Yang Hongyang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55C9A05D.3010509@cn.fujitsu.com \
    --to=wency@cn.fujitsu.com \
    --cc=jasowang@redhat.com \
    --cc=lizhijian@cn.fujitsu.com \
    --cc=mrhines@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=thuth@redhat.com \
    --cc=yanghy@cn.fujitsu.com \
    --cc=zhang.zhanghailiang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.