From: Yonghong Song <yonghong.song@linux.dev>
To: Jerome Marchand <jmarchan@redhat.com>, bpf@vger.kernel.org
Cc: Martin KaFai Lau <martin.lau@linux.dev>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
linux-kernel@vger.kernel.org,
Eduard Zingerman <eddyz87@gmail.com>
Subject: Re: [PATCH v2 2/2] selftests/bpf: Convert test_sysctl to prog_tests
Date: Tue, 10 Jun 2025 10:16:55 -0700 [thread overview]
Message-ID: <32cb1c74-4a15-491b-90b0-6c2fdf07dbb9@linux.dev> (raw)
In-Reply-To: <20250610091933.717824-3-jmarchan@redhat.com>
On 6/10/25 2:19 AM, Jerome Marchand wrote:
> Convert test_sysctl test to prog_tests with minimal change to the
> tests themselves.
>
> Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
> ---
> tools/testing/selftests/bpf/.gitignore | 1 -
> tools/testing/selftests/bpf/Makefile | 5 ++-
> .../bpf/{ => prog_tests}/test_sysctl.c | 32 ++++---------------
> 3 files changed, 9 insertions(+), 29 deletions(-)
> rename tools/testing/selftests/bpf/{ => prog_tests}/test_sysctl.c (98%)
>
> diff --git a/tools/testing/selftests/bpf/.gitignore b/tools/testing/selftests/bpf/.gitignore
> index e2a2c46c008b1..3d8378972d26c 100644
> --- a/tools/testing/selftests/bpf/.gitignore
> +++ b/tools/testing/selftests/bpf/.gitignore
> @@ -21,7 +21,6 @@ test_lirc_mode2_user
> flow_dissector_load
> test_tcpnotify_user
> test_libbpf
> -test_sysctl
> xdping
> test_cpp
> *.d
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index 66bb50356be08..53dc08d905bd1 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -70,7 +70,7 @@ endif
> # Order correspond to 'make run_tests' order
> TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_progs \
> test_sockmap \
> - test_tcpnotify_user test_sysctl \
> + test_tcpnotify_user \
> test_progs-no_alu32
> TEST_INST_SUBDIRS := no_alu32
>
> @@ -215,7 +215,7 @@ ifeq ($(VMLINUX_BTF),)
> $(error Cannot find a vmlinux for VMLINUX_BTF at any of "$(VMLINUX_BTF_PATHS)")
> endif
>
> -# Define simple and short `make test_progs`, `make test_sysctl`, etc targets
> +# Define simple and short `make test_progs`, `make test_maps`, etc targets
> # to build individual tests.
> # NOTE: Semicolon at the end is critical to override lib.mk's default static
> # rule for binaries.
> @@ -324,7 +324,6 @@ NETWORK_HELPERS := $(OUTPUT)/network_helpers.o
> $(OUTPUT)/test_sockmap: $(CGROUP_HELPERS) $(TESTING_HELPERS)
> $(OUTPUT)/test_tcpnotify_user: $(CGROUP_HELPERS) $(TESTING_HELPERS) $(TRACE_HELPERS)
> $(OUTPUT)/test_sock_fields: $(CGROUP_HELPERS) $(TESTING_HELPERS)
> -$(OUTPUT)/test_sysctl: $(CGROUP_HELPERS) $(TESTING_HELPERS)
> $(OUTPUT)/test_tag: $(TESTING_HELPERS)
> $(OUTPUT)/test_lirc_mode2_user: $(TESTING_HELPERS)
> $(OUTPUT)/xdping: $(TESTING_HELPERS)
> diff --git a/tools/testing/selftests/bpf/test_sysctl.c b/tools/testing/selftests/bpf/prog_tests/test_sysctl.c
> similarity index 98%
> rename from tools/testing/selftests/bpf/test_sysctl.c
> rename to tools/testing/selftests/bpf/prog_tests/test_sysctl.c
> index bcdbd27f22f08..049671361f8fa 100644
> --- a/tools/testing/selftests/bpf/test_sysctl.c
> +++ b/tools/testing/selftests/bpf/prog_tests/test_sysctl.c
> @@ -1,22 +1,8 @@
> // SPDX-License-Identifier: GPL-2.0
> // Copyright (c) 2019 Facebook
>
> -#include <fcntl.h>
> -#include <stdint.h>
> -#include <stdio.h>
> -#include <stdlib.h>
> -#include <string.h>
> -#include <unistd.h>
> -
> -#include <linux/filter.h>
> -
> -#include <bpf/bpf.h>
> -#include <bpf/libbpf.h>
> -
> -#include <bpf/bpf_endian.h>
> -#include "bpf_util.h"
> +#include "test_progs.h"
> #include "cgroup_helpers.h"
> -#include "testing_helpers.h"
>
> #define CG_PATH "/foo"
> #define MAX_INSNS 512
> @@ -1608,26 +1594,22 @@ static int run_tests(int cgfd)
> return fails ? -1 : 0;
> }
>
> -int main(int argc, char **argv)
> +void test_sysctl(void)
> {
> int cgfd = -1;
-1 is not needed.
> - int err = 0;
>
> cgfd = cgroup_setup_and_join(CG_PATH);
> - if (cgfd < 0)
> - goto err;
> + if (CHECK_FAIL(cgfd < 0))
Use ASSERT* macros. For example, if (!ASSERT_OK_FD(cgfd, "create cgroup"))
> + goto out;
>
> /* Use libbpf 1.0 API mode */
> libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
This is not needed.
>
> - if (run_tests(cgfd))
> - goto err;
> + if (CHECK_FAIL(run_tests(cgfd)))
if (!ASSERT_OK(run_tests(cgfd), "run_tests"))
> + goto out;
>
> - goto out;
> -err:
> - err = -1;
> out:
> close(cgfd);
> cleanup_cgroup_environment();
> - return err;
> + return;
> }
prev parent reply other threads:[~2025-06-10 17:17 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-27 16:54 [PATCH] bpf: Specify access type of bpf_sysctl_get_name args Jerome Marchand
2025-05-27 19:56 ` Yonghong Song
2025-05-28 9:09 ` Jerome Marchand
2025-05-28 17:41 ` Yonghong Song
2025-05-27 21:39 ` Eduard Zingerman
2025-05-28 12:47 ` Jerome Marchand
2025-05-28 16:41 ` Eduard Zingerman
2025-05-29 11:35 ` Jerome Marchand
2025-06-10 9:19 ` [PATCH v2 0/2] " Jerome Marchand
2025-06-10 9:19 ` [PATCH v2 1/2] " Jerome Marchand
2025-06-10 16:41 ` Yonghong Song
2025-06-10 9:19 ` [PATCH v2 2/2] selftests/bpf: Convert test_sysctl to prog_tests Jerome Marchand
2025-06-10 17:16 ` Yonghong Song [this message]
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=32cb1c74-4a15-491b-90b0-6c2fdf07dbb9@linux.dev \
--to=yonghong.song@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=jmarchan@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®