Commit Graph

11 Commits

Author SHA1 Message Date
Jerome Marchand 2e8d9541af selftests/bpf: Correct two typos
JIRA: https://issues.redhat.com/browse/RHEL-10691

commit 856fe03d929205b4c8c8fa51296342cd85592e3f
Author: Lu Hongfei <luhongfei@vivo.com>
Date:   Fri Jul 7 16:12:50 2023 +0800

    selftests/bpf: Correct two typos

    When wrapping code, use ';' better than using ',' which is more in line with
    the coding habits of most engineers.

    Signed-off-by: Lu Hongfei <luhongfei@vivo.com>
    Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
    Acked-by: Hou Tao <houtao1@huawei.com>
    Acked-by: Stanislav Fomichev <sdf@google.com>
    Link: https://lore.kernel.org/bpf/20230707081253.34638-1-luhongfei@vivo.com

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
2023-12-14 15:22:24 +01:00
Artem Savkov 938749c2f6 selftests/bpf: Use ASSERT_EQ instead ASSERT_OK for testing memcmp result
Bugzilla: https://bugzilla.redhat.com/2221599

commit ed01385c0d78a025bdc72128b7aa7c3309cd5852
Author: Martin KaFai Lau <martin.lau@kernel.org>
Date:   Wed Mar 15 17:07:25 2023 -0700

    selftests/bpf: Use ASSERT_EQ instead ASSERT_OK for testing memcmp result
    
    In tcp_hdr_options test, it ensures the received tcp hdr option
    and the sk local storage have the expected values. It uses memcmp
    to check that. Testing the memcmp result with ASSERT_OK is confusing
    because ASSERT_OK will print out the errno which is not set.
    This patch uses ASSERT_EQ to check for 0 instead.
    
    Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
    Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
    Acked-by: Yonghong Song <yhs@fb.com>
    Acked-by: John Fastabend <john.fastabend@gmail.com>
    Link: https://lore.kernel.org/bpf/20230316000726.1016773-1-martin.lau@linux.dev

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2023-09-22 09:12:17 +02:00
Felix Maurer 768f17ebc3 selftests/bpf: Test skops->skb_hwtstamp
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2166911

commit 8cac7a59b252732d8427ebc29c3fc6c36ff653e1
Author: Martin KaFai Lau <martin.lau@kernel.org>
Date:   Mon Nov 7 15:04:20 2022 -0800

    selftests/bpf: Test skops->skb_hwtstamp

    This patch tests reading the skops->skb_hwtstamp field.

    A local test was also done such that the shinfo hwtstamp was temporary
    set to a non zero value in the kernel bpf_skops_parse_hdr()
    and the same value can be read by the skops test.

    An adjustment is needed to the btf_dump selftest because
    the changes in the 'struct bpf_sock_ops'.

    Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Acked-by: Yonghong Song <yhs@fb.com>
    Link: https://lore.kernel.org/bpf/20221107230420.4192307-4-martin.lau@linux.dev

Signed-off-by: Felix Maurer <fmaurer@redhat.com>
2023-03-06 14:54:40 +01:00
Felix Maurer 42ee00a314 selftests/bpf: Fix incorrect ASSERT in the tcp_hdr_options test
Bugzilla: https://bugzilla.redhat.com/2166911

commit 52929912d7bda040b43538e8d88e8d231b76eb4e
Author: Martin KaFai Lau <martin.lau@kernel.org>
Date:   Mon Nov 7 15:04:19 2022 -0800

    selftests/bpf: Fix incorrect ASSERT in the tcp_hdr_options test
    
    This patch fixes the incorrect ASSERT test in tcp_hdr_options during
    the CHECK to ASSERT macro cleanup.
    
    Fixes: 3082f8cd4ba3 ("selftests/bpf: Convert tcp_hdr_options test to ASSERT_* macros")
    Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Acked-by: Wang Yufen <wangyufen@huawei.com>
    Acked-by: Yonghong Song <yhs@fb.com>
    Link: https://lore.kernel.org/bpf/20221107230420.4192307-3-martin.lau@linux.dev

Signed-off-by: Felix Maurer <fmaurer@redhat.com>
2023-03-06 14:54:39 +01:00
Felix Maurer 7c97c2a4af selftests/bpf: Convert tcp_hdr_options test to ASSERT_* macros
Bugzilla: https://bugzilla.redhat.com/2166911

commit 3082f8cd4ba32091be82c19c357ddfd300c5a433
Author: Wang Yufen <wangyufen@huawei.com>
Date:   Mon Sep 26 13:12:08 2022 +0800

    selftests/bpf: Convert tcp_hdr_options test to ASSERT_* macros
    
    Convert the selftest to use the preferred ASSERT_* macros instead of the
    deprecated CHECK().
    
    Signed-off-by: Wang Yufen <wangyufen@huawei.com>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/1664169131-32405-9-git-send-email-wangyufen@huawei.com

Signed-off-by: Felix Maurer <fmaurer@redhat.com>
2023-03-06 14:54:37 +01:00
Artem Savkov 3576fc32b2 selftests/bpf: Deduplicate write_sysctl() to test_progs.c
Bugzilla: https://bugzilla.redhat.com/2166911

