Commit Graph

28 Commits

Author SHA1 Message Date
Jerome Marchand 5ae639adc1 selftests/bpf: Provide a generic [un]load_module helper
JIRA: https://issues.redhat.com/browse/RHEL-63880

commit 4192bb294f80928bc2257c7a2ff6c86a27de6807
Author: Simon Sundberg <simon.sundberg@kau.se>
Date:   Thu Oct 10 15:27:08 2024 +0200

    selftests/bpf: Provide a generic [un]load_module helper

    Generalize the previous [un]load_bpf_testmod() helpers (in
    testing_helpers.c) to the more generic [un]load_module(), which can
    load an arbitrary kernel module by name. This allows future selftests
    to more easily load custom kernel modules other than bpf_testmod.ko.
    Refactor [un]load_bpf_testmod() to wrap this new helper.

    Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
    Acked-by: Jiri Olsa <jolsa@kernel.org>
    Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
    Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
    Link: https://lore.kernel.org/r/20241010-fix-kfunc-btf-caching-for-modules-v2-2-745af6c1af98@redhat.com
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
2025-01-21 11:27:08 +01:00
Jerome Marchand 294f30b236 selftests/bpf: Fix arg parsing in veristat, test_progs
JIRA: https://issues.redhat.com/browse/RHEL-63880

commit 03bfcda1fbc37ef34aa21d2b9e09138335afc6ee
Author: Tony Ambardar <tony.ambardar@gmail.com>
Date:   Mon Jul 29 02:24:18 2024 -0700

    selftests/bpf: Fix arg parsing in veristat, test_progs

    Current code parses arguments with strtok_r() using a construct like

        char *state = NULL;
        while ((next = strtok_r(state ? NULL : input, ",", &state))) {
            ...
        }

    where logic assumes the 'state' var can distinguish between first and
    subsequent strtok_r() calls, and adjusts parameters accordingly. However,
    'state' is strictly internal context for strtok_r() and no such assumptions
    are supported in the man page. Moreover, the exact behaviour of 'state'
    depends on the libc implementation, making the above code fragile.

    Indeed, invoking "./test_progs -t <test_name>" on mips64el/musl will hang,
    with the above code in an infinite loop.

    Similarly, we see strange behaviour running 'veristat' on mips64el/musl:

        $ ./veristat -e file,prog,verdict,insns -C two-ok add-failure
        Can't specify more than 9 stats

    Rewrite code using a counter to distinguish between strtok_r() calls.

    Fixes: 61ddff373ffa ("selftests/bpf: Improve by-name subtest selection logic in prog_tests")
    Fixes: 394169b079b5 ("selftests/bpf: add comparison mode to veristat")
    Fixes: c8bc5e050976 ("selftests/bpf: Add veristat tool for mass-verifying BPF object files")
    Signed-off-by: Tony Ambardar <tony.ambardar@gmail.com>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/392d8bf5559f85fa37926c1494e62312ef252c3d.1722244708.git.tony.ambardar@gmail.com

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
2025-01-13 17:36:36 +01:00
Jerome Marchand 4c24993512 selftests/bpf: extract utility function for BPF disassembly
JIRA: https://issues.redhat.com/browse/RHEL-63880

