Skip to content

Commit 51bad0f

Browse files
lmbborkmann
authored andcommitted
selftests: bpf: Reset global state between reuseport test runs
Currently, there is a lot of false positives if a single reuseport test fails. This is because expected_results and the result map are not cleared. Zero both after individual test runs, which fixes the mentioned false positives. Fixes: 91134d8 ("bpf: Test BPF_PROG_TYPE_SK_REUSEPORT") Signed-off-by: Lorenz Bauer <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Reviewed-by: Jakub Sitnicki <[email protected]> Acked-by: Martin KaFai Lau <[email protected]> Acked-by: John Fastabend <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 603fba9 commit 51bad0f

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

tools/testing/selftests/bpf/prog_tests/select_reuseport.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#define REUSEPORT_ARRAY_SIZE 32
3434

3535
static int result_map, tmp_index_ovr_map, linum_map, data_check_map;
36-
static enum result expected_results[NR_RESULTS];
36+
static __u32 expected_results[NR_RESULTS];
3737
static int sk_fds[REUSEPORT_ARRAY_SIZE];
3838
static int reuseport_array = -1, outer_map = -1;
3939
static int select_by_skb_data_prog;
@@ -697,7 +697,19 @@ static void setup_per_test(int type, sa_family_t family, bool inany,
697697

698698
static void cleanup_per_test(bool no_inner_map)
699699
{
700-
int i, err;
700+
int i, err, zero = 0;
701+
702+
memset(expected_results, 0, sizeof(expected_results));
703+
704+
for (i = 0; i < NR_RESULTS; i++) {
705+
err = bpf_map_update_elem(result_map, &i, &zero, BPF_ANY);
706+
RET_IF(err, "reset elem in result_map",
707+
"i:%u err:%d errno:%d\n", i, err, errno);
708+
}
709+
710+
err = bpf_map_update_elem(linum_map, &zero, &zero, BPF_ANY);
711+
RET_IF(err, "reset line number in linum_map", "err:%d errno:%d\n",
712+
err, errno);
701713

702714
for (i = 0; i < REUSEPORT_ARRAY_SIZE; i++)
703715
close(sk_fds[i]);

0 commit comments

Comments
 (0)