Commit aaf376bd authored by Alexander Duyck's avatar Alexander Duyck Committed by Alexei Starovoitov

selftests/bpf: Move test_tcppbf_user into test_progs

Recently a bug was missed due to the fact that test_tcpbpf_user is not a
part of test_progs. In order to prevent similar issues in the future move
the test functionality into test_progs. By doing this we can make certain
that it is a part of standard testing and will not be overlooked.

As a part of moving the functionality into test_progs it is necessary to
integrate with the test_progs framework and to drop any redundant code.
This patch:
1. Cleans up the include headers
2. Dropped a duplicate definition of bpf_find_map
3. Switched over to using test_progs specific cgroup functions
4. Renamed main to test_tcpbpf_user
5. Dropped return value in favor of CHECK_FAIL to check for errors

The general idea is that I wanted to keep the changes as small as possible
while moving the file into the test_progs framework. The follow-on patches
are meant to clean up the remaining issues such as the use of CHECK_FAIL.
Signed-off-by: default avatarAlexander Duyck <alexanderduyck@fb.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/160443928881.1086697.17661359319919165370.stgit@localhost.localdomain
parent 8aaeed81
...@@ -8,7 +8,6 @@ FEATURE-DUMP.libbpf ...@@ -8,7 +8,6 @@ FEATURE-DUMP.libbpf
fixdep fixdep
test_dev_cgroup test_dev_cgroup
/test_progs* /test_progs*
test_tcpbpf_user
test_verifier_log test_verifier_log
feature feature
test_sock test_sock
......
...@@ -32,7 +32,7 @@ LDLIBS += -lcap -lelf -lz -lrt -lpthread ...@@ -32,7 +32,7 @@ LDLIBS += -lcap -lelf -lz -lrt -lpthread
# Order correspond to 'make run_tests' order # Order correspond to 'make run_tests' order
TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \ TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \
test_verifier_log test_dev_cgroup test_tcpbpf_user \ test_verifier_log test_dev_cgroup \
test_sock test_sockmap get_cgroup_id_user test_socket_cookie \ test_sock test_sockmap get_cgroup_id_user test_socket_cookie \
test_cgroup_storage \ test_cgroup_storage \
test_netcnt test_tcpnotify_user test_sysctl \ test_netcnt test_tcpnotify_user test_sysctl \
...@@ -163,7 +163,6 @@ $(OUTPUT)/test_sock: cgroup_helpers.c ...@@ -163,7 +163,6 @@ $(OUTPUT)/test_sock: cgroup_helpers.c
$(OUTPUT)/test_sock_addr: cgroup_helpers.c $(OUTPUT)/test_sock_addr: cgroup_helpers.c
$(OUTPUT)/test_socket_cookie: cgroup_helpers.c $(OUTPUT)/test_socket_cookie: cgroup_helpers.c
$(OUTPUT)/test_sockmap: cgroup_helpers.c $(OUTPUT)/test_sockmap: cgroup_helpers.c
$(OUTPUT)/test_tcpbpf_user: cgroup_helpers.c
$(OUTPUT)/test_tcpnotify_user: cgroup_helpers.c trace_helpers.c $(OUTPUT)/test_tcpnotify_user: cgroup_helpers.c trace_helpers.c
$(OUTPUT)/get_cgroup_id_user: cgroup_helpers.c $(OUTPUT)/get_cgroup_id_user: cgroup_helpers.c
$(OUTPUT)/test_cgroup_storage: cgroup_helpers.c $(OUTPUT)/test_cgroup_storage: cgroup_helpers.c
......
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include <inttypes.h> #include <inttypes.h>
#include <stdio.h> #include <test_progs.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <linux/bpf.h>
#include <sys/types.h>
#include <bpf/bpf.h>
#include <bpf/libbpf.h>
#include "bpf_rlimit.h"
#include "bpf_util.h"
#include "cgroup_helpers.h"
#include "test_tcpbpf.h" #include "test_tcpbpf.h"
#define CG_NAME "/tcpbpf-user-test"
/* 3 comes from one listening socket + both ends of the connection */ /* 3 comes from one listening socket + both ends of the connection */
#define EXPECTED_CLOSE_EVENTS 3 #define EXPECTED_CLOSE_EVENTS 3
...@@ -76,25 +66,11 @@ int verify_sockopt_result(int sock_map_fd) ...@@ -76,25 +66,11 @@ int verify_sockopt_result(int sock_map_fd)
return ret; return ret;
} }
static int bpf_find_map(const char *test, struct bpf_object *obj, void test_tcpbpf_user(void)
const char *name)
{
struct bpf_map *map;
map = bpf_object__find_map_by_name(obj, name);
if (!map) {
printf("%s:FAIL:map '%s' not found\n", test, name);
return -1;
}
return bpf_map__fd(map);
}
int main(int argc, char **argv)
{ {
const char *file = "test_tcpbpf_kern.o"; const char *file = "test_tcpbpf_kern.o";
int prog_fd, map_fd, sock_map_fd; int prog_fd, map_fd, sock_map_fd;
struct tcpbpf_globals g = {0}; struct tcpbpf_globals g = {0};
const char *cg_path = "/foo";
int error = EXIT_FAILURE; int error = EXIT_FAILURE;
struct bpf_object *obj; struct bpf_object *obj;
int cg_fd = -1; int cg_fd = -1;
...@@ -102,7 +78,7 @@ int main(int argc, char **argv) ...@@ -102,7 +78,7 @@ int main(int argc, char **argv)
__u32 key = 0; __u32 key = 0;
int rv; int rv;
cg_fd = cgroup_setup_and_join(cg_path); cg_fd = test__join_cgroup(CG_NAME);
if (cg_fd < 0) if (cg_fd < 0)
goto err; goto err;
...@@ -155,11 +131,11 @@ int main(int argc, char **argv) ...@@ -155,11 +131,11 @@ int main(int argc, char **argv)
goto err; goto err;
} }
printf("PASSED!\n");
error = 0; error = 0;
err: err:
bpf_prog_detach(cg_fd, BPF_CGROUP_SOCK_OPS); bpf_prog_detach(cg_fd, BPF_CGROUP_SOCK_OPS);
if (cg_fd != -1)
close(cg_fd); close(cg_fd);
cleanup_cgroup_environment();
return error; CHECK_FAIL(error);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment