LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Roman Gushchin <guro@fb.com>, Alexei Starovoitov <ast@kernel.org>,
	"bpf@vger.kernel.org" <bpf@vger.kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Tejun Heo <tj@kernel.org>, Kernel Team <Kernel-team@fb.com>,
	"cgroups@vger.kernel.org" <cgroups@vger.kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 bpf-next 2/4] selftests/bpf: convert test_cgrp2_attach2 example into kselftest
Date: Thu, 23 May 2019 05:39:13 +0000	[thread overview]
Message-ID: <f9f4843c-8f52-b373-1e85-4bccd3311a55@fb.com> (raw)
In-Reply-To: <20190522232051.2938491-3-guro@fb.com>



On 5/22/19 4:20 PM, Roman Gushchin wrote:
> Convert test_cgrp2_attach2 example into a proper test_cgroup_attach
> kselftest. It's better because we do run kselftest on a constant
> basis, so there are better chances to spot a potential regression.
> 
> Also make it slightly less verbose to conform kselftests output style.
> 
> Output example:
>    $ ./test_cgroup_attach
>    #override:PASS
>    #multi:PASS
>    test_cgroup_attach:PASS
> 
> Signed-off-by: Roman Gushchin <guro@fb.com>
Ack except the nit below.
Acked-by: Yonghong Song <yhs@fb.com>
> ---
>   samples/bpf/Makefile                          |  2 -
>   tools/testing/selftests/bpf/Makefile          |  4 +-
>   .../selftests/bpf/test_cgroup_attach.c        | 48 ++++++++++++-------
>   3 files changed, 35 insertions(+), 19 deletions(-)
>   rename samples/bpf/test_cgrp2_attach2.c => tools/testing/selftests/bpf/test_cgroup_attach.c (92%)
> 
> diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
> index 4f0a1cdbfe7c..253e5a2856be 100644
> --- a/samples/bpf/Makefile
> +++ b/samples/bpf/Makefile
> @@ -26,7 +26,6 @@ hostprogs-y += map_perf_test
>   hostprogs-y += test_overhead
>   hostprogs-y += test_cgrp2_array_pin
>   hostprogs-y += test_cgrp2_attach
> -hostprogs-y += test_cgrp2_attach2
>   hostprogs-y += test_cgrp2_sock
>   hostprogs-y += test_cgrp2_sock2
>   hostprogs-y += xdp1
> @@ -81,7 +80,6 @@ map_perf_test-objs := bpf_load.o map_perf_test_user.o
>   test_overhead-objs := bpf_load.o test_overhead_user.o
>   test_cgrp2_array_pin-objs := test_cgrp2_array_pin.o
>   test_cgrp2_attach-objs := test_cgrp2_attach.o
> -test_cgrp2_attach2-objs := test_cgrp2_attach2.o $(CGROUP_HELPERS)
>   test_cgrp2_sock-objs := test_cgrp2_sock.o
>   test_cgrp2_sock2-objs := bpf_load.o test_cgrp2_sock2.o
>   xdp1-objs := xdp1_user.o
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index 66f2dca1dee1..e09f419f4d7e 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -23,7 +23,8 @@ TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test
>   	test_align test_verifier_log test_dev_cgroup test_tcpbpf_user \
>   	test_sock test_btf test_sockmap test_lirc_mode2_user get_cgroup_id_user \
>   	test_socket_cookie test_cgroup_storage test_select_reuseport test_section_names \
> -	test_netcnt test_tcpnotify_user test_sock_fields test_sysctl
> +	test_netcnt test_tcpnotify_user test_sock_fields test_sysctl \
> +	test_cgroup_attach
>   
>   BPF_OBJ_FILES = $(patsubst %.c,%.o, $(notdir $(wildcard progs/*.c)))
>   TEST_GEN_FILES = $(BPF_OBJ_FILES)
> @@ -96,6 +97,7 @@ $(OUTPUT)/test_cgroup_storage: cgroup_helpers.c
>   $(OUTPUT)/test_netcnt: cgroup_helpers.c
>   $(OUTPUT)/test_sock_fields: cgroup_helpers.c
>   $(OUTPUT)/test_sysctl: cgroup_helpers.c
> +$(OUTPUT)/test_cgroup_attach: cgroup_helpers.c
>   
>   .PHONY: force
>   
> diff --git a/samples/bpf/test_cgrp2_attach2.c b/tools/testing/selftests/bpf/test_cgroup_attach.c
> similarity index 92%
> rename from samples/bpf/test_cgrp2_attach2.c
> rename to tools/testing/selftests/bpf/test_cgroup_attach.c
> index 0bb6507256b7..93d4fe295e7d 100644
> --- a/samples/bpf/test_cgrp2_attach2.c
> +++ b/tools/testing/selftests/bpf/test_cgroup_attach.c
> @@ -1,3 +1,5 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
>   /* eBPF example program:
>    *
>    * - Creates arraymap in kernel with 4 bytes keys and 8 byte values
> @@ -25,20 +27,27 @@
>   #include <sys/resource.h>
>   #include <sys/time.h>
>   #include <unistd.h>
> +#include <linux/filter.h>
>   
>   #include <linux/bpf.h>
>   #include <bpf/bpf.h>
>   
> -#include "bpf_insn.h"
> +#include "bpf_util.h"
>   #include "bpf_rlimit.h"
>   #include "cgroup_helpers.h"
>   
>   #define FOO		"/foo"
>   #define BAR		"/foo/bar/"
> -#define PING_CMD	"ping -c1 -w1 127.0.0.1 > /dev/null"
> +#define PING_CMD	"ping -q -c1 -w1 127.0.0.1 > /dev/null"
>   
>   char bpf_log_buf[BPF_LOG_BUF_SIZE];
>   
> +#ifdef DEBUG
> +#define debug(args...) printf(args)
> +#else
> +#define debug(args...)
> +#endif
> +
>   static int prog_load(int verdict)
>   {
>   	int ret;
> @@ -89,7 +98,7 @@ static int test_foo_bar(void)
>   		goto err;
>   	}
>   
> -	printf("Attached DROP prog. This ping in cgroup /foo should fail...\n");
> +	debug("Attached DROP prog. This ping in cgroup /foo should fail...\n");
>   	assert(system(PING_CMD) != 0);
>   
>   	/* Create cgroup /foo/bar, get fd, and join it */
> @@ -100,7 +109,7 @@ static int test_foo_bar(void)
>   	if (join_cgroup(BAR))
>   		goto err;
>   
> -	printf("Attached DROP prog. This ping in cgroup /foo/bar should fail...\n");
> +	debug("Attached DROP prog. This ping in cgroup /foo/bar should fail...\n");
>   	assert(system(PING_CMD) != 0);
>   
>   	if (bpf_prog_attach(allow_prog, bar, BPF_CGROUP_INET_EGRESS,
> @@ -109,7 +118,7 @@ static int test_foo_bar(void)
>   		goto err;
>   	}
>   
> -	printf("Attached PASS prog. This ping in cgroup /foo/bar should pass...\n");
> +	debug("Attached PASS prog. This ping in cgroup /foo/bar should pass...\n");
>   	assert(system(PING_CMD) == 0);
>   
>   	if (bpf_prog_detach(bar, BPF_CGROUP_INET_EGRESS)) {
> @@ -117,7 +126,7 @@ static int test_foo_bar(void)
>   		goto err;
>   	}
>   
> -	printf("Detached PASS from /foo/bar while DROP is attached to /foo.\n"
> +	debug("Detached PASS from /foo/bar while DROP is attached to /foo.\n"
>   	       "This ping in cgroup /foo/bar should fail...\n");
>   	assert(system(PING_CMD) != 0);
>   
> @@ -132,7 +141,7 @@ static int test_foo_bar(void)
>   		goto err;
>   	}
>   
> -	printf("Attached PASS from /foo/bar and detached DROP from /foo.\n"
> +	debug("Attached PASS from /foo/bar and detached DROP from /foo.\n"
>   	       "This ping in cgroup /foo/bar should pass...\n");
>   	assert(system(PING_CMD) == 0);
>   
> @@ -199,9 +208,9 @@ static int test_foo_bar(void)
>   	close(bar);
>   	cleanup_cgroup_environment();
>   	if (!rc)
> -		printf("### override:PASS\n");
> +		printf("#override:PASS\n");
>   	else
> -		printf("### override:FAIL\n");
> +		printf("#override:FAIL\n");
>   	return rc;
>   }
>   
> @@ -441,19 +450,26 @@ static int test_multiprog(void)
>   	close(cg5);
>   	cleanup_cgroup_environment();
>   	if (!rc)
> -		printf("### multi:PASS\n");
> +		printf("#multi:PASS\n");
>   	else
> -		printf("### multi:FAIL\n");
> +		printf("#multi:FAIL\n");
>   	return rc;
>   }
>   
>   int main(int argc, char **argv)

argc and argv are not used.

currently, the debug output is controlled by macro DEBUG.
you could enable debug output with command line option.
But I am okay with the current mechanism as well.

>   {
> -	int rc = 0;
> +	int (*tests[])(void) = {test_foo_bar, test_multiprog};
> +	int errors = 0;
> +	int i;
>   
> -	rc = test_foo_bar();
> -	if (rc)
> -		return rc;
> +	for (i = 0; i < ARRAY_SIZE(tests); i++)
> +		if (tests[i]())
> +			errors++;
> +
> +	if (errors)
> +		printf("test_cgroup_attach:FAIL\n");
> +	else
> +		printf("test_cgroup_attach:PASS\n");
>   
> -	return test_multiprog();
> +	return errors ? EXIT_FAILURE : EXIT_SUCCESS;
>   }
> 

  reply	other threads:[~2019-05-23  5:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-22 23:20 [PATCH v2 bpf-next 0/4] cgroup bpf auto-detachment Roman Gushchin
2019-05-22 23:20 ` [PATCH v2 bpf-next 1/4] bpf: decouple the lifetime of cgroup_bpf from cgroup itself Roman Gushchin
2019-05-23  5:33   ` Yonghong Song
2019-05-22 23:20 ` [PATCH v2 bpf-next 2/4] selftests/bpf: convert test_cgrp2_attach2 example into kselftest Roman Gushchin
2019-05-23  5:39   ` Yonghong Song [this message]
2019-05-22 23:20 ` [PATCH v2 bpf-next 3/4] selftests/bpf: enable all available cgroup v2 controllers Roman Gushchin
2019-05-23  5:45   ` Yonghong Song
2019-05-22 23:20 ` [PATCH v2 bpf-next 4/4] selftests/bpf: add auto-detach test Roman Gushchin
2019-05-23  5:47   ` Yonghong Song
2019-05-23 17:58     ` Roman Gushchin
2019-05-23 23:06       ` Yonghong Song
2019-05-23  5:52   ` Yonghong Song
2019-05-23  5:17 ` [PATCH v2 bpf-next 0/4] cgroup bpf auto-detachment Yonghong Song

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=f9f4843c-8f52-b373-1e85-4bccd3311a55@fb.com \
    --to=yhs@fb.com \
    --cc=Kernel-team@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=guro@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sdf@fomichev.me \
    --cc=tj@kernel.org \
    --subject='Re: [PATCH v2 bpf-next 2/4] selftests/bpf: convert test_cgrp2_attach2 example into kselftest' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).