]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/bpf: Convert test_sysctl to prog_tests
authorJerome Marchand <jmarchan@redhat.com>
Thu, 19 Jun 2025 14:06:03 +0000 (16:06 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 24 Jun 2025 04:50:44 +0000 (21:50 -0700)
Convert test_sysctl test to prog_tests with minimal change to the
tests themselves.

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20250619140603.148942-3-jmarchan@redhat.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/.gitignore
tools/testing/selftests/bpf/Makefile
tools/testing/selftests/bpf/prog_tests/test_sysctl.c [moved from tools/testing/selftests/bpf/test_sysctl.c with 98% similarity]

index e2a2c46c008b12a680593a1d65e416d67777c9a0..3d8378972d26cccc15746f0974e69727e26e1048 100644 (file)
@@ -21,7 +21,6 @@ test_lirc_mode2_user
 flow_dissector_load
 test_tcpnotify_user
 test_libbpf
-test_sysctl
 xdping
 test_cpp
 *.d
index cf5ed3bee573e45bc3fe6d32d074fd6a25fed008..910d8d6402ef1910b2b5b10391f9badd5a2b7977 100644 (file)
@@ -73,7 +73,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
 
@@ -220,7 +220,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.
@@ -329,7 +329,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)
similarity index 98%
rename from tools/testing/selftests/bpf/test_sysctl.c
rename to tools/testing/selftests/bpf/prog_tests/test_sysctl.c
index bcdbd27f22f08cba4cc2785a01e00ba59e893d4c..273dd41ca09e4b11853fd4c260c024588fa3cd09 100644 (file)
@@ -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,19 @@ static int run_tests(int cgfd)
        return fails ? -1 : 0;
 }
 
-int main(int argc, char **argv)
+void test_sysctl(void)
 {
-       int cgfd = -1;
-       int err = 0;
+       int cgfd;
 
        cgfd = cgroup_setup_and_join(CG_PATH);
-       if (cgfd < 0)
-               goto err;
+       if (!ASSERT_OK_FD(cgfd < 0, "create_cgroup"))
+               goto out;
 
-       /* Use libbpf 1.0 API mode */
-       libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
+       if (!ASSERT_OK(run_tests(cgfd), "run_tests"))
+               goto out;
 
-       if (run_tests(cgfd))
-               goto err;
-
-       goto out;
-err:
-       err = -1;
 out:
        close(cgfd);
        cleanup_cgroup_environment();
-       return err;
+       return;
 }