commit e42921c3c346b1b49068af3f3881322081e1dddd
Author: YiFei Zhu <zhuyifei@google.com>
Date:   Fri Sep 9 00:49:40 2022 +0000

    selftests/bpf: Deduplicate write_sysctl() to test_progs.c
    
    This helper is needed in multiple tests. Instead of copying it over
    and over, better to deduplicate this helper to test_progs.c.
    
    test_progs.c is chosen over testing_helpers.c because of this helper's
    use of CHECK / ASSERT_*, and the CHECK was modified to use ASSERT_*
    so it does not rely on a duration variable.
    
    Suggested-by: Martin KaFai Lau <kafai@fb.com>
    Signed-off-by: YiFei Zhu <zhuyifei@google.com>
    Link: https://lore.kernel.org/r/9b4fc9a27bd52f771b657b4c4090fc8d61f3a6b5.1662682323.git.zhuyifei@google.com
    Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2023-03-06 14:54:11 +01:00
Andrii Nakryiko bad2e478af selftests/bpf: Turn on libbpf 1.0 mode and fix all IS_ERR checks
Turn ony libbpf 1.0 mode. Fix all the explicit IS_ERR checks that now will be
broken because libbpf returns NULL on error (and sets errno). Fix
ASSERT_OK_PTR and ASSERT_ERR_PTR to work for both old mode and new modes and
use them throughout selftests. This is trivial to do by using
libbpf_get_error() API that all libbpf users are supposed to use, instead of
IS_ERR checks.

A bunch of checks also did explicit -1 comparison for various fd-returning
APIs. Such checks are replaced with >= 0 or < 0 cases.

There were also few misuses of bpf_object__find_map_by_name() in test_maps.
Those are fixed in this patch as well.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>
Link: https://lore.kernel.org/bpf/20210525035935.1461796-3-andrii@kernel.org
2021-05-25 17:32:35 -07:00
Martin KaFai Lau f52b8fd332 bpf: selftest: Use static globals in tcp_hdr_options and btf_skc_cls_ingress
Some globals in the tcp_hdr_options test and btf_skc_cls_ingress test
are not using static scope.  This patch fixes it.

Targeting bpf-next branch as an improvement since it currently does not
break the build.

Fixes: ad2f8eb009 ("bpf: selftests: Tcp header options")
Fixes: 9a856cae22 ("bpf: selftest: Add test_btf_skc_cls_ingress")
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20201106225402.4135741-1-kafai@fb.com
2020-11-09 16:18:36 -08:00
Martin KaFai Lau 8a3feed90e bpf, selftest: Fix flaky tcp_hdr_options test when adding addr to lo
The tcp_hdr_options test adds a "::eB9F" addr to the lo dev.
However, this non loopback address will have a race on ipv6 dad
which may lead to EADDRNOTAVAIL error from time to time.

Even nodad is used in the iproute2 command, there is still a race in
when the route will be added.  This will then lead to ENETUNREACH from
time to time.

To avoid the above, this patch uses the default loopback address "::1"
to do the test.

Fixes: ad2f8eb009 ("bpf: selftests: Tcp header options")
Reported-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20201012234940.1707941-1-kafai@fb.com
2020-10-15 20:53:15 +02:00
Martin KaFai Lau 96d46c5085 bpf: selftest: Ensure the child sk inherited all bpf_sock_ops_cb_flags
This patch adds a test to ensure the child sk inherited everything
from the bpf_sock_ops_cb_flags of the listen sk:
1. Sets one more cb_flags (BPF_SOCK_OPS_STATE_CB_FLAG) to the listen sk
   in test_tcp_hdr_options.c
2. Saves the skops->bpf_sock_ops_cb_flags when handling the newly
   established passive connection
3. CHECK() it is the same as the listen sk

This also covers the fastopen case as the existing test_tcp_hdr_options.c
does.

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20201002013454.2542367-1-kafai@fb.com
2020-10-02 11:34:48 -07:00
Martin KaFai Lau ad2f8eb009 bpf: selftests: Tcp header options
This patch adds tests for the new bpf tcp header option feature.

test_tcp_hdr_options.c:
- It tests header option writing and parsing in 3WHS: regular
  connection establishment, fastopen, and syncookie.
- In syncookie, the passive side's bpf prog is asking the active side
  to resend its bpf header option by specifying a RESEND bit in the
  outgoing SYNACK. handle_active_estab() and write_nodata_opt() has
  some details.
- handle_passive_estab() has comments on fastopen.
- It also has test for header writing and parsing in FIN packet.
- Most of the tests is writing an experimental option 254 with magic 0xeB9F.
- The no_exprm_estab() also tests writing a regular TCP option
  without any magic.

test_misc_tcp_options.c:
- It is an one directional test.  Active side writes option and
  passive side parses option.  The focus is to exercise
  the new helpers and API.
- Testing the new helper: bpf_load_hdr_opt() and bpf_store_hdr_opt().
- Testing the bpf_getsockopt(TCP_BPF_SYN).
- Negative tests for the above helpers.
- Testing the sock_ops->skb_data.

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200820190117.2886749-1-kafai@fb.com
2020-08-24 14:35:00 -07:00