Commit 1f4f80fe authored by Stanislav Fomichev's avatar Stanislav Fomichev Committed by Alexei Starovoitov

selftests/bpf: test_progs: convert test_tcp_rtt

Move the files, adjust includes, remove entry from Makefile & .gitignore
Signed-off-by: default avatarStanislav Fomichev <sdf@google.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent e3e02e1d
...@@ -39,4 +39,3 @@ libbpf.so.* ...@@ -39,4 +39,3 @@ libbpf.so.*
test_hashmap test_hashmap
test_btf_dump test_btf_dump
xdping xdping
test_tcp_rtt
...@@ -28,7 +28,7 @@ TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test ...@@ -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_sock test_btf test_sockmap get_cgroup_id_user test_socket_cookie \
test_cgroup_storage test_select_reuseport test_section_names \ test_cgroup_storage test_select_reuseport test_section_names \
test_netcnt test_tcpnotify_user test_sock_fields test_sysctl test_hashmap \ test_netcnt test_tcpnotify_user test_sock_fields test_sysctl test_hashmap \
test_btf_dump test_cgroup_attach xdping test_tcp_rtt test_btf_dump test_cgroup_attach xdping
BPF_OBJ_FILES = $(patsubst %.c,%.o, $(notdir $(wildcard progs/*.c))) BPF_OBJ_FILES = $(patsubst %.c,%.o, $(notdir $(wildcard progs/*.c)))
TEST_GEN_FILES = $(BPF_OBJ_FILES) TEST_GEN_FILES = $(BPF_OBJ_FILES)
...@@ -112,7 +112,6 @@ $(OUTPUT)/test_netcnt: cgroup_helpers.c ...@@ -112,7 +112,6 @@ $(OUTPUT)/test_netcnt: cgroup_helpers.c
$(OUTPUT)/test_sock_fields: cgroup_helpers.c $(OUTPUT)/test_sock_fields: cgroup_helpers.c
$(OUTPUT)/test_sysctl: cgroup_helpers.c $(OUTPUT)/test_sysctl: cgroup_helpers.c
$(OUTPUT)/test_cgroup_attach: cgroup_helpers.c $(OUTPUT)/test_cgroup_attach: cgroup_helpers.c
$(OUTPUT)/test_tcp_rtt: cgroup_helpers.c
.PHONY: force .PHONY: force
......
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include <error.h> #include <test_progs.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <pthread.h>
#include <linux/filter.h>
#include <bpf/bpf.h>
#include <bpf/libbpf.h>
#include "bpf_rlimit.h"
#include "bpf_util.h"
#include "cgroup_helpers.h" #include "cgroup_helpers.h"
#define CG_PATH "/tcp_rtt"
struct tcp_rtt_storage { struct tcp_rtt_storage {
__u32 invoked; __u32 invoked;
__u32 dsack_dups; __u32 dsack_dups;
...@@ -31,8 +14,8 @@ static void send_byte(int fd) ...@@ -31,8 +14,8 @@ static void send_byte(int fd)
{ {
char b = 0x55; char b = 0x55;
if (write(fd, &b, sizeof(b)) != 1) if (CHECK_FAIL(write(fd, &b, sizeof(b)) != 1))
error(1, errno, "Failed to send single byte"); perror("Failed to send single byte");
} }
static int wait_for_ack(int fd, int retries) static int wait_for_ack(int fd, int retries)
...@@ -66,8 +49,10 @@ static int verify_sk(int map_fd, int client_fd, const char *msg, __u32 invoked, ...@@ -66,8 +49,10 @@ static int verify_sk(int map_fd, int client_fd, const char *msg, __u32 invoked,
int err = 0; int err = 0;
struct tcp_rtt_storage val; struct tcp_rtt_storage val;
if (bpf_map_lookup_elem(map_fd, &client_fd, &val) < 0) if (CHECK_FAIL(bpf_map_lookup_elem(map_fd, &client_fd, &val) < 0)) {
error(1, errno, "Failed to read socket storage"); perror("Failed to read socket storage");
return -1;
}
if (val.invoked != invoked) { if (val.invoked != invoked) {
log_err("%s: unexpected bpf_tcp_sock.invoked %d != %d", log_err("%s: unexpected bpf_tcp_sock.invoked %d != %d",
...@@ -225,61 +210,47 @@ static void *server_thread(void *arg) ...@@ -225,61 +210,47 @@ static void *server_thread(void *arg)
int fd = *(int *)arg; int fd = *(int *)arg;
int client_fd; int client_fd;
if (listen(fd, 1) < 0) if (CHECK_FAIL(listen(fd, 1)) < 0) {
error(1, errno, "Failed to listed on socket"); perror("Failed to listed on socket");
return NULL;
}
client_fd = accept(fd, (struct sockaddr *)&addr, &len); client_fd = accept(fd, (struct sockaddr *)&addr, &len);
if (client_fd < 0) if (CHECK_FAIL(client_fd < 0)) {
error(1, errno, "Failed to accept client"); perror("Failed to accept client");
return NULL;
}
/* Wait for the next connection (that never arrives) /* Wait for the next connection (that never arrives)
* to keep this thread alive to prevent calling * to keep this thread alive to prevent calling
* close() on client_fd. * close() on client_fd.
*/ */
if (accept(fd, (struct sockaddr *)&addr, &len) >= 0) if (CHECK_FAIL(accept(fd, (struct sockaddr *)&addr, &len) >= 0)) {
error(1, errno, "Unexpected success in second accept"); perror("Unexpected success in second accept");
return NULL;
}
close(client_fd); close(client_fd);
return NULL; return NULL;
} }
int main(int args, char **argv) void test_tcp_rtt(void)
{ {
int server_fd, cgroup_fd; int server_fd, cgroup_fd;
int err = EXIT_SUCCESS;
pthread_t tid; pthread_t tid;
if (setup_cgroup_environment()) cgroup_fd = test__join_cgroup("/tcp_rtt");
goto cleanup_obj; if (CHECK_FAIL(cgroup_fd < 0))
return;
cgroup_fd = create_and_get_cgroup(CG_PATH);
if (cgroup_fd < 0)
goto cleanup_cgroup_env;
if (join_cgroup(CG_PATH))
goto cleanup_cgroup;
server_fd = start_server(); server_fd = start_server();
if (server_fd < 0) { if (CHECK_FAIL(server_fd < 0))
err = EXIT_FAILURE; goto close_cgroup_fd;
goto cleanup_cgroup;
}
pthread_create(&tid, NULL, server_thread, (void *)&server_fd); pthread_create(&tid, NULL, server_thread, (void *)&server_fd);
CHECK_FAIL(run_test(cgroup_fd, server_fd));
if (run_test(cgroup_fd, server_fd))
err = EXIT_FAILURE;
close(server_fd); close(server_fd);
close_cgroup_fd:
printf("test_sockopt_sk: %s\n",
err == EXIT_SUCCESS ? "PASSED" : "FAILED");
cleanup_cgroup:
close(cgroup_fd); close(cgroup_fd);
cleanup_cgroup_env:
cleanup_cgroup_environment();
cleanup_obj:
return err;
} }
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