aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf
diff options
context:
space:
mode:
authorJakub Sitnicki <jakub@cloudflare.com>2019-12-12 11:22:55 +0100
committerAlexei Starovoitov <ast@kernel.org>2019-12-13 12:38:00 -0800
commitce7cb5f3921cdf0f65ab877764265c6c0be34c3c (patch)
tree1d5b83e4ee38e4bd7bb5113f43712d5b0cbb1e60 /tools/testing/selftests/bpf
parentselftests/bpf: Unroll the main loop in reuseport test (diff)
downloadlinux-dev-ce7cb5f3921cdf0f65ab877764265c6c0be34c3c.tar.xz
linux-dev-ce7cb5f3921cdf0f65ab877764265c6c0be34c3c.zip
selftests/bpf: Run reuseport tests in a loop
Prepare for switching reuseport tests to test_progs framework. Loop over the tests and perform setup/cleanup for each test separately, remembering that with test_progs we can select tests to run. Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20191212102259.418536-7-jakub@cloudflare.com
Diffstat (limited to 'tools/testing/selftests/bpf')
-rw-r--r--tools/testing/selftests/bpf/test_select_reuseport.c55
1 files changed, 34 insertions, 21 deletions
diff --git a/tools/testing/selftests/bpf/test_select_reuseport.c b/tools/testing/selftests/bpf/test_select_reuseport.c
index 63ce2e75e758..cfff958da570 100644
--- a/tools/testing/selftests/bpf/test_select_reuseport.c
+++ b/tools/testing/selftests/bpf/test_select_reuseport.c
@@ -643,7 +643,8 @@ static void prepare_sk_fds(int type, sa_family_t family, bool inany)
}
}
-static void setup_per_test(int type, sa_family_t family, bool inany)
+static void setup_per_test(int type, sa_family_t family, bool inany,
+ bool no_inner_map)
{
int ovr = -1, err;
@@ -652,9 +653,18 @@ static void setup_per_test(int type, sa_family_t family, bool inany)
BPF_ANY);
CHECK(err == -1, "update_elem(tmp_index_ovr_map, 0, -1)",
"err:%d errno:%d\n", err, errno);
+
+ /* Install reuseport_array to outer_map? */
+ if (no_inner_map)
+ return;
+
+ err = bpf_map_update_elem(outer_map, &index_zero, &reuseport_array,
+ BPF_ANY);
+ CHECK(err == -1, "update_elem(outer_map, 0, reuseport_array)",
+ "err:%d errno:%d\n", err, errno);
}
-static void cleanup_per_test(void)
+static void cleanup_per_test(bool no_inner_map)
{
int i, err;
@@ -662,6 +672,10 @@ static void cleanup_per_test(void)
close(sk_fds[i]);
close(epfd);
+ /* Delete reuseport_array from outer_map? */
+ if (no_inner_map)
+ return;
+
err = bpf_map_delete_elem(outer_map, &index_zero);
CHECK(err == -1, "delete_elem(outer_map)",
"err:%d errno:%d\n", err, errno);
@@ -700,31 +714,30 @@ static const char *sotype_str(int sotype)
static void test_config(int type, sa_family_t family, bool inany)
{
- int err;
+ const struct test {
+ void (*fn)(int sotype, sa_family_t family);
+ bool no_inner_map;
+ } tests[] = {
+ { test_err_inner_map, true /* no_inner_map */ },
+ { test_err_skb_data },
+ { test_err_sk_select_port },
+ { test_pass },
+ { test_syncookie },
+ { test_pass_on_err },
+ { test_detach_bpf },
+ };
+ const struct test *t;
printf("######## %s/%s %s ########\n",
family_str(family), sotype_str(type),
inany ? " INANY " : "LOOPBACK");
- setup_per_test(type, family, inany);
-
- test_err_inner_map(type, family);
-
- /* Install reuseport_array to the outer_map */
- err = bpf_map_update_elem(outer_map, &index_zero,
- &reuseport_array, BPF_ANY);
- CHECK(err == -1, "update_elem(outer_map)",
- "err:%d errno:%d\n", err, errno);
-
- test_err_skb_data(type, family);
- test_err_sk_select_port(type, family);
- test_pass(type, family);
- test_syncookie(type, family);
- test_pass_on_err(type, family);
- /* Must be the last test */
- test_detach_bpf(type, family);
+ for (t = tests; t < tests + ARRAY_SIZE(tests); t++) {
+ setup_per_test(type, family, inany, t->no_inner_map);
+ t->fn(type, family);
+ cleanup_per_test(t->no_inner_map);
+ }
- cleanup_per_test();
printf("\n");
}