Commit Graph

9 Commits

Author SHA1 Message Date
Artem Savkov de45ca5271 selftests/bpf: Add tests for ring_buffer__ring
JIRA: https://issues.redhat.com/browse/RHEL-23643

commit c1ad2e47f97c6d95e52be0c2a68b23fc99214734
Author: Martin Kelly <martin.kelly@crowdstrike.com>
Date:   Mon Sep 25 14:50:35 2023 -0700

    selftests/bpf: Add tests for ring_buffer__ring
    
    Add tests for the new API ring_buffer__ring.
    
    Signed-off-by: Martin Kelly <martin.kelly@crowdstrike.com>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/20230925215045.2375758-5-martin.kelly@crowdstrike.com

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2024-03-27 10:27:50 +01:00
Artem Savkov 10a9d3be28 selftests/bpf: test eager BPF ringbuf size adjustment logic
Bugzilla: https://bugzilla.redhat.com/2137876

commit e134601961fef4516df9413b270fb96ef6d034bc
Author: Andrii Nakryiko <andrii@kernel.org>
Date:   Fri Jul 15 16:09:52 2022 -0700

    selftests/bpf: test eager BPF ringbuf size adjustment logic
    
    Add test validating that libbpf adjusts (and reflects adjusted) ringbuf
    size early, before bpf_object is loaded. Also make sure we can't
    successfully resize ringbuf map after bpf_object is loaded.
    
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Acked-by: Yonghong Song <yhs@fb.com>
    Link: https://lore.kernel.org/r/20220715230952.2219271-2-andrii@kernel.org
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2023-01-05 15:46:41 +01:00
Yauheni Kaliuta b04e893128 selftests/bpf: Test libbpf's ringbuf size fix up logic
Bugzilla: https://bugzilla.redhat.com/2120968

commit 7b3a06382442c4d83c9d35253638cb3f561da9b9
Author: Andrii Nakryiko <andrii@kernel.org>
Date:   Sun May 8 17:41:48 2022 -0700

    selftests/bpf: Test libbpf's ringbuf size fix up logic
    
    Make sure we always excercise libbpf's ringbuf map size adjustment logic
    by specifying non-zero size that's definitely not a page size multiple.
    
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
    Link: https://lore.kernel.org/bpf/20220509004148.1801791-10-andrii@kernel.org

Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
2022-11-30 12:47:02 +02:00
Artem Savkov 91c8c1ff60 selftests/bpf: Migrate selftests to bpf_map_create()
Bugzilla: https://bugzilla.redhat.com/2069046

Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit 2fe256a429cb6c0b0064563af4158470143a363c
Author: Andrii Nakryiko <andrii@kernel.org>
Date:   Wed Nov 24 11:32:33 2021 -0800

    selftests/bpf: Migrate selftests to bpf_map_create()

    Conversion is straightforward for most cases. In few cases tests are
    using mutable map_flags and attribute structs, but bpf_map_create_opts
    can be used in the similar fashion, so there were no problems. Just lots
    of repetitive conversions.

    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
    Link: https://lore.kernel.org/bpf/20211124193233.3115996-5-andrii@kernel.org

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2022-08-24 12:53:40 +02: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
Yauheni Kaliuta cfc0889ceb selftests/bpf: ringbuf_multi: Test bpf_map__set_inner_map_fd
Test map__set_inner_map_fd() interaction with map-in-map
initialization. Use hashmap of maps just to make it different to
existing array of maps.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210408061310.95877-9-yauheni.kaliuta@redhat.com
2021-04-08 23:54:48 -07:00
Yauheni Kaliuta f3f4c23e12 selftests/bpf: ringbuf_multi: Use runtime page size
Set bpf table sizes dynamically according to the runtime page size
value.

Do not switch to ASSERT macros, keep CHECK, for consistency with the
rest of the test. Can be a separate cleanup patch.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210408061310.95877-8-yauheni.kaliuta@redhat.com
2021-04-08 23:54:48 -07:00
Andrii Nakryiko f6a8250ea1 libbpf: Fix ring_buffer__poll() to return number of consumed samples
Fix ring_buffer__poll() to return the number of non-discarded records
consumed, just like its documentation states. It's also consistent with
ring_buffer__consume() return. Fix up selftests with wrong expected results.

Fixes: bf99c936f9 ("libbpf: Add BPF ring buffer support")
Fixes: cb1c9ddd55 ("selftests/bpf: Add BPF ringbuf selftests")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20201130223336.904192-1-andrii@kernel.org
2020-12-01 20:21:45 -08:00
Andrii Nakryiko cb1c9ddd55 selftests/bpf: Add BPF ringbuf selftests
Both singleton BPF ringbuf and BPF ringbuf with map-in-map use cases are tested.
Also reserve+submit/discards and output variants of API are validated.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20200529075424.3139988-4-andriin@fb.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2020-06-01 14:38:22 -07:00