selftests/bpf: convert lirc_mode2 to prog_tests and extend coverage
Subsystems (3)
PATCH v3 1/1 selftests/bpf: convert lirc_mode2 to prog_tests and extend coverage
While porting, extend coverage of the BPF_LIRC_MODE2 attach/detach/ query API:
- bpf_prog_attach() with invalid flags is rejected with -EINVAL and does not attach the program
- bpf_prog_query() with invalid flags is rejected with -EINVAL without disturbing existing attachments
- bpf_prog_query() reports the correct program id, not just count, at each step, via bpf_prog_get_info_by_fd()
- a lirc chardev can hold more than one attached program: load a second, independent instance, attach it alongside the first, confirm both are reported by bpf_prog_query(), then detach it without disturbing the first program's attachment
- detaching an already-detached program consistently fails with -ENOENT, for both the first and second program
---
Since v2:
- Fix compilation bug - I sent the wrong version
Since v1:
- Remove obsolete test_lirc_mode2_user.c file
- Use SYS_NOFAIL() rather than system()
- Fix comment formatting
- Fix leaks in error paths
tools/testing/selftests/bpf/.gitignore | 1 - tools/testing/selftests/bpf/Makefile | 3 - .../selftests/bpf/prog_tests/lirc_mode2.c | 334 ++++++++++++++++++ .../testing/selftests/bpf/progs/lirc_mode2.c | 32 ++ .../bpf/progs/test_lirc_mode2_kern.c | 26 -- .../testing/selftests/bpf/test_lirc_mode2.sh | 41 --- .../selftests/bpf/test_lirc_mode2_user.c | 177 ---------- 7 files changed, 366 insertions(+), 248 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/lirc_mode2.c create mode 100644 tools/testing/selftests/bpf/progs/lirc_mode2.c delete mode 100644 tools/testing/selftests/bpf/progs/test_lirc_mode2_kern.c delete mode 100755 tools/testing/selftests/bpf/test_lirc_mode2.sh delete mode 100644 tools/testing/selftests/bpf/test_lirc_mode2_user.c
tools/testing/selftests/bpf/.gitignore +0 -1
@@ -17,7 +17,6 @@ test_verifier_log feature urandom_read test_sockmap -test_lirc_mode2_user flow_dissector_load test_tcpnotify_user test_libbpf
tools/testing/selftests/bpf/Makefile +0 -3
@@ -123,7 +123,6 @@ TEST_FILES = xsk_prereqs.sh $(wildcard progs/btf_dump_test_case_*.c) # Order correspond to 'make run_tests' order TEST_PROGS := test_kmod.sh \ - test_lirc_mode2.sh \ test_bpftool_build.sh \ test_doc_build.sh \ test_xsk.sh \
@@ -141,7 +140,6 @@ TEST_GEN_PROGS_EXTENDED = \ bench \ flow_dissector_load \ test_cpp \ - test_lirc_mode2_user \ veristat \ xdp_features \ xdp_hw_metadata \
@@ -338,7 +336,6 @@ $(OUTPUT)/test_sockmap: $(CGROUP_HELPERS) $(TESTING_HELPERS) $(OUTPUT)/test_tcpnotify_user: $(CGROUP_HELPERS) $(TESTING_HELPERS) $(TRACE_HELPERS) $(OUTPUT)/test_sock_fields: $(CGROUP_HELPERS) $(TESTING_HELPERS) $(OUTPUT)/test_tag: $(TESTING_HELPERS) -$(OUTPUT)/test_lirc_mode2_user: $(TESTING_HELPERS) $(OUTPUT)/flow_dissector_load: $(TESTING_HELPERS) $(OUTPUT)/test_maps: $(TESTING_HELPERS) $(OUTPUT)/test_verifier: $(TESTING_HELPERS) $(CAP_HELPERS) $(UNPRIV_HELPERS)
tools/testing/selftests/bpf/prog_tests/lirc_mode2.c new file +334 -0
334 lines not on this page · raw message
tools/testing/selftests/bpf/progs/lirc_mode2.c new file +32 -0
@@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 +// test ir decoder +// +// Copyright (C) 2018 Sean Young <[email protected]> + +#include <linux/bpf.h> +#include <linux/lirc.h> +#include <bpf/bpf_helpers.h> + +SEC("lirc_mode2") +int bpf_decoder (unsigned int *sample) +{ +if (LIRC_IS_PULSE (*sample)) { +unsigned int duration =LIRC_VALUE (*sample); + +/* +* Flag bits picked deliberately low: rc-loopback simulates +* a receiver overflow for any pulse over MS_TO_US(50) (see +* loop_tx_ir() in rc-loopback.c), which would silently +* swallow the sample before it ever reaches this decoder. +*/ +if (duration &0x8000 ) +bpf_rc_keydown (sample,0x40 , duration &0x3fff ,0 ); +if (duration &0x4000 ) +bpf_rc_pointer_rel (sample, (duration >>7 ) &0x7f , + duration &0x7f ); + } + +return 0 ; +} + +char _license[] SEC("license") = "GPL";
tools/testing/selftests/bpf/progs/test_lirc_mode2_kern.c deleted +0 -26
@@ -1,26 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -// test ir decoder -// -// Copyright (C) 2018 Sean Young <[email protected]> - -#include <linux/bpf.h> -#include <linux/lirc.h> -#include <bpf/bpf_helpers.h> - -SEC("lirc_mode2") -int bpf_decoder (unsigned int *sample) -{ -if (LIRC_IS_PULSE (*sample)) { -unsigned int duration =LIRC_VALUE (*sample); - -if (duration &0x1000 ) -bpf_rc_keydown (sample,0x40 , duration &0xffff ,0 ); -if (duration &0x2000 ) -bpf_rc_pointer_rel (sample, (duration >>8 ) &0xff , - duration &0xff ); - } - -return 0 ; -} - -char _license[] SEC("license") = "GPL";
tools/testing/selftests/bpf/test_lirc_mode2.sh deleted +0 -41
41 lines not on this page · raw message
tools/testing/selftests/bpf/test_lirc_mode2_user.c deleted +0 -177
177 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Multi-line comments use C++ style `//` instead of the mandated kernel `/* ... */` format. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Multi-line comments use C++ style // instead of the mandated kernel /* ... */ format. --
--- Patch [1]: [PATCH v3] selftests/bpf: convert lirc_mode2 to prog_tests and extend coverage --- commit 5795d2e92debc935e217deb800d55dcb81234f7f
Author: Sean Young <[email protected]>
selftests/bpf: convert lirc_mode2 to prog_tests and extend coverage
This commit ports the lirc_mode2 test to the prog_tests framework and extends coverage of the BPF_LIRC_MODE2 attach/detach/query APIs. It also removes the obsolete user and kernel test files alongside the shell script.
Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/lirc_mode2.c new file +1
-0@@ -0,0 +1,334 @@ +// SPDX-License-Identifier: GPL-2.0
tools/testing/selftests/bpf/prog_tests/lirc_mode2.c line 11
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/lirc_mode2.c new file +10
-0+// test ir decoder +// +// Copyright (C) 2018 Sean Young <[email protected]> + +// A lirc chardev is a device representing a consumer IR (cir) device which +// can receive infrared signals from remote control and/or transmit IR. +// +// IR is sent as a series of pulses and space somewhat like morse code. The +// BPF program can decode this into scancodes so that rc-core can translate +// this into input key codes using the rc keymap.
[Severity: Low]
This isn't a bug, but does this violate the BPF subsystem comment style? Multi-line comments under the BPF subsystem generally require the standard kernel C-style block comment format, with the opening /* on its own line.
Should these be converted to the /* ... */ format?
[ ... ]
tools/testing/selftests/bpf/progs/lirc_mode2.c line 4
Quoted 10 lines
tools/testing/selftests/bpf/progs/lirc_mode2.c new file +4
-0@@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 +// test ir decoder +// +// Copyright (C) 2018 Sean Young <[email protected]>
[Severity: Low]
This isn't a bug, but this file header also uses the C++ style multi-line comments instead of the preferred kernel block comment format.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewThis isn't a bug, but now that find_loopback_devices() discovers the nodes itself, should the ir-keytable(1) sentence be reworded (or dropped) so the header does not describe a manual step that no…
Quoted 12 lines
tools/testing/selftests/bpf/.gitignore +0
-1@@ -17,7 +17,6 @@ test_verifier_log feature urandom_read test_sockmap -test_lirc_mode2_user flow_dissector_load test_tcpnotify_user test_libbpf
[ ... ]
Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/lirc_mode2.c new file +0
-0@@ -0,0 +1,334 @@
[ ... ]
tools/testing/selftests/bpf/prog_tests/lirc_mode2.c line 15
Quoted 3 lines
tools/testing/selftests/bpf/prog_tests/lirc_mode2.c new file +3
-0+// This test works by sending IR over rc-loopback, so the IR is processed by +// BPF and then decoded into scancodes. The lirc chardev must be the one +// associated with rc-loopback, see the output of ir-keytable(1).
This isn't a bug, but now that find_loopback_devices() discovers the nodes itself, should the ir-keytable(1) sentence be reworded (or dropped) so the header does not describe a manual step that no longer exists?
tools/testing/selftests/bpf/prog_tests/lirc_mode2.c line 24
Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/lirc_mode2.c new file +9
-0+// +// The following CONFIG options must be enabled for the test to succeed: +// CONFIG_RC_CORE=y +// CONFIG_BPF_LIRC_MODE2=y +// CONFIG_RC_LOOPBACK=y +// CONFIG_LIRC=y + +#include <linux/input.h> +#include <linux/lirc.h>
This isn't a bug, but is <linux/lirc.h> still needed in prog_tests/lirc_mode2.c, or can it be dropped now that the raw-IR values are written as plain ints?
Quoted 14 lines
tools/testing/selftests/bpf/prog_tests/lirc_mode2.c new file +14
-0+#include <glob.h> +#include <limits.h> +#include <poll.h> +#include <test_progs.h> +#include "lirc_mode2.skel.h" + +/* +* Read the DEVNAME= line out of the first uevent file that matches +* pattern, and turn it into a /dev/<name> path. +*/ +static bool find_devname (const char *pattern,char *path,size_t path_sz) +{ +glob_t gl = {}; +bool found = false;
tools/testing/selftests/bpf/prog_tests/lirc_mode2.c line 48
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/lirc_mode2.c new file +10
-0+FILE *f; + +if (glob (pattern,0 ,NULL , &gl) || gl.gl_pathc ==0 ) + goto out; + + f =fopen (gl.gl_pathv[0 ],"r" ); +if (!f) + goto out; + +char line[256 ];
This isn't a bug, but could char line[256] move up with the other locals at the top of find_devname(), to match the rest of the function?
Quoted 19 lines
tools/testing/selftests/bpf/prog_tests/lirc_mode2.c new file +19
-0+ +while (fgets (line,sizeof (line), f)) { +char *val; + +if (strncmp (line,"DEVNAME=" ,8 )) +continue ; + + val = line +8 ; + val[strcspn (val,"\n" )] ='\0' ; +snprintf (path, path_sz,"/dev/%s" , val); + found = true; +break ; + } + +fclose (f); +out: +globfree (&gl); +return found; +}
[ ... ]
Quoted 8 lines
commit
13acc020a68a79fa42ce134695e01654e17c1edf
Author: Sean Young <[email protected]>selftests/bpf: convert
lirc_mode2toprog_testsand extend coverageWhile porting, extend coverage of the
BPF_LIRC_MODE2attach/detach/ query API:
Quoted 12 lines
-
bpf_prog_attach()with invalid flags is rejected with-EINVALand does not attach the program
-bpf_prog_query()with invalid flags is rejected with-EINVALwithout disturbing existing attachments
-bpf_prog_query()reports the correct program id, not just count, at each step, viabpf_prog_get_info_by_fd()
- a lirc chardev can hold more than one attached program: load a second, independent instance, attach it alongside the first, confirm both are reported bybpf_prog_query(), then detach it without disturbing the first program's attachment
- detaching an already-detached program consistently fails with-ENOENT, for both the first and second program
This isn't a bug, but could the changelog open with why the test is being moved under test_progs, before listing the extra coverage that was added while porting?
The changelog body starts at the secondary half of the change and enumerates the new assertions, but never states the primary change or its motivation. The conversion itself - deleting test_lirc_mode2.sh plus test_lirc_mode2_user.c and the standalone TEST_PROGS/ TEST_GEN_PROGS_EXTENDED wiring, and re-adding the test as a prog_tests entry with a skeleton - is what most of the diff does, and a reader learns only what was added on top of it, not why running under test_progs is preferable (single runner, DENYLIST/CI integration, no separate binary to install).
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/32422213902
This patch was applied to bpf/bpf-next.git (master) by Kumar Kartikeya Dwivedi <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Kumar Kartikeya Dwivedi <[email protected]>:
Quoted 16 lines · On Thu, 20 Aug 2026 22:43:29 +0100 you wrote:
While porting, extend coverage of the
BPF_LIRC_MODE2attach/detach/ query API:-
bpf_prog_attach()with invalid flags is rejected with-EINVALand does not attach the program
-bpf_prog_query()with invalid flags is rejected with-EINVALwithout disturbing existing attachments
-bpf_prog_query()reports the correct program id, not just count, at each step, viabpf_prog_get_info_by_fd()
- a lirc chardev can hold more than one attached program: load a second, independent instance, attach it alongside the first, confirm both are reported bybpf_prog_query(), then detach it without disturbing the first program's attachment
- detaching an already-detached program consistently fails with-ENOENT, for both the first and second program
Quoted 1 line
[...]
Here is the summary with links:
- [v3] selftests/bpf: convert lirc_mode2 to prog_tests and extend coverage
https://git.kernel.org/bpf/bpf-next/c/d761934c9483
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html