Skip to content

Commit

Permalink
selftests: bpf: Reset global state between reuseport test runs
Browse files Browse the repository at this point in the history
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 <lmb@cloudflare.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20200124112754.19664-5-lmb@cloudflare.com
  • Loading branch information
Lorenz Bauer authored and Daniel Borkmann committed Jan 24, 2020
1 parent 603fba9 commit 51bad0f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions tools/testing/selftests/bpf/prog_tests/select_reuseport.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#define REUSEPORT_ARRAY_SIZE 32

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

static void cleanup_per_test(bool no_inner_map)
{
int i, err;
int i, err, zero = 0;

memset(expected_results, 0, sizeof(expected_results));

for (i = 0; i < NR_RESULTS; i++) {
err = bpf_map_update_elem(result_map, &i, &zero, BPF_ANY);
RET_IF(err, "reset elem in result_map",
"i:%u err:%d errno:%d\n", i, err, errno);
}

err = bpf_map_update_elem(linum_map, &zero, &zero, BPF_ANY);
RET_IF(err, "reset line number in linum_map", "err:%d errno:%d\n",
err, errno);

for (i = 0; i < REUSEPORT_ARRAY_SIZE; i++)
close(sk_fds[i]);
Expand Down

0 comments on commit 51bad0f

Please sign in to comment.