Hi all,
This is part of a hackathon organized by LKCAMP [1], focused on writing
tests using KUnit. We reached out a while ago asking for advice on what would
be a useful contribution [2] and ended up choosing data structures that did
not yet have tests.
This patch series depends on the patch that moves the KUnit tests on lib/
into lib/tests/ [3].
This patch adds tests for the kfifo data structure, defined in
include/linux/kfifo.h, and is inspired by the KUnit tests for the doubly
linked list in lib/tests/list-test.c (previously at lib/list-test.c) [4].
[1] https://lkcamp.dev/about/
[2] https://lore.kernel.org/all/Zktnt7rjKryTh9-N@arch/
[3] https://lore.kernel.org/all/20240720181025.work.002-kees@kernel.org/
[4] https://elixir.bootlin.com/linux/latest/source/lib/list-test.c
---
Changes in v2:
- Add MODULE_DESCRIPTION()
- Move the tests from lib/kfifo-test.c to lib/tests/kfifo_kunit.c
Diego Vieira (1):
lib/tests/kfifo_kunit.c: add tests for the kfifo structure
lib/Kconfig.debug | 14 +++
lib/tests/Makefile | 1 +
lib/tests/kfifo_kunit.c | 224 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 239 insertions(+)
create mode 100644 lib/tests/kfifo_kunit.c
--
2.34.1
The BPF testing framework has evolved significantly over time. However,
some legacy tests in the samples/bpf directory have not kept up with
these changes. These outdated tests can cause confusion and increase
maintenance efforts.
This patchset focuses on migrating outdated cgroup and tracing-related
tests from samples/bpf to selftests/bpf, ensuring the BPF test suite
remains current and efficient. Tests that are already covered by
selftests/bpf are removed, while those not yet covered are migrated.
This includes cgroup sock create tests for setting socket attributes
and blocking socket creation, as well as the removal of redundant
cgroup and tracing tests that have been replaced by newer tests.
This patchset covers the following cgroup/tracing tests:
- test_overhead: tests the overhead of BPF programs with task_rename,
now covered by selftests and benchmark tests (rename-*). [1]
- test_override_return: tests the return override functionality, now
handled by kprobe_multi_override in selftests.
- test_probe_write_user: tests the probe_write_user functionality,
now replaced by the probe_user test in selftests.
- test_cgrp2_sock: tests cgroup BPF's ability to set sk_bound_dev_if,
mark, and priority during socket creation. Migrated to selftests as
'sock_create' since no existing tests fully cover this.
- test_cgrp2_sock2: tests blocking socket creation for specific types
(AF_INET{6}, SOCK_DGRAM, IPPROTO_ICMP{V6}). Migrated to selftests
in 'sock_create' test for coverage.
- test_current_task_under_cgroup: tests bpf_current_task_under_cgroup()
to check if a task belongs to a cgroup. Already covered by
task_under_cgroup at selftest and other cgroup ID tests.
- test_cgrp2_tc: tests bpf_skb_under_cgroup() to filter packets based
on cgroup. This behavior is now validated by cgroup_skb_sk_lookup,
which uses bpf_skb_cgroup_id, making this test redundant.
[1]: https://patchwork.kernel.org/cover/13759916
Daniel T. Lee (4):
selftests/bpf: migrate cgroup sock create test for setting
iface/mark/prio
selftests/bpf: migrate cgroup sock create tests for prohibitig sockets
samples/bpf: remove obsolete cgroup related tests
samples/bpf: remove obsolete tracing related tests
---
Changes in v2:
- commit message fix
samples/bpf/Makefile | 24 --
samples/bpf/sock_flags.bpf.c | 47 ---
samples/bpf/test_cgrp2_array_pin.c | 106 ------
samples/bpf/test_cgrp2_attach.c | 177 ----------
samples/bpf/test_cgrp2_sock.c | 296 ----------------
samples/bpf/test_cgrp2_sock.sh | 137 -------
samples/bpf/test_cgrp2_sock2.c | 95 -----
samples/bpf/test_cgrp2_sock2.sh | 103 ------
samples/bpf/test_cgrp2_tc.bpf.c | 56 ---
samples/bpf/test_cgrp2_tc.sh | 187 ----------
.../bpf/test_current_task_under_cgroup.bpf.c | 43 ---
.../bpf/test_current_task_under_cgroup_user.c | 115 ------
samples/bpf/test_overhead_kprobe.bpf.c | 41 ---
samples/bpf/test_overhead_raw_tp.bpf.c | 17 -
samples/bpf/test_overhead_tp.bpf.c | 23 --
samples/bpf/test_overhead_user.c | 225 ------------
samples/bpf/test_override_return.sh | 16 -
samples/bpf/test_probe_write_user.bpf.c | 52 ---
samples/bpf/test_probe_write_user_user.c | 108 ------
samples/bpf/tracex7.bpf.c | 15 -
samples/bpf/tracex7_user.c | 56 ---
.../selftests/bpf/prog_tests/sock_create.c | 333 ++++++++++++++++++
22 files changed, 333 insertions(+), 1939 deletions(-)
delete mode 100644 samples/bpf/sock_flags.bpf.c
delete mode 100644 samples/bpf/test_cgrp2_array_pin.c
delete mode 100644 samples/bpf/test_cgrp2_attach.c
delete mode 100644 samples/bpf/test_cgrp2_sock.c
delete mode 100755 samples/bpf/test_cgrp2_sock.sh
delete mode 100644 samples/bpf/test_cgrp2_sock2.c
delete mode 100755 samples/bpf/test_cgrp2_sock2.sh
delete mode 100644 samples/bpf/test_cgrp2_tc.bpf.c
delete mode 100755 samples/bpf/test_cgrp2_tc.sh
delete mode 100644 samples/bpf/test_current_task_under_cgroup.bpf.c
delete mode 100644 samples/bpf/test_current_task_under_cgroup_user.c
delete mode 100644 samples/bpf/test_overhead_kprobe.bpf.c
delete mode 100644 samples/bpf/test_overhead_raw_tp.bpf.c
delete mode 100644 samples/bpf/test_overhead_tp.bpf.c
delete mode 100644 samples/bpf/test_overhead_user.c
delete mode 100755 samples/bpf/test_override_return.sh
delete mode 100644 samples/bpf/test_probe_write_user.bpf.c
delete mode 100644 samples/bpf/test_probe_write_user_user.c
delete mode 100644 samples/bpf/tracex7.bpf.c
delete mode 100644 samples/bpf/tracex7_user.c
create mode 100644 tools/testing/selftests/bpf/prog_tests/sock_create.c
--
2.43.0
The BPF testing framework has evolved significantly over time. However,
some legacy tests in the samples/bpf directory have not kept up with
these changes. These outdated tests can cause confusion and increase
maintenance efforts.
This patchset focuses on migrating outdated cgroup and tracing-related
tests from samples/bpf to selftests/bpf, ensuring the BPF test suite
remains current and efficient. Tests that are already covered by
selftests/bpf are removed, while those not yet covered are migrated.
This includes cgroup sock create tests for setting socket attributes
and blocking socket creation, as well as the removal of redundant
cgroup and tracing tests that have been replaced by newer tests.
This patchset covers the following cgroup/tracing tests:
- test_overhead: tests the overhead of BPF programs with task_rename,
now covered by selftests and benchmark tests (rename-*). [1]
- test_override_return: tests the return override functionality, now
handled by kprobe_multi_override in selftests.
- test_probe_write_user: tests the probe_write_user functionality,
now replaced by the probe_user test in selftests.
- test_cgrp2_sock: tests cgroup BPF's ability to set sk_bound_dev_if,
mark, and priority during socket creation. Migrated to selftests as
'sock_create' since no existing tests fully cover this.
- test_cgrp2_sock2: tests blocking socket creation for specific types
(AF_INET{6}, SOCK_DGRAM, IPPROTO_ICMP{V6}). Migrated to selftests
in 'sock_create' test for coverage.
- test_current_task_under_cgroup: tests bpf_current_task_under_cgroup()
to check if a task belongs to a cgroup. Already covered by
task_under_cgroup at selftest and other cgroup ID tests.
- test_cgrp2_tc: tests bpf_skb_under_cgroup() to filter packets based
on cgroup. This behavior is now validated by cgroup_skb_sk_lookup,
which uses bpf_skb_cgroup_id, making this test redundant.
Daniel T. Lee (4):
selftests/bpf: migrate cgroup sock create test for setting
iface/mark/prio
selftests/bpf: migrate sock create tests for prohibitig sockets
samples/bpf: remove obsolete cgroup related tests
samples/bpf: remove obsolete tracing related tests
samples/bpf/Makefile | 24 --
samples/bpf/sock_flags.bpf.c | 47 ---
samples/bpf/test_cgrp2_array_pin.c | 106 ------
samples/bpf/test_cgrp2_attach.c | 177 ----------
samples/bpf/test_cgrp2_sock.c | 296 ----------------
samples/bpf/test_cgrp2_sock.sh | 137 -------
samples/bpf/test_cgrp2_sock2.c | 95 -----
samples/bpf/test_cgrp2_sock2.sh | 103 ------
samples/bpf/test_cgrp2_tc.bpf.c | 56 ---
samples/bpf/test_cgrp2_tc.sh | 187 ----------
.../bpf/test_current_task_under_cgroup.bpf.c | 43 ---
.../bpf/test_current_task_under_cgroup_user.c | 115 ------
samples/bpf/test_overhead_kprobe.bpf.c | 41 ---
samples/bpf/test_overhead_raw_tp.bpf.c | 17 -
samples/bpf/test_overhead_tp.bpf.c | 23 --
samples/bpf/test_overhead_user.c | 225 ------------
samples/bpf/test_override_return.sh | 16 -
samples/bpf/test_probe_write_user.bpf.c | 52 ---
samples/bpf/test_probe_write_user_user.c | 108 ------
samples/bpf/tracex7.bpf.c | 15 -
samples/bpf/tracex7_user.c | 56 ---
.../selftests/bpf/prog_tests/sock_create.c | 333 ++++++++++++++++++
22 files changed, 333 insertions(+), 1939 deletions(-)
delete mode 100644 samples/bpf/sock_flags.bpf.c
delete mode 100644 samples/bpf/test_cgrp2_array_pin.c
delete mode 100644 samples/bpf/test_cgrp2_attach.c
delete mode 100644 samples/bpf/test_cgrp2_sock.c
delete mode 100755 samples/bpf/test_cgrp2_sock.sh
delete mode 100644 samples/bpf/test_cgrp2_sock2.c
delete mode 100755 samples/bpf/test_cgrp2_sock2.sh
delete mode 100644 samples/bpf/test_cgrp2_tc.bpf.c
delete mode 100755 samples/bpf/test_cgrp2_tc.sh
delete mode 100644 samples/bpf/test_current_task_under_cgroup.bpf.c
delete mode 100644 samples/bpf/test_current_task_under_cgroup_user.c
delete mode 100644 samples/bpf/test_overhead_kprobe.bpf.c
delete mode 100644 samples/bpf/test_overhead_raw_tp.bpf.c
delete mode 100644 samples/bpf/test_overhead_tp.bpf.c
delete mode 100644 samples/bpf/test_overhead_user.c
delete mode 100755 samples/bpf/test_override_return.sh
delete mode 100644 samples/bpf/test_probe_write_user.bpf.c
delete mode 100644 samples/bpf/test_probe_write_user_user.c
delete mode 100644 samples/bpf/tracex7.bpf.c
delete mode 100644 samples/bpf/tracex7_user.c
create mode 100644 tools/testing/selftests/bpf/prog_tests/sock_create.c
--
2.43.0
Linking of urandom_read and liburandom_read.so prefers LLVM's 'ld.lld' but
falls back to using 'ld' if unsupported. However, this fallback discards
any existing makefile macro for LD and can break cross-compilation.
Fix by changing the fallback to use the target linker $(LD), passed via
'-fuse-ld=' using an absolute path rather than a linker "flavour".
Fixes: 08c79c9cd67f ("selftests/bpf: Don't force lld on non-x86 architectures")
Signed-off-by: Tony Ambardar <tony.ambardar(a)gmail.com>
---
tools/testing/selftests/bpf/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 5e366f2fc02a..f2a0f912e038 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -263,7 +263,7 @@ $(OUTPUT)/%:%.c
ifeq ($(SRCARCH),$(filter $(SRCARCH),x86 riscv))
LLD := lld
else
-LLD := ld
+LLD := $(shell command -v $(LD))
endif
# Filter out -static for liburandom_read.so and its dependent targets so that static builds
--
2.34.1