selftests/bpf: test_progs: convert test_sockopt
authorStanislav Fomichev <sdf@google.com>
Wed, 4 Sep 2019 16:25:05 +0000 (09:25 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 6 Sep 2019 16:59:05 +0000 (09:59 -0700)
Move the files, adjust includes, remove entry from Makefile & .gitignore

Signed-off-by: Stanislav Fomichev <sdf@google.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/sockopt.c [moved from tools/testing/selftests/bpf/test_sockopt.c with 96% similarity]

index 60c9338..0315120 100644 (file)
@@ -39,7 +39,6 @@ libbpf.so.*
 test_hashmap
 test_btf_dump
 xdping
-test_sockopt
 test_sockopt_sk
 test_sockopt_multi
 test_sockopt_inherit
index ce9650b..7151cbc 100644 (file)
@@ -28,7 +28,7 @@ TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test
        test_sock test_btf test_sockmap 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_hashmap \
-       test_btf_dump test_cgroup_attach xdping test_sockopt test_sockopt_sk \
+       test_btf_dump test_cgroup_attach xdping test_sockopt_sk \
        test_sockopt_multi test_sockopt_inherit test_tcp_rtt
 
 BPF_OBJ_FILES = $(patsubst %.c,%.o, $(notdir $(wildcard progs/*.c)))
@@ -113,7 +113,6 @@ $(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
-$(OUTPUT)/test_sockopt: cgroup_helpers.c
 $(OUTPUT)/test_sockopt_sk: cgroup_helpers.c
 $(OUTPUT)/test_sockopt_multi: cgroup_helpers.c
 $(OUTPUT)/test_sockopt_inherit: cgroup_helpers.c
@@ -1,22 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
-
-#include <errno.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-
-#include <linux/filter.h>
-#include <bpf/bpf.h>
-#include <bpf/libbpf.h>
-
-#include "bpf_rlimit.h"
-#include "bpf_util.h"
+#include <test_progs.h>
 #include "cgroup_helpers.h"
 
-#define CG_PATH                                "/sockopt"
-
 static char bpf_log_buf[4096];
 static bool verbose;
 
@@ -983,39 +968,18 @@ close_prog_fd:
        return ret;
 }
 
-int main(int args, char **argv)
+void test_sockopt(void)
 {
-       int err = EXIT_FAILURE, error_cnt = 0;
        int cgroup_fd, i;
 
-       if (setup_cgroup_environment())
-               goto cleanup_obj;
-
-       cgroup_fd = create_and_get_cgroup(CG_PATH);
-       if (cgroup_fd < 0)
-               goto cleanup_cgroup_env;
-
-       if (join_cgroup(CG_PATH))
-               goto cleanup_cgroup;
+       cgroup_fd = test__join_cgroup("/sockopt");
+       if (CHECK_FAIL(cgroup_fd < 0))
+               return;
 
        for (i = 0; i < ARRAY_SIZE(tests); i++) {
-               int err = run_test(cgroup_fd, &tests[i]);
-
-               if (err)
-                       error_cnt++;
-
-               printf("#%d %s: %s\n", i, err ? "FAIL" : "PASS",
-                      tests[i].descr);
+               test__start_subtest(tests[i].descr);
+               CHECK_FAIL(run_test(cgroup_fd, &tests[i]));
        }
 
-       printf("Summary: %ld PASSED, %d FAILED\n",
-              ARRAY_SIZE(tests) - error_cnt, error_cnt);
-       err = error_cnt ? EXIT_FAILURE : EXIT_SUCCESS;
-
-cleanup_cgroup:
        close(cgroup_fd);
-cleanup_cgroup_env:
-       cleanup_cgroup_environment();
-cleanup_obj:
-       return err;
 }