summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests
diff options
context:
space:
mode:
authorStanislav Fomichev <sdf@google.com>2019-09-04 12:25:09 -0400
committerAlexei Starovoitov <ast@kernel.org>2019-09-06 12:59:06 -0400
commit1f4f80fed217e8186a7e1067ae71260e133012ce (patch)
tree9a63bd66be8610501906cb8585378578096863da /tools/testing/selftests
parente3e02e1d9c24b0c3a36f9c854ae80e61fd62b2a9 (diff)
selftests/bpf: test_progs: convert test_tcp_rtt
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>
Diffstat (limited to 'tools/testing/selftests')
-rw-r--r--tools/testing/selftests/bpf/.gitignore1
-rw-r--r--tools/testing/selftests/bpf/Makefile3
-rw-r--r--tools/testing/selftests/bpf/prog_tests/tcp_rtt.c (renamed from tools/testing/selftests/bpf/test_tcp_rtt.c)83
3 files changed, 28 insertions, 59 deletions
diff --git a/tools/testing/selftests/bpf/.gitignore b/tools/testing/selftests/bpf/.gitignore
index 5b06bb45b500..7470327edcfe 100644
--- a/tools/testing/selftests/bpf/.gitignore
+++ b/tools/testing/selftests/bpf/.gitignore
@@ -39,4 +39,3 @@ libbpf.so.*
39test_hashmap 39test_hashmap
40test_btf_dump 40test_btf_dump
41xdping 41xdping
42test_tcp_rtt
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 4d9a0304a011..7f3196af1ae4 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -28,7 +28,7 @@ TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test
28 test_sock test_btf test_sockmap get_cgroup_id_user test_socket_cookie \ 28 test_sock test_btf test_sockmap get_cgroup_id_user test_socket_cookie \
29 test_cgroup_storage test_select_reuseport test_section_names \ 29 test_cgroup_storage test_select_reuseport test_section_names \
30 test_netcnt test_tcpnotify_user test_sock_fields test_sysctl test_hashmap \ 30 test_netcnt test_tcpnotify_user test_sock_fields test_sysctl test_hashmap \
31 test_btf_dump test_cgroup_attach xdping test_tcp_rtt 31 test_btf_dump test_cgroup_attach xdping
32 32
33BPF_OBJ_FILES = $(patsubst %.c,%.o, $(notdir $(wildcard progs/*.c))) 33BPF_OBJ_FILES = $(patsubst %.c,%.o, $(notdir $(wildcard progs/*.c)))
34TEST_GEN_FILES = $(BPF_OBJ_FILES) 34TEST_GEN_FILES = $(BPF_OBJ_FILES)
@@ -112,7 +112,6 @@ $(OUTPUT)/test_netcnt: cgroup_helpers.c
112$(OUTPUT)/test_sock_fields: cgroup_helpers.c 112$(OUTPUT)/test_sock_fields: cgroup_helpers.c
113$(OUTPUT)/test_sysctl: cgroup_helpers.c 113$(OUTPUT)/test_sysctl: cgroup_helpers.c
114$(OUTPUT)/test_cgroup_attach: cgroup_helpers.c 114$(OUTPUT)/test_cgroup_attach: cgroup_helpers.c
115$(OUTPUT)/test_tcp_rtt: cgroup_helpers.c
116 115
117.PHONY: force 116.PHONY: force
118 117
diff --git a/tools/testing/selftests/bpf/test_tcp_rtt.c b/tools/testing/selftests/bpf/prog_tests/tcp_rtt.c
index 93916a69823e..fdc0b3614a9e 100644
--- a/tools/testing/selftests/bpf/test_tcp_rtt.c
+++ b/tools/testing/selftests/bpf/prog_tests/tcp_rtt.c
@@ -1,24 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0
2#include <error.h> 2#include <test_progs.h>
3#include <errno.h>
4#include <stdio.h>
5#include <unistd.h>
6#include <sys/types.h>
7#include <sys/socket.h>
8#include <netinet/in.h>
9#include <netinet/tcp.h>
10#include <pthread.h>
11
12#include <linux/filter.h>
13#include <bpf/bpf.h>
14#include <bpf/libbpf.h>
15
16#include "bpf_rlimit.h"
17#include "bpf_util.h"
18#include "cgroup_helpers.h" 3#include "cgroup_helpers.h"
19 4
20#define CG_PATH "/tcp_rtt"
21
22struct tcp_rtt_storage { 5struct tcp_rtt_storage {
23 __u32 invoked; 6 __u32 invoked;
24 __u32 dsack_dups; 7 __u32 dsack_dups;
@@ -31,8 +14,8 @@ static void send_byte(int fd)
31{ 14{
32 char b = 0x55; 15 char b = 0x55;
33 16
34 if (write(fd, &b, sizeof(b)) != 1) 17 if (CHECK_FAIL(write(fd, &b, sizeof(b)) != 1))
35 error(1, errno, "Failed to send single byte"); 18 perror("Failed to send single byte");
36} 19}
37 20
38static int wait_for_ack(int fd, int retries) 21static 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 int err = 0; 49 int err = 0;
67 struct tcp_rtt_storage val; 50 struct tcp_rtt_storage val;
68 51
69 if (bpf_map_lookup_elem(map_fd, &client_fd, &val) < 0) 52 if (CHECK_FAIL(bpf_map_lookup_elem(map_fd, &client_fd, &val) < 0)) {
70 error(1, errno, "Failed to read socket storage"); 53 perror("Failed to read socket storage");
54 return -1;
55 }
71 56
72 if (val.invoked != invoked) { 57 if (val.invoked != invoked) {
73 log_err("%s: unexpected bpf_tcp_sock.invoked %d != %d", 58 log_err("%s: unexpected bpf_tcp_sock.invoked %d != %d",
@@ -225,61 +210,47 @@ static void *server_thread(void *arg)
225 int fd = *(int *)arg; 210 int fd = *(int *)arg;
226 int client_fd; 211 int client_fd;
227 212
228 if (listen(fd, 1) < 0) 213 if (CHECK_FAIL(listen(fd, 1)) < 0) {
229 error(1, errno, "Failed to listed on socket"); 214 perror("Failed to listed on socket");
215 return NULL;
216 }
230 217
231 client_fd = accept(fd, (struct sockaddr *)&addr, &len); 218 client_fd = accept(fd, (struct sockaddr *)&addr, &len);
232 if (client_fd < 0) 219 if (CHECK_FAIL(client_fd < 0)) {
233 error(1, errno, "Failed to accept client"); 220 perror("Failed to accept client");
221 return NULL;
222 }
234 223
235 /* Wait for the next connection (that never arrives) 224 /* Wait for the next connection (that never arrives)
236 * to keep this thread alive to prevent calling 225 * to keep this thread alive to prevent calling
237 * close() on client_fd. 226 * close() on client_fd.
238 */ 227 */
239 if (accept(fd, (struct sockaddr *)&addr, &len) >= 0) 228 if (CHECK_FAIL(accept(fd, (struct sockaddr *)&addr, &len) >= 0)) {
240 error(1, errno, "Unexpected success in second accept"); 229 perror("Unexpected success in second accept");
230 return NULL;
231 }
241 232
242 close(client_fd); 233 close(client_fd);
243 234
244 return NULL; 235 return NULL;
245} 236}
246 237
247int main(int args, char **argv) 238void test_tcp_rtt(void)
248{ 239{
249 int server_fd, cgroup_fd; 240 int server_fd, cgroup_fd;
250 int err = EXIT_SUCCESS;
251 pthread_t tid; 241 pthread_t tid;
252 242
253 if (setup_cgroup_environment()) 243 cgroup_fd = test__join_cgroup("/tcp_rtt");
254 goto cleanup_obj; 244 if (CHECK_FAIL(cgroup_fd < 0))
255 245 return;
256 cgroup_fd = create_and_get_cgroup(CG_PATH);
257 if (cgroup_fd < 0)
258 goto cleanup_cgroup_env;
259
260 if (join_cgroup(CG_PATH))
261 goto cleanup_cgroup;
262 246
263 server_fd = start_server(); 247 server_fd = start_server();
264 if (server_fd < 0) { 248 if (CHECK_FAIL(server_fd < 0))
265 err = EXIT_FAILURE; 249 goto close_cgroup_fd;
266 goto cleanup_cgroup;
267 }
268 250
269 pthread_create(&tid, NULL, server_thread, (void *)&server_fd); 251 pthread_create(&tid, NULL, server_thread, (void *)&server_fd);
270 252 CHECK_FAIL(run_test(cgroup_fd, server_fd));
271 if (run_test(cgroup_fd, server_fd))
272 err = EXIT_FAILURE;
273
274 close(server_fd); 253 close(server_fd);
275 254close_cgroup_fd:
276 printf("test_sockopt_sk: %s\n",
277 err == EXIT_SUCCESS ? "PASSED" : "FAILED");
278
279cleanup_cgroup:
280 close(cgroup_fd); 255 close(cgroup_fd);
281cleanup_cgroup_env:
282 cleanup_cgroup_environment();
283cleanup_obj:
284 return err;
285} 256}