Re: [PATCH v4 3/3] bpf: add selftest for lirc_mode2 type program
On Fri, May 18, 2018 at 1:17 PM, Y Song wrote: > On Fri, May 18, 2018 at 7:07 AM, Sean Young wrote: >> This is simple test over rc-loopback. >> >> Signed-off-by: Sean Young > > Acked-by: Yonghong Song Just one minor thing. You need to add "test_lirc_mode2_user" in tools/testing/selftests/bpf/.gitignore so it will not show up when you do "git status". If the patch needs respin, you can add this in the new revision. Otherwise, I think a followup patch to fix this should be fine. > >> --- >> tools/bpf/bpftool/prog.c | 1 + >> tools/include/uapi/linux/bpf.h| 53 - >> tools/include/uapi/linux/lirc.h | 217 ++ >> tools/lib/bpf/libbpf.c| 1 + >> tools/testing/selftests/bpf/Makefile | 8 +- >> tools/testing/selftests/bpf/bpf_helpers.h | 6 + >> .../testing/selftests/bpf/test_lirc_mode2.sh | 28 +++ >> .../selftests/bpf/test_lirc_mode2_kern.c | 23 ++ >> .../selftests/bpf/test_lirc_mode2_user.c | 154 + >> 9 files changed, 487 insertions(+), 4 deletions(-) >> create mode 100644 tools/include/uapi/linux/lirc.h >> create mode 100755 tools/testing/selftests/bpf/test_lirc_mode2.sh >> create mode 100644 tools/testing/selftests/bpf/test_lirc_mode2_kern.c >> create mode 100644 tools/testing/selftests/bpf/test_lirc_mode2_user.c >> >> diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c >> index 9bdfdf2d3fbe..07f1ace39a46 100644 >> --- a/tools/bpf/bpftool/prog.c >> +++ b/tools/bpf/bpftool/prog.c >> @@ -71,6 +71,7 @@ static const char * const prog_type_name[] = { >> [BPF_PROG_TYPE_SK_MSG] = "sk_msg", >> [BPF_PROG_TYPE_RAW_TRACEPOINT] = "raw_tracepoint", >> [BPF_PROG_TYPE_CGROUP_SOCK_ADDR] = "cgroup_sock_addr", >> + [BPF_PROG_TYPE_LIRC_MODE2] = "lirc_mode2", >> }; >> >> static void print_boot_time(__u64 nsecs, char *buf, unsigned int size) >> diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h >> index d94d333a8225..8227832b713e 100644 >> --- a/tools/include/uapi/linux/bpf.h >> +++ b/tools/include/uapi/linux/bpf.h >> @@ -141,6 +141,7 @@ enum bpf_prog_type { >> BPF_PROG_TYPE_SK_MSG, >> BPF_PROG_TYPE_RAW_TRACEPOINT, >> BPF_PROG_TYPE_CGROUP_SOCK_ADDR, >> + BPF_PROG_TYPE_LIRC_MODE2, >> }; >> >> enum bpf_attach_type { >> @@ -158,6 +159,7 @@ enum bpf_attach_type { >> BPF_CGROUP_INET6_CONNECT, >> BPF_CGROUP_INET4_POST_BIND, >> BPF_CGROUP_INET6_POST_BIND, >> + BPF_LIRC_MODE2, >> __MAX_BPF_ATTACH_TYPE >> }; >> >> @@ -1902,6 +1904,53 @@ union bpf_attr { >> * egress otherwise). This is the only flag supported for now. >> * Return >> * **SK_PASS** on success, or **SK_DROP** on error. >> + * >> + * int bpf_rc_keydown(void *ctx, u32 protocol, u64 scancode, u32 toggle) >> + * Description >> + * This helper is used in programs implementing IR decoding, to >> + * report a successfully decoded key press with *scancode*, >> + * *toggle* value in the given *protocol*. The scancode will be >> + * translated to a keycode using the rc keymap, and reported as >> + * an input key down event. After a period a key up event is >> + * generated. This period can be extended by calling either >> + * **bpf_rc_keydown** () with the same values, or calling >> + * **bpf_rc_repeat** (). >> + * >> + * Some protocols include a toggle bit, in case the button >> + * was released and pressed again between consecutive scancodes >> + * >> + * The *ctx* should point to the lirc sample as passed into >> + * the program. >> + * >> + * The *protocol* is the decoded protocol number (see >> + * **enum rc_proto** for some predefined values). >> + * >> + * This helper is only available is the kernel was compiled with >> + * the **CONFIG_BPF_LIRC_MODE2** configuration option set to >> + * "**y**". >> + * >> + * Return >> + * 0 >> + * >> + * int bpf_rc_repeat(void *ctx) >> + * Description >> + * This helper is used in programs implementing IR decoding, to >> + * report a successfully decoded repeat key message. This delays >> + * the generation of a key up event for previously generated >> + * key down event. >> + * >> + * Some IR protocols like NEC have a special IR message for >> + * repeating last button, for when a button is held down. >> + * >> + * The *ctx* should point to the lirc sample as passed into >> + * the program. >> + * >> + * This helper is only available is the kernel was compiled with >> + * the **CONFIG_BPF_LIRC_MODE2** configuration option set to >> + * "**y**". >> +
Re: [PATCH v4 3/3] bpf: add selftest for lirc_mode2 type program
On Fri, May 18, 2018 at 7:07 AM, Sean Young wrote: > This is simple test over rc-loopback. > > Signed-off-by: Sean Young Acked-by: Yonghong Song > --- > tools/bpf/bpftool/prog.c | 1 + > tools/include/uapi/linux/bpf.h| 53 - > tools/include/uapi/linux/lirc.h | 217 ++ > tools/lib/bpf/libbpf.c| 1 + > tools/testing/selftests/bpf/Makefile | 8 +- > tools/testing/selftests/bpf/bpf_helpers.h | 6 + > .../testing/selftests/bpf/test_lirc_mode2.sh | 28 +++ > .../selftests/bpf/test_lirc_mode2_kern.c | 23 ++ > .../selftests/bpf/test_lirc_mode2_user.c | 154 + > 9 files changed, 487 insertions(+), 4 deletions(-) > create mode 100644 tools/include/uapi/linux/lirc.h > create mode 100755 tools/testing/selftests/bpf/test_lirc_mode2.sh > create mode 100644 tools/testing/selftests/bpf/test_lirc_mode2_kern.c > create mode 100644 tools/testing/selftests/bpf/test_lirc_mode2_user.c > > diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c > index 9bdfdf2d3fbe..07f1ace39a46 100644 > --- a/tools/bpf/bpftool/prog.c > +++ b/tools/bpf/bpftool/prog.c > @@ -71,6 +71,7 @@ static const char * const prog_type_name[] = { > [BPF_PROG_TYPE_SK_MSG] = "sk_msg", > [BPF_PROG_TYPE_RAW_TRACEPOINT] = "raw_tracepoint", > [BPF_PROG_TYPE_CGROUP_SOCK_ADDR] = "cgroup_sock_addr", > + [BPF_PROG_TYPE_LIRC_MODE2] = "lirc_mode2", > }; > > static void print_boot_time(__u64 nsecs, char *buf, unsigned int size) > diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h > index d94d333a8225..8227832b713e 100644 > --- a/tools/include/uapi/linux/bpf.h > +++ b/tools/include/uapi/linux/bpf.h > @@ -141,6 +141,7 @@ enum bpf_prog_type { > BPF_PROG_TYPE_SK_MSG, > BPF_PROG_TYPE_RAW_TRACEPOINT, > BPF_PROG_TYPE_CGROUP_SOCK_ADDR, > + BPF_PROG_TYPE_LIRC_MODE2, > }; > > enum bpf_attach_type { > @@ -158,6 +159,7 @@ enum bpf_attach_type { > BPF_CGROUP_INET6_CONNECT, > BPF_CGROUP_INET4_POST_BIND, > BPF_CGROUP_INET6_POST_BIND, > + BPF_LIRC_MODE2, > __MAX_BPF_ATTACH_TYPE > }; > > @@ -1902,6 +1904,53 @@ union bpf_attr { > * egress otherwise). This is the only flag supported for now. > * Return > * **SK_PASS** on success, or **SK_DROP** on error. > + * > + * int bpf_rc_keydown(void *ctx, u32 protocol, u64 scancode, u32 toggle) > + * Description > + * This helper is used in programs implementing IR decoding, to > + * report a successfully decoded key press with *scancode*, > + * *toggle* value in the given *protocol*. The scancode will be > + * translated to a keycode using the rc keymap, and reported as > + * an input key down event. After a period a key up event is > + * generated. This period can be extended by calling either > + * **bpf_rc_keydown** () with the same values, or calling > + * **bpf_rc_repeat** (). > + * > + * Some protocols include a toggle bit, in case the button > + * was released and pressed again between consecutive scancodes > + * > + * The *ctx* should point to the lirc sample as passed into > + * the program. > + * > + * The *protocol* is the decoded protocol number (see > + * **enum rc_proto** for some predefined values). > + * > + * This helper is only available is the kernel was compiled with > + * the **CONFIG_BPF_LIRC_MODE2** configuration option set to > + * "**y**". > + * > + * Return > + * 0 > + * > + * int bpf_rc_repeat(void *ctx) > + * Description > + * This helper is used in programs implementing IR decoding, to > + * report a successfully decoded repeat key message. This delays > + * the generation of a key up event for previously generated > + * key down event. > + * > + * Some IR protocols like NEC have a special IR message for > + * repeating last button, for when a button is held down. > + * > + * The *ctx* should point to the lirc sample as passed into > + * the program. > + * > + * This helper is only available is the kernel was compiled with > + * the **CONFIG_BPF_LIRC_MODE2** configuration option set to > + * "**y**". > + * > + * Return > + * 0 > */ > #define __BPF_FUNC_MAPPER(FN) \ > FN(unspec), \ > @@ -1976,7 +2025,9 @@ union bpf_attr { > FN(fib_lookup), \ > FN(sock_hash_update), \ > FN(msg_redirect_hash), \ > - FN(sk_redirect_hash), > + FN(sk_redirect_hash), \ > + FN(rc_repeat), \ > + F
[PATCH v4 3/3] bpf: add selftest for lirc_mode2 type program
This is simple test over rc-loopback. Signed-off-by: Sean Young --- tools/bpf/bpftool/prog.c | 1 + tools/include/uapi/linux/bpf.h| 53 - tools/include/uapi/linux/lirc.h | 217 ++ tools/lib/bpf/libbpf.c| 1 + tools/testing/selftests/bpf/Makefile | 8 +- tools/testing/selftests/bpf/bpf_helpers.h | 6 + .../testing/selftests/bpf/test_lirc_mode2.sh | 28 +++ .../selftests/bpf/test_lirc_mode2_kern.c | 23 ++ .../selftests/bpf/test_lirc_mode2_user.c | 154 + 9 files changed, 487 insertions(+), 4 deletions(-) create mode 100644 tools/include/uapi/linux/lirc.h create mode 100755 tools/testing/selftests/bpf/test_lirc_mode2.sh create mode 100644 tools/testing/selftests/bpf/test_lirc_mode2_kern.c create mode 100644 tools/testing/selftests/bpf/test_lirc_mode2_user.c diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index 9bdfdf2d3fbe..07f1ace39a46 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c @@ -71,6 +71,7 @@ static const char * const prog_type_name[] = { [BPF_PROG_TYPE_SK_MSG] = "sk_msg", [BPF_PROG_TYPE_RAW_TRACEPOINT] = "raw_tracepoint", [BPF_PROG_TYPE_CGROUP_SOCK_ADDR] = "cgroup_sock_addr", + [BPF_PROG_TYPE_LIRC_MODE2] = "lirc_mode2", }; static void print_boot_time(__u64 nsecs, char *buf, unsigned int size) diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index d94d333a8225..8227832b713e 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -141,6 +141,7 @@ enum bpf_prog_type { BPF_PROG_TYPE_SK_MSG, BPF_PROG_TYPE_RAW_TRACEPOINT, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, + BPF_PROG_TYPE_LIRC_MODE2, }; enum bpf_attach_type { @@ -158,6 +159,7 @@ enum bpf_attach_type { BPF_CGROUP_INET6_CONNECT, BPF_CGROUP_INET4_POST_BIND, BPF_CGROUP_INET6_POST_BIND, + BPF_LIRC_MODE2, __MAX_BPF_ATTACH_TYPE }; @@ -1902,6 +1904,53 @@ union bpf_attr { * egress otherwise). This is the only flag supported for now. * Return * **SK_PASS** on success, or **SK_DROP** on error. + * + * int bpf_rc_keydown(void *ctx, u32 protocol, u64 scancode, u32 toggle) + * Description + * This helper is used in programs implementing IR decoding, to + * report a successfully decoded key press with *scancode*, + * *toggle* value in the given *protocol*. The scancode will be + * translated to a keycode using the rc keymap, and reported as + * an input key down event. After a period a key up event is + * generated. This period can be extended by calling either + * **bpf_rc_keydown** () with the same values, or calling + * **bpf_rc_repeat** (). + * + * Some protocols include a toggle bit, in case the button + * was released and pressed again between consecutive scancodes + * + * The *ctx* should point to the lirc sample as passed into + * the program. + * + * The *protocol* is the decoded protocol number (see + * **enum rc_proto** for some predefined values). + * + * This helper is only available is the kernel was compiled with + * the **CONFIG_BPF_LIRC_MODE2** configuration option set to + * "**y**". + * + * Return + * 0 + * + * int bpf_rc_repeat(void *ctx) + * Description + * This helper is used in programs implementing IR decoding, to + * report a successfully decoded repeat key message. This delays + * the generation of a key up event for previously generated + * key down event. + * + * Some IR protocols like NEC have a special IR message for + * repeating last button, for when a button is held down. + * + * The *ctx* should point to the lirc sample as passed into + * the program. + * + * This helper is only available is the kernel was compiled with + * the **CONFIG_BPF_LIRC_MODE2** configuration option set to + * "**y**". + * + * Return + * 0 */ #define __BPF_FUNC_MAPPER(FN) \ FN(unspec), \ @@ -1976,7 +2025,9 @@ union bpf_attr { FN(fib_lookup), \ FN(sock_hash_update), \ FN(msg_redirect_hash), \ - FN(sk_redirect_hash), + FN(sk_redirect_hash), \ + FN(rc_repeat), \ + FN(rc_keydown), /* integer value in 'imm' field of BPF_CALL instruction selects which helper * function eBPF program intends to call diff --git a/tools/include/uapi/linux/lirc.h b/tools/include/uapi/linux/lirc.h new file mode 100644 index ..f189931042a7 --- /dev/null +++ b/tools/i