bpf: selftest: Adapt sock_fields test to use skel and global variables
authorMartin KaFai Lau <kafai@fb.com>
Fri, 25 Sep 2020 00:04:34 +0000 (17:04 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 25 Sep 2020 20:58:02 +0000 (13:58 -0700)
commitb18c1f0aa4775bf1ecfbe5942e4e7c6bffdeff6a
tree90e21ef44629ff498cd5688a1f69c39ea965fa69
parent6f521a2bd26870bcd14aac42ff2ce0b1a22ae477
bpf: selftest: Adapt sock_fields test to use skel and global variables

skel is used.

Global variables are used to store the result from bpf prog.
addr_map, sock_result_map, and tcp_sock_result_map are gone.
Instead, global variables listen_tp, srv_sa6, cli_tp,, srv_tp,
listen_sk, srv_sk, and cli_sk are added.
Because of that, bpf_addr_array_idx and bpf_result_array_idx are also
no longer needed.

CHECK() macro from test_progs.h is reused and bail as soon as
a CHECK failure.

shutdown() is used to ensure the previous data-ack is received.
The bytes_acked, bytes_received, and the pkt_out_cnt checks are
using "<" to accommodate the final ack may not have been received/sent.
It is enough since it is not the focus of this test.

The sk local storage is all initialized to 0xeB9F now, so the
check_sk_pkt_out_cnt() always checks with the 0xeB9F base.  It is to
keep things simple.

The next patch will reuse helpers from network_helpers.h to simplify
things further.

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200925000434.3858204-1-kafai@fb.com
tools/testing/selftests/bpf/prog_tests/sock_fields.c
tools/testing/selftests/bpf/progs/test_sock_fields.c