Conflicts:
Context change due to missing commit 51f1892b5289 ("selftests/bpf: Add
netlink helper library") that rearrange the list of
TRUNNER_EXTRA_SOURCES files in the Makefile. I change the list so that
it conforms to upstream format.

commit 424ebaa3678b0d7f653dffb08eae90424740e0f4
Author: Eduard Zingerman <eddyz87@gmail.com>
Date:   Mon Jul 22 16:38:38 2024 -0700

    selftests/bpf: extract utility function for BPF disassembly

    struct bpf_insn *disasm_insn(struct bpf_insn *insn, char *buf, size_t buf_sz);

      Disassembles instruction 'insn' to a text buffer 'buf'.
      Removes insn->code hex prefix added by kernel disassembly routine.
      Returns a pointer to the next instruction
      (increments insn by either 1 or 2).

    Acked-by: Andrii Nakryiko <andrii@kernel.org>
    Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
    Link: https://lore.kernel.org/r/20240722233844.1406874-5-eddyz87@gmail.com
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
2025-01-13 17:36:34 +01:00
Viktor Malik bbdd64f2db
selftests/bpf: Fix wq test.
JIRA: https://issues.redhat.com/browse/RHEL-30773

commit 82e38a505c9868e784ec31e743fd8a9fa5ca1084
Author: Alexei Starovoitov <ast@kernel.org>
Date:   Wed Apr 24 13:57:18 2024 -0700

    selftests/bpf: Fix wq test.
    
    The wq test was missing destroy(skel) part which was causing bpf progs to stay
    loaded. That was causing test_progs to complain with
    "Failed to unload bpf_testmod.ko from kernel: -11" message, but adding
    destroy() wasn't enough, since wq callback may be delayed, so loop on unload of
    bpf_testmod if errno is EAGAIN.
    
    Acked-by: Andrii Nakryiko <andrii@kernel.org>
    Fixes: 8290dba51910 ("selftests/bpf: wq: add bpf_wq_start() checks")
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2024-11-11 07:44:52 +01:00
Jerome Marchand b0b314470a selftests/bpf: Fix incorrect parameters in NULL pointer checking
JIRA: https://issues.redhat.com/browse/RHEL-23649

commit c264487e5410e5a72db8a414566ab7d144223e6c
Author: Hao Ge <gehao@kylinos.cn>
Date:   Tue Aug 20 10:36:22 2024 +0800

    selftests/bpf: Fix incorrect parameters in NULL pointer checking

    Smatch reported the following warning:
        ./tools/testing/selftests/bpf/testing_helpers.c:455 get_xlated_program()
        warn: variable dereferenced before check 'buf' (see line 454)

    It seems correct,so let's modify it based on it's suggestion.

    Actually,commit b23ed4d74c4d ("selftests/bpf: Fix invalid pointer
    check in get_xlated_program()") fixed an issue in the test_verifier.c
    once,but it was reverted this time.

    Let's solve this issue with the minimal changes possible.

    Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
    Closes: https://lore.kernel.org/all/1eb3732f-605a-479d-ba64-cd14250cbf91@stanley.mountain/
    Fixes: b4b7a4099b8c ("selftests/bpf: Factor out get_xlated_program() helper")
    Signed-off-by: Hao Ge <gehao@kylinos.cn>
    Link: https://lore.kernel.org/r/20240820023622.29190-1-hao.ge@linux.dev
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
2024-10-15 10:49:18 +02:00
Jerome Marchand 05b622234d selftests/bpf: Test case for lacking CFI stub functions.
JIRA: https://issues.redhat.com/browse/RHEL-23649

Conflicts: Context change due to missing commit c313eae739b9a ("bpf:
selftests: Add defrag selftests")

commit e9bbda13a7b876451285ab15fb600b809e5e2290
Author: Kui-Feng Lee <thinker.li@gmail.com>
Date:   Wed Feb 21 18:11:05 2024 -0800

    selftests/bpf: Test case for lacking CFI stub functions.

    Ensure struct_ops rejects the registration of struct_ops types without
    proper CFI stub functions.

    bpf_test_no_cfi.ko is a module that attempts to register a struct_ops type
    called "bpf_test_no_cfi_ops" with cfi_stubs of NULL and non-NULL value.
    The NULL one should fail, and the non-NULL one should succeed. The module
    can only be loaded successfully if these registrations yield the expected
    results.

    Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com>
    Link: https://lore.kernel.org/r/20240222021105.1180475-3-thinker.li@gmail.com
    Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
2024-10-15 10:49:11 +02:00
Jerome Marchand 0d221c5639 selftests/bpf: Move is_jit_enabled() into testing_helpers
JIRA: https://issues.redhat.com/browse/RHEL-23649

commit 15b4f88dcc0a751f790bfea5ef9dcc6385c62236
Author: Tiezhu Yang <yangtiezhu@loongson.cn>
Date:   Tue Jan 23 17:03:50 2024 +0800

    selftests/bpf: Move is_jit_enabled() into testing_helpers

    Currently, is_jit_enabled() is only used in test_progs, move it into
    testing_helpers so that it can be used in test_verifier. While at it,
    remove the second argument "0" of open() as Hou Tao suggested.

    Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Acked-by: Hou Tao <houtao1@huawei.com>
    Acked-by: Song Liu <song@kernel.org>
    Link: https://lore.kernel.org/bpf/20240123090351.2207-2-yangtiezhu@loongson.cn

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
2024-10-15 10:49:02 +02:00
Jerome Marchand 2e970feb23 selftests/bpf: detect testing prog flags support
JIRA: https://issues.redhat.com/browse/RHEL-23649

commit 56d3e44af80c6b4c7cb89a73061ee35d4a7aee18
Author: Andrii Nakryiko <andrii@kernel.org>
Date:   Tue Jan 9 15:17:38 2024 -0800

    selftests/bpf: detect testing prog flags support

    Various tests specify extra testing prog_flags when loading BPF
    programs, like BPF_F_TEST_RND_HI32, and more recently also
    BPF_F_TEST_REG_INVARIANTS. While BPF_F_TEST_RND_HI32 is old enough to
    not cause much problem on older kernels, BPF_F_TEST_REG_INVARIANTS is
    very fresh and unconditionally specifying it causes selftests to fail on
    even slightly outdated kernels.

    This breaks libbpf CI test against 4.9 and 5.15 kernels, it can break
    some local development (done outside of VM), etc.

    To prevent this, and guard against similar problems in the future, do
    runtime detection of supported "testing flags", and only provide those
    that host kernel recognizes.

    Acked-by: Song Liu <song@kernel.org>
    Acked-by: Jiri Olsa <jolsa@kernel.org>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/r/20240109231738.575844-1-andrii@kernel.org
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
2024-10-15 10:48:59 +02:00
Jerome Marchand 245de41b94 selftests/bpf: Factor out get_xlated_program() helper
JIRA: https://issues.redhat.com/browse/RHEL-23649

commit b4b7a4099b8ccea224577003fcf9d321bf0817b7
Author: Hou Tao <houtao1@huawei.com>
Date:   Fri Jan 5 18:48:18 2024 +0800

    selftests/bpf: Factor out get_xlated_program() helper

    Both test_verifier and test_progs use get_xlated_program(), so moving
    the helper into testing_helpers.h to reuse it.

    Acked-by: Eduard Zingerman <eddyz87@gmail.com>
    Signed-off-by: Hou Tao <houtao1@huawei.com>
    Link: https://lore.kernel.org/r/20240105104819.3916743-3-houtao@huaweicloud.com
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
2024-10-15 10:48:58 +02:00
Viktor Malik 20f6073121
bpf: rename BPF_F_TEST_SANITY_STRICT to BPF_F_TEST_REG_INVARIANTS
JIRA: https://issues.redhat.com/browse/RHEL-23644

commit ff8867af01daa7ea770bebf5f91199b7434b74e5
Author: Andrii Nakryiko <andrii@kernel.org>
Date:   Fri Nov 17 09:14:04 2023 -0800

    bpf: rename BPF_F_TEST_SANITY_STRICT to BPF_F_TEST_REG_INVARIANTS
    
    Rename verifier internal flag BPF_F_TEST_SANITY_STRICT to more neutral
    BPF_F_TEST_REG_INVARIANTS. This is a follow up to [0].
    
    A few selftests and veristat need to be adjusted in the same patch as
    well.
    
      [0] https://patchwork.kernel.org/project/netdevbpf/patch/20231112010609.848406-5-andrii@kernel.org/
    
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/r/20231117171404.225508-1-andrii@kernel.org
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2024-06-25 10:51:50 +02:00
Viktor Malik 5b45207906
selftests/bpf: set BPF_F_TEST_SANITY_SCRIPT by default
JIRA: https://issues.redhat.com/browse/RHEL-23644

commit 8c5677f8b31e92b57be7d5d0fbb1ac66eedf4f91
Author: Andrii Nakryiko <andrii@kernel.org>
Date:   Sat Nov 11 17:06:07 2023 -0800

    selftests/bpf: set BPF_F_TEST_SANITY_SCRIPT by default
    
    Make sure to set BPF_F_TEST_SANITY_STRICT program flag by default across
    most verifier tests (and a bunch of others that set custom prog flags).
    
    There are currently two tests that do fail validation, if enforced
    strictly: verifier_bounds/crossing_64_bit_signed_boundary_2 and
    verifier_bounds/crossing_32_bit_signed_boundary_2. To accommodate them,
    we teach test_loader a flag negation:
    
    __flag(!<flagname>) will *clear* specified flag, allowing easy opt-out.
    
    We apply __flag(!BPF_F_TEST_SANITY_STRICT) to these to tests.
    
    Also sprinkle BPF_F_TEST_SANITY_STRICT everywhere where we already set
    test-only BPF_F_TEST_RND_HI32 flag, for completeness.
    
    Acked-by: Eduard Zingerman <eddyz87@gmail.com>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/r/20231112010609.848406-12-andrii@kernel.org
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2024-06-25 10:51:49 +02:00
Viktor Malik 499cb041c5
selftests/bpf: Use un/load_bpf_testmod functions in tests
JIRA: https://issues.redhat.com/browse/RHEL-9957

commit 11642eb92b3bc67171b23abff0d062758c5a4730
Author: Jiri Olsa <jolsa@kernel.org>
Date:   Mon May 15 15:37:52 2023 +0200

    selftests/bpf: Use un/load_bpf_testmod functions in tests
    
    Now that we have un/load_bpf_testmod helpers in testing_helpers.h,
    we can use it in other tests and save some lines.
    
    Acked-by: David Vernet <void@manifault.com>
    Signed-off-by: Jiri Olsa <jolsa@kernel.org>
    Link: https://lore.kernel.org/r/20230515133756.1658301-7-jolsa@kernel.org
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2023-10-12 11:41:07 +02:00
Viktor Malik e08ff85383
selftests/bpf: Do not unload bpf_testmod in load_bpf_testmod
JIRA: https://issues.redhat.com/browse/RHEL-9957

commit b58f3f0e6f3cbea56be39d8fb190b37f049505bb
Author: Jiri Olsa <jolsa@kernel.org>
Date:   Mon May 15 15:37:51 2023 +0200

    selftests/bpf: Do not unload bpf_testmod in load_bpf_testmod
    
    Do not unload bpf_testmod in load_bpf_testmod, instead call
    unload_bpf_testmod separatelly.
    
    This way we will be able use un/load_bpf_testmod functions
    in other tests that un/load bpf_testmod module.
    
    Acked-by: David Vernet <void@manifault.com>
    Signed-off-by: Jiri Olsa <jolsa@kernel.org>
    Link: https://lore.kernel.org/r/20230515133756.1658301-6-jolsa@kernel.org
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2023-10-12 11:41:06 +02:00
Viktor Malik 6c14a9977a
selftests/bpf: Use only stdout in un/load_bpf_testmod functions
JIRA: https://issues.redhat.com/browse/RHEL-9957

commit d18decca69e36480247a73086336f4a44a08e36f
Author: Jiri Olsa <jolsa@kernel.org>
Date:   Mon May 15 15:37:50 2023 +0200

    selftests/bpf: Use only stdout in un/load_bpf_testmod functions
    
    We are about to use un/load_bpf_testmod functions in couple tests
    and it's better  to print output to stdout,  so it's aligned with
    tests ASSERT macros output, which use stdout as well.
    
    Acked-by: David Vernet <void@manifault.com>
    Signed-off-by: Jiri Olsa <jolsa@kernel.org>
    Link: https://lore.kernel.org/r/20230515133756.1658301-5-jolsa@kernel.org
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2023-10-12 11:41:06 +02:00
Viktor Malik bca517d785
selftests/bpf: Move test_progs helpers to testing_helpers object
JIRA: https://issues.redhat.com/browse/RHEL-9957

commit 45db310984bfea977177fb5fc0ea23ab430129bd
Author: Jiri Olsa <jolsa@kernel.org>
Date:   Mon May 15 15:37:49 2023 +0200

    selftests/bpf: Move test_progs helpers to testing_helpers object
    
    Moving test_progs helpers to testing_helpers object so they can be
    used from test_verifier in following changes.
    
    Also adding missing ifndef header guard to testing_helpers.h header.
    
    Using stderr instead of env.stderr because un/load_bpf_testmod helpers
    will be used outside test_progs. Also at the point of calling them
    in test_progs the std files are not hijacked yet and stderr is the
    same as env.stderr.
    
    Acked-by: David Vernet <void@manifault.com>
    Signed-off-by: Jiri Olsa <jolsa@kernel.org>
    Link: https://lore.kernel.org/r/20230515133756.1658301-4-jolsa@kernel.org
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2023-10-12 11:41:06 +02:00
Viktor Malik 70fdb28d14
selftests/bpf: Test_progs can read test lists from file
JIRA: https://issues.redhat.com/browse/RHEL-9957

commit 64276f01dce85f72853617e513622b5645497d81
Author: Stephen Veiss <sveiss@meta.com>
Date:   Thu Apr 27 15:53:33 2023 -0700

    selftests/bpf: Test_progs can read test lists from file
    
    Improve test selection logic when using -a/-b/-d/-t options.
    The list of tests to include or exclude can now be read from a file,
    specified as @<filename>.
    
    The file contains one name (or wildcard pattern) per line, and
    comments beginning with # are ignored.
    
    These options can be passed multiple times to read more than one file.
    
    Signed-off-by: Stephen Veiss <sveiss@meta.com>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Acked-by: Yonghong Song <yhs@fb.com>
    Link: https://lore.kernel.org/bpf/20230427225333.3506052-3-sveiss@meta.com

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2023-10-12 11:40:56 +02:00
Viktor Malik 08e500b522
selftests/bpf: Extract insert_test from parse_test_list
JIRA: https://issues.redhat.com/browse/RHEL-9957

commit 0a5c0de8b66f9789422f04de7304e374a2ea8df5
Author: Stephen Veiss <sveiss@meta.com>
Date:   Thu Apr 27 15:53:32 2023 -0700

    selftests/bpf: Extract insert_test from parse_test_list
    
    Split the logic to insert new tests into test filter sets out from
    parse_test_list.
    
    Fix the subtest insertion logic to reuse an existing top-level test
    filter, which prevents the creation of duplicate top-level test filters
    each with a single subtest.
    
    Signed-off-by: Stephen Veiss <sveiss@meta.com>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Acked-by: Yonghong Song <yhs@fb.com>
    Link: https://lore.kernel.org/bpf/20230427225333.3506052-2-sveiss@meta.com

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2023-10-12 11:40:55 +02:00
Artem Savkov 8ecb9b65b0 selftests/bpf: Use read_perf_max_sample_freq() in perf_event_stackmap
Bugzilla: https://bugzilla.redhat.com/2221599

commit de6d014a09bf12a9a8959d60c0a1d4a41d394a89
Author: Song Liu <song@kernel.org>
Date:   Wed Apr 12 14:04:21 2023 -0700

    selftests/bpf: Use read_perf_max_sample_freq() in perf_event_stackmap
    
    Currently, perf_event sample period in perf_event_stackmap is set too low
    that the test fails randomly. Fix this by using the max sample frequency,
    from read_perf_max_sample_freq().
    
    Move read_perf_max_sample_freq() to testing_helpers.c. Replace the CHECK()
    with if-printf, as CHECK is not available in testing_helpers.c.
    
    Fixes: 1da4864c2b ("selftests/bpf: Add callchain_stackid")
    Signed-off-by: Song Liu <song@kernel.org>
    Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
    Link: https://lore.kernel.org/bpf/20230412210423.900851-2-song@kernel.org

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2023-09-22 09:12:29 +02:00
Artem Savkov c2142f3b4c libbpf: disassociate section handler on explicit bpf_program__set_type() call
Bugzilla: https://bugzilla.redhat.com/2221599

commit d6e6286a12e7b8a4ddc66237c4ccf6f531ef1c82
Author: Andrii Nakryiko <andrii@kernel.org>
Date:   Mon Mar 27 11:52:00 2023 -0700

    libbpf: disassociate section handler on explicit bpf_program__set_type() call
    
    If user explicitly overrides programs's type with
    bpf_program__set_type() API call, we need to disassociate whatever
    SEC_DEF handler libbpf determined initially based on program's SEC()
    definition, as it's not goind to be valid anymore and could lead to
    crashes and/or confusing failures.
    
    Also, fix up bpf_prog_test_load() helper in selftests/bpf, which is
    force-setting program type (even if that's completely unnecessary; this
    is quite a legacy piece of code), and thus should expect auto-attach to
    not work, yet one of the tests explicitly relies on auto-attach for
    testing.
    
    Instead, force-set program type only if it differs from the desired one.
    
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/r/20230327185202.1929145-2-andrii@kernel.org
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2023-09-22 09:12:24 +02:00
Viktor Malik 7a4a8ac4be selftests/bpf: Use bpf_{btf,link,map,prog}_get_info_by_fd()
Bugzilla: https://bugzilla.redhat.com/2178930

commit c5a237a4db21ca7a28518c994def39d7bd62a0d1
Author: Ilya Leoshkevich <iii@linux.ibm.com>
Date:   Wed Feb 15 00:12:18 2023 +0100

    selftests/bpf: Use bpf_{btf,link,map,prog}_get_info_by_fd()
    
    Use the new type-safe wrappers around bpf_obj_get_info_by_fd().
    Fix a prog/map mixup in prog_holds_map().
    
    Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/20230214231221.249277-6-iii@linux.ibm.com

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2023-06-13 22:45:39 +02:00
Yauheni Kaliuta 7a1e191693 selftests/bpf: Improve by-name subtest selection logic in prog_tests
Bugzilla: https://bugzilla.redhat.com/2120968

commit 61ddff373ffa843155eba6a507973b1b78bb5a14
Author: Mykola Lysenko <mykolal@fb.com>
Date:   Fri Apr 8 17:17:49 2022 -0700

    selftests/bpf: Improve by-name subtest selection logic in prog_tests
    
    Improve subtest selection logic when using -t/-a/-d parameters.
    In particular, more than one subtest can be specified or a
    combination of tests / subtests.
    
    -a send_signal -d send_signal/send_signal_nmi* - runs send_signal
    test without nmi tests
    
    -a send_signal/send_signal_nmi*,find_vma - runs two send_signal
    subtests and find_vma test
    
    -a 'send_signal*' -a find_vma -d send_signal/send_signal_nmi* -
    runs 2 send_signal test and find_vma test. Disables two send_signal
    nmi subtests
    
    -t send_signal -t find_vma - runs two *send_signal* tests and one
    *find_vma* test
    
    This will allow us to have granular control over which subtests
    to disable in the CI system instead of disabling whole tests.
    
    Also, add new selftest to avoid possible regression when
    changing prog_test test name selection logic.
    
    Signed-off-by: Mykola Lysenko <mykolal@fb.com>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/20220409001750.529930-1-mykolal@fb.com

Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
2022-11-28 16:48:58 +02:00
Yauheni Kaliuta fc41a5a9a5 selftests/bpf: Fix issues in parse_num_list()
Bugzilla: https://bugzilla.redhat.com/2120968

commit 958ddfd75d83d83e713027677c8786781e1f4576
Author: Yuntao Wang <ytcoode@gmail.com>
Date:   Wed Apr 6 08:36:22 2022 +0800

    selftests/bpf: Fix issues in parse_num_list()
    
    The function does not check that parsing_end is false after parsing
    argument. Thus, if the final part of the argument is something like '4-',
    which is invalid, parse_num_list() will discard it instead of returning
    -EINVAL.
    
    Before:
    
     $ ./test_progs -n 2,4-
     #2 atomic_bounds:OK
     Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED
    
    After:
    
     $ ./test_progs -n 2,4-
     Failed to parse test numbers.
    
    Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/20220406003622.73539-1-ytcoode@gmail.com

Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
2022-11-28 16:48:57 +02:00
Artem Savkov b03d6ed8de selftests/bpf: Remove the only use of deprecated bpf_object__load_xattr()
Bugzilla: https://bugzilla.redhat.com/2069046

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

commit 3fc5fdcca144badbaf29b62aacbf7877f2f39a74
Author: Andrii Nakryiko <andrii@kernel.org>
Date:   Thu Dec 9 11:38:39 2021 -0800

    selftests/bpf: Remove the only use of deprecated bpf_object__load_xattr()

    Switch from bpf_object__load_xattr() to bpf_object__load() and
    kernel_log_level in bpf_object_open_opts.

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

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2022-08-24 12:53:46 +02:00
Artem Savkov 357dfc09dd libbpf: Change bpf_program__set_extra_flags to bpf_program__set_flags
Bugzilla: https://bugzilla.redhat.com/2069046

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

commit 8cccee9e91e19207671b94af40bacf7c1d2e74ef
Author: Florent Revest <revest@chromium.org>
Date:   Fri Nov 19 19:00:35 2021 +0100

    libbpf: Change bpf_program__set_extra_flags to bpf_program__set_flags

    bpf_program__set_extra_flags has just been introduced so we can still
    change it without breaking users.

    This new interface is a bit more flexible (for example if someone wants
    to clear a flag).

    Signed-off-by: Florent Revest <revest@chromium.org>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/20211119180035.1396139-1-revest@chromium.org

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2022-08-24 12:53:39 +02:00
Artem Savkov ef958d1f26 selftests/bpf: Fix bpf_prog_test_load() logic to pass extra log level
Bugzilla: https://bugzilla.redhat.com/2069046

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

commit 50dee7078b66d881c62f6177844d625f7ead6003
Author: Andrii Nakryiko <andrii@kernel.org>
Date:   Wed Nov 10 21:17:58 2021 -0800

    selftests/bpf: Fix bpf_prog_test_load() logic to pass extra log level

    After recent refactoring bpf_prog_test_load(), used across multiple
    selftests, lost ability to specify extra log_level 1 or 2 (for -vv and
    -vvv, respectively). Fix that problem by using bpf_object__load_xattr()
    API that supports extra log_level flags. Also restore
    BPF_F_TEST_RND_HI32 prog_flags by utilizing new bpf_program__set_extra_flags()
    API.

    Fixes: f87c1930ac29 ("selftests/bpf: Merge test_stub.c into testing_helpers.c")
    Reported-by: Alexei Starovoitov <ast@kernel.org>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>
    Link: https://lore.kernel.org/bpf/20211111051758.92283-3-andrii@kernel.org

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2022-08-24 12:53:35 +02:00
Artem Savkov 72ae0ff503 selftests/bpf: Merge test_stub.c into testing_helpers.c
Bugzilla: https://bugzilla.redhat.com/2069046

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

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

    selftests/bpf: Merge test_stub.c into testing_helpers.c

    Move testing prog and object load wrappers (bpf_prog_test_load and
    bpf_test_load_program) into testing_helpers.{c,h} and get rid of
    otherwise useless test_stub.c. Make testing_helpers.c available to
    non-test_progs binaries as well.

    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-11-andrii@kernel.org

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2022-08-24 12:53:33 +02:00
Andrii Nakryiko 90806ccc90 selftests/bpf: Add link detach tests for cgroup, netns, and xdp bpf_links
Add bpf_link__detach() testing to selftests for cgroup, netns, and xdp
bpf_links.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Song Liu <songliubraving@fb.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20200731182830.286260-4-andriin@fb.com
2020-08-01 20:38:28 -07:00
Andrii Nakryiko cd49291ce1 selftests/bpf: Extract parse_num_list into generic testing_helpers.c
Add testing_helpers.c, which will contain generic helpers for test runners and
tests needing some common generic functionality, like parsing a set of
numbers.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20200512192445.2351848-2-andriin@fb.com
2020-05-13 12:19:38 -07:00