selftests/bpf: Add tcp/udp iterator programs to selftests

Added tcp{4,6} and udp{4,6} bpf programs into test_progs
selftest so that they at least can load successfully.
  $ ./test_progs -n 3
  ...
  #3/7 tcp4:OK
  #3/8 tcp6:OK
  #3/9 udp4:OK
  #3/10 udp6:OK
  ...
  #3 bpf_iter:OK
  Summary: 1/16 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20200623230823.3989372-1-yhs@fb.com
This commit is contained in:
Yonghong Song 2020-06-23 16:08:23 -07:00 committed by Alexei Starovoitov
parent ace6d6ec9e
commit cfcd75f9bf

View File

@ -6,6 +6,10 @@
#include "bpf_iter_bpf_map.skel.h" #include "bpf_iter_bpf_map.skel.h"
#include "bpf_iter_task.skel.h" #include "bpf_iter_task.skel.h"
#include "bpf_iter_task_file.skel.h" #include "bpf_iter_task_file.skel.h"
#include "bpf_iter_tcp4.skel.h"
#include "bpf_iter_tcp6.skel.h"
#include "bpf_iter_udp4.skel.h"
#include "bpf_iter_udp6.skel.h"
#include "bpf_iter_test_kern1.skel.h" #include "bpf_iter_test_kern1.skel.h"
#include "bpf_iter_test_kern2.skel.h" #include "bpf_iter_test_kern2.skel.h"
#include "bpf_iter_test_kern3.skel.h" #include "bpf_iter_test_kern3.skel.h"
@ -120,6 +124,62 @@ static void test_task_file(void)
bpf_iter_task_file__destroy(skel); bpf_iter_task_file__destroy(skel);
} }
static void test_tcp4(void)
{
struct bpf_iter_tcp4 *skel;
skel = bpf_iter_tcp4__open_and_load();
if (CHECK(!skel, "bpf_iter_tcp4__open_and_load",
"skeleton open_and_load failed\n"))
return;
do_dummy_read(skel->progs.dump_tcp4);
bpf_iter_tcp4__destroy(skel);
}
static void test_tcp6(void)
{
struct bpf_iter_tcp6 *skel;
skel = bpf_iter_tcp6__open_and_load();
if (CHECK(!skel, "bpf_iter_tcp6__open_and_load",
"skeleton open_and_load failed\n"))
return;
do_dummy_read(skel->progs.dump_tcp6);
bpf_iter_tcp6__destroy(skel);
}
static void test_udp4(void)
{
struct bpf_iter_udp4 *skel;
skel = bpf_iter_udp4__open_and_load();
if (CHECK(!skel, "bpf_iter_udp4__open_and_load",
"skeleton open_and_load failed\n"))
return;
do_dummy_read(skel->progs.dump_udp4);
bpf_iter_udp4__destroy(skel);
}
static void test_udp6(void)
{
struct bpf_iter_udp6 *skel;
skel = bpf_iter_udp6__open_and_load();
if (CHECK(!skel, "bpf_iter_udp6__open_and_load",
"skeleton open_and_load failed\n"))
return;
do_dummy_read(skel->progs.dump_udp6);
bpf_iter_udp6__destroy(skel);
}
/* The expected string is less than 16 bytes */ /* The expected string is less than 16 bytes */
static int do_read_with_fd(int iter_fd, const char *expected, static int do_read_with_fd(int iter_fd, const char *expected,
bool read_one_char) bool read_one_char)
@ -394,6 +454,14 @@ void test_bpf_iter(void)
test_task(); test_task();
if (test__start_subtest("task_file")) if (test__start_subtest("task_file"))
test_task_file(); test_task_file();
if (test__start_subtest("tcp4"))
test_tcp4();
if (test__start_subtest("tcp6"))
test_tcp6();
if (test__start_subtest("udp4"))
test_udp4();
if (test__start_subtest("udp6"))
test_udp6();
if (test__start_subtest("anon")) if (test__start_subtest("anon"))
test_anon_iter(false); test_anon_iter(false);
if (test__start_subtest("anon-read-one-char")) if (test__start_subtest("anon-read-one-char"))