Commit Graph

11 Commits

Author SHA1 Message Date
Artem Savkov fbd9cfcd5b selftests/bpf: Store BPF object files with .bpf.o extension
Bugzilla: https://bugzilla.redhat.com/2166911

commit afef88e65554c3e8691513b8350d6445e292560e
Author: Daniel Müller <deso@posteo.net>
Date:   Thu Sep 1 22:22:53 2022 +0000

    selftests/bpf: Store BPF object files with .bpf.o extension
    
    BPF object files are, in a way, the final artifact produced as part of
    the ahead-of-time compilation process. That makes them somewhat special
    compared to "regular" object files, which are a intermediate build
    artifacts that can typically be removed safely. As such, it can make
    sense to name them differently to make it easier to spot this difference
    at a glance.
    
    Among others, libbpf-bootstrap [0] has established the extension .bpf.o
    for BPF object files. It seems reasonable to follow this example and
    establish the same denomination for selftest build artifacts. To that
    end, this change adjusts the corresponding part of the build system and
    the test programs loading BPF object files to work with .bpf.o files.
    
      [0] https://github.com/libbpf/libbpf-bootstrap
    
    Suggested-by: Andrii Nakryiko <andrii@kernel.org>
    Signed-off-by: Daniel Müller <deso@posteo.net>
    Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
    Link: https://lore.kernel.org/bpf/20220901222253.1199242-1-deso@posteo.net

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2023-03-06 14:54:06 +01:00
Yauheni Kaliuta c36a904150 selftests/bpf: Use libbpf 1.0 API mode instead of RLIMIT_MEMLOCK
Bugzilla: https://bugzilla.redhat.com/2120968

commit b858ba8c52b64c038de156c455a39a89bfd214e8
Author: Yafang Shao <laoar.shao@gmail.com>
Date:   Sat Apr 9 12:59:56 2022 +0000

    selftests/bpf: Use libbpf 1.0 API mode instead of RLIMIT_MEMLOCK
    
    We have switched to memcg-based memory accouting and thus the rlimit is
    not needed any more. LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK was introduced in
    libbpf for backward compatibility, so we can use it instead now. After
    this change, the header tools/testing/selftests/bpf/bpf_rlimit.h can be
    removed.
    
    This patch also removes the useless header sys/resource.h from many files
    in tools/testing/selftests/bpf/.
    
    Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/20220409125958.92629-3-laoar.shao@gmail.com

Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
2022-11-28 16:48:58 +02:00
Artem Savkov 07caccf2d8 selftests/bpf: Migrate all deprecated perf_buffer uses
Bugzilla: https://bugzilla.redhat.com/2069046

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

commit 0b52a5f4b994c05070237271c7fac3265b640ffb
Author: Andrii Nakryiko <andrii@kernel.org>
Date:   Wed Nov 10 21:36:21 2021 -0800

    selftests/bpf: Migrate all deprecated perf_buffer uses

    Migrate all old-style perf_buffer__new() and perf_buffer__new_raw()
    calls to new v1.0+ variants.

    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>
    Link: https://lore.kernel.org/bpf/20211111053624.190580-7-andrii@kernel.org

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2022-08-24 12:53:35 +02:00
Artem Savkov 15a59583f8 selftests/bpf: Use explicit bpf_prog_test_load() calls everywhere
Bugzilla: https://bugzilla.redhat.com/2069046

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

commit cbdb1461dcf45765a036e9f6975ffe19e69bdc33
Author: Andrii Nakryiko <andrii@kernel.org>
Date:   Wed Nov 3 15:08:44 2021 -0700

    selftests/bpf: Use explicit bpf_prog_test_load() calls everywhere

    -Dbpf_prog_load_deprecated=bpf_prog_test_load trick is both ugly and
    breaks when deprecation goes into effect due to macro magic. Convert all
    the uses to explicit bpf_prog_test_load() calls which avoid deprecation
    errors and makes everything less magical.

    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>
    Acked-by: Dave Marchevsky <davemarchevsky@fb.com>
    Link: https://lore.kernel.org/bpf/20211103220845.2676888-12-andrii@kernel.org

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2022-08-24 12:53:33 +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
Jianlin Lv 929e54a989 bpf: Fix compilation warning of selftests
Clang compiler version: 12.0.0
The following warning appears during the selftests/bpf compilation:

