Parametrize the SK_REUSEPORT tests so that the map type for storing sockets is not hard-coded in the test setup routine. This, together with careful state cleaning after the tests, let's us run the test cases once with REUSEPORT_ARRAY and once with SOCKMAP (TCP only), to have test coverage for the latter as well. Signed-off-by: Jakub Sitnicki <jakub@xxxxxxxxxxxxxx> --- Now a test run looks like so: bash-5.0# ./test_progs -t reuseport #39/1 reuseport_sockarray IPv4/TCP LOOPBACK test_err_inner_map:OK #39/2 reuseport_sockarray IPv4/TCP LOOPBACK test_err_skb_data:OK #39/3 reuseport_sockarray IPv4/TCP LOOPBACK test_err_sk_select_port:OK #39/4 reuseport_sockarray IPv4/TCP LOOPBACK test_pass:OK #39/5 reuseport_sockarray IPv4/TCP LOOPBACK test_syncookie:OK #39/6 reuseport_sockarray IPv4/TCP LOOPBACK test_pass_on_err:OK #39/7 reuseport_sockarray IPv4/TCP LOOPBACK test_detach_bpf:OK #39/8 reuseport_sockarray IPv4/TCP INANY test_err_inner_map:OK #39/9 reuseport_sockarray IPv4/TCP INANY test_err_skb_data:OK #39/10 reuseport_sockarray IPv4/TCP INANY test_err_sk_select_port:OK #39/11 reuseport_sockarray IPv4/TCP INANY test_pass:OK #39/12 reuseport_sockarray IPv4/TCP INANY test_syncookie:OK #39/13 reuseport_sockarray IPv4/TCP INANY test_pass_on_err:OK #39/14 reuseport_sockarray IPv4/TCP INANY test_detach_bpf:OK #39/15 reuseport_sockarray IPv6/TCP LOOPBACK test_err_inner_map:OK #39/16 reuseport_sockarray IPv6/TCP LOOPBACK test_err_skb_data:OK #39/17 reuseport_sockarray IPv6/TCP LOOPBACK test_err_sk_select_port:OK #39/18 reuseport_sockarray IPv6/TCP LOOPBACK test_pass:OK #39/19 reuseport_sockarray IPv6/TCP LOOPBACK test_syncookie:OK #39/20 reuseport_sockarray IPv6/TCP LOOPBACK test_pass_on_err:OK #39/21 reuseport_sockarray IPv6/TCP LOOPBACK test_detach_bpf:OK #39/22 reuseport_sockarray IPv6/TCP INANY test_err_inner_map:OK #39/23 reuseport_sockarray IPv6/TCP INANY test_err_skb_data:OK #39/24 reuseport_sockarray IPv6/TCP INANY test_err_sk_select_port:OK #39/25 reuseport_sockarray IPv6/TCP INANY test_pass:OK #39/26 reuseport_sockarray IPv6/TCP INANY test_syncookie:OK #39/27 reuseport_sockarray IPv6/TCP INANY test_pass_on_err:OK #39/28 reuseport_sockarray IPv6/TCP INANY test_detach_bpf:OK #39/29 reuseport_sockarray IPv4/UDP LOOPBACK test_err_inner_map:OK #39/30 reuseport_sockarray IPv4/UDP LOOPBACK test_err_skb_data:OK #39/31 reuseport_sockarray IPv4/UDP LOOPBACK test_err_sk_select_port:OK #39/32 reuseport_sockarray IPv4/UDP LOOPBACK test_pass:OK #39/33 reuseport_sockarray IPv4/UDP LOOPBACK test_syncookie:OK #39/34 reuseport_sockarray IPv4/UDP LOOPBACK test_pass_on_err:OK #39/35 reuseport_sockarray IPv4/UDP LOOPBACK test_detach_bpf:OK #39/36 reuseport_sockarray IPv6/UDP LOOPBACK test_err_inner_map:OK #39/37 reuseport_sockarray IPv6/UDP LOOPBACK test_err_skb_data:OK #39/38 reuseport_sockarray IPv6/UDP LOOPBACK test_err_sk_select_port:OK #39/39 reuseport_sockarray IPv6/UDP LOOPBACK test_pass:OK #39/40 reuseport_sockarray IPv6/UDP LOOPBACK test_syncookie:OK #39/41 reuseport_sockarray IPv6/UDP LOOPBACK test_pass_on_err:OK #39/42 reuseport_sockarray IPv6/UDP LOOPBACK test_detach_bpf:OK #39/43 sockmap IPv4/TCP LOOPBACK test_err_inner_map:OK #39/44 sockmap IPv4/TCP LOOPBACK test_err_skb_data:OK #39/45 sockmap IPv4/TCP LOOPBACK test_err_sk_select_port:OK #39/46 sockmap IPv4/TCP LOOPBACK test_pass:OK #39/47 sockmap IPv4/TCP LOOPBACK test_syncookie:OK #39/48 sockmap IPv4/TCP LOOPBACK test_pass_on_err:OK #39/49 sockmap IPv4/TCP LOOPBACK test_detach_bpf:OK #39/50 sockmap IPv4/TCP INANY test_err_inner_map:OK #39/51 sockmap IPv4/TCP INANY test_err_skb_data:OK #39/52 sockmap IPv4/TCP INANY test_err_sk_select_port:OK #39/53 sockmap IPv4/TCP INANY test_pass:OK #39/54 sockmap IPv4/TCP INANY test_syncookie:OK #39/55 sockmap IPv4/TCP INANY test_pass_on_err:OK #39/56 sockmap IPv4/TCP INANY test_detach_bpf:OK #39/57 sockmap IPv6/TCP LOOPBACK test_err_inner_map:OK #39/58 sockmap IPv6/TCP LOOPBACK test_err_skb_data:OK #39/59 sockmap IPv6/TCP LOOPBACK test_err_sk_select_port:OK #39/60 sockmap IPv6/TCP LOOPBACK test_pass:OK #39/61 sockmap IPv6/TCP LOOPBACK test_syncookie:OK #39/62 sockmap IPv6/TCP LOOPBACK test_pass_on_err:OK #39/63 sockmap IPv6/TCP LOOPBACK test_detach_bpf:OK #39/64 sockmap IPv6/TCP INANY test_err_inner_map:OK #39/65 sockmap IPv6/TCP INANY test_err_skb_data:OK #39/66 sockmap IPv6/TCP INANY test_err_sk_select_port:OK #39/67 sockmap IPv6/TCP INANY test_pass:OK #39/68 sockmap IPv6/TCP INANY test_syncookie:OK #39/69 sockmap IPv6/TCP INANY test_pass_on_err:OK #39/70 sockmap IPv6/TCP INANY test_detach_bpf:OK #39/71 sockmap IPv4/UDP LOOPBACK test_err_inner_map:OK #39/72 sockmap IPv4/UDP LOOPBACK test_err_skb_data:OK #39/73 sockmap IPv4/UDP LOOPBACK test_err_sk_select_port:OK #39/74 sockmap IPv4/UDP LOOPBACK test_pass:OK #39/75 sockmap IPv4/UDP LOOPBACK test_syncookie:OK #39/76 sockmap IPv4/UDP LOOPBACK test_pass_on_err:OK #39/77 sockmap IPv4/UDP LOOPBACK test_detach_bpf:OK #39/78 sockmap IPv6/UDP LOOPBACK test_err_inner_map:OK #39/79 sockmap IPv6/UDP LOOPBACK test_err_skb_data:OK #39/80 sockmap IPv6/UDP LOOPBACK test_err_sk_select_port:OK #39/81 sockmap IPv6/UDP LOOPBACK test_pass:OK #39/82 sockmap IPv6/UDP LOOPBACK test_syncookie:OK #39/83 sockmap IPv6/UDP LOOPBACK test_pass_on_err:OK #39/84 sockmap IPv6/UDP LOOPBACK test_detach_bpf:OK #39 select_reuseport:OK Summary: 1/84 PASSED, 14 SKIPPED, 0 FAILED .../bpf/prog_tests/select_reuseport.c | 60 +++++++++++++++---- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/select_reuseport.c b/tools/testing/selftests/bpf/prog_tests/select_reuseport.c index 2c37ae7dc214..e7b4abfca2ab 100644 --- a/tools/testing/selftests/bpf/prog_tests/select_reuseport.c +++ b/tools/testing/selftests/bpf/prog_tests/select_reuseport.c @@ -36,6 +36,7 @@ static int result_map, tmp_index_ovr_map, linum_map, data_check_map; static enum result expected_results[NR_RESULTS]; static int sk_fds[REUSEPORT_ARRAY_SIZE]; static int reuseport_array = -1, outer_map = -1; +static enum bpf_map_type inner_map_type; static int select_by_skb_data_prog; static int saved_tcp_syncookie = -1; static struct bpf_object *obj; @@ -63,13 +64,15 @@ static union sa46 { } \ }) -static int create_maps(void) +static int create_maps(enum bpf_map_type inner_type) { struct bpf_create_map_attr attr = {}; + inner_map_type = inner_type; + /* Creating reuseport_array */ attr.name = "reuseport_array"; - attr.map_type = BPF_MAP_TYPE_REUSEPORT_SOCKARRAY; + attr.map_type = inner_type; attr.key_size = sizeof(__u32); attr.value_size = sizeof(__u32); attr.max_entries = REUSEPORT_ARRAY_SIZE; @@ -694,12 +697,34 @@ static void cleanup_per_test(bool no_inner_map) static void cleanup(void) { - if (outer_map != -1) + if (outer_map != -1) { close(outer_map); - if (reuseport_array != -1) + outer_map = -1; + } + + if (reuseport_array != -1) { close(reuseport_array); - if (obj) + reuseport_array = -1; + } + + if (obj) { bpf_object__close(obj); + obj = NULL; + } + + memset(expected_results, 0, sizeof(expected_results)); +} + +static const char *maptype_str(enum bpf_map_type type) +{ + switch (type) { + case BPF_MAP_TYPE_REUSEPORT_SOCKARRAY: + return "reuseport_sockarray"; + case BPF_MAP_TYPE_SOCKMAP: + return "sockmap"; + default: + return "unknown"; + } } static const char *family_str(sa_family_t family) @@ -747,13 +772,21 @@ static void test_config(int sotype, sa_family_t family, bool inany) const struct test *t; for (t = tests; t < tests + ARRAY_SIZE(tests); t++) { - snprintf(s, sizeof(s), "%s/%s %s %s", + snprintf(s, sizeof(s), "%s %s/%s %s %s", + maptype_str(inner_map_type), family_str(family), sotype_str(sotype), inany ? "INANY" : "LOOPBACK", t->name); if (!test__start_subtest(s)) continue; + if (sotype == SOCK_DGRAM && + inner_map_type == BPF_MAP_TYPE_SOCKMAP) { + /* SOCKMAP doesn't support UDP yet */ + test__skip(); + continue; + } + setup_per_test(sotype, family, inany, t->no_inner_map); t->fn(sotype, family); cleanup_per_test(t->no_inner_map); @@ -782,13 +815,20 @@ static void test_all(void) test_config(c->sotype, c->family, c->inany); } -void test_select_reuseport(void) +void test_map_type(enum bpf_map_type mt) { - if (create_maps()) + if (create_maps(mt)) goto out; if (prepare_bpf_obj()) goto out; + test_all(); +out: + cleanup(); +} + +void test_select_reuseport(void) +{ saved_tcp_fo = read_int_sysctl(TCP_FO_SYSCTL); saved_tcp_syncookie = read_int_sysctl(TCP_SYNCOOKIE_SYSCTL); if (saved_tcp_syncookie < 0 || saved_tcp_syncookie < 0) @@ -799,8 +839,8 @@ void test_select_reuseport(void) if (disable_syncookie()) goto out; - test_all(); + test_map_type(BPF_MAP_TYPE_REUSEPORT_SOCKARRAY); + test_map_type(BPF_MAP_TYPE_SOCKMAP); out: - cleanup(); restore_sysctls(); } -- 2.24.1