mbox series

[bpf-next,00/10] selftests/bpf: Migrate test_tunnel.sh to test_progs

Message ID 20250227-tunnels-v1-0-33df5c30aa04@bootlin.com
Headers show
Series selftests/bpf: Migrate test_tunnel.sh to test_progs | expand

Message

Bastien Curutchet Feb. 27, 2025, 1:24 p.m. UTC
Hi all,

This patch series continues the work to migrate the *.sh tests into
prog_tests framework.

The test_tunnel.sh script has already been partly migrated to
test_progs in prog_tests/test_tunnel.c so I add my work to it.

PATCH 1 & 2 create some helpers to avoid code duplication and ease the
migration in the following patches.
PATCH 3 to 9 migrate the tests of gre, ip6gre, erspan, ip6erspan,
geneve, ip6geneve and ip6tnl tunnels.
PATCH 10 removes test_tunnel.sh

Signed-off-by: Bastien Curutchet (eBPF Foundation) <bastien.curutchet@bootlin.com>
---
Bastien Curutchet (eBPF Foundation) (10):
      selftests/bpf: test_tunnel: Add generic_attach* helpers
      selftests/bpf: test_tunnel: Add ping helpers
      selftests/bpf: test_tunnel: Move gre tunnel test to test_progs
      selftests/bpf: test_tunnel: Move ip6gre tunnel test to test_progs
      selftests/bpf: test_tunnel: Move erspan tunnel tests to test_progs
      selftests/bpf: test_tunnel: Move ip6erspan tunnel test to test_progs
      selftests/bpf: test_tunnel: Move geneve tunnel test to test_progs
      selftests/bpf: test_tunnel: Move ip6geneve tunnel test to test_progs
      selftests/bpf: test_tunnel: Move ip6tnl tunnel tests to test_progs
      selftests/bpf: test_tunnel: Remove test_tunnel.sh

 tools/testing/selftests/bpf/Makefile               |   1 -
 .../testing/selftests/bpf/prog_tests/test_tunnel.c | 627 +++++++++++++++++---
 tools/testing/selftests/bpf/test_tunnel.sh         | 645 ---------------------
 3 files changed, 532 insertions(+), 741 deletions(-)
---
base-commit: 16566afa71143757b49fc4b2a331639f487d105a
change-id: 20250131-tunnels-59b641ea3f10

Best regards,

Comments

Bastien Curutchet Feb. 28, 2025, 8:13 a.m. UTC | #1
Hi Stanislav,

On 2/27/25 11:08 PM, Stanislav Fomichev wrote:
> On 02/27, Bastien Curutchet (eBPF Foundation) wrote:
>> A fair amount of code duplication is present among tests to attach BPF
>> programs.
>>
>> Create generic_attach* helpers that attach BPF programs to a given
>> interface.
>> Use ASSERT_OK_FD() instead of ASSERT_GE() to check fd's validity.
>> Use these helpers in all the available tests.
>>
>> Signed-off-by: Bastien Curutchet (eBPF Foundation) <bastien.curutchet@bootlin.com>
>> ---
>>   .../testing/selftests/bpf/prog_tests/test_tunnel.c | 128 ++++++++++-----------
>>   1 file changed, 62 insertions(+), 66 deletions(-)
>>
>> diff --git a/tools/testing/selftests/bpf/prog_tests/test_tunnel.c b/tools/testing/selftests/bpf/prog_tests/test_tunnel.c
>> index cec746e77cd3abdf561cfc2422fa0a934fc481cd..27a8c8caa87e4c6b39b2b26c2aa9860b131a70a9 100644
>> --- a/tools/testing/selftests/bpf/prog_tests/test_tunnel.c
>> +++ b/tools/testing/selftests/bpf/prog_tests/test_tunnel.c
>> @@ -397,6 +397,56 @@ static int attach_tc_prog(struct bpf_tc_hook *hook, int igr_fd, int egr_fd)
>>   	return 0;
>>   }
>>   
>> +static int generic_attach(const char *dev, int igr_fd, int egr_fd)
>> +{
>> +	DECLARE_LIBBPF_OPTS(bpf_tc_hook, tc_hook, .attach_point = BPF_TC_INGRESS);
> 
> nit: .attach_point = BPF_TC_INGRESS is a bit confusing to me here
> (because we later attach both ingress and egress progs); mostly
> because the way attach_tc_prog is written I think. Can we move
> tc_hook definition to attach_tc_prog and make it
> .attach_point=BPF_TC_INGRESS|BPF_TC_EGRESS? And then we can make
> attach_tc_prog accept ifindex instead of tc_hook.
> 
> int attach_tc_prog(int ifindex, igr_fd, egr_fd)
> {
> 	DECLARE_LIBBPF_OPTS(bpf_tc_hook, tc_hook, .attach_point = BPF_TC_INGRESS|BPF_TC_EGRESS);
> 
> 	bpf_tc_hook_create(&tc_hook);
> 	if (igr_fd >= 0) {
> 		tc_hook.attach_point = BPF_TC_INGRESS;
> 		...
> 	}
> 	if (egr_fd >= 0) {
> 		tc_hook.attach_point = BPF_TC_EGRESS;
> 		...
> 	}
> }
> 
> Or is it just me?

I agree with you, it will be better this way. I'll do it in V2.


Best regards,
Bastien