prog_tests/send_signal.c:51:3: warning: ignoring return value of ‘write’,
declared with attribute warn_unused_result [-Wunused-result]
   51 |   write(pipe_c2p[1], buf, 1);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~
prog_tests/send_signal.c:54:3: warning: ignoring return value of ‘read’,
declared with attribute warn_unused_result [-Wunused-result]
   54 |   read(pipe_p2c[0], buf, 1);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~
......

prog_tests/stacktrace_build_id_nmi.c:13:2: warning: ignoring return value
of ‘fscanf’,declared with attribute warn_unused_result [-Wunused-resul]
   13 |  fscanf(f, "%llu", &sample_freq);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

test_tcpnotify_user.c:133:2: warning:ignoring return value of ‘system’,
declared with attribute warn_unused_result [-Wunused-result]
  133 |  system(test_script);
      |  ^~~~~~~~~~~~~~~~~~~
test_tcpnotify_user.c:138:2: warning:ignoring return value of ‘system’,
declared with attribute warn_unused_result [-Wunused-result]
  138 |  system(test_script);
      |  ^~~~~~~~~~~~~~~~~~~
test_tcpnotify_user.c:143:2: warning:ignoring return value of ‘system’,
declared with attribute warn_unused_result [-Wunused-result]
  143 |  system(test_script);
      |  ^~~~~~~~~~~~~~~~~~~

Add code that fix compilation warning about ignoring return value and
handles any errors; Check return value of library`s API make the code
more secure.

Signed-off-by: Jianlin Lv <Jianlin.Lv@arm.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200806104224.95306-1-Jianlin.Lv@arm.com
2020-08-06 16:58:42 -07:00
John Fastabend 4939b2847d bpf, selftests: Use single cgroup helpers for both test_sockmap/progs
Nearly every user of cgroup helpers does the same sequence of API calls. So
push these into a single helper cgroup_setup_and_join. The cases that do
a bit of extra logic are test_progs which currently uses an env variable
to decide if it needs to setup the cgroup environment or can use an
existingi environment. And then tests that are doing cgroup tests
themselves. We skip these cases for now.

Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/159623335418.30208.15807461815525100199.stgit@john-XPS-13-9370
2020-08-01 20:20:59 -07:00
Andrii Nakryiko 898ca681cd selftests/bpf: switch test_tcpnotify to perf_buffer API
Switch test_tcpnotify test to use libbpf's perf_buffer API instead of
re-implementing portion of it.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-23 16:05:42 -07:00
Stanislav Fomichev bbebce8eb9 selftests/bpf: don't hardcode iptables/nc path in test_tcpnotify_user
system() is calling shell which should find the appropriate full path
via $PATH. On some systems, full path to iptables and/or nc might be
different that we one we have hardcoded.

Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-01-23 12:56:30 +01:00
Stanislav Fomichev a8911d6d58 selftests/bpf: fix incorrect users of create_and_get_cgroup
We have some tests that assume create_and_get_cgroup returns -1 on error
which is incorrect (it returns 0 on error). Since fd might be zero in
general case, change create_and_get_cgroup to return -1 on error
and fix the users that assume 0 on error.

Fixes: f269099a7e ("tools/bpf: add a selftest for bpf_get_current_cgroup_id() helper")
Fixes: 7d2c6cfc54 ("bpf: use --cgroup in test_suite if supplied")

v2:
- instead of fixing the uses that assume -1 on error, convert the users
  that assume 0 on error (fd might be zero in general case)

Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-01-07 13:15:55 -08:00
Sowmini Varadhan 435f90a338 selftests/bpf: add a test case for sock_ops perf-event notification
This patch provides a tcp_bpf based eBPF sample. The test

- ncat(1) as the TCP client program to connect() to a port
  with the intention of triggerring SYN retransmissions: we
  first install an iptables DROP rule to make sure ncat SYNs are
  resent (instead of aborting instantly after a TCP RST)

- has a bpf kernel module that sends a perf-event notification for
  each TCP retransmit, and also tracks the number of such notifications
  sent in the global_map

The test passes when the number of event notifications intercepted
in user-space matches the value in the global_map.

Signed-off-by: Sowmini Varadhan <sowmini.varadhan@oracle.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2018-11-09 09:40:17 +01:00