selftests/bpf: support custom per-test flags and multiple expected messages
Subsystems (3)
Eduard Zingerman
maintainercover selftests/bpf: support custom per-test flags and multiple expected messages
This patch allows to specify program flags and multiple verifier log messages for the test_loader kind of tests. For example:
tools/testing/selftets/bpf/progs/foobar.c:
SEC("tc")
__success __log_level(7)
__msg("first message")
__msg("next message")
__flag(BPF_F_ANY_ALIGNMENT)
int buz(struct __sk_buff *skb)
{ ... }It was developed by Andrii Nakryiko ([1]), I reused it in a "test_verifier tests migration to inline assembly" patch series ([2]), but the series is currently stuck on my side.
Andrii asked to spin this particular patch separately ([3]).
[1] https://lore.kernel.org/bpf/CAEf4BzZH0ZxorCi7nPDbRqSK9f+410RooNwNJGwfw8=0a5i1nw@mail.gmail.com/
[2] https://lore.kernel.org/bpf/[email protected]/
[3] https://lore.kernel.org/bpf/[email protected]/T/#m52e806c5a679a2aa8f484d011be7ec105939127a
Andrii Nakryiko (1):
selftests/bpf: support custom per-test flags and multiple expected
messages
tools/testing/selftests/bpf/progs/bpf_misc.h | 23 +++++++ tools/testing/selftests/bpf/test_loader.c | 69 +++++++++++++++++--- tools/testing/selftests/bpf/test_progs.h | 1 + 3 files changed, 84 insertions(+), 9 deletions(-)
Signature · 1 line
2.39.1
Eduard Zingerman
maintainerPATCH 1/1 selftests/bpf: support custom per-test flags and multiple expected messages
From: Andrii Nakryiko <[email protected]>
Extend __flag attribute by allowing to specify one of the following:
* BPF_F_STRICT_ALIGNMENT
* BPF_F_ANY_ALIGNMENT
* BPF_F_TEST_RND_HI32
* BPF_F_TEST_STATE_FREQ
* BPF_F_SLEEPABLE
* BPF_F_XDP_HAS_FRAGS
* Some numeric value
Extend __msg attribute by allowing to specify multiple exepcted messages. All messages are expected to be present in the verifier log in the order of application.
--- tools/testing/selftests/bpf/progs/bpf_misc.h | 23 +++++++ tools/testing/selftests/bpf/test_loader.c | 69 +++++++++++++++++--- tools/testing/selftests/bpf/test_progs.h | 1 + 3 files changed, 84 insertions(+), 9 deletions(-)
tools/testing/selftests/bpf/progs/bpf_misc.h +23 -0
@@ -2,10 +2,33 @@#ifndef __BPF_MISC_H__#define __BPF_MISC_H__ +/* This set of attributes controls behavior of the +* test_loader.c:test_loader__run_subtests(). +* +* __msg Message expected to be found in the verifier log. +* Multiple __msg attributes could be specified. +* +* __success Expect program load success in privileged mode. +* +* __failure Expect program load failure in privileged mode. +* +* __log_level Log level to use for the program, numeric value expected. +* +* __flag Adds one flag use for the program, the following values are valid: +* - BPF_F_STRICT_ALIGNMENT; +* - BPF_F_TEST_RND_HI32; +* - BPF_F_TEST_STATE_FREQ; +* - BPF_F_SLEEPABLE; +* - BPF_F_XDP_HAS_FRAGS; +* - A numeric value. +* Multiple __flag attributes could be specified, the final flags +* value is derived by applying binary "or" to all specified values. +*/ #define __msg (msg) __attribute__((btf_decl_tag("comment:test_expect_msg=" msg)))#define __failure __attribute__((btf_decl_tag("comment:test_expect_failure")))#define __success __attribute__((btf_decl_tag("comment:test_expect_success")))#define __log_level (lvl) __attribute__((btf_decl_tag("comment:test_log_level="#lvl))) +#define __flag (flag) __attribute__((btf_decl_tag("comment:test_prog_flags="#flag)))/* Convenience macro for use with 'asm volatile' blocks */ #define __naked __attribute__((naked))
tools/testing/selftests/bpf/test_loader.c +60 -9
124 lines not on this page · raw message
tools/testing/selftests/bpf/test_progs.h +1 -0
@@ -427,6 +427,7 @@ int get_bpf_max_tramp_links(void);struct test_loader {char *log_buf;size_t log_buf_sz; +size_t next_match_pos;struct bpf_object *obj; };
Signature · 1 line
2.39.1
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Quoted 13 lines · On Wed, 1 Mar 2023 19:54:16 +0200 you wrote:
This patch allows to specify program flags and multiple verifier log messages for the
test_loaderkind of tests. For example:
tools/testing/selftets/bpf/progs/foobar.c:SEC("tc") __success __log_level(7) __msg("first message") __msg("next message") __flag(BPF_F_ANY_ALIGNMENT) int buz(struct __sk_buff *skb) { ... }
Quoted 1 line
[...]
Here is the summary with links:
- [bpf-next,1/1] selftests/bpf: support custom per-test flags and multiple expected messages
https://git.kernel.org/bpf/bpf-next/c/35cbf7f91568